OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <list> | 5 #include <list> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // Helper for observing extension unloads. | 24 // Helper for observing extension unloads. |
25 class UnloadObserver : public ExtensionRegistryObserver { | 25 class UnloadObserver : public ExtensionRegistryObserver { |
26 public: | 26 public: |
27 explicit UnloadObserver(ExtensionRegistry* registry) : observer_(this) { | 27 explicit UnloadObserver(ExtensionRegistry* registry) : observer_(this) { |
28 observer_.Add(registry); | 28 observer_.Add(registry); |
29 } | 29 } |
30 ~UnloadObserver() override {} | 30 ~UnloadObserver() override {} |
31 | 31 |
32 void WaitForUnload(const ExtensionId& id) { | 32 void WaitForUnload(const ExtensionId& id) { |
33 if (ContainsKey(observed_, id)) | 33 if (base::ContainsKey(observed_, id)) |
34 return; | 34 return; |
35 | 35 |
36 ASSERT_TRUE(loop_runner_.get() == NULL); | 36 ASSERT_TRUE(loop_runner_.get() == NULL); |
37 awaited_id_ = id; | 37 awaited_id_ = id; |
38 loop_runner_ = new content::MessageLoopRunner(); | 38 loop_runner_ = new content::MessageLoopRunner(); |
39 loop_runner_->Run(); | 39 loop_runner_->Run(); |
40 } | 40 } |
41 | 41 |
42 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 42 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
43 const Extension* extension, | 43 const Extension* extension, |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // signatures, and contains paths with a leading "./" in various places. | 355 // signatures, and contains paths with a leading "./" in various places. |
356 const Extension* extension = InstallExtensionFromWebstore( | 356 const Extension* extension = InstallExtensionFromWebstore( |
357 test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1); | 357 test_data_dir_.AppendASCII("content_verifier/dot_slash_paths.crx"), 1); |
358 | 358 |
359 ASSERT_TRUE(extension); | 359 ASSERT_TRUE(extension); |
360 ASSERT_EQ(extension->id(), id); | 360 ASSERT_EQ(extension->id(), id); |
361 | 361 |
362 // The content scripts might fail verification the first time since the | 362 // The content scripts might fail verification the first time since the |
363 // one-time processing might not be finished yet - if that's the case then | 363 // one-time processing might not be finished yet - if that's the case then |
364 // we want to wait until that work is done. | 364 // we want to wait until that work is done. |
365 if (!ContainsKey(verifier_observer.completed_fetches(), id)) | 365 if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) |
366 verifier_observer.WaitForFetchComplete(id); | 366 verifier_observer.WaitForFetchComplete(id); |
367 | 367 |
368 // Now disable/re-enable the extension to cause the content scripts to be | 368 // Now disable/re-enable the extension to cause the content scripts to be |
369 // read again. | 369 // read again. |
370 DisableExtension(id); | 370 DisableExtension(id); |
371 EnableExtension(id); | 371 EnableExtension(id); |
372 | 372 |
373 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | 373 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
374 | 374 |
375 ContentVerifyJob::SetObserverForTests(NULL); | 375 ContentVerifyJob::SetObserverForTests(NULL); |
(...skipping 10 matching lines...) Expand all Loading... |
386 // tree, but the content verification system builds the entire tree and | 386 // tree, but the content verification system builds the entire tree and |
387 // caches it in the extension install directory - see ContentHashFetcher for | 387 // caches it in the extension install directory - see ContentHashFetcher for |
388 // more details). | 388 // more details). |
389 std::string id = "jmllhlobpjcnnomjlipadejplhmheiif"; | 389 std::string id = "jmllhlobpjcnnomjlipadejplhmheiif"; |
390 const Extension* extension = InstallExtensionFromWebstore( | 390 const Extension* extension = InstallExtensionFromWebstore( |
391 test_data_dir_.AppendASCII("content_verifier/content_script.crx"), 1); | 391 test_data_dir_.AppendASCII("content_verifier/content_script.crx"), 1); |
392 ASSERT_TRUE(extension); | 392 ASSERT_TRUE(extension); |
393 ASSERT_EQ(extension->id(), id); | 393 ASSERT_EQ(extension->id(), id); |
394 | 394 |
395 // Wait for the content verification code to finish processing the hashes. | 395 // Wait for the content verification code to finish processing the hashes. |
396 if (!ContainsKey(verifier_observer.completed_fetches(), id)) | 396 if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) |
397 verifier_observer.WaitForFetchComplete(id); | 397 verifier_observer.WaitForFetchComplete(id); |
398 | 398 |
399 // Now disable the extension, since content scripts are read at enable time, | 399 // Now disable the extension, since content scripts are read at enable time, |
400 // set up our job observer, and re-enable, expecting a success this time. | 400 // set up our job observer, and re-enable, expecting a success this time. |
401 DisableExtension(id); | 401 DisableExtension(id); |
402 JobObserver job_observer; | 402 JobObserver job_observer; |
403 ContentVerifyJob::SetObserverForTests(&job_observer); | 403 ContentVerifyJob::SetObserverForTests(&job_observer); |
404 job_observer.ExpectJobResult(id, | 404 job_observer.ExpectJobResult(id, |
405 base::FilePath(FILE_PATH_LITERAL("script.js")), | 405 base::FilePath(FILE_PATH_LITERAL("script.js")), |
406 JobObserver::Result::SUCCESS); | 406 JobObserver::Result::SUCCESS); |
(...skipping 10 matching lines...) Expand all Loading... |
417 job_observer.ExpectJobResult(id, | 417 job_observer.ExpectJobResult(id, |
418 base::FilePath(FILE_PATH_LITERAL("script.js")), | 418 base::FilePath(FILE_PATH_LITERAL("script.js")), |
419 JobObserver::Result::FAILURE); | 419 JobObserver::Result::FAILURE); |
420 EnableExtension(id); | 420 EnableExtension(id); |
421 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | 421 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
422 | 422 |
423 ContentVerifyJob::SetObserverForTests(NULL); | 423 ContentVerifyJob::SetObserverForTests(NULL); |
424 } | 424 } |
425 | 425 |
426 } // namespace extensions | 426 } // namespace extensions |
OLD | NEW |