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

Side by Side Diff: chrome/browser/extensions/content_verifier_browsertest.cc

Issue 2495123003: Continue attempts to reinstall corrupt policy extensions across restarts (Closed)
Patch Set: cleanup Created 4 years, 1 month 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 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/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/extensions/browsertest_util.h"
16 #include "chrome/browser/extensions/extension_browsertest.h" 17 #include "chrome/browser/extensions/extension_browsertest.h"
18 #include "chrome/browser/extensions/extension_management_test_util.h"
17 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "components/policy/core/browser/browser_policy_connector.h"
22 #include "components/policy/core/common/mock_configuration_policy_provider.h"
19 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
20 #include "extensions/browser/content_verifier.h" 24 #include "extensions/browser/content_verifier.h"
21 #include "extensions/browser/content_verify_job.h" 25 #include "extensions/browser/content_verify_job.h"
22 #include "extensions/browser/crx_file_info.h" 26 #include "extensions/browser/crx_file_info.h"
23 #include "extensions/browser/extension_prefs.h" 27 #include "extensions/browser/extension_prefs.h"
24 #include "extensions/browser/extension_registry.h" 28 #include "extensions/browser/extension_registry.h"
25 #include "extensions/browser/extension_registry_observer.h" 29 #include "extensions/browser/extension_registry_observer.h"
26 #include "extensions/browser/external_install_info.h" 30 #include "extensions/browser/external_install_info.h"
27 #include "extensions/browser/external_provider_interface.h" 31 #include "extensions/browser/external_provider_interface.h"
28 #include "extensions/browser/management_policy.h" 32 #include "extensions/browser/management_policy.h"
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 418
415 std::string GetDebugPolicyProviderName() const override { 419 std::string GetDebugPolicyProviderName() const override {
416 return "ForceInstallProvider"; 420 return "ForceInstallProvider";
417 } 421 }
418 422
419 // MananagementPolicy::Provider: 423 // MananagementPolicy::Provider:
420 bool UserMayModifySettings(const Extension* extension, 424 bool UserMayModifySettings(const Extension* extension,
421 base::string16* error) const override { 425 base::string16* error) const override {
422 return extension->id() != id_; 426 return extension->id() != id_;
423 } 427 }
428 bool MustRemainEnabled(const Extension* extension,
429 base::string16* error) const override {
430 return extension->id() != id_;
lazyboy 2016/11/16 01:44:53 Should this be id() == id_ instead? We don't want
asargent_no_longer_on_chrome 2016/11/17 21:48:01 Good catch - it took me a while to understand why
431 }
424 432
425 private: 433 private:
426 // The extension id we want to disallow uninstall/disable for. 434 // The extension id we want to disallow uninstall/disable for.
427 ExtensionId id_; 435 ExtensionId id_;
428 436
429 DISALLOW_COPY_AND_ASSIGN(ForceInstallProvider); 437 DISALLOW_COPY_AND_ASSIGN(ForceInstallProvider);
430 }; 438 };
431 439
432 } // namespace 440 } // namespace
433 441
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 part.find(std::string("id%3D") + id) != std::string::npos) { 663 part.find(std::string("id%3D") + id) != std::string::npos) {
656 found = true; 664 found = true;
657 EXPECT_NE(std::string::npos, part.find("installsource%3Dreinstall")); 665 EXPECT_NE(std::string::npos, part.find("installsource%3Dreinstall"));
658 } 666 }
659 } 667 }
660 } 668 }
661 } 669 }
662 EXPECT_TRUE(found); 670 EXPECT_TRUE(found);
663 } 671 }
664 672
673 class ContentVerifierPolicyTest : public ContentVerifierTest {
674 public:
675 // We need to do this work here because the force-install policy values are
676 // checked pretty early on in the startup of the ExtensionService, which
677 // happens between SetUpInProcessBrowserTestFixture and SetUpOnMainThread.
678 void SetUpInProcessBrowserTestFixture() override {
679 ContentVerifierTest::SetUpInProcessBrowserTestFixture();
680
681 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_))
682 .WillRepeatedly(testing::Return(true));
683
684 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
685 &policy_provider_);
686 ExtensionManagementPolicyUpdater management_policy(&policy_provider_);
687 management_policy.SetIndividualExtensionAutoInstalled(
688 id_, extension_urls::kChromeWebstoreUpdateURL, true /* forced */);
689
690 ExtensionDownloader::set_test_delegate(&downloader_);
691 base::FilePath crx_path =
692 test_data_dir_.AppendASCII("content_verifier/v1.crx");
693 std::string version = "2";
694 downloader_.AddResponse(id_, version, crx_path);
695 }
696
697 void SetUpOnMainThread() override {
698 extensions::browsertest_util::CreateAndInitializeLocalCache();
699 }
700
701 protected:
702 // The id of the extension we want to have force-installed.
703 std::string id_ = "npnbmohejbjohgpjnmjagbafnjhkmgko";
704
705 private:
706 policy::MockConfigurationPolicyProvider policy_provider_;
707 DownloaderTestDelegate downloader_;
708 };
709
710 // We want to test what happens at startup with a corroption-disabled policy
711 // force installed extension. So we set that up in the PRE test here.
712 IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest,
713 PRE_PolicyCorruptedOnStartup) {
714 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
715 RegistryObserver registry_observer(registry);
716
717 // Wait for the extension to be installed by policy we set up in
718 // SetUpInProcessBrowserTestFixture.
719 if (!registry->GetInstalledExtension(id_)) {
720 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
721 }
722
723 // Simulate corruption of the extension so that we can test what happens
724 // at startup in the non-PRE test.
725 ExtensionSystem* system = ExtensionSystem::Get(profile());
726 ContentVerifier* verifier = system->content_verifier();
727 verifier->VerifyFailed(id_, ContentVerifyJob::HASH_MISMATCH);
728 EXPECT_TRUE(registry_observer.WaitForUnload(id_));
729 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
730 int reasons = prefs->GetDisableReasons(id_);
731 EXPECT_TRUE(reasons & Extension::DISABLE_CORRUPTED);
732 }
733
734 // Now actually test what happens on the next startup after the PRE test above.
735 IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest, PolicyCorruptedOnStartup) {
736 // Expect that the extension is still disabled for corruption.
737 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
738 int reasons = prefs->GetDisableReasons(id_);
739 EXPECT_TRUE(reasons & Extension::DISABLE_CORRUPTED);
740
741 // Now expect that it gets reinstalled (because a job should have been kicked
742 // off by the installed extension loading code).
743 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
744 RegistryObserver registry_observer(registry);
745 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
746 reasons = prefs->GetDisableReasons(id_);
747 EXPECT_FALSE(reasons & Extension::DISABLE_CORRUPTED);
748 }
749
665 } // namespace extensions 750 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698