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/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // the WebContents. | 498 // the WebContents. |
499 AddTabAtIndexToBrowser(browser(), 1, page_url_, ui::PAGE_TRANSITION_LINK, | 499 AddTabAtIndexToBrowser(browser(), 1, page_url_, ui::PAGE_TRANSITION_LINK, |
500 false); | 500 false); |
501 | 501 |
502 EXPECT_TRUE(unload_observer.WaitForUnload(id)); | 502 EXPECT_TRUE(unload_observer.WaitForUnload(id)); |
503 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 503 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
504 int reasons = prefs->GetDisableReasons(id); | 504 int reasons = prefs->GetDisableReasons(id); |
505 EXPECT_TRUE(reasons & Extension::DISABLE_CORRUPTED); | 505 EXPECT_TRUE(reasons & Extension::DISABLE_CORRUPTED); |
506 } | 506 } |
507 | 507 |
| 508 void TestContentScriptExtension(const std::string& crx_relpath, |
| 509 const std::string& id, |
| 510 const std::string& script_relpath) { |
| 511 VerifierObserver verifier_observer; |
| 512 |
| 513 // Install the extension with content scripts. The initial read of the |
| 514 // content scripts will fail verification because they are read before the |
| 515 // content verification system has completed a one-time processing of the |
| 516 // expected hashes. (The extension only contains the root level hashes of |
| 517 // the merkle tree, but the content verification system builds the entire |
| 518 // tree and caches it in the extension install directory - see |
| 519 // ContentHashFetcher for more details). |
| 520 const Extension* extension = InstallExtensionFromWebstore( |
| 521 test_data_dir_.AppendASCII(crx_relpath), 1); |
| 522 ASSERT_TRUE(extension); |
| 523 EXPECT_EQ(id, extension->id()); |
| 524 |
| 525 // Wait for the content verification code to finish processing the hashes. |
| 526 if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) |
| 527 verifier_observer.WaitForFetchComplete(id); |
| 528 |
| 529 // Now disable the extension, since content scripts are read at enable time, |
| 530 // set up our job observer, and re-enable, expecting a success this time. |
| 531 DisableExtension(id); |
| 532 JobObserver job_observer; |
| 533 base::FilePath script_relfilepath = |
| 534 base::FilePath().AppendASCII(script_relpath); |
| 535 job_observer.ExpectJobResult(id, script_relfilepath, |
| 536 JobObserver::Result::SUCCESS); |
| 537 EnableExtension(id); |
| 538 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
| 539 |
| 540 // Now alter the contents of the content script, reload the extension, and |
| 541 // expect to see a job failure due to the content script content hash not |
| 542 // being what was signed by the webstore. |
| 543 base::FilePath scriptfile = extension->path().AppendASCII(script_relpath); |
| 544 std::string extra = "some_extra_function_call();"; |
| 545 ASSERT_TRUE(base::AppendToFile(scriptfile, extra.data(), extra.size())); |
| 546 DisableExtension(id); |
| 547 job_observer.ExpectJobResult(id, script_relfilepath, |
| 548 JobObserver::Result::FAILURE); |
| 549 EnableExtension(id); |
| 550 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
| 551 } |
| 552 |
508 protected: | 553 protected: |
509 JobDelegate delegate_; | 554 JobDelegate delegate_; |
510 GURL page_url_; | 555 GURL page_url_; |
511 }; | 556 }; |
512 | 557 |
513 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, FailOnRead) { | 558 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, FailOnRead) { |
514 #if defined(OS_WIN) | 559 #if defined(OS_WIN) |
515 if (content::IsBrowserSideNavigationEnabled() && | 560 if (content::IsBrowserSideNavigationEnabled() && |
516 base::win::GetVersion() >= base::win::VERSION_WIN10) { | 561 base::win::GetVersion() >= base::win::VERSION_WIN10) { |
517 // http://crbug.com/699437 | 562 // http://crbug.com/699437 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 | 624 |
580 // Now disable/re-enable the extension to cause the content scripts to be | 625 // Now disable/re-enable the extension to cause the content scripts to be |
581 // read again. | 626 // read again. |
582 DisableExtension(id); | 627 DisableExtension(id); |
583 EnableExtension(id); | 628 EnableExtension(id); |
584 | 629 |
585 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | 630 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); |
586 } | 631 } |
587 | 632 |
588 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { | 633 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScripts) { |
589 VerifierObserver verifier_observer; | 634 TestContentScriptExtension("content_verifier/content_script.crx", |
| 635 "jmllhlobpjcnnomjlipadejplhmheiif", "script.js"); |
| 636 } |
590 | 637 |
591 // Install an extension with content scripts. The initial read of the content | 638 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, ContentScriptsInLocales) { |
592 // scripts will fail verification because they are read before the content | 639 TestContentScriptExtension("content_verifier/content_script_locales.crx", |
593 // verification system has completed a one-time processing of the expected | 640 "jaghonccckpcikmliipifpoodmeofoon", |
594 // hashes. (The extension only contains the root level hashes of the merkle | 641 "_locales/en/content_script.js"); |
595 // tree, but the content verification system builds the entire tree and | |
596 // caches it in the extension install directory - see ContentHashFetcher for | |
597 // more details). | |
598 std::string id = "jmllhlobpjcnnomjlipadejplhmheiif"; | |
599 const Extension* extension = InstallExtensionFromWebstore( | |
600 test_data_dir_.AppendASCII("content_verifier/content_script.crx"), 1); | |
601 ASSERT_TRUE(extension); | |
602 ASSERT_EQ(extension->id(), id); | |
603 | |
604 // Wait for the content verification code to finish processing the hashes. | |
605 if (!base::ContainsKey(verifier_observer.completed_fetches(), id)) | |
606 verifier_observer.WaitForFetchComplete(id); | |
607 | |
608 // Now disable the extension, since content scripts are read at enable time, | |
609 // set up our job observer, and re-enable, expecting a success this time. | |
610 DisableExtension(id); | |
611 JobObserver job_observer; | |
612 job_observer.ExpectJobResult(id, | |
613 base::FilePath(FILE_PATH_LITERAL("script.js")), | |
614 JobObserver::Result::SUCCESS); | |
615 EnableExtension(id); | |
616 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | |
617 | |
618 // Now alter the contents of the content script, reload the extension, and | |
619 // expect to see a job failure due to the content script content hash not | |
620 // being what was signed by the webstore. | |
621 base::FilePath scriptfile = extension->path().AppendASCII("script.js"); | |
622 std::string extra = "some_extra_function_call();"; | |
623 ASSERT_TRUE(base::AppendToFile(scriptfile, extra.data(), extra.size())); | |
624 DisableExtension(id); | |
625 job_observer.ExpectJobResult(id, | |
626 base::FilePath(FILE_PATH_LITERAL("script.js")), | |
627 JobObserver::Result::FAILURE); | |
628 EnableExtension(id); | |
629 EXPECT_TRUE(job_observer.WaitForExpectedJobs()); | |
630 } | 642 } |
631 | 643 |
632 // Tests the case of a corrupt extension that is force-installed by policy and | 644 // Tests the case of a corrupt extension that is force-installed by policy and |
633 // should not be allowed to be manually uninstalled/disabled by the user. | 645 // should not be allowed to be manually uninstalled/disabled by the user. |
634 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, PolicyCorrupted) { | 646 IN_PROC_BROWSER_TEST_F(ContentVerifierTest, PolicyCorrupted) { |
635 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 647 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
636 ExtensionService* service = system->extension_service(); | 648 ExtensionService* service = system->extension_service(); |
637 | 649 |
638 // The id of our test extension. | 650 // The id of our test extension. |
639 std::string id("npnbmohejbjohgpjnmjagbafnjhkmgko"); | 651 std::string id("npnbmohejbjohgpjnmjagbafnjhkmgko"); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 // Remove the override and set ExtensionService to update again. The extension | 899 // Remove the override and set ExtensionService to update again. The extension |
888 // should be now installed. | 900 // should be now installed. |
889 PolicyExtensionReinstaller::set_policy_reinstall_action_for_test(nullptr); | 901 PolicyExtensionReinstaller::set_policy_reinstall_action_for_test(nullptr); |
890 service->set_external_updates_disabled_for_test(false); | 902 service->set_external_updates_disabled_for_test(false); |
891 delay_tracker.Proceed(); | 903 delay_tracker.Proceed(); |
892 | 904 |
893 EXPECT_TRUE(registry_observer.WaitForInstall(id_)); | 905 EXPECT_TRUE(registry_observer.WaitForInstall(id_)); |
894 } | 906 } |
895 | 907 |
896 } // namespace extensions | 908 } // namespace extensions |
OLD | NEW |