OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
7 | 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/values.h" | 10 #include "base/values.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
12 #include "chrome/common/extensions/features/feature.h" | 13 #include "chrome/common/extensions/features/feature.h" |
13 #include "chrome/common/extensions/manifest.h" | 14 #include "chrome/common/extensions/manifest.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 class ExtensionManifestTest : public testing::Test { | 17 class ExtensionManifestTest : public testing::Test { |
17 public: | 18 public: |
18 ExtensionManifestTest(); | 19 ExtensionManifestTest(); |
19 | 20 |
20 protected: | 21 protected: |
21 virtual void TearDown() OVERRIDE; | 22 virtual void TearDown() OVERRIDE; |
22 | 23 |
23 // If filename is a relative path, LoadManifestFile will treat it relative to | |
24 // the appropriate test directory. | |
25 static DictionaryValue* LoadManifestFile(const std::string& filename, | |
26 std::string* error); | |
27 | |
28 // Helper class that simplifies creating methods that take either a filename | 24 // Helper class that simplifies creating methods that take either a filename |
29 // to a manifest or the manifest itself. | 25 // to a manifest or the manifest itself. |
30 class Manifest { | 26 class Manifest { |
31 public: | 27 public: |
32 explicit Manifest(const char* name); | 28 explicit Manifest(const char* name); |
33 Manifest(DictionaryValue* manifest, const char* name); | 29 Manifest(DictionaryValue* manifest, const char* name); |
34 // C++98 requires the copy constructor for a type to be visible if you | 30 // C++98 requires the copy constructor for a type to be visible if you |
35 // take a const-ref of a temporary for that type. Since Manifest | 31 // take a const-ref of a temporary for that type. Since Manifest |
36 // contains a scoped_ptr, its implicit copy constructor is declared | 32 // contains a scoped_ptr, its implicit copy constructor is declared |
37 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first | 33 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first |
38 // requirement and thus you cannot use it with LoadAndExpectError() or | 34 // requirement and thus you cannot use it with LoadAndExpectError() or |
39 // LoadAndExpectSuccess() easily. | 35 // LoadAndExpectSuccess() easily. |
40 // | 36 // |
41 // To get around this spec pedantry, we declare the copy constructor | 37 // To get around this spec pedantry, we declare the copy constructor |
42 // explicitly. It will never get invoked. | 38 // explicitly. It will never get invoked. |
43 Manifest(const Manifest& m); | 39 Manifest(const Manifest& m); |
44 | 40 |
45 ~Manifest(); | 41 ~Manifest(); |
46 | 42 |
47 const std::string& name() const { return name_; }; | 43 const std::string& name() const { return name_; }; |
48 | 44 |
49 DictionaryValue* GetManifest(std::string* error) const; | 45 DictionaryValue* GetManifest(char const* test_data_dir, |
| 46 std::string* error) const; |
50 | 47 |
51 private: | 48 private: |
52 const std::string name_; | 49 const std::string name_; |
53 mutable DictionaryValue* manifest_; | 50 mutable DictionaryValue* manifest_; |
54 mutable scoped_ptr<DictionaryValue> manifest_holder_; | 51 mutable scoped_ptr<DictionaryValue> manifest_holder_; |
55 }; | 52 }; |
56 | 53 |
| 54 // The subdirectory in which to find test data files. |
| 55 virtual char const* test_data_dir(); |
| 56 |
| 57 scoped_ptr<DictionaryValue> LoadManifest( |
| 58 char const* manifest_name, |
| 59 std::string* error); |
| 60 |
57 scoped_refptr<extensions::Extension> LoadExtension( | 61 scoped_refptr<extensions::Extension> LoadExtension( |
58 const Manifest& manifest, | 62 const Manifest& manifest, |
59 std::string* error, | 63 std::string* error, |
60 extensions::Manifest::Location location = | 64 extensions::Manifest::Location location = |
61 extensions::Manifest::INTERNAL, | 65 extensions::Manifest::INTERNAL, |
62 int flags = extensions::Extension::NO_FLAGS); | 66 int flags = extensions::Extension::NO_FLAGS); |
63 | 67 |
64 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( | 68 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( |
65 const Manifest& manifest, | 69 const Manifest& manifest, |
66 extensions::Manifest::Location location = | 70 extensions::Manifest::Location location = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Force the manifest tests to run as though they are on trunk, since several | 145 // Force the manifest tests to run as though they are on trunk, since several |
142 // tests rely on manifest features being available that aren't on | 146 // tests rely on manifest features being available that aren't on |
143 // stable/beta. | 147 // stable/beta. |
144 // | 148 // |
145 // These objects nest, so if a test wants to explicitly test the behaviour | 149 // These objects nest, so if a test wants to explicitly test the behaviour |
146 // on stable or beta, declare it inside that test. | 150 // on stable or beta, declare it inside that test. |
147 extensions::Feature::ScopedCurrentChannel current_channel_; | 151 extensions::Feature::ScopedCurrentChannel current_channel_; |
148 }; | 152 }; |
149 | 153 |
150 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 154 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
OLD | NEW |