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

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

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check db on DB thread 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 | « chrome/browser/sync/profile_sync_service.cc ('k') | sync/internal_api/DEPS » ('j') | 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 "base/run_loop.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 10 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 11 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
11 #include "chrome/browser/sync/test/integration/preferences_helper.h" 12 #include "chrome/browser/sync/test/integration/preferences_helper.h"
12 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
13 #include "chrome/browser/sync/test/integration/sync_test.h" 14 #include "chrome/browser/sync/test/integration/sync_test.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "components/bookmarks/browser/bookmark_model.h" 17 #include "components/bookmarks/browser/bookmark_model.h"
18 #include "sync/internal_api/public/util/sync_db_util.h"
17 #include "sync/test/fake_server/fake_server_verifier.h" 19 #include "sync/test/fake_server/fake_server_verifier.h"
20 #include "sync/util/time.h"
18 21
19 using bookmarks_helper::AddFolder; 22 using bookmarks_helper::AddFolder;
20 using bookmarks_helper::AddURL; 23 using bookmarks_helper::AddURL;
21 using bookmarks_helper::GetOtherNode; 24 using bookmarks_helper::GetOtherNode;
22 using bookmarks_helper::ModelMatchesVerifier; 25 using bookmarks_helper::ModelMatchesVerifier;
23 using bookmarks_helper::Move; 26 using bookmarks_helper::Move;
24 using bookmarks_helper::Remove; 27 using bookmarks_helper::Remove;
25 using sync_integration_test_util::AwaitCommitActivityCompletion; 28 using sync_integration_test_util::AwaitCommitActivityCompletion;
26 29
27 namespace { 30 namespace {
(...skipping 10 matching lines...) Expand all
38 void DisableBackup() { 41 void DisableBackup() {
39 CommandLine::ForCurrentProcess()->AppendSwitch( 42 CommandLine::ForCurrentProcess()->AppendSwitch(
40 switches::kSyncDisableBackup); 43 switches::kSyncDisableBackup);
41 } 44 }
42 45
43 void EnableRollback() { 46 void EnableRollback() {
44 CommandLine::ForCurrentProcess()->AppendSwitch( 47 CommandLine::ForCurrentProcess()->AppendSwitch(
45 switches::kSyncEnableRollback); 48 switches::kSyncEnableRollback);
46 } 49 }
47 50
51 base::Time GetBackupDbLastModified() {
52 base::RunLoop run_loop;
53
54 base::Time backup_time;
55 syncer::CheckSyncDbLastModifiedTime(
56 GetProfile(0)->GetPath().Append(FILE_PATH_LITERAL("Sync Data Backup")),
57 base::MessageLoopProxy::current(),
58 base::Bind(&SingleClientBackupRollbackTest::CheckDbCallback,
59 base::Unretained(this), &backup_time));
60 base::MessageLoopProxy::current()->PostTask(
61 FROM_HERE, run_loop.QuitClosure());
62 run_loop.Run();
63 return backup_time;
64 }
65
48 private: 66 private:
67 void CheckDbCallback(base::Time* time_out, base::Time time_in) {
68 *time_out = syncer::ProtoTimeToTime(syncer::TimeToProtoTime(time_in));
69 }
70
49 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); 71 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest);
50 }; 72 };
51 73
52 class BackupModeChecker { 74 class BackupModeChecker {
53 public: 75 public:
54 explicit BackupModeChecker(ProfileSyncService* service, 76 explicit BackupModeChecker(ProfileSyncService* service,
55 base::TimeDelta timeout) 77 base::TimeDelta timeout)
56 : pss_(service), 78 : pss_(service),
57 timeout_(timeout) {} 79 timeout_(timeout) {}
58 80
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 GURL("http://mail.google.com"))); 203 GURL("http://mail.google.com")));
182 ASSERT_TRUE(AddURL(0, tier1_b, 0, "tier1_b_url0", 204 ASSERT_TRUE(AddURL(0, tier1_b, 0, "tier1_b_url0",
183 GURL("http://www.nhl.com"))); 205 GURL("http://www.nhl.com")));
184 206
185 BackupModeChecker checker(GetSyncService(0), 207 BackupModeChecker checker(GetSyncService(0),
186 base::TimeDelta::FromSeconds(15)); 208 base::TimeDelta::FromSeconds(15));
187 ASSERT_TRUE(checker.Wait()); 209 ASSERT_TRUE(checker.Wait());
188 210
189 // Setup sync, wait for its completion, and make sure changes were synced. 211 // Setup sync, wait for its completion, and make sure changes were synced.
190 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 212 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
191 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 213 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0)));
192 ASSERT_TRUE(ModelMatchesVerifier(0)); 214 ASSERT_TRUE(ModelMatchesVerifier(0));
193 215
194 // Made bookmark changes while sync is on. 216 // Made bookmark changes while sync is on.
195 Move(0, tier1_a->GetChild(0), tier1_b, 1); 217 Move(0, tier1_a->GetChild(0), tier1_b, 1);
196 Remove(0, tier1_b, 0); 218 Remove(0, tier1_b, 0);
197 ASSERT_TRUE(AddFolder(0, tier1_b, 1, "tier2_c")); 219 ASSERT_TRUE(AddFolder(0, tier1_b, 1, "tier2_c"));
198 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 220 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0)));
199 ASSERT_TRUE(ModelMatchesVerifier(0)); 221 ASSERT_TRUE(ModelMatchesVerifier(0));
200 222
223 // Verify backup time is set on device info.
224 base::Time backup_time = GetBackupDbLastModified();
225 ASSERT_FALSE(backup_time.is_null());
226 ASSERT_EQ(backup_time, GetSyncService(0)->GetDeviceBackupTimeForTesting());
227
201 // Let server to return rollback command on next sync request. 228 // Let server to return rollback command on next sync request.
202 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK); 229 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK);
203 230
204 // Make another change to trigger downloading of rollback command. 231 // Make another change to trigger downloading of rollback command.
205 Remove(0, tier1_b, 0); 232 Remove(0, tier1_b, 0);
206 233
207 // Wait for sync to switch to backup mode after finishing rollback. 234 // Wait for sync to switch to backup mode after finishing rollback.
208 ASSERT_TRUE(checker.Wait()); 235 ASSERT_TRUE(checker.Wait());
209 236
210 // Verify bookmarks are restored. 237 // Verify bookmarks are restored.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 GetSyncService(0)->StartStopBackupForTesting(); 358 GetSyncService(0)->StartStopBackupForTesting();
332 GetSyncService(0)->StartStopBackupForTesting(); 359 GetSyncService(0)->StartStopBackupForTesting();
333 ASSERT_TRUE(checker.Wait()); 360 ASSERT_TRUE(checker.Wait());
334 361
335 // Verify bookmarks are unchanged. 362 // Verify bookmarks are unchanged.
336 ASSERT_EQ(3, sub_folder->child_count()); 363 ASSERT_EQ(3, sub_folder->child_count());
337 ASSERT_EQ(GURL(kUrl1), sub_folder->GetChild(0)->url()); 364 ASSERT_EQ(GURL(kUrl1), sub_folder->GetChild(0)->url());
338 ASSERT_EQ(GURL(kUrl2), sub_folder->GetChild(1)->url()); 365 ASSERT_EQ(GURL(kUrl2), sub_folder->GetChild(1)->url());
339 ASSERT_EQ(GURL(kUrl3), sub_folder->GetChild(2)->url()); 366 ASSERT_EQ(GURL(kUrl3), sub_folder->GetChild(2)->url());
340 } 367 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | sync/internal_api/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698