Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: extensions/common/manifest_test.h

Issue 574173002: Reland: Refactor ExtensionManifestTest to allow usage in src/extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (manifest-test) add ScopedChannel Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 EXTENSIONS_COMMON_MANIFEST_TEST_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ 6 #define EXTENSIONS_COMMON_MANIFEST_TEST_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/extensions/features/feature_channel.h"
12 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest.h" 12 #include "extensions/common/manifest.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 class ExtensionManifestTest : public testing::Test { 15 namespace base {
16 class FilePath;
17 }
18
19 namespace extensions {
20
21 // Base class for tests that parse a manifest file.
22 class ManifestTest : public testing::Test {
17 public: 23 public:
18 ExtensionManifestTest(); 24 ManifestTest();
25 virtual ~ManifestTest();
19 26
20 protected: 27 protected:
21 // Helper class that simplifies creating methods that take either a filename 28 // Helper class that simplifies creating methods that take either a filename
22 // to a manifest or the manifest itself. 29 // to a manifest or the manifest itself.
23 class Manifest { 30 class ManifestData {
24 public: 31 public:
25 explicit Manifest(const char* name); 32 explicit ManifestData(const char* name);
26 Manifest(base::DictionaryValue* manifest, const char* name); 33 ManifestData(base::DictionaryValue* manifest, const char* name);
27 explicit Manifest(scoped_ptr<base::DictionaryValue> manifest); 34 explicit ManifestData(scoped_ptr<base::DictionaryValue> manifest);
28 // C++98 requires the copy constructor for a type to be visible if you 35 // C++98 requires the copy constructor for a type to be visible if you
29 // take a const-ref of a temporary for that type. Since Manifest 36 // take a const-ref of a temporary for that type. Since Manifest
30 // contains a scoped_ptr, its implicit copy constructor is declared 37 // contains a scoped_ptr, its implicit copy constructor is declared
31 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first 38 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first
32 // requirement and thus you cannot use it with LoadAndExpectError() or 39 // requirement and thus you cannot use it with LoadAndExpectError() or
33 // LoadAndExpectSuccess() easily. 40 // LoadAndExpectSuccess() easily.
34 // 41 //
35 // To get around this spec pedantry, we declare the copy constructor 42 // To get around this spec pedantry, we declare the copy constructor
36 // explicitly. It will never get invoked. 43 // explicitly. It will never get invoked.
37 Manifest(const Manifest& m); 44 ManifestData(const ManifestData& m);
38 45
39 ~Manifest(); 46 ~ManifestData();
40 47
41 const std::string& name() const { return name_; }; 48 const std::string& name() const { return name_; };
42 49
43 base::DictionaryValue* GetManifest(char const* test_data_dir, 50 base::DictionaryValue* GetManifest(base::FilePath manifest_path,
44 std::string* error) const; 51 std::string* error) const;
45 52
46 private: 53 private:
47 const std::string name_; 54 const std::string name_;
48 mutable base::DictionaryValue* manifest_; 55 mutable base::DictionaryValue* manifest_;
49 mutable scoped_ptr<base::DictionaryValue> manifest_holder_; 56 mutable scoped_ptr<base::DictionaryValue> manifest_holder_;
50 }; 57 };
51 58
52 // The subdirectory in which to find test data files. 59 // Returns the path in which to find test manifest data files, for example
53 virtual char const* test_data_dir(); 60 // extensions/test/data/manifest_tests.
61 virtual base::FilePath GetTestDataDir();
54 62
55 scoped_ptr<base::DictionaryValue> LoadManifest( 63 scoped_ptr<base::DictionaryValue> LoadManifest(
56 char const* manifest_name, 64 char const* manifest_name,
57 std::string* error); 65 std::string* error);
58 66
59 scoped_refptr<extensions::Extension> LoadExtension( 67 scoped_refptr<extensions::Extension> LoadExtension(
60 const Manifest& manifest, 68 const ManifestData& manifest,
61 std::string* error, 69 std::string* error,
62 extensions::Manifest::Location location = 70 extensions::Manifest::Location location =
63 extensions::Manifest::INTERNAL, 71 extensions::Manifest::INTERNAL,
64 int flags = extensions::Extension::NO_FLAGS); 72 int flags = extensions::Extension::NO_FLAGS);
65 73
66 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( 74 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
67 const Manifest& manifest, 75 const ManifestData& manifest,
68 extensions::Manifest::Location location = 76 extensions::Manifest::Location location =
69 extensions::Manifest::INTERNAL, 77 extensions::Manifest::INTERNAL,
70 int flags = extensions::Extension::NO_FLAGS); 78 int flags = extensions::Extension::NO_FLAGS);
71 79
72 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( 80 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
73 char const* manifest_name, 81 char const* manifest_name,
74 extensions::Manifest::Location location = 82 extensions::Manifest::Location location =
75 extensions::Manifest::INTERNAL, 83 extensions::Manifest::INTERNAL,
76 int flags = extensions::Extension::NO_FLAGS); 84 int flags = extensions::Extension::NO_FLAGS);
77 85
78 // Load and expect success from a manifest provided as a json string. Single
79 // quotes will be replaced with double quotes for test readability.
80 scoped_refptr<extensions::Extension> LoadFromStringAndExpectSuccess(
81 char const* manifest_json);
82
83 scoped_refptr<extensions::Extension> LoadAndExpectWarning( 86 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
84 const Manifest& manifest, 87 const ManifestData& manifest,
85 const std::string& expected_error, 88 const std::string& expected_error,
86 extensions::Manifest::Location location = 89 extensions::Manifest::Location location =
87 extensions::Manifest::INTERNAL, 90 extensions::Manifest::INTERNAL,
88 int flags = extensions::Extension::NO_FLAGS); 91 int flags = extensions::Extension::NO_FLAGS);
89 92
90 scoped_refptr<extensions::Extension> LoadAndExpectWarning( 93 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
91 char const* manifest_name, 94 char const* manifest_name,
92 const std::string& expected_error, 95 const std::string& expected_error,
93 extensions::Manifest::Location location = 96 extensions::Manifest::Location location =
94 extensions::Manifest::INTERNAL, 97 extensions::Manifest::INTERNAL,
95 int flags = extensions::Extension::NO_FLAGS); 98 int flags = extensions::Extension::NO_FLAGS);
96 99
97 void VerifyExpectedError(extensions::Extension* extension, 100 void VerifyExpectedError(extensions::Extension* extension,
98 const std::string& name, 101 const std::string& name,
99 const std::string& error, 102 const std::string& error,
100 const std::string& expected_error); 103 const std::string& expected_error);
101 104
102 void LoadAndExpectError(char const* manifest_name, 105 void LoadAndExpectError(char const* manifest_name,
103 const std::string& expected_error, 106 const std::string& expected_error,
104 extensions::Manifest::Location location = 107 extensions::Manifest::Location location =
105 extensions::Manifest::INTERNAL, 108 extensions::Manifest::INTERNAL,
106 int flags = extensions::Extension::NO_FLAGS); 109 int flags = extensions::Extension::NO_FLAGS);
107 110
108 void LoadAndExpectError(const Manifest& manifest, 111 void LoadAndExpectError(const ManifestData& manifest,
109 const std::string& expected_error, 112 const std::string& expected_error,
110 extensions::Manifest::Location location = 113 extensions::Manifest::Location location =
111 extensions::Manifest::INTERNAL, 114 extensions::Manifest::INTERNAL,
112 int flags = extensions::Extension::NO_FLAGS); 115 int flags = extensions::Extension::NO_FLAGS);
113 116
114 // Load and expect an error from a manifest provided as a json string. Single
115 // quotes will be replaced with double quotes for test readability.
116 void LoadFromStringAndExpectError(char const* manifest_json,
117 const std::string& expected_error);
118
119 void AddPattern(extensions::URLPatternSet* extent, 117 void AddPattern(extensions::URLPatternSet* extent,
120 const std::string& pattern); 118 const std::string& pattern);
121 119
122 // used to differentiate between calls to LoadAndExpectError, 120 // used to differentiate between calls to LoadAndExpectError,
123 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases. 121 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases.
124 enum ExpectType { 122 enum ExpectType {
125 EXPECT_TYPE_ERROR, 123 EXPECT_TYPE_ERROR,
126 EXPECT_TYPE_WARNING, 124 EXPECT_TYPE_WARNING,
127 EXPECT_TYPE_SUCCESS 125 EXPECT_TYPE_SUCCESS
128 }; 126 };
(...skipping 17 matching lines...) Expand all
146 }; 144 };
147 145
148 void RunTestcases(const Testcase* testcases, 146 void RunTestcases(const Testcase* testcases,
149 size_t num_testcases, 147 size_t num_testcases,
150 ExpectType type); 148 ExpectType type);
151 149
152 void RunTestcase(const Testcase& testcase, ExpectType type); 150 void RunTestcase(const Testcase& testcase, ExpectType type);
153 151
154 bool enable_apps_; 152 bool enable_apps_;
155 153
156 // Force the manifest tests to run as though they are on trunk, since several 154 private:
157 // tests rely on manifest features being available that aren't on 155 DISALLOW_COPY_AND_ASSIGN(ManifestTest);
158 // stable/beta.
159 //
160 // These objects nest, so if a test wants to explicitly test the behaviour
161 // on stable or beta, declare it inside that test.
162 extensions::ScopedCurrentChannel current_channel_;
163 }; 156 };
164 157
165 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ 158 } // namespace extensions
159
160 #endif // EXTENSIONS_COMMON_MANIFEST_TEST_H_
OLDNEW
« no previous file with comments | « extensions/common/manifest_handlers/shared_module_manifest_unittest.cc ('k') | extensions/common/manifest_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698