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

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

Issue 310103004: Add integraton test for sync backup/rollback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 class SingleClientBackupRollbackTest : public SyncTest {
25 public:
26 SingleClientBackupRollbackTest() : SyncTest(SINGLE_CLIENT) {}
27 virtual ~SingleClientBackupRollbackTest() {}
28
29 virtual void SetUp() OVERRIDE {
30 CommandLine::ForCurrentProcess()->AppendSwitch(
31 switches::kSyncEnableBackupRollback);
32 SyncTest::SetUp();
33 }
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(SingleClientBackupRollbackTest);
37 };
38
39 class BackupModeChecker {
40 public:
41 explicit BackupModeChecker(ProfileSyncService* service,
42 base::TimeDelta timeout)
43 : pss_(service),
44 expiration_(base::TimeTicks::Now() + timeout) {}
45
46 bool Wait() {
47 base::MessageLoop::current()->PostDelayedTask(
48 FROM_HERE,
49 base::Bind(&BackupModeChecker::PeriodicCheck, base::Unretained(this)),
50 base::TimeDelta::FromSeconds(1));
51 base::MessageLoop::current()->Run();
52 return IsBackupComplete();
53 }
54
55 private:
56 void PeriodicCheck() {
57 if (IsBackupComplete() || base::TimeTicks::Now() > expiration_) {
58 base::MessageLoop::current()->Quit();
59 } else {
60 base::MessageLoop::current()->PostDelayedTask(
61 FROM_HERE,
62 base::Bind(&BackupModeChecker::PeriodicCheck, base::Unretained(this)),
63 base::TimeDelta::FromSeconds(1));
64 }
65 }
66
67 bool IsBackupComplete() {
68 return pss_->backend_mode() == ProfileSyncService::BACKUP &&
69 pss_->ShouldPushChanges();
70 }
71
72 ProfileSyncService* pss_;
73 base::TimeTicks expiration_;
74 };
75
76 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_C HROMEOS))
77 #define MAYBE_TestBackupRollback TestBackupRollback
78 #else
79 #define MAYBE_TestBackupRollback DISABLED_TestBackupRollback
80 #endif
81 IN_PROC_BROWSER_TEST_F(SingleClientBackupRollbackTest,
82 MAYBE_TestBackupRollback) {
83 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
84
85 // Starting state:
86 // other_node
87 // -> top
88 // -> tier1_a
89 // -> http://mail.google.com "tier1_a_url0"
90 // -> tier1_b
91 // -> http://www.nhl.com "tier1_b_url0"
92 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, L"top");
93 const BookmarkNode* tier1_a = AddFolder(0, top, 0, L"tier1_a");
94 const BookmarkNode* tier1_b = AddFolder(0, top, 1, L"tier1_b");
95 AddURL(0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com"));
96 AddURL(0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com"));
97
98 BackupModeChecker checker(GetSyncService(0),
99 base::TimeDelta::FromSeconds(15));
100 ASSERT_TRUE(checker.Wait());
101
102 // Setup sync, wait for its completion, and make sure changes were synced.
103 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
104 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
105 ASSERT_TRUE(ModelMatchesVerifier(0));
106
107 // Made bookmark changes while sync is on.
108 Move(0, tier1_a->GetChild(0), tier1_b, 1);
109 Remove(0, tier1_b, 0);
110 AddFolder(0, tier1_b, 1, L"tier2_c");
111 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
112 ASSERT_TRUE(ModelMatchesVerifier(0));
113
114 // Let server to return rolllback command on next sync request.
rlarocque 2014/06/04 22:54:07 s/rolllback/rollback
haitaol1 2014/06/05 17:44:11 Done.
115 GetFakeServer()->TriggerError(sync_pb::SyncEnums::USER_ROLLBACK);
116
117 // Make another change to trigger downloading of rollback command.
118 Remove(0, tier1_b, 0);
119
120 // Wait for sync to switch to backup mode after finishing rollback.
121 ASSERT_TRUE(checker.Wait());
122
123 // Verify bookmarks are restored.
124 ASSERT_EQ(1, tier1_a->child_count());
125 const BookmarkNode* url1 = tier1_a->GetChild(0);
126 ASSERT_EQ(GURL("http://mail.google.com"), url1->url());
127
128 ASSERT_EQ(1, tier1_b->child_count());
129 const BookmarkNode* url2 = tier1_b->GetChild(0);
130 ASSERT_EQ(GURL("http://www.nhl.com"), url2->url());
131 }
rlarocque 2014/06/04 22:54:07 Verify tier2_c is not present?
haitaol1 2014/06/05 17:44:11 It's verified because tier1_b only has one child f
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698