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

Side by Side Diff: chrome/browser/sync/backup_rollback_controller_unittest.cc

Issue 1354883003: Componentize chrome/browser/sync/backup_rollback_controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated Created 5 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/backup_rollback_controller.h"
6
7 #include "base/command_line.h"
8 #include "base/location.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "components/sync_driver/signin_manager_wrapper.h"
13 #include "components/sync_driver/sync_driver_switches.h"
14 #include "components/sync_driver/sync_prefs.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using ::testing::Return;
19
20 namespace {
21
22 #if defined(ENABLE_PRE_SYNC_BACKUP)
23
24 class MockSigninManagerWrapper : public SigninManagerWrapper {
25 public:
26 MockSigninManagerWrapper() : SigninManagerWrapper(NULL) {}
27
28 MOCK_CONST_METHOD0(GetEffectiveUsername, std::string());
29 };
30
31 class FakeSyncPrefs : public sync_driver::SyncPrefs {
32 public:
33 FakeSyncPrefs() : rollback_tries_left_(0) {}
34
35 int GetRemainingRollbackTries() const override {
36 return rollback_tries_left_;
37 }
38
39 void SetRemainingRollbackTries(int v) override { rollback_tries_left_ = v; }
40
41 private:
42 int rollback_tries_left_;
43 };
44
45 class BackupRollbackControllerTest : public testing::Test {
46 public:
47 void ControllerCallback(bool start_backup) {
48 if (start_backup)
49 backup_started_ = true;
50 else
51 rollback_started_ = true;
52 }
53
54 protected:
55 void SetUp() override {
56 backup_started_ = false;
57 rollback_started_ = false;
58
59 EXPECT_CALL(signin_wrapper_, GetEffectiveUsername())
60 .WillRepeatedly(Return(""));
61
62 controller_.reset(new browser_sync::BackupRollbackController(
63 &fake_prefs_, &signin_wrapper_,
64 base::Bind(&BackupRollbackControllerTest::ControllerCallback,
65 base::Unretained(this), true),
66 base::Bind(&BackupRollbackControllerTest::ControllerCallback,
67 base::Unretained(this), false)));
68 }
69
70 void PumpLoop() {
71 base::RunLoop run_loop;
72 loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
73 run_loop.Run();
74 }
75
76 MockSigninManagerWrapper signin_wrapper_;
77 FakeSyncPrefs fake_prefs_;
78 scoped_ptr<browser_sync::BackupRollbackController> controller_;
79 bool backup_started_;
80 bool rollback_started_;
81 base::MessageLoop loop_;
82 };
83
84 TEST_F(BackupRollbackControllerTest, StartBackup) {
85 EXPECT_TRUE(controller_->StartBackup());
86 PumpLoop();
87 EXPECT_TRUE(backup_started_);
88 }
89
90 TEST_F(BackupRollbackControllerTest, NoBackupIfDisabled) {
91 base::CommandLine::ForCurrentProcess()->AppendSwitch(
92 switches::kSyncDisableBackup);
93
94 base::RunLoop run_loop;
95 EXPECT_FALSE(controller_->StartBackup());
96 loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
97 run_loop.Run();
98 EXPECT_FALSE(backup_started_);
99 }
100
101 TEST_F(BackupRollbackControllerTest, StartRollback) {
102 fake_prefs_.SetRemainingRollbackTries(1);
103
104 EXPECT_TRUE(controller_->StartRollback());
105 PumpLoop();
106 EXPECT_TRUE(rollback_started_);
107 EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries());
108 }
109
110 TEST_F(BackupRollbackControllerTest, NoRollbackIfOutOfTries) {
111 fake_prefs_.SetRemainingRollbackTries(0);
112
113 EXPECT_FALSE(controller_->StartRollback());
114 PumpLoop();
115 EXPECT_FALSE(rollback_started_);
116 }
117
118 TEST_F(BackupRollbackControllerTest, NoRollbackIfUserSignedIn) {
119 fake_prefs_.SetRemainingRollbackTries(1);
120 EXPECT_CALL(signin_wrapper_, GetEffectiveUsername())
121 .Times(1)
122 .WillOnce(Return("test"));
123 EXPECT_FALSE(controller_->StartRollback());
124 EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries());
125
126 PumpLoop();
127 EXPECT_FALSE(backup_started_);
128 EXPECT_FALSE(rollback_started_);
129 }
130
131 TEST_F(BackupRollbackControllerTest, NoRollbackIfDisabled) {
132 fake_prefs_.SetRemainingRollbackTries(1);
133
134 base::CommandLine::ForCurrentProcess()->AppendSwitch(
135 switches::kSyncDisableRollback);
136 EXPECT_FALSE(controller_->StartRollback());
137 EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries());
138
139 PumpLoop();
140 EXPECT_FALSE(rollback_started_);
141 }
142
143 #endif
144
145 } // anonymous namespace
146
OLDNEW
« no previous file with comments | « chrome/browser/sync/backup_rollback_controller.cc ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698