OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 .Build()); | 222 .Build()); |
223 | 223 |
224 // Succeeds when "a" is not recognized. | 224 // Succeeds when "a" is not recognized. |
225 std::string error; | 225 std::string error; |
226 scoped_refptr<Extension> extension = Extension::Create( | 226 scoped_refptr<Extension> extension = Extension::Create( |
227 base::FilePath(), | 227 base::FilePath(), |
228 Manifest::INVALID_LOCATION, | 228 Manifest::INVALID_LOCATION, |
229 *manifest_a, | 229 *manifest_a, |
230 Extension::NO_FLAGS, | 230 Extension::NO_FLAGS, |
231 &error); | 231 &error); |
232 EXPECT_TRUE(extension); | 232 EXPECT_TRUE(extension.get()); |
233 | 233 |
234 // Register a handler for "a" that fails. | 234 // Register a handler for "a" that fails. |
235 ParsingWatcher watcher; | 235 ParsingWatcher watcher; |
236 (new FailingTestManifestHandler( | 236 (new FailingTestManifestHandler( |
237 "A", SingleKey("a"), std::vector<std::string>(), &watcher))->Register(); | 237 "A", SingleKey("a"), std::vector<std::string>(), &watcher))->Register(); |
238 | 238 |
239 extension = Extension::Create( | 239 extension = Extension::Create( |
240 base::FilePath(), | 240 base::FilePath(), |
241 Manifest::INVALID_LOCATION, | 241 Manifest::INVALID_LOCATION, |
242 *manifest_a, | 242 *manifest_a, |
243 Extension::NO_FLAGS, | 243 Extension::NO_FLAGS, |
244 &error); | 244 &error); |
245 EXPECT_FALSE(extension); | 245 EXPECT_FALSE(extension.get()); |
246 EXPECT_EQ("A", error); | 246 EXPECT_EQ("A", error); |
247 } | 247 } |
248 | 248 |
249 TEST_F(ManifestHandlerTest, Validate) { | 249 TEST_F(ManifestHandlerTest, Validate) { |
250 ScopedTestingManifestHandlerRegistry registry; | 250 ScopedTestingManifestHandlerRegistry registry; |
251 scoped_refptr<Extension> extension = ExtensionBuilder() | 251 scoped_refptr<Extension> extension = ExtensionBuilder() |
252 .SetManifest(DictionaryBuilder() | 252 .SetManifest(DictionaryBuilder() |
253 .Set("name", "no name") | 253 .Set("name", "no name") |
254 .Set("version", "0") | 254 .Set("version", "0") |
255 .Set("manifest_version", 2) | 255 .Set("manifest_version", 2) |
256 .Set("a", 1) | 256 .Set("a", 1) |
257 .Set("b", 2)) | 257 .Set("b", 2)) |
258 .Build(); | 258 .Build(); |
259 EXPECT_TRUE(extension); | 259 EXPECT_TRUE(extension.get()); |
260 | 260 |
261 std::string error; | 261 std::string error; |
262 std::vector<InstallWarning> warnings; | 262 std::vector<InstallWarning> warnings; |
263 // Always validates and fails. | 263 // Always validates and fails. |
264 (new TestManifestValidator(false, true, SingleKey("c")))->Register(); | 264 (new TestManifestValidator(false, true, SingleKey("c")))->Register(); |
265 EXPECT_FALSE(ManifestHandler::ValidateExtension( | 265 EXPECT_FALSE( |
266 extension, &error, &warnings)); | 266 ManifestHandler::ValidateExtension(extension.get(), &error, &warnings)); |
267 | 267 |
268 // This overrides the registered handler for "c". | 268 // This overrides the registered handler for "c". |
269 (new TestManifestValidator(false, false, SingleKey("c")))->Register(); | 269 (new TestManifestValidator(false, false, SingleKey("c")))->Register(); |
270 EXPECT_TRUE(ManifestHandler::ValidateExtension( | 270 EXPECT_TRUE( |
271 extension, &error, &warnings)); | 271 ManifestHandler::ValidateExtension(extension.get(), &error, &warnings)); |
272 | 272 |
273 // Validates "a" and fails. | 273 // Validates "a" and fails. |
274 (new TestManifestValidator(false, true, SingleKey("a")))->Register(); | 274 (new TestManifestValidator(false, true, SingleKey("a")))->Register(); |
275 EXPECT_FALSE(ManifestHandler::ValidateExtension( | 275 EXPECT_FALSE( |
276 extension, &error, &warnings)); | 276 ManifestHandler::ValidateExtension(extension.get(), &error, &warnings)); |
277 } | 277 } |
278 | 278 |
279 } // namespace extensions | 279 } // namespace extensions |
OLD | NEW |