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

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

Issue 2533873003: Add throttling to corrupt policy extensions reinstall (Closed)
Patch Set: merge latest origin/master Created 4 years 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
« no previous file with comments | « chrome/browser/extensions/chrome_content_verifier_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind_helpers.h"
9 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
14 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/extensions/browsertest_util.h" 17 #include "chrome/browser/extensions/browsertest_util.h"
18 #include "chrome/browser/extensions/chrome_content_verifier_delegate.h"
17 #include "chrome/browser/extensions/extension_browsertest.h" 19 #include "chrome/browser/extensions/extension_browsertest.h"
18 #include "chrome/browser/extensions/extension_management_test_util.h" 20 #include "chrome/browser/extensions/extension_management_test_util.h"
19 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
21 #include "components/policy/core/browser/browser_policy_connector.h" 23 #include "components/policy/core/browser/browser_policy_connector.h"
22 #include "components/policy/core/common/mock_configuration_policy_provider.h" 24 #include "components/policy/core/common/mock_configuration_policy_provider.h"
23 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
24 #include "extensions/browser/content_verifier.h" 26 #include "extensions/browser/content_verifier.h"
25 #include "extensions/browser/content_verify_job.h" 27 #include "extensions/browser/content_verify_job.h"
26 #include "extensions/browser/crx_file_info.h" 28 #include "extensions/browser/crx_file_info.h"
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 int disable_reasons = prefs->GetDisableReasons(id_); 745 int disable_reasons = prefs->GetDisableReasons(id_);
744 if (disable_reasons & Extension::DISABLE_CORRUPTED) { 746 if (disable_reasons & Extension::DISABLE_CORRUPTED) {
745 RegistryObserver registry_observer(registry); 747 RegistryObserver registry_observer(registry);
746 EXPECT_TRUE(registry_observer.WaitForInstall(id_)); 748 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
747 disable_reasons = prefs->GetDisableReasons(id_); 749 disable_reasons = prefs->GetDisableReasons(id_);
748 } 750 }
749 EXPECT_FALSE(disable_reasons & Extension::DISABLE_CORRUPTED); 751 EXPECT_FALSE(disable_reasons & Extension::DISABLE_CORRUPTED);
750 EXPECT_TRUE(registry->enabled_extensions().Contains(id_)); 752 EXPECT_TRUE(registry->enabled_extensions().Contains(id_));
751 } 753 }
752 754
755 namespace {
756
757 // A helper for intercepting the normal action that
758 // ChromeContentVerifierDelegate would take on discovering corruption, letting
759 // us track the delay for each consecutive reinstall.
760 class DelayTracker {
761 public:
762 DelayTracker() {}
763
764 const std::vector<base::TimeDelta>& calls() { return calls_; }
765
766 void ReinstallAction(base::TimeDelta delay) { calls_.push_back(delay); }
767
768 private:
769 std::vector<base::TimeDelta> calls_;
770
771 DISALLOW_COPY_AND_ASSIGN(DelayTracker);
772 };
773
774 } // namespace
775
776 IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest, Backoff) {
777 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
778 ExtensionSystem* system = ExtensionSystem::Get(profile());
779 ExtensionService* service = system->extension_service();
780 ContentVerifier* verifier = system->content_verifier();
781
782 // Wait for the extension to be installed by the policy we set up in
783 // SetUpInProcessBrowserTestFixture.
784 if (!registry->GetInstalledExtension(id_)) {
785 RegistryObserver registry_observer(registry);
786 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
787 }
788
789 // Setup to intercept reinstall action, so we can see what the delay would
790 // have been for the real action.
791 DelayTracker delay_tracker;
792 base::Callback<void(base::TimeDelta)> action = base::Bind(
793 &DelayTracker::ReinstallAction, base::Unretained(&delay_tracker));
794 ChromeContentVerifierDelegate::set_policy_reinstall_action_for_test(&action);
795
796 // Do 4 iterations of disabling followed by reinstall.
797 const size_t iterations = 4;
798 for (size_t i = 0; i < iterations; i++) {
799 RegistryObserver registry_observer(registry);
800 verifier->VerifyFailed(id_, ContentVerifyJob::HASH_MISMATCH);
801 EXPECT_TRUE(registry_observer.WaitForUnload(id_));
802 // Trigger reinstall manually (since we overrode default reinstall action).
803 service->CheckForExternalUpdates();
804 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
805 }
806 const std::vector<base::TimeDelta>& calls = delay_tracker.calls();
807
808 // Assert that the first reinstall action happened with a delay of 0, and
809 // then kept growing each additional time.
810 ASSERT_EQ(iterations, calls.size());
811 EXPECT_EQ(base::TimeDelta(), delay_tracker.calls()[0]);
812 for (size_t i = 1; i < delay_tracker.calls().size(); i++) {
813 EXPECT_LT(calls[i - 1], calls[i]);
814 }
815 }
816
753 } // namespace extensions 817 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_content_verifier_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698