OLD | NEW |
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 "chrome/browser/sync/backup_rollback_controller.h" | 5 #include "chrome/browser/sync/backup_rollback_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" |
11 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 12 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "components/sync_driver/sync_prefs.h" | 14 #include "components/sync_driver/sync_prefs.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using ::testing::Return; | 18 using ::testing::Return; |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 controller_.reset(new browser_sync::BackupRollbackController( | 62 controller_.reset(new browser_sync::BackupRollbackController( |
62 &fake_prefs_, &signin_wrapper_, | 63 &fake_prefs_, &signin_wrapper_, |
63 base::Bind(&BackupRollbackControllerTest::ControllerCallback, | 64 base::Bind(&BackupRollbackControllerTest::ControllerCallback, |
64 base::Unretained(this), true), | 65 base::Unretained(this), true), |
65 base::Bind(&BackupRollbackControllerTest::ControllerCallback, | 66 base::Bind(&BackupRollbackControllerTest::ControllerCallback, |
66 base::Unretained(this), false))); | 67 base::Unretained(this), false))); |
67 } | 68 } |
68 | 69 |
69 void PumpLoop() { | 70 void PumpLoop() { |
70 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
71 loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); | 72 loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
72 run_loop.Run(); | 73 run_loop.Run(); |
73 } | 74 } |
74 | 75 |
75 MockSigninManagerWrapper signin_wrapper_; | 76 MockSigninManagerWrapper signin_wrapper_; |
76 FakeSyncPrefs fake_prefs_; | 77 FakeSyncPrefs fake_prefs_; |
77 scoped_ptr<browser_sync::BackupRollbackController> controller_; | 78 scoped_ptr<browser_sync::BackupRollbackController> controller_; |
78 bool backup_started_; | 79 bool backup_started_; |
79 bool rollback_started_; | 80 bool rollback_started_; |
80 base::MessageLoop loop_; | 81 base::MessageLoop loop_; |
81 }; | 82 }; |
82 | 83 |
83 TEST_F(BackupRollbackControllerTest, StartBackup) { | 84 TEST_F(BackupRollbackControllerTest, StartBackup) { |
84 EXPECT_TRUE(controller_->StartBackup()); | 85 EXPECT_TRUE(controller_->StartBackup()); |
85 PumpLoop(); | 86 PumpLoop(); |
86 EXPECT_TRUE(backup_started_); | 87 EXPECT_TRUE(backup_started_); |
87 } | 88 } |
88 | 89 |
89 TEST_F(BackupRollbackControllerTest, NoBackupIfDisabled) { | 90 TEST_F(BackupRollbackControllerTest, NoBackupIfDisabled) { |
90 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 91 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
91 switches::kSyncDisableBackup); | 92 switches::kSyncDisableBackup); |
92 | 93 |
93 base::RunLoop run_loop; | 94 base::RunLoop run_loop; |
94 EXPECT_FALSE(controller_->StartBackup()); | 95 EXPECT_FALSE(controller_->StartBackup()); |
95 loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); | 96 loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
96 run_loop.Run(); | 97 run_loop.Run(); |
97 EXPECT_FALSE(backup_started_); | 98 EXPECT_FALSE(backup_started_); |
98 } | 99 } |
99 | 100 |
100 TEST_F(BackupRollbackControllerTest, StartRollback) { | 101 TEST_F(BackupRollbackControllerTest, StartRollback) { |
101 fake_prefs_.SetRemainingRollbackTries(1); | 102 fake_prefs_.SetRemainingRollbackTries(1); |
102 | 103 |
103 EXPECT_TRUE(controller_->StartRollback()); | 104 EXPECT_TRUE(controller_->StartRollback()); |
104 PumpLoop(); | 105 PumpLoop(); |
105 EXPECT_TRUE(rollback_started_); | 106 EXPECT_TRUE(rollback_started_); |
(...skipping 30 matching lines...) Expand all Loading... |
136 EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries()); | 137 EXPECT_EQ(0, fake_prefs_.GetRemainingRollbackTries()); |
137 | 138 |
138 PumpLoop(); | 139 PumpLoop(); |
139 EXPECT_FALSE(rollback_started_); | 140 EXPECT_FALSE(rollback_started_); |
140 } | 141 } |
141 | 142 |
142 #endif | 143 #endif |
143 | 144 |
144 } // anonymous namespace | 145 } // anonymous namespace |
145 | 146 |
OLD | NEW |