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

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

Issue 2533873003: Add throttling to corrupt policy extensions reinstall (Closed)
Patch Set: ready for review 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
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/browsertest_util.h"
17 #include "chrome/browser/extensions/chrome_content_verifier_delegate.h"
17 #include "chrome/browser/extensions/extension_browsertest.h" 18 #include "chrome/browser/extensions/extension_browsertest.h"
18 #include "chrome/browser/extensions/extension_management_test_util.h" 19 #include "chrome/browser/extensions/extension_management_test_util.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "components/policy/core/browser/browser_policy_connector.h" 22 #include "components/policy/core/browser/browser_policy_connector.h"
22 #include "components/policy/core/common/mock_configuration_policy_provider.h" 23 #include "components/policy/core/common/mock_configuration_policy_provider.h"
23 #include "content/public/test/test_utils.h" 24 #include "content/public/test/test_utils.h"
24 #include "extensions/browser/content_verifier.h" 25 #include "extensions/browser/content_verifier.h"
25 #include "extensions/browser/content_verify_job.h" 26 #include "extensions/browser/content_verify_job.h"
26 #include "extensions/browser/crx_file_info.h" 27 #include "extensions/browser/crx_file_info.h"
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 744
744 // Now expect that it gets reinstalled (because a job should have been kicked 745 // Now expect that it gets reinstalled (because a job should have been kicked
745 // off by the installed extension loading code). 746 // off by the installed extension loading code).
746 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 747 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
747 RegistryObserver registry_observer(registry); 748 RegistryObserver registry_observer(registry);
748 EXPECT_TRUE(registry_observer.WaitForInstall(id_)); 749 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
749 reasons = prefs->GetDisableReasons(id_); 750 reasons = prefs->GetDisableReasons(id_);
750 EXPECT_FALSE(reasons & Extension::DISABLE_CORRUPTED); 751 EXPECT_FALSE(reasons & Extension::DISABLE_CORRUPTED);
751 } 752 }
752 753
754 namespace {
755
756 // A helper for intercepting the normal action that
757 // ChromeContentVerifierDelegate would take on discovering corruption, letting
758 // us track the delay for each consecutive reinstall.
759 class DelayTracker : public base::SupportsWeakPtr<DelayTracker> {
Devlin 2016/11/29 22:31:24 probably safe to just use unretained here.
asargent_no_longer_on_chrome 2016/11/30 00:11:49 Done.
760 public:
761 DelayTracker() {}
762
763 const std::vector<base::TimeDelta>& calls() { return calls_; }
764
765 void ReinstallAction(base::TimeDelta delay) { calls_.push_back(delay); }
766
767 private:
768 std::vector<base::TimeDelta> calls_;
769
770 DISALLOW_COPY_AND_ASSIGN(DelayTracker);
771 };
772
773 } // namespace
774
775 IN_PROC_BROWSER_TEST_F(ContentVerifierPolicyTest, Backoff) {
776 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
777 ExtensionSystem* system = ExtensionSystem::Get(profile());
778 ExtensionService* service = system->extension_service();
779 // ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
Devlin 2016/11/29 22:31:24 delete?
asargent_no_longer_on_chrome 2016/11/30 00:11:48 Good catch, done.
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 ChromeContentVerifierDelegate::set_policy_reinstall_action_for_test(
793 base::Bind(&DelayTracker::ReinstallAction, delay_tracker.AsWeakPtr()));
794
795 // Do 4 iterations of disabling followed by reinstall.
796 const size_t iterations = 4;
797 for (size_t i = 0; i < iterations; i++) {
798 RegistryObserver registry_observer(registry);
799 verifier->VerifyFailed(id_, ContentVerifyJob::HASH_MISMATCH);
800 EXPECT_TRUE(registry_observer.WaitForUnload(id_));
801 // Trigger reinstall manually (since we overrode default reinstall action).
802 service->CheckForExternalUpdates();
803 EXPECT_TRUE(registry_observer.WaitForInstall(id_));
804 }
805 const std::vector<base::TimeDelta>& calls = delay_tracker.calls();
806
807 // Assert that the first reinstall action happened with a delay of 0, and
808 // then kept growing each additional time.
809 EXPECT_EQ(iterations, calls.size());
810 EXPECT_EQ(base::TimeDelta(), delay_tracker.calls()[0]);
Devlin 2016/11/29 22:31:25 we should either ASSERT_EQ the size above or shoul
asargent_no_longer_on_chrome 2016/11/30 00:11:48 Done.
811 for (size_t i = 1; i < delay_tracker.calls().size(); i++) {
812 EXPECT_LT(calls[i - 1], calls[i]);
813 }
814 }
815
753 } // namespace extensions 816 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698