OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile.h" | |
6 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
7 #include "chrome/browser/sync/test/live_sync/bookmarks_helper.h" | |
8 #include "chrome/browser/sync/test/live_sync/live_sync_test.h" | |
9 | |
10 using bookmarks_helper::AddFolder; | |
11 using bookmarks_helper::AddURL; | |
12 using bookmarks_helper::GetBookmarkBarNode; | |
13 using bookmarks_helper::GetOtherNode; | |
14 using bookmarks_helper::ModelMatchesVerifier; | |
15 using bookmarks_helper::Move; | |
16 using bookmarks_helper::Remove; | |
17 using bookmarks_helper::SetTitle; | |
18 | |
19 class SingleClientBookmarksSyncTest : public LiveSyncTest { | |
20 public: | |
21 SingleClientBookmarksSyncTest() : LiveSyncTest(SINGLE_CLIENT) {} | |
22 virtual ~SingleClientBookmarksSyncTest() {} | |
23 | |
24 private: | |
25 DISALLOW_COPY_AND_ASSIGN(SingleClientBookmarksSyncTest); | |
26 }; | |
27 | |
28 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OfflineToOnline) { | |
29 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
30 | |
31 DisableNetwork(GetProfile(0)); | |
32 const BookmarkNode* node = AddFolder(0, L"title"); | |
33 SetTitle(0, node, L"new_title"); | |
34 ASSERT_FALSE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change.")); | |
35 ASSERT_EQ(ProfileSyncService::Status::OFFLINE_UNSYNCED, | |
36 GetClient(0)->GetStatus().summary); | |
37 | |
38 EnableNetwork(GetProfile(0)); | |
39 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Commit changes.")); | |
40 ASSERT_EQ(ProfileSyncService::Status::READY, | |
41 GetClient(0)->GetStatus().summary); | |
42 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
43 } | |
44 | |
45 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { | |
46 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
47 | |
48 // Starting state: | |
49 // other_node | |
50 // -> top | |
51 // -> tier1_a | |
52 // -> http://mail.google.com "tier1_a_url0" | |
53 // -> http://www.pandora.com "tier1_a_url1" | |
54 // -> http://www.facebook.com "tier1_a_url2" | |
55 // -> tier1_b | |
56 // -> http://www.nhl.com "tier1_b_url0" | |
57 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, L"top"); | |
58 const BookmarkNode* tier1_a = AddFolder(0, top, 0, L"tier1_a"); | |
59 const BookmarkNode* tier1_b = AddFolder(0, top, 1, L"tier1_b"); | |
60 const BookmarkNode* tier1_a_url0 = AddURL( | |
61 0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com")); | |
62 const BookmarkNode* tier1_a_url1 = AddURL( | |
63 0, tier1_a, 1, L"tier1_a_url1", GURL("http://www.pandora.com")); | |
64 const BookmarkNode* tier1_a_url2 = AddURL( | |
65 0, tier1_a, 2, L"tier1_a_url2", GURL("http://www.facebook.com")); | |
66 const BookmarkNode* tier1_b_url0 = AddURL( | |
67 0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com")); | |
68 | |
69 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
70 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( | |
71 "Waiting for initial sync completed.")); | |
72 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
73 | |
74 // Ultimately we want to end up with the following model; but this test is | |
75 // more about the journey than the destination. | |
76 // | |
77 // bookmark_bar | |
78 // -> CNN (www.cnn.com) | |
79 // -> tier1_a | |
80 // -> tier1_a_url2 (www.facebook.com) | |
81 // -> tier1_a_url1 (www.pandora.com) | |
82 // -> Porsche (www.porsche.com) | |
83 // -> Bank of America (www.bankofamerica.com) | |
84 // -> Seattle Bubble | |
85 // other_node | |
86 // -> top | |
87 // -> tier1_b | |
88 // -> Wired News (www.wired.com) | |
89 // -> tier2_b | |
90 // -> tier1_b_url0 | |
91 // -> tier3_b | |
92 // -> Toronto Maple Leafs (mapleleafs.nhl.com) | |
93 // -> Wynn (www.wynnlasvegas.com) | |
94 // -> tier1_a_url0 | |
95 const BookmarkNode* bar = GetBookmarkBarNode(0); | |
96 const BookmarkNode* cnn = AddURL(0, bar, 0, L"CNN", | |
97 GURL("http://www.cnn.com")); | |
98 ASSERT_TRUE(cnn != NULL); | |
99 Move(0, tier1_a, bar, 1); | |
100 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Bookmark moved.")); | |
101 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
102 | |
103 const BookmarkNode* porsche = AddURL(0, bar, 2, L"Porsche", | |
104 GURL("http://www.porsche.com")); | |
105 // Rearrange stuff in tier1_a. | |
106 ASSERT_EQ(tier1_a, tier1_a_url2->parent()); | |
107 ASSERT_EQ(tier1_a, tier1_a_url1->parent()); | |
108 Move(0, tier1_a_url2, tier1_a, 0); | |
109 Move(0, tier1_a_url1, tier1_a, 2); | |
110 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( | |
111 "Rearrange stuff in tier1_a")); | |
112 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
113 | |
114 ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0)); | |
115 Move(0, tier1_a_url0, bar, bar->child_count()); | |
116 const BookmarkNode* boa = AddURL(0, bar, bar->child_count(), | |
117 L"Bank of America", GURL("https://www.bankofamerica.com")); | |
118 ASSERT_TRUE(boa != NULL); | |
119 Move(0, tier1_a_url0, top, top->child_count()); | |
120 const BookmarkNode* bubble = AddURL( | |
121 0, bar, bar->child_count(), L"Seattle Bubble", | |
122 GURL("http://seattlebubble.com")); | |
123 ASSERT_TRUE(bubble != NULL); | |
124 const BookmarkNode* wired = AddURL(0, bar, 2, L"Wired News", | |
125 GURL("http://www.wired.com")); | |
126 const BookmarkNode* tier2_b = AddFolder( | |
127 0, tier1_b, 0, L"tier2_b"); | |
128 Move(0, tier1_b_url0, tier2_b, 0); | |
129 Move(0, porsche, bar, 0); | |
130 SetTitle(0, wired, L"News Wired"); | |
131 SetTitle(0, porsche, L"ICanHazPorsche?"); | |
132 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Change title.")); | |
133 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
134 | |
135 ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id()); | |
136 Remove(0, top, top->child_count() - 1); | |
137 Move(0, wired, tier1_b, 0); | |
138 Move(0, porsche, bar, 3); | |
139 const BookmarkNode* tier3_b = AddFolder(0, tier2_b, 1, L"tier3_b"); | |
140 const BookmarkNode* leafs = AddURL( | |
141 0, tier1_a, 0, L"Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com")); | |
142 const BookmarkNode* wynn = AddURL(0, bar, 1, L"Wynn", | |
143 GURL("http://www.wynnlasvegas.com")); | |
144 | |
145 Move(0, wynn, tier3_b, 0); | |
146 Move(0, leafs, tier3_b, 0); | |
147 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion( | |
148 "Move after addition of bookmarks.")); | |
149 ASSERT_TRUE(ModelMatchesVerifier(0)); | |
150 } | |
OLD | NEW |