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

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

Issue 2790823004: Retry reinstallation of corrupted policy extensions. (Closed)
Patch Set: address comments Created 3 years, 8 months 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/policy_extension_reinstaller.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/policy_extension_reinstaller.h"
6
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_service_test_base.h"
11 #include "chrome/test/base/testing_profile.h"
12
13 namespace extensions {
14
15 namespace {
16 const char kDummyExtensionId[] = "whatever";
17 }
18
19 class TestReinstallerTracker {
20 public:
21 TestReinstallerTracker()
22 : action_(base::Bind(&TestReinstallerTracker::ReinstallAction,
23 base::Unretained(this))) {
24 PolicyExtensionReinstaller::set_policy_reinstall_action_for_test(&action_);
25 }
26 ~TestReinstallerTracker() {
27 PolicyExtensionReinstaller::set_policy_reinstall_action_for_test(nullptr);
28 }
29 void ReinstallAction(const base::Closure& callback,
30 base::TimeDelta reinstall_delay) {
31 ++call_count_;
32 saved_callback_ = callback;
33 }
34 void Proceed() {
35 DCHECK(saved_callback_);
36 DCHECK(!saved_callback_->is_null());
37 // Run() will set |saved_callback_| again, so use a temporary.
38 base::Closure callback = saved_callback_.value();
39 saved_callback_.reset();
40 callback.Run();
41 }
42 int call_count() { return call_count_; }
43
44 private:
45 int call_count_ = 0;
46 base::Optional<base::Closure> saved_callback_;
47 PolicyExtensionReinstaller::ReinstallCallback action_;
48
49 DISALLOW_COPY_AND_ASSIGN(TestReinstallerTracker);
50 };
51
52 using PolicyExtensionReinstallerUnittest = ExtensionServiceTestBase;
53
54 // Tests that a single extension corruption will keep retrying reinstallation.
55 TEST_F(PolicyExtensionReinstallerUnittest, Retry) {
56 InitializeEmptyExtensionService();
57 service()->pending_extension_manager()->ExpectPolicyReinstallForCorruption(
58 kDummyExtensionId);
59
60 PolicyExtensionReinstaller reinstaller(profile_.get());
61 TestReinstallerTracker tracker;
62
63 reinstaller.NotifyExtensionDisabledDueToCorruption();
64 EXPECT_EQ(1, tracker.call_count());
65 tracker.Proceed();
66 EXPECT_EQ(2, tracker.call_count());
67 tracker.Proceed();
68 EXPECT_EQ(3, tracker.call_count());
69 }
70
71 // Tests that PolicyExtensionReinstaller doesn't schedule a
72 // CheckForExternalUpdates() when one is already in-flight through PostTask.
73 TEST_F(PolicyExtensionReinstallerUnittest, DoNotScheduleWhenAlreadyInflight) {
74 InitializeEmptyExtensionService();
75 service()->pending_extension_manager()->ExpectPolicyReinstallForCorruption(
76 kDummyExtensionId);
77
78 PolicyExtensionReinstaller reinstaller(profile_.get());
79 TestReinstallerTracker tracker;
80
81 reinstaller.NotifyExtensionDisabledDueToCorruption();
82 EXPECT_EQ(1, tracker.call_count());
83 reinstaller.NotifyExtensionDisabledDueToCorruption();
84 // Resolve the reinstall attempt.
85 tracker.Proceed();
86 EXPECT_EQ(2, tracker.call_count());
87 reinstaller.NotifyExtensionDisabledDueToCorruption();
88 // Not resolving the pending attempt will not produce further calls.
89 EXPECT_EQ(2, tracker.call_count());
90 }
91
92 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/policy_extension_reinstaller.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698