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

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifest_test.cc

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/extension_l10n_util.h" 13 #include "chrome/common/extensions/extension_l10n_util.h"
15 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
16 15
17 using extensions::Extension; 16 using extensions::Extension;
18 17
19 ExtensionManifestTest::ExtensionManifestTest() 18 ExtensionManifestTest::ExtensionManifestTest()
20 : enable_apps_(true), 19 : enable_apps_(true),
21 // UNKNOWN == trunk. 20 // UNKNOWN == trunk.
22 current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} 21 current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
23 22
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return manifest_; 81 return manifest_;
83 82
84 manifest_ = LoadManifestFile(name_, error); 83 manifest_ = LoadManifestFile(name_, error);
85 manifest_holder_.reset(manifest_); 84 manifest_holder_.reset(manifest_);
86 return manifest_; 85 return manifest_;
87 } 86 }
88 87
89 scoped_refptr<Extension> ExtensionManifestTest::LoadExtension( 88 scoped_refptr<Extension> ExtensionManifestTest::LoadExtension(
90 const Manifest& manifest, 89 const Manifest& manifest,
91 std::string* error, 90 std::string* error,
92 Extension::Location location, 91 extensions::Manifest::Location location,
93 int flags) { 92 int flags) {
94 DictionaryValue* value = manifest.GetManifest(error); 93 DictionaryValue* value = manifest.GetManifest(error);
95 if (!value) 94 if (!value)
96 return NULL; 95 return NULL;
97 FilePath path; 96 FilePath path;
98 PathService::Get(chrome::DIR_TEST_DATA, &path); 97 PathService::Get(chrome::DIR_TEST_DATA, &path);
99 path = path.AppendASCII("extensions").AppendASCII("manifest_tests"); 98 path = path.AppendASCII("extensions").AppendASCII("manifest_tests");
100 return Extension::Create(path.DirName(), location, *value, flags, error); 99 return Extension::Create(path.DirName(), location, *value, flags, error);
101 } 100 }
102 101
103 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess( 102 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
104 const Manifest& manifest, 103 const Manifest& manifest,
105 Extension::Location location, 104 extensions::Manifest::Location location,
106 int flags) { 105 int flags) {
107 std::string error; 106 std::string error;
108 scoped_refptr<Extension> extension = 107 scoped_refptr<Extension> extension =
109 LoadExtension(manifest, &error, location, flags); 108 LoadExtension(manifest, &error, location, flags);
110 EXPECT_TRUE(extension) << manifest.name(); 109 EXPECT_TRUE(extension) << manifest.name();
111 EXPECT_EQ("", error) << manifest.name(); 110 EXPECT_EQ("", error) << manifest.name();
112 return extension; 111 return extension;
113 } 112 }
114 113
115 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess( 114 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectSuccess(
116 char const* manifest_name, 115 char const* manifest_name,
117 Extension::Location location, 116 extensions::Manifest::Location location,
118 int flags) { 117 int flags) {
119 return LoadAndExpectSuccess(Manifest(manifest_name), location, flags); 118 return LoadAndExpectSuccess(Manifest(manifest_name), location, flags);
120 } 119 }
121 120
122 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning( 121 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning(
123 const Manifest& manifest, 122 const Manifest& manifest,
124 const std::string& expected_warning, 123 const std::string& expected_warning,
125 Extension::Location location, 124 extensions::Manifest::Location location,
126 int flags) { 125 int flags) {
127 std::string error; 126 std::string error;
128 scoped_refptr<Extension> extension = 127 scoped_refptr<Extension> extension =
129 LoadExtension(manifest, &error, location, flags); 128 LoadExtension(manifest, &error, location, flags);
130 EXPECT_TRUE(extension) << manifest.name(); 129 EXPECT_TRUE(extension) << manifest.name();
131 EXPECT_EQ("", error) << manifest.name(); 130 EXPECT_EQ("", error) << manifest.name();
132 EXPECT_EQ(1u, extension->install_warnings().size()); 131 EXPECT_EQ(1u, extension->install_warnings().size());
133 EXPECT_EQ(expected_warning, extension->install_warnings()[0].message); 132 EXPECT_EQ(expected_warning, extension->install_warnings()[0].message);
134 return extension; 133 return extension;
135 } 134 }
136 135
137 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning( 136 scoped_refptr<Extension> ExtensionManifestTest::LoadAndExpectWarning(
138 char const* manifest_name, 137 char const* manifest_name,
139 const std::string& expected_warning, 138 const std::string& expected_warning,
140 Extension::Location location, 139 extensions::Manifest::Location location,
141 int flags) { 140 int flags) {
142 return LoadAndExpectWarning( 141 return LoadAndExpectWarning(
143 Manifest(manifest_name), expected_warning, location, flags); 142 Manifest(manifest_name), expected_warning, location, flags);
144 } 143 }
145 144
146 void ExtensionManifestTest::VerifyExpectedError( 145 void ExtensionManifestTest::VerifyExpectedError(
147 Extension* extension, 146 Extension* extension,
148 const std::string& name, 147 const std::string& name,
149 const std::string& error, 148 const std::string& error,
150 const std::string& expected_error) { 149 const std::string& expected_error) {
151 EXPECT_FALSE(extension) << 150 EXPECT_FALSE(extension) <<
152 "Expected failure loading extension '" << name << 151 "Expected failure loading extension '" << name <<
153 "', but didn't get one."; 152 "', but didn't get one.";
154 EXPECT_TRUE(MatchPattern(error, expected_error)) << name << 153 EXPECT_TRUE(MatchPattern(error, expected_error)) << name <<
155 " expected '" << expected_error << "' but got '" << error << "'"; 154 " expected '" << expected_error << "' but got '" << error << "'";
156 } 155 }
157 156
158 void ExtensionManifestTest::LoadAndExpectError( 157 void ExtensionManifestTest::LoadAndExpectError(
159 const Manifest& manifest, 158 const Manifest& manifest,
160 const std::string& expected_error, 159 const std::string& expected_error,
161 Extension::Location location, 160 extensions::Manifest::Location location,
162 int flags) { 161 int flags) {
163 std::string error; 162 std::string error;
164 scoped_refptr<Extension> extension( 163 scoped_refptr<Extension> extension(
165 LoadExtension(manifest, &error, location, flags)); 164 LoadExtension(manifest, &error, location, flags));
166 VerifyExpectedError(extension.get(), manifest.name(), error, 165 VerifyExpectedError(extension.get(), manifest.name(), error,
167 expected_error); 166 expected_error);
168 } 167 }
169 168
170 void ExtensionManifestTest::LoadAndExpectError( 169 void ExtensionManifestTest::LoadAndExpectError(
171 char const* manifest_name, 170 char const* manifest_name,
172 const std::string& expected_error, 171 const std::string& expected_error,
173 Extension::Location location, 172 extensions::Manifest::Location location,
174 int flags) { 173 int flags) {
175 return LoadAndExpectError( 174 return LoadAndExpectError(
176 Manifest(manifest_name), expected_error, location, flags); 175 Manifest(manifest_name), expected_error, location, flags);
177 } 176 }
178 177
179 void ExtensionManifestTest::AddPattern(extensions::URLPatternSet* extent, 178 void ExtensionManifestTest::AddPattern(extensions::URLPatternSet* extent,
180 const std::string& pattern) { 179 const std::string& pattern) {
181 int schemes = URLPattern::SCHEME_ALL; 180 int schemes = URLPattern::SCHEME_ALL;
182 extent->AddPattern(URLPattern(schemes, pattern)); 181 extent->AddPattern(URLPattern(schemes, pattern));
183 } 182 }
184 183
185 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename, 184 ExtensionManifestTest::Testcase::Testcase(
186 std::string expected_error, 185 std::string manifest_filename,
187 Extension::Location location, 186 std::string expected_error,
188 int flags) 187 extensions::Manifest::Location location,
188 int flags)
189 : manifest_filename_(manifest_filename), 189 : manifest_filename_(manifest_filename),
190 expected_error_(expected_error), 190 expected_error_(expected_error),
191 location_(location), flags_(flags) { 191 location_(location), flags_(flags) {
192 } 192 }
193 193
194 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename, 194 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename,
195 std::string expected_error) 195 std::string expected_error)
196 : manifest_filename_(manifest_filename), 196 : manifest_filename_(manifest_filename),
197 expected_error_(expected_error), 197 expected_error_(expected_error),
198 location_(Extension::INTERNAL), 198 location_(extensions::Manifest::INTERNAL),
199 flags_(Extension::NO_FLAGS) { 199 flags_(Extension::NO_FLAGS) {
200 } 200 }
201 201
202 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename) 202 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename)
203 : manifest_filename_(manifest_filename), 203 : manifest_filename_(manifest_filename),
204 expected_error_(""), 204 expected_error_(""),
205 location_(Extension::INTERNAL), 205 location_(extensions::Manifest::INTERNAL),
206 flags_(Extension::NO_FLAGS) { 206 flags_(Extension::NO_FLAGS) {
207 } 207 }
208 208
209 ExtensionManifestTest::Testcase::Testcase(std::string manifest_filename, 209 ExtensionManifestTest::Testcase::Testcase(
210 Extension::Location location, 210 std::string manifest_filename,
211 int flags) 211 extensions::Manifest::Location location,
212 int flags)
212 : manifest_filename_(manifest_filename), 213 : manifest_filename_(manifest_filename),
213 expected_error_(""), 214 expected_error_(""),
214 location_(location), 215 location_(location),
215 flags_(flags) { 216 flags_(flags) {
216 } 217 }
217 218
218 void ExtensionManifestTest::RunTestcases(const Testcase* testcases, 219 void ExtensionManifestTest::RunTestcases(const Testcase* testcases,
219 size_t num_testcases, 220 size_t num_testcases,
220 EXPECT_TYPE type) { 221 EXPECT_TYPE type) {
221 switch (type) { 222 switch (type) {
(...skipping 15 matching lines...) Expand all
237 break; 238 break;
238 case EXPECT_TYPE_SUCCESS: 239 case EXPECT_TYPE_SUCCESS:
239 for (size_t i = 0; i < num_testcases; ++i) { 240 for (size_t i = 0; i < num_testcases; ++i) {
240 LoadAndExpectSuccess(testcases[i].manifest_filename_.c_str(), 241 LoadAndExpectSuccess(testcases[i].manifest_filename_.c_str(),
241 testcases[i].location_, 242 testcases[i].location_,
242 testcases[i].flags_); 243 testcases[i].flags_);
243 } 244 }
244 break; 245 break;
245 } 246 }
246 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698