Chromium Code Reviews| 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 "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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/sync/profile_sync_service.h" | 8 #include "chrome/browser/sync/profile_sync_service.h" |
| 9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 11 #include "chrome/browser/sync/test/integration/sync_test.h" | 11 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
| 14 #include "sync/internal_api/public/util/sync_db_util.h" | |
| 14 #include "sync/test/fake_server/fake_server_verifier.h" | 15 #include "sync/test/fake_server/fake_server_verifier.h" |
| 15 | 16 |
| 16 using bookmarks_helper::AddFolder; | 17 using bookmarks_helper::AddFolder; |
| 17 using bookmarks_helper::AddURL; | 18 using bookmarks_helper::AddURL; |
| 18 using bookmarks_helper::GetOtherNode; | 19 using bookmarks_helper::GetOtherNode; |
| 19 using bookmarks_helper::ModelMatchesVerifier; | 20 using bookmarks_helper::ModelMatchesVerifier; |
| 20 using bookmarks_helper::Move; | 21 using bookmarks_helper::Move; |
| 21 using bookmarks_helper::Remove; | 22 using bookmarks_helper::Remove; |
| 22 using sync_integration_test_util::AwaitCommitActivityCompletion; | 23 using sync_integration_test_util::AwaitCommitActivityCompletion; |
| 23 | 24 |
| 24 class SingleClientBackupRollbackTest : public SyncTest { | 25 class SingleClientBackupRollbackTest : public SyncTest { |
| 25 public: | 26 public: |
| 26 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {} | 27 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {} |
| 27 virtual ~SingleClientBackupRollbackTest() {} | 28 virtual ~SingleClientBackupRollbackTest() {} |
| 28 | 29 |
| 29 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
| 30 CommandLine::ForCurrentProcess()->AppendSwitch( | 31 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 31 switches::kSyncEnableRollback); | 32 switches::kSyncEnableRollback); |
| 32 SyncTest::SetUp(); | 33 SyncTest::SetUp(); |
| 33 } | 34 } |
| 34 | 35 |
| 36 base::Time GetBackupDbLastModified() { | |
| 37 base::Time backup_time; | |
| 38 syncer::CheckSyncDbLastModifiedTime( | |
| 39 GetProfile(0)->GetPath().Append(FILE_PATH_LITERAL("Sync Data Backup")), | |
| 40 base::MessageLoopProxy::current(), | |
| 41 base::Bind(&SingleClientBackupRollbackTest::CheckDbCallback, | |
| 42 base::Unretained(this), &backup_time)); | |
| 43 base::MessageLoop::current()->Run(); | |
|
Nicolas Zea
2014/06/13 22:36:41
Run is deprecated, RunLoops should be used instead
haitaol1
2014/06/13 23:28:25
Done.
| |
| 44 return backup_time; | |
| 45 } | |
| 46 | |
| 35 private: | 47 private: |
| 48 void CheckDbCallback(base::Time* time_out, base::Time time_in) { | |
|
Nicolas Zea
2014/06/13 22:36:41
nit: output params should be ordered after input o
haitaol1
2014/06/13 23:28:25
time_out is provided at binding time while time_in
| |
| 49 *time_out = time_in; | |
| 50 base::MessageLoop::current()->Quit(); | |
| 51 } | |
| 52 | |
| 36 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); | 53 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); |
| 37 }; | 54 }; |
| 38 | 55 |
| 39 class BackupModeChecker { | 56 class BackupModeChecker { |
| 40 public: | 57 public: |
| 41 explicit BackupModeChecker(ProfileSyncService* service, | 58 explicit BackupModeChecker(ProfileSyncService* service, |
| 42 base::TimeDelta timeout) | 59 base::TimeDelta timeout) |
| 43 : pss_(service), | 60 : pss_(service), |
| 44 expiration_(base::TimeTicks::Now() + timeout) {} | 61 expiration_(base::TimeTicks::Now() + timeout) {} |
| 45 | 62 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 GURL("http://mail.google.com"))); | 113 GURL("http://mail.google.com"))); |
| 97 ASSERT_TRUE(AddURL(0, tier1_b, 0, "tier1_b_url0", | 114 ASSERT_TRUE(AddURL(0, tier1_b, 0, "tier1_b_url0", |
| 98 GURL("http://www.nhl.com"))); | 115 GURL("http://www.nhl.com"))); |
| 99 | 116 |
| 100 BackupModeChecker checker(GetSyncService(0), | 117 BackupModeChecker checker(GetSyncService(0), |
| 101 base::TimeDelta::FromSeconds(15)); | 118 base::TimeDelta::FromSeconds(15)); |
| 102 ASSERT_TRUE(checker.Wait()); | 119 ASSERT_TRUE(checker.Wait()); |
| 103 | 120 |
| 104 // Setup sync, wait for its completion, and make sure changes were synced. | 121 // Setup sync, wait for its completion, and make sure changes were synced. |
| 105 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 122 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 106 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 123 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); |
| 107 ASSERT_TRUE(ModelMatchesVerifier(0)); | 124 ASSERT_TRUE(ModelMatchesVerifier(0)); |
| 108 | 125 |
| 109 // Made bookmark changes while sync is on. | 126 // Made bookmark changes while sync is on. |
| 110 Move(0, tier1_a->GetChild(0), tier1_b, 1); | 127 Move(0, tier1_a->GetChild(0), tier1_b, 1); |
| 111 Remove(0, tier1_b, 0); | 128 Remove(0, tier1_b, 0); |
| 112 ASSERT_TRUE(AddFolder(0, tier1_b, 1, "tier2_c")); | 129 ASSERT_TRUE(AddFolder(0, tier1_b, 1, "tier2_c")); |
| 113 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 130 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); |
| 114 ASSERT_TRUE(ModelMatchesVerifier(0)); | 131 ASSERT_TRUE(ModelMatchesVerifier(0)); |
| 115 | 132 |
| 133 // Verify backup time is set on device info. | |
| 134 base::Time backup_time = GetBackupDbLastModified(); | |
| 135 ASSERT_FALSE(backup_time.is_null()); | |
| 136 ASSERT_EQ(backup_time, GetSyncService(0)->GetDeviceBackupTimeForTesting()); | |
| 137 | |
| 116 // Let server to return rollback command on next sync request. | 138 // Let server to return rollback command on next sync request. |
| 117 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK); | 139 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK); |
| 118 | 140 |
| 119 // Make another change to trigger downloading of rollback command. | 141 // Make another change to trigger downloading of rollback command. |
| 120 Remove(0, tier1_b, 0); | 142 Remove(0, tier1_b, 0); |
| 121 | 143 |
| 122 // Wait for sync to switch to backup mode after finishing rollback. | 144 // Wait for sync to switch to backup mode after finishing rollback. |
| 123 ASSERT_TRUE(checker.Wait()); | 145 ASSERT_TRUE(checker.Wait()); |
| 124 | 146 |
| 125 // Verify bookmarks are restored. | 147 // Verify bookmarks are restored. |
| 126 ASSERT_EQ(1, tier1_a->child_count()); | 148 ASSERT_EQ(1, tier1_a->child_count()); |
| 127 const BookmarkNode* url1 = tier1_a->GetChild(0); | 149 const BookmarkNode* url1 = tier1_a->GetChild(0); |
| 128 ASSERT_EQ(GURL("http://mail.google.com"), url1->url()); | 150 ASSERT_EQ(GURL("http://mail.google.com"), url1->url()); |
| 129 | 151 |
| 130 ASSERT_EQ(1, tier1_b->child_count()); | 152 ASSERT_EQ(1, tier1_b->child_count()); |
| 131 const BookmarkNode* url2 = tier1_b->GetChild(0); | 153 const BookmarkNode* url2 = tier1_b->GetChild(0); |
| 132 ASSERT_EQ(GURL("http://www.nhl.com"), url2->url()); | 154 ASSERT_EQ(GURL("http://www.nhl.com"), url2->url()); |
| 133 } | 155 } |
| OLD | NEW |