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

Side by Side Diff: chrome/browser/sync/test/integration/single_client_bookmarks_sync_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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/sync/profile_sync_service.h" 7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h" 10 #include "chrome/browser/sync/test/integration/sync_test.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 // Starting state: 72 // Starting state:
73 // other_node 73 // other_node
74 // -> top 74 // -> top
75 // -> tier1_a 75 // -> tier1_a
76 // -> http://mail.google.com "tier1_a_url0" 76 // -> http://mail.google.com "tier1_a_url0"
77 // -> http://www.pandora.com "tier1_a_url1" 77 // -> http://www.pandora.com "tier1_a_url1"
78 // -> http://www.facebook.com "tier1_a_url2" 78 // -> http://www.facebook.com "tier1_a_url2"
79 // -> tier1_b 79 // -> tier1_b
80 // -> http://www.nhl.com "tier1_b_url0" 80 // -> http://www.nhl.com "tier1_b_url0"
81 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, L"top"); 81 const BookmarkNode* top = AddFolder(0, GetOtherNode(0), 0, "top");
82 const BookmarkNode* tier1_a = AddFolder(0, top, 0, L"tier1_a"); 82 const BookmarkNode* tier1_a = AddFolder(0, top, 0, "tier1_a");
83 const BookmarkNode* tier1_b = AddFolder(0, top, 1, L"tier1_b"); 83 const BookmarkNode* tier1_b = AddFolder(0, top, 1, "tier1_b");
84 const BookmarkNode* tier1_a_url0 = AddURL( 84 const BookmarkNode* tier1_a_url0 = AddURL(
85 0, tier1_a, 0, L"tier1_a_url0", GURL("http://mail.google.com")); 85 0, tier1_a, 0, "tier1_a_url0", GURL("http://mail.google.com"));
86 const BookmarkNode* tier1_a_url1 = AddURL( 86 const BookmarkNode* tier1_a_url1 = AddURL(
87 0, tier1_a, 1, L"tier1_a_url1", GURL("http://www.pandora.com")); 87 0, tier1_a, 1, "tier1_a_url1", GURL("http://www.pandora.com"));
88 const BookmarkNode* tier1_a_url2 = AddURL( 88 const BookmarkNode* tier1_a_url2 = AddURL(
89 0, tier1_a, 2, L"tier1_a_url2", GURL("http://www.facebook.com")); 89 0, tier1_a, 2, "tier1_a_url2", GURL("http://www.facebook.com"));
90 const BookmarkNode* tier1_b_url0 = AddURL( 90 const BookmarkNode* tier1_b_url0 = AddURL(
91 0, tier1_b, 0, L"tier1_b_url0", GURL("http://www.nhl.com")); 91 0, tier1_b, 0, "tier1_b_url0", GURL("http://www.nhl.com"));
92 92
93 // Setup sync, wait for its completion, and make sure changes were synced. 93 // Setup sync, wait for its completion, and make sure changes were synced.
94 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 94 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
95 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 95 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
96 ASSERT_TRUE(ModelMatchesVerifier(0)); 96 ASSERT_TRUE(ModelMatchesVerifier(0));
97 97
98 // Ultimately we want to end up with the following model; but this test is 98 // Ultimately we want to end up with the following model; but this test is
99 // more about the journey than the destination. 99 // more about the journey than the destination.
100 // 100 //
101 // bookmark_bar 101 // bookmark_bar
102 // -> CNN (www.cnn.com) 102 // -> CNN (www.cnn.com)
103 // -> tier1_a 103 // -> tier1_a
104 // -> tier1_a_url2 (www.facebook.com) 104 // -> tier1_a_url2 (www.facebook.com)
105 // -> tier1_a_url1 (www.pandora.com) 105 // -> tier1_a_url1 (www.pandora.com)
106 // -> Porsche (www.porsche.com) 106 // -> Porsche (www.porsche.com)
107 // -> Bank of America (www.bankofamerica.com) 107 // -> Bank of America (www.bankofamerica.com)
108 // -> Seattle Bubble 108 // -> Seattle Bubble
109 // other_node 109 // other_node
110 // -> top 110 // -> top
111 // -> tier1_b 111 // -> tier1_b
112 // -> Wired News (www.wired.com) 112 // -> Wired News (www.wired.com)
113 // -> tier2_b 113 // -> tier2_b
114 // -> tier1_b_url0 114 // -> tier1_b_url0
115 // -> tier3_b 115 // -> tier3_b
116 // -> Toronto Maple Leafs (mapleleafs.nhl.com) 116 // -> Toronto Maple Leafs (mapleleafs.nhl.com)
117 // -> Wynn (www.wynnlasvegas.com) 117 // -> Wynn (www.wynnlasvegas.com)
118 // -> tier1_a_url0 118 // -> tier1_a_url0
119 const BookmarkNode* bar = GetBookmarkBarNode(0); 119 const BookmarkNode* bar = GetBookmarkBarNode(0);
120 const BookmarkNode* cnn = AddURL(0, bar, 0, L"CNN", 120 const BookmarkNode* cnn = AddURL(0, bar, 0, "CNN",
121 GURL("http://www.cnn.com")); 121 GURL("http://www.cnn.com"));
122 ASSERT_TRUE(cnn != NULL); 122 ASSERT_TRUE(cnn != NULL);
123 Move(0, tier1_a, bar, 1); 123 Move(0, tier1_a, bar, 1);
124 124
125 // Wait for the bookmark position change to sync. 125 // Wait for the bookmark position change to sync.
126 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 126 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
127 ASSERT_TRUE(ModelMatchesVerifier(0)); 127 ASSERT_TRUE(ModelMatchesVerifier(0));
128 128
129 const BookmarkNode* porsche = AddURL(0, bar, 2, L"Porsche", 129 const BookmarkNode* porsche = AddURL(0, bar, 2, "Porsche",
130 GURL("http://www.porsche.com")); 130 GURL("http://www.porsche.com"));
131 // Rearrange stuff in tier1_a. 131 // Rearrange stuff in tier1_a.
132 ASSERT_EQ(tier1_a, tier1_a_url2->parent()); 132 ASSERT_EQ(tier1_a, tier1_a_url2->parent());
133 ASSERT_EQ(tier1_a, tier1_a_url1->parent()); 133 ASSERT_EQ(tier1_a, tier1_a_url1->parent());
134 Move(0, tier1_a_url2, tier1_a, 0); 134 Move(0, tier1_a_url2, tier1_a, 0);
135 Move(0, tier1_a_url1, tier1_a, 2); 135 Move(0, tier1_a_url1, tier1_a, 2);
136 136
137 // Wait for the rearranged hierarchy to sync. 137 // Wait for the rearranged hierarchy to sync.
138 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 138 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
139 ASSERT_TRUE(ModelMatchesVerifier(0)); 139 ASSERT_TRUE(ModelMatchesVerifier(0));
140 140
141 ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0)); 141 ASSERT_EQ(1, tier1_a_url0->parent()->GetIndexOf(tier1_a_url0));
142 Move(0, tier1_a_url0, bar, bar->child_count()); 142 Move(0, tier1_a_url0, bar, bar->child_count());
143 const BookmarkNode* boa = AddURL(0, bar, bar->child_count(), 143 const BookmarkNode* boa = AddURL(0, bar, bar->child_count(),
144 L"Bank of America", GURL("https://www.bankofamerica.com")); 144 "Bank of America", GURL("https://www.bankofamerica.com"));
145 ASSERT_TRUE(boa != NULL); 145 ASSERT_TRUE(boa != NULL);
146 Move(0, tier1_a_url0, top, top->child_count()); 146 Move(0, tier1_a_url0, top, top->child_count());
147 const BookmarkNode* bubble = AddURL( 147 const BookmarkNode* bubble = AddURL(
148 0, bar, bar->child_count(), L"Seattle Bubble", 148 0, bar, bar->child_count(), "Seattle Bubble",
149 GURL("http://seattlebubble.com")); 149 GURL("http://seattlebubble.com"));
150 ASSERT_TRUE(bubble != NULL); 150 ASSERT_TRUE(bubble != NULL);
151 const BookmarkNode* wired = AddURL(0, bar, 2, L"Wired News", 151 const BookmarkNode* wired = AddURL(0, bar, 2, "Wired News",
152 GURL("http://www.wired.com")); 152 GURL("http://www.wired.com"));
153 const BookmarkNode* tier2_b = AddFolder( 153 const BookmarkNode* tier2_b = AddFolder(
154 0, tier1_b, 0, L"tier2_b"); 154 0, tier1_b, 0, "tier2_b");
155 Move(0, tier1_b_url0, tier2_b, 0); 155 Move(0, tier1_b_url0, tier2_b, 0);
156 Move(0, porsche, bar, 0); 156 Move(0, porsche, bar, 0);
157 SetTitle(0, wired, L"News Wired"); 157 SetTitle(0, wired, "News Wired");
158 SetTitle(0, porsche, L"ICanHazPorsche?"); 158 SetTitle(0, porsche, "ICanHazPorsche?");
159 159
160 // Wait for the title change to sync. 160 // Wait for the title change to sync.
161 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 161 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
162 ASSERT_TRUE(ModelMatchesVerifier(0)); 162 ASSERT_TRUE(ModelMatchesVerifier(0));
163 163
164 ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id()); 164 ASSERT_EQ(tier1_a_url0->id(), top->GetChild(top->child_count() - 1)->id());
165 Remove(0, top, top->child_count() - 1); 165 Remove(0, top, top->child_count() - 1);
166 Move(0, wired, tier1_b, 0); 166 Move(0, wired, tier1_b, 0);
167 Move(0, porsche, bar, 3); 167 Move(0, porsche, bar, 3);
168 const BookmarkNode* tier3_b = AddFolder(0, tier2_b, 1, L"tier3_b"); 168 const BookmarkNode* tier3_b = AddFolder(0, tier2_b, 1, "tier3_b");
169 const BookmarkNode* leafs = AddURL( 169 const BookmarkNode* leafs = AddURL(
170 0, tier1_a, 0, L"Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com")); 170 0, tier1_a, 0, "Toronto Maple Leafs", GURL("http://mapleleafs.nhl.com"));
171 const BookmarkNode* wynn = AddURL(0, bar, 1, L"Wynn", 171 const BookmarkNode* wynn = AddURL(0, bar, 1, "Wynn",
172 GURL("http://www.wynnlasvegas.com")); 172 GURL("http://www.wynnlasvegas.com"));
173 173
174 Move(0, wynn, tier3_b, 0); 174 Move(0, wynn, tier3_b, 0);
175 Move(0, leafs, tier3_b, 0); 175 Move(0, leafs, tier3_b, 0);
176 176
177 // Wait for newly added bookmarks to sync. 177 // Wait for newly added bookmarks to sync.
178 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 178 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
179 ASSERT_TRUE(ModelMatchesVerifier(0)); 179 ASSERT_TRUE(ModelMatchesVerifier(0));
180 180
181 // Only verify FakeServer data if FakeServer is being used. 181 // Only verify FakeServer data if FakeServer is being used.
182 // TODO(pvalenzuela): Use this style of verification in more tests once it is 182 // TODO(pvalenzuela): Use this style of verification in more tests once it is
183 // proven stable. 183 // proven stable.
184 if (GetFakeServer()) 184 if (GetFakeServer())
185 VerifyBookmarkModelMatchesFakeServer(0); 185 VerifyBookmarkModelMatchesFakeServer(0);
186 } 186 }
187 187
188 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, InjectedBookmark) { 188 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, InjectedBookmark) {
189 std::string title = "Montreal Canadiens"; 189 std::string title = "Montreal Canadiens";
190 fake_server::EntityBuilderFactory entity_builder_factory; 190 fake_server::EntityBuilderFactory entity_builder_factory;
191 scoped_ptr<fake_server::FakeServerEntity> entity = 191 scoped_ptr<fake_server::FakeServerEntity> entity =
192 entity_builder_factory.NewBookmarkEntityBuilder( 192 entity_builder_factory.NewBookmarkEntityBuilder(
193 title, GURL("http://canadiens.nhl.com")).Build(); 193 title, GURL("http://canadiens.nhl.com")).Build();
194 fake_server_->InjectEntity(entity.Pass()); 194 fake_server_->InjectEntity(entity.Pass());
195 195
196 DisableVerifier(); 196 DisableVerifier();
197 ASSERT_TRUE(SetupClients()); 197 ASSERT_TRUE(SetupClients());
198 ASSERT_TRUE(SetupSync()); 198 ASSERT_TRUE(SetupSync());
199 199
200 ASSERT_EQ(1, CountBookmarksWithTitlesMatching(0, base::UTF8ToWide(title))); 200 ASSERT_EQ(1, CountBookmarksWithTitlesMatching(0, title));
201 } 201 }
202 202
203 // Test that a client doesn't mutate the favicon data in the process 203 // Test that a client doesn't mutate the favicon data in the process
204 // of storing the favicon data from sync to the database or in the process 204 // of storing the favicon data from sync to the database or in the process
205 // of requesting data from the database for sync. 205 // of requesting data from the database for sync.
206 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, 206 IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
207 SetFaviconHiDPIDifferentCodec) { 207 SetFaviconHiDPIDifferentCodec) {
208 // Set the supported scale factors to 1x and 2x such that 208 // Set the supported scale factors to 1x and 2x such that
209 // BookmarkModel::GetFavicon() requests both 1x and 2x. 209 // BookmarkModel::GetFavicon() requests both 1x and 2x.
210 // 1x -> for sync, 2x -> for the UI. 210 // 1x -> for sync, 2x -> for the UI.
211 std::vector<ui::ScaleFactor> supported_scale_factors; 211 std::vector<ui::ScaleFactor> supported_scale_factors;
212 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); 212 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
213 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); 213 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
214 ui::SetSupportedScaleFactors(supported_scale_factors); 214 ui::SetSupportedScaleFactors(supported_scale_factors);
215 215
216 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 216 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
217 ASSERT_TRUE(ModelMatchesVerifier(0)); 217 ASSERT_TRUE(ModelMatchesVerifier(0));
218 218
219 const GURL page_url("http://www.google.com"); 219 const GURL page_url("http://www.google.com");
220 const GURL icon_url("http://www.google.com/favicon.ico"); 220 const GURL icon_url("http://www.google.com/favicon.ico");
221 const BookmarkNode* bookmark = AddURL(0, L"title", page_url); 221 const BookmarkNode* bookmark = AddURL(0, "title", page_url);
222 222
223 // Simulate receiving a favicon from sync encoded by a different PNG encoder 223 // Simulate receiving a favicon from sync encoded by a different PNG encoder
224 // than the one native to the OS. This tests the PNG data is not decoded to 224 // than the one native to the OS. This tests the PNG data is not decoded to
225 // SkBitmap (or any other image format) then encoded back to PNG on the path 225 // SkBitmap (or any other image format) then encoded back to PNG on the path
226 // between sync and the database. 226 // between sync and the database.
227 gfx::Image original_favicon = Create1xFaviconFromPNGFile( 227 gfx::Image original_favicon = Create1xFaviconFromPNGFile(
228 "favicon_cocoa_png_codec.png"); 228 "favicon_cocoa_png_codec.png");
229 ASSERT_FALSE(original_favicon.IsEmpty()); 229 ASSERT_FALSE(original_favicon.IsEmpty());
230 SetFavicon(0, bookmark, icon_url, original_favicon, 230 SetFavicon(0, bookmark, icon_url, original_favicon,
231 bookmarks_helper::FROM_SYNC); 231 bookmarks_helper::FROM_SYNC);
(...skipping 23 matching lines...) Expand all
255 // -> http://www.google.com 255 // -> http://www.google.com
256 // -> http://news.google.com 256 // -> http://news.google.com
257 // -> http://yahoo.com 257 // -> http://yahoo.com
258 // -> http://www.cnn.com 258 // -> http://www.cnn.com
259 // bookmark_bar 259 // bookmark_bar
260 // -> empty_folder 260 // -> empty_folder
261 // -> folder1 261 // -> folder1
262 // -> http://yahoo.com 262 // -> http://yahoo.com
263 // -> http://gmail.com 263 // -> http://gmail.com
264 264
265 const BookmarkNode* folder0 = AddFolder(0, GetOtherNode(0), 0, L"folder0"); 265 const BookmarkNode* folder0 = AddFolder(0, GetOtherNode(0), 0, "folder0");
266 const BookmarkNode* tier1_a = AddFolder(0, folder0, 0, L"tier1_a"); 266 const BookmarkNode* tier1_a = AddFolder(0, folder0, 0, "tier1_a");
267 ASSERT_TRUE(AddURL(0, folder0, 1, L"News", GURL("http://news.google.com"))); 267 ASSERT_TRUE(AddURL(0, folder0, 1, "News", GURL("http://news.google.com")));
268 ASSERT_TRUE(AddURL(0, folder0, 2, L"Yahoo", GURL("http://www.yahoo.com"))); 268 ASSERT_TRUE(AddURL(0, folder0, 2, "Yahoo", GURL("http://www.yahoo.com")));
269 ASSERT_TRUE(AddURL(0, tier1_a, 0, L"Gmail", GURL("http://mail.google.com"))); 269 ASSERT_TRUE(AddURL(0, tier1_a, 0, "Gmai", GURL("http://mail.google.com")));
270 ASSERT_TRUE(AddURL(0, tier1_a, 1, L"Google", GURL("http://www.google.com"))); 270 ASSERT_TRUE(AddURL(0, tier1_a, 1, "Google", GURL("http://www.google.com")));
271 ASSERT_TRUE( 271 ASSERT_TRUE(
272 AddURL(0, GetOtherNode(0), 1, L"CNN", GURL("http://www.cnn.com"))); 272 AddURL(0, GetOtherNode(0), 1, "CNN", GURL("http://www.cnn.com")));
273 273
274 ASSERT_TRUE(AddFolder(0, GetBookmarkBarNode(0), 0, L"empty_folder")); 274 ASSERT_TRUE(AddFolder(0, GetBookmarkBarNode(0), 0, "empty_folder"));
275 const BookmarkNode* folder1 = 275 const BookmarkNode* folder1 =
276 AddFolder(0, GetBookmarkBarNode(0), 1, L"folder1"); 276 AddFolder(0, GetBookmarkBarNode(0), 1, "folder1");
277 ASSERT_TRUE(AddURL(0, folder1, 0, L"Yahoo", GURL("http://www.yahoo.com"))); 277 ASSERT_TRUE(AddURL(0, folder1, 0, "Yahoo", GURL("http://www.yahoo.com")));
278 ASSERT_TRUE( 278 ASSERT_TRUE(
279 AddURL(0, GetBookmarkBarNode(0), 2, L"Gmail", GURL("http://gmail.com"))); 279 AddURL(0, GetBookmarkBarNode(0), 2, "Gmai", GURL("http://gmail.com")));
280 280
281 // Set up sync, wait for its completion and verify that changes propagated. 281 // Set up sync, wait for its completion and verify that changes propagated.
282 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 282 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
283 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 283 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
284 ASSERT_TRUE(ModelMatchesVerifier(0)); 284 ASSERT_TRUE(ModelMatchesVerifier(0));
285 285
286 // Remove all bookmarks and wait for sync completion. 286 // Remove all bookmarks and wait for sync completion.
287 RemoveAll(0); 287 RemoveAll(0);
288 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); 288 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
289 // Verify other node has no children now. 289 // Verify other node has no children now.
290 EXPECT_EQ(0, GetOtherNode(0)->child_count()); 290 EXPECT_EQ(0, GetOtherNode(0)->child_count());
291 EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count()); 291 EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count());
292 // Verify model matches verifier. 292 // Verify model matches verifier.
293 ASSERT_TRUE(ModelMatchesVerifier(0)); 293 ASSERT_TRUE(ModelMatchesVerifier(0));
294 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698