Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "base/command_line.h" | |
| 6 #include "base/message_loop/message_loop.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/sync/profile_sync_service.h" | |
| 9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | |
| 10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | |
| 11 #include "chrome/browser/sync/test/integration/sync_test.h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "components/bookmarks/browser/bookmark_model.h" | |
| 14 #include "sync/test/fake_server/fake_server_verifier.h" | |
| 15 | |
| 16 using bookmarks_helper::AddFolder; | |
| 17 using bookmarks_helper::AddURL; | |
| 18 using bookmarks_helper::GetOtherNode; | |
| 19 using bookmarks_helper::ModelMatchesVerifier; | |
| 20 using bookmarks_helper::Move; | |
| 21 using bookmarks_helper::Remove; | |
| 22 using sync_integration_test_util::AwaitCommitActivityCompletion; | |
| 23 | |
| 24 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_C HROMEOS)) | |
|
pval...(no longer on Chromium)
2014/06/03 22:08:18
I think conditionally disabling the test on Chrome
rlarocque
2014/06/03 22:59:48
It would be even better if you could disable only
haitaol1
2014/06/04 18:21:30
Done.
haitaol1
2014/06/04 18:21:30
Done.
| |
| 25 | |
| 26 class SingleClientBackupRollbackTest : public SyncTest { | |
| 27 public: | |
| 28 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {} | |
| 29 virtual ~SingleClientBackupRollbackTest() {} | |
| 30 | |
| 31 virtual void SetUp() OVERRIDE { | |
| 32 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 33 switches::kSyncEnableBackupRollback); | |
| 34 SyncTest::SetUp(); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest); | |
| 39 }; | |
| 40 | |
| 41 class BackupModeChecker { | |
|
rlarocque
2014/06/03 22:59:48
I think there are better ways to test than this.
haitaol1
2014/06/04 18:21:30
The exit condition here is not bookmark change. I
| |
| 42 public: | |
| 43 explicit BackupModeChecker(ProfileSyncService* service, | |
| 44 base::TimeDelta timeout) | |
| 45 : pss_(service), | |
| 46 expiration_(base::TimeTicks::Now() + timeout) {} | |
| 47 | |
| 48 bool Wait() { | |
| 49 base::MessageLoop::current()->PostDelayedTask( | |
| 50 FROM_HERE, | |
| 51 base::Bind(&BackupModeChecker::PeriodicCheck, base::Unretained(this)), | |
| 52 base::TimeDelta::FromSeconds(1)); | |
| 53 base::MessageLoop::current()->Run(); | |
| 54 return IsBackupComplete(); | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 void PeriodicCheck() { | |
| 59 if (IsBackupComplete() || base::TimeTicks::Now() > expiration_) { | |
| 60 base::MessageLoop::current()->Quit(); | |
| 61 } else { | |
| 62 base::MessageLoop::current()->PostDelayedTask( | |
| 63 FROM_HERE, | |
| 64 base::Bind(&BackupModeChecker::PeriodicCheck, base::Unretained(this)), | |
| 65 base::TimeDelta::FromSeconds(1)); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 bool IsBackupComplete() { | |
| 70 return pss_->backend_mode() == ProfileSyncService::BACKUP && | |
|
pval...(no longer on Chromium)
2014/06/03 22:08:18
Richard knows more about verifying client state th
haitaol1
2014/06/04 18:21:30
Yes, Richard pointed to an existing funciton.
On
| |
| 71 pss_->is_syncing(); | |
|
pval...(no longer on Chromium)
2014/06/03 22:08:18
Based on the changes to PSS in this CL, doesn't ps
haitaol1
2014/06/04 18:21:30
Backup is a continuous process as long as user's n
| |
| 72 } | |
| 73 | |
| 74 ProfileSyncService* pss_; | |
| 75 base::TimeTicks expiration_; | |
| 76 }; | |
| 77 | |
| 78 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest, Sanity) { | |
| 79 logging::SetMinLogLevel(-1); | |
|
rlarocque
2014/06/04 18:30:29
Remove this before commit?
| |
| 80 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
| 81 | |
| 82 // Starting state: | |
| 83 // other_node | |
| 84 // -> top | |
| 85 // -> tier1_a | |
| 86 // -> http://mail.google.com "tier1_a_url0" | |
| 87 // -> tier1_b | |
| 88 // -> http://www.nhl.com "tier1_b_url0" | |
| 89 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, L"top"); | |
| 90 const BookmarkNode* tier1_a = AddFolder(0, top, 0, L"tier1_a"); | |
| 91 const BookmarkNode* tier1_b = AddFolder(0, top, 1, L"tier1_b"); | |
| 92 AddURL(0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com")); | |
| 93 AddURL(0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com")); | |
| 94 | |
| 95 BackupModeChecker checker(GetSyncService(0), | |
| 96 base::TimeDelta::FromSeconds(15)); | |
| 97 ASSERT_TRUE(checker.Wait()); | |
|
pval...(no longer on Chromium)
2014/06/03 22:08:18
Why wait for the checker here? As far as I can tel
haitaol1
2014/06/04 18:21:30
To make sure backup is finished in order to set ro
rlarocque
2014/06/04 18:30:29
In the real world, outside of tests, what would st
| |
| 98 | |
| 99 // Setup sync, wait for its completion, and make sure changes were synced. | |
| 100 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 101 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | |
| 102 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
| 103 | |
| 104 // Made bookmark changes while sync is on. | |
| 105 Move(0, tier1_a->GetChild(0), tier1_b, 1); | |
| 106 Remove(0, tier1_b, 0); | |
| 107 AddFolder(0, tier1_b, 1, L"tier2_c"); | |
| 108 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | |
| 109 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
| 110 | |
| 111 // Let server to return rolllback command on next sync request. | |
| 112 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK); | |
| 113 | |
| 114 // Make another change to trigger downloading of rollback command. | |
| 115 Remove(0, tier1_b, 0); | |
| 116 | |
| 117 // Wait for sync to switch to backup mode after finishing rollback. | |
| 118 ASSERT_TRUE(checker.Wait()); | |
| 119 | |
| 120 // Verify bookmarks are restored. | |
| 121 ASSERT_EQ(1, tier1_a->child_count()); | |
| 122 const BookmarkNode* url1 = tier1_a->GetChild(0); | |
| 123 ASSERT_EQ(GURL("http://mail.google.com"), url1->url()); | |
| 124 | |
| 125 ASSERT_EQ(1, tier1_b->child_count()); | |
| 126 const BookmarkNode* url2 = tier1_b->GetChild(0); | |
| 127 ASSERT_EQ(GURL("http://www.nhl.com"), url2->url()); | |
| 128 } | |
| 129 | |
| 130 #endif | |
| OLD | NEW |