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

Side by Side Diff: chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc

Issue 344193005: Add more integration tests for backup/rollback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
(...skipping 11 matching lines...) Expand all
22 using bookmarks_helper::ModelMatchesVerifier; 22 using bookmarks_helper::ModelMatchesVerifier;
23 using bookmarks_helper::Move; 23 using bookmarks_helper::Move;
24 using bookmarks_helper::Remove; 24 using bookmarks_helper::Remove;
25 using sync_integration_test_util::AwaitCommitActivityCompletion; 25 using sync_integration_test_util::AwaitCommitActivityCompletion;
26 26
27 class SingleClientBackupRollbackTest : public SyncTest { 27 class SingleClientBackupRollbackTest : public SyncTest {
28 public: 28 public:
29 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {} 29 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {}
30 virtual ~SingleClientBackupRollbackTest() {} 30 virtual ~SingleClientBackupRollbackTest() {}
31 31
32 virtual void SetUp() OVERRIDE { 32 void DisableBackup() {
33 CommandLine::ForCurrentProcess()->AppendSwitch(
34 switches::kSyncDisableBackup);
35 }
36
37 void EnableRollback() {
33 CommandLine::ForCurrentProcess()->AppendSwitch( 38 CommandLine::ForCurrentProcess()->AppendSwitch(
34 switches::kSyncEnableRollback); 39 switches::kSyncEnableRollback);
35 SyncTest::SetUp();
36 } 40 }
37 41
38 private: 42 private:
39 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); 43 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest);
40 }; 44 };
41 45
42 class BackupModeChecker { 46 class BackupModeChecker {
43 public: 47 public:
44 explicit BackupModeChecker(ProfileSyncService* service, 48 explicit BackupModeChecker(ProfileSyncService* service,
45 base::TimeDelta timeout) 49 base::TimeDelta timeout)
(...skipping 26 matching lines...) Expand all
72 return pss_->backend_mode() == ProfileSyncService::BACKUP && 76 return pss_->backend_mode() == ProfileSyncService::BACKUP &&
73 pss_->ShouldPushChanges(); 77 pss_->ShouldPushChanges();
74 } 78 }
75 79
76 ProfileSyncService* pss_; 80 ProfileSyncService* pss_;
77 base::TimeDelta timeout_; 81 base::TimeDelta timeout_;
78 base::TimeTicks expiration_; 82 base::TimeTicks expiration_;
79 }; 83 };
80 84
81 #if defined(ENABLE_PRE_SYNC_BACKUP) 85 #if defined(ENABLE_PRE_SYNC_BACKUP)
86 #define MAYBE_TestBackupDisabled TestBackupDisabled
87 #else
88 #define MAYBE_TestBackupDisabled DISABLED_TestBackupDisabled
89 #endif
90 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
91 MAYBE_TestBackupDisabled) {
92 DisableBackup();
93
94 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
95
96 BackupModeChecker checker(GetSyncService(0),
97 base::TimeDelta::FromSeconds(15));
98 ASSERT_FALSE(checker.Wait());
pval...(no longer on Chromium) 2014/06/28 00:12:00 does Wait() have to wait the entire timeout to eve
haitaol1 2014/07/01 16:49:36 Unfortunately yes because backup controller won't
99
100 ASSERT_EQ(ProfileSyncService::IDLE, GetSyncService(0)->backend_mode());
101 }
102
103 #if defined(ENABLE_PRE_SYNC_BACKUP)
104 #define MAYBE_TestBackupOnly TestBackupOnly
105 #else
106 #define MAYBE_TestBackupOnly DISABLED_TestBackupOnly
107 #endif
108 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
109 MAYBE_TestBackupOnly) {
110 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
111
112 // Starting state:
113 // other_node
114 // -> http://mail.google.com "url0"
115 // -> http://www.nhl.com "url1"
116 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "url0",
117 GURL("http://mail.google.com")));
118 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url1",
119 GURL("http://www.nhl.com")));
120
121 BackupModeChecker checker(GetSyncService(0),
122 base::TimeDelta::FromSeconds(15));
123 ASSERT_TRUE(checker.Wait());
124
125 // Setup sync, wait for its completion, and make sure changes were synced.
126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
127 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
128 ASSERT_TRUE(ModelMatchesVerifier(0));
129
130 // Made bookmark changes while sync is on.
131 Remove(0, GetOtherNode(0), 1);
132 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url2",
133 GURL("http://www.yahoo.com")));
134 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
135 ASSERT_TRUE(ModelMatchesVerifier(0));
136
137 // Let server to return rollback command on next sync request.
138 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK);
139
140 // Make another change to trigger downloading of rollback command.
141 Remove(0, GetOtherNode(0), 0);
pval...(no longer on Chromium) 2014/06/28 00:12:00 Is there another way we can trigger a sync that wo
haitaol1 2014/07/01 16:49:36 Can you point me to a sample to trigger invalidati
pval...(no longer on Chromium) 2014/07/02 18:10:59 Let's save it for another CL. Add a TODO here (in
142
143 // Wait for sync to switch to backup mode after finishing rollback.
pval...(no longer on Chromium) 2014/06/28 00:12:00 Update comment to reflect that a rollback isn't ac
haitaol1 2014/07/01 16:49:36 Done.
144 ASSERT_TRUE(checker.Wait());
145
146 // With rollback disabled, bookmarks in backup DB should not be restored.
147 // Only bookmark added during sync is present.
148 ASSERT_EQ(1, GetOtherNode(0)->child_count());
149 ASSERT_EQ(GURL("http://www.yahoo.com"),
150 GetOtherNode(0)->GetChild(0)->url());
151 }
152
153 #if defined(ENABLE_PRE_SYNC_BACKUP)
82 #define MAYBE_TestBackupRollback TestBackupRollback 154 #define MAYBE_TestBackupRollback TestBackupRollback
83 #else 155 #else
84 #define MAYBE_TestBackupRollback DISABLED_TestBackupRollback 156 #define MAYBE_TestBackupRollback DISABLED_TestBackupRollback
85 #endif 157 #endif
86 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, 158 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
87 MAYBE_TestBackupRollback) { 159 MAYBE_TestBackupRollback) {
160 EnableRollback();
161
88 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; 162 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
89 163
90 // Starting state: 164 // Starting state:
91 // other_node 165 // other_node
92 // -> top 166 // -> top
93 // -> tier1_a 167 // -> tier1_a
94 // -> http://mail.google.com "tier1_a_url0" 168 // -> http://mail.google.com "tier1_a_url0"
95 // -> tier1_b 169 // -> tier1_b
96 // -> http://www.nhl.com "tier1_b_url0" 170 // -> http://www.nhl.com "tier1_b_url0"
97 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, "top"); 171 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, "top");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 213
140 #if defined(ENABLE_PRE_SYNC_BACKUP) 214 #if defined(ENABLE_PRE_SYNC_BACKUP)
141 #define MAYBE_TestPrefBackupRollback TestPrefBackupRollback 215 #define MAYBE_TestPrefBackupRollback TestPrefBackupRollback
142 #else 216 #else
143 #define MAYBE_TestPrefBackupRollback DISABLED_TestPrefBackupRollback 217 #define MAYBE_TestPrefBackupRollback DISABLED_TestPrefBackupRollback
144 #endif 218 #endif
145 // Verify local preferences are not affected by preferences in backup DB under 219 // Verify local preferences are not affected by preferences in backup DB under
146 // backup mode. 220 // backup mode.
147 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, 221 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
148 MAYBE_TestPrefBackupRollback) { 222 MAYBE_TestPrefBackupRollback) {
223 EnableRollback();
224
149 const char kUrl1[] = "http://www.google.com"; 225 const char kUrl1[] = "http://www.google.com";
150 const char kUrl2[] = "http://map.google.com"; 226 const char kUrl2[] = "http://map.google.com";
151 const char kUrl3[] = "http://plus.google.com"; 227 const char kUrl3[] = "http://plus.google.com";
152 228
153 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; 229 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
154 230
155 preferences_helper::ChangeStringPref(0, prefs::kHomePage, kUrl1); 231 preferences_helper::ChangeStringPref(0, prefs::kHomePage, kUrl1);
156 232
157 BackupModeChecker checker(GetSyncService(0), 233 BackupModeChecker checker(GetSyncService(0),
158 base::TimeDelta::FromSeconds(15)); 234 base::TimeDelta::FromSeconds(15));
(...skipping 21 matching lines...) Expand all
180 // Make another change to trigger downloading of rollback command. 256 // Make another change to trigger downloading of rollback command.
181 preferences_helper::ChangeStringPref(0, prefs::kHomePage, ""); 257 preferences_helper::ChangeStringPref(0, prefs::kHomePage, "");
182 258
183 // Wait for sync to switch to backup mode after finishing rollback. 259 // Wait for sync to switch to backup mode after finishing rollback.
184 ASSERT_TRUE(checker.Wait()); 260 ASSERT_TRUE(checker.Wait());
185 261
186 // Verify preference is restored. 262 // Verify preference is restored.
187 ASSERT_EQ(kUrl2, 263 ASSERT_EQ(kUrl2,
188 preferences_helper::GetPrefs(0)->GetString(prefs::kHomePage)); 264 preferences_helper::GetPrefs(0)->GetString(prefs::kHomePage));
189 } 265 }
266
267 #if defined(ENABLE_PRE_SYNC_BACKUP)
268 #define MAYBE_RollbackNoBackup RollbackNoBackup
269 #else
270 #define MAYBE_RollbackNoBackup DISABLED_RollbackNoBackup
271 #endif
272 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
273 MAYBE_RollbackNoBackup) {
274 EnableRollback();
275
276 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
277
278 // Setup sync, wait for its completion, and make sure changes were synced.
279 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
280
281 // Starting state:
282 // other_node
283 // -> http://mail.google.com "url0"
284 // -> http://www.nhl.com "url1"
285 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "url0",
286 GURL("http://mail.google.com")));
287 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 1, "url1",
288 GURL("http://www.nhl.com")));
289
290 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
291 ASSERT_TRUE(ModelMatchesVerifier(0));
292
293 // Let server to return rollback command on next sync request.
294 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK);
295
296 // Make another change to trigger downloading of rollback command.
297 Remove(0, GetOtherNode(0), 0);
298
299 // Wait for sync to switch to backup mode after finishing rollback.
300 BackupModeChecker checker(GetSyncService(0),
301 base::TimeDelta::FromSeconds(15));
302 ASSERT_TRUE(checker.Wait());
303
304 // Without backup DB, bookmarks added during sync shouldn't be removed.
305 ASSERT_EQ(1, GetOtherNode(0)->child_count());
306 ASSERT_EQ(GURL("http://www.nhl.com"),
307 GetOtherNode(0)->GetChild(0)->url());
308 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698