Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_bookmarks_sync_test.cc
blob13cbbc014964de810b5949196373c501cbd3b6e9
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
3 // found in the LICENSE file.
5 #include "base/rand_util.h"
6 #include "base/run_loop.h"
7 #include "base/values.h"
8 #include "chrome/browser/policy/profile_policy_connector_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
11 #include "chrome/browser/sync/test/integration/passwords_helper.h"
12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
14 #include "chrome/browser/sync/test/integration/sync_test.h"
15 #include "components/bookmarks/browser/bookmark_node.h"
16 #include "components/policy/core/common/mock_configuration_policy_provider.h"
17 #include "components/policy/core/common/policy_map.h"
18 #include "components/policy/core/common/policy_types.h"
19 #include "policy/policy_constants.h"
20 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "ui/base/layout.h"
24 using bookmarks::BookmarkNode;
25 using bookmarks_helper::AddFolder;
26 using bookmarks_helper::AddURL;
27 using bookmarks_helper::AllModelsMatch;
28 using bookmarks_helper::AllModelsMatchVerifier;
29 using bookmarks_helper::CheckFaviconExpired;
30 using bookmarks_helper::ContainsDuplicateBookmarks;
31 using bookmarks_helper::CountBookmarksWithTitlesMatching;
32 using bookmarks_helper::CreateFavicon;
33 using bookmarks_helper::ExpireFavicon;
34 using bookmarks_helper::GetBookmarkBarNode;
35 using bookmarks_helper::GetManagedNode;
36 using bookmarks_helper::GetOtherNode;
37 using bookmarks_helper::GetSyncedBookmarksNode;
38 using bookmarks_helper::GetUniqueNodeByURL;
39 using bookmarks_helper::HasNodeWithURL;
40 using bookmarks_helper::IndexedFolderName;
41 using bookmarks_helper::IndexedSubfolderName;
42 using bookmarks_helper::IndexedSubsubfolderName;
43 using bookmarks_helper::IndexedURL;
44 using bookmarks_helper::IndexedURLTitle;
45 using bookmarks_helper::Move;
46 using bookmarks_helper::Remove;
47 using bookmarks_helper::RemoveAll;
48 using bookmarks_helper::ReverseChildOrder;
49 using bookmarks_helper::SetFavicon;
50 using bookmarks_helper::SetTitle;
51 using bookmarks_helper::SetURL;
52 using bookmarks_helper::SortChildren;
53 using passwords_helper::SetDecryptionPassphrase;
54 using passwords_helper::SetEncryptionPassphrase;
55 using sync_integration_test_util::AwaitCommitActivityCompletion;
56 using sync_integration_test_util::AwaitPassphraseAccepted;
57 using sync_integration_test_util::AwaitPassphraseRequired;
59 namespace {
61 const char kGenericURL[] = "http://www.host.ext:1234/path/filename";
62 const char kGenericURLTitle[] = "URL Title";
63 const char kGenericFolderName[] = "Folder Name";
64 const char kGenericSubfolderName[] = "Subfolder Name";
65 const char kValidPassphrase[] = "passphrase!";
67 } // namespace
69 class TwoClientBookmarksSyncTest : public SyncTest {
70 public:
71 TwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT) {}
72 ~TwoClientBookmarksSyncTest() override {}
74 void TearDownInProcessBrowserTestFixture() override {
75 SyncTest::TearDownInProcessBrowserTestFixture();
76 policy_provider_.Shutdown();
79 protected:
80 // Needs to be deleted after all Profiles are deleted.
81 policy::MockConfigurationPolicyProvider policy_provider_;
83 private:
84 DISALLOW_COPY_AND_ASSIGN(TwoClientBookmarksSyncTest);
87 class LegacyTwoClientBookmarksSyncTest : public SyncTest {
88 public:
89 LegacyTwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {}
90 ~LegacyTwoClientBookmarksSyncTest() override {}
92 private:
93 DISALLOW_COPY_AND_ASSIGN(LegacyTwoClientBookmarksSyncTest);
96 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, Sanity) {
97 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
98 ASSERT_TRUE(AllModelsMatchVerifier());
100 GURL google_url("http://www.google.com");
101 ASSERT_TRUE(AddURL(0, "Google", google_url) != NULL);
102 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
103 ASSERT_TRUE(AddURL(1, "Yahoo", GURL("http://www.yahoo.com")) != NULL);
104 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
105 ASSERT_TRUE(AllModelsMatchVerifier());
107 const BookmarkNode* new_folder = AddFolder(0, 2, "New Folder");
108 Move(0, GetUniqueNodeByURL(0, google_url), new_folder, 0);
109 SetTitle(0, GetBookmarkBarNode(0)->GetChild(0), "Yahoo!!");
110 ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 1, "CNN",
111 GURL("http://www.cnn.com")) != NULL);
112 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
113 ASSERT_TRUE(AllModelsMatchVerifier());
115 ASSERT_TRUE(AddURL(1, "Facebook", GURL("http://www.facebook.com")) != NULL);
116 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
117 ASSERT_TRUE(AllModelsMatchVerifier());
119 SortChildren(1, GetBookmarkBarNode(1));
120 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
121 ASSERT_TRUE(AllModelsMatchVerifier());
123 DisableVerifier();
124 SetTitle(0, GetUniqueNodeByURL(0, google_url), "Google++");
125 SetTitle(1, GetUniqueNodeByURL(1, google_url), "Google--");
126 ASSERT_TRUE(AwaitQuiescence());
127 ASSERT_TRUE(AllModelsMatch());
130 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SimultaneousURLChanges) {
131 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
132 ASSERT_TRUE(AllModelsMatchVerifier());
134 GURL initial_url("http://www.google.com");
135 GURL second_url("http://www.google.com/abc");
136 GURL third_url("http://www.google.com/def");
137 std::string title = "Google";
139 ASSERT_TRUE(AddURL(0, title, initial_url) != NULL);
140 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
142 DisableVerifier();
143 ASSERT_TRUE(SetURL(
144 0, GetUniqueNodeByURL(0, initial_url), second_url) != NULL);
145 ASSERT_TRUE(SetURL(
146 1, GetUniqueNodeByURL(1, initial_url), third_url) != NULL);
147 ASSERT_TRUE(AwaitQuiescence());
148 ASSERT_TRUE(AllModelsMatch());
150 SetTitle(0, GetBookmarkBarNode(0)->GetChild(0), "Google1");
151 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
152 ASSERT_TRUE(AllModelsMatch());
155 // Test Scribe ID - 370558.
156 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddFirstFolder) {
157 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
158 ASSERT_TRUE(AllModelsMatchVerifier());
160 ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
161 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
162 ASSERT_TRUE(AllModelsMatchVerifier());
165 // Test Scribe ID - 370559.
166 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
167 SC_AddFirstBMWithoutFavicon) {
168 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
169 ASSERT_TRUE(AllModelsMatchVerifier());
171 ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
172 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
173 ASSERT_TRUE(AllModelsMatchVerifier());
176 // Test Scribe ID - 370489.
177 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddFirstBMWithFavicon) {
178 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
179 ASSERT_TRUE(AllModelsMatchVerifier());
181 const GURL page_url(kGenericURL);
182 const GURL icon_url("http://www.google.com/favicon.ico");
184 const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, page_url);
186 ASSERT_TRUE(bookmark != NULL);
187 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
188 SetFavicon(0, bookmark, icon_url, CreateFavicon(SK_ColorWHITE),
189 bookmarks_helper::FROM_UI);
190 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
191 ASSERT_TRUE(AllModelsMatchVerifier());
194 // Test that the history service logic for not losing the hidpi versions of
195 // favicons as a result of sync does not result in dropping sync updates.
196 // In particular, the synced 16x16 favicon bitmap should overwrite 16x16
197 // favicon bitmaps on all clients. (Though non-16x16 favicon bitmaps
198 // are unchanged).
199 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_SetFaviconHiDPI) {
200 // Set the supported scale factors to include 2x such that CreateFavicon()
201 // creates a favicon with hidpi representations and that methods in the
202 // FaviconService request hidpi favicons.
203 std::vector<ui::ScaleFactor> supported_scale_factors;
204 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
205 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
206 ui::SetSupportedScaleFactors(supported_scale_factors);
208 const GURL page_url(kGenericURL);
209 const GURL icon_url1("http://www.google.com/favicon1.ico");
210 const GURL icon_url2("http://www.google.com/favicon2.ico");
212 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
213 ASSERT_TRUE(AllModelsMatchVerifier());
215 const BookmarkNode* bookmark0 = AddURL(0, kGenericURLTitle, page_url);
216 ASSERT_TRUE(bookmark0 != NULL);
217 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
218 SetFavicon(0, bookmark0, icon_url1, CreateFavicon(SK_ColorWHITE),
219 bookmarks_helper::FROM_UI);
220 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
221 ASSERT_TRUE(AllModelsMatchVerifier());
223 const BookmarkNode* bookmark1 = GetUniqueNodeByURL(1, page_url);
224 SetFavicon(1, bookmark1, icon_url1, CreateFavicon(SK_ColorBLUE),
225 bookmarks_helper::FROM_UI);
226 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
227 ASSERT_TRUE(AllModelsMatchVerifier());
229 SetFavicon(0, bookmark0, icon_url2, CreateFavicon(SK_ColorGREEN),
230 bookmarks_helper::FROM_UI);
231 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
232 ASSERT_TRUE(AllModelsMatchVerifier());
235 // Test that if sync does not modify a favicon bitmap's data that it does not
236 // modify the favicon bitmap's "last updated time" either. This is important
237 // because the last updated time is used to determine whether a bookmark's
238 // favicon should be redownloaded when the web when the bookmark is visited.
239 // If sync prevents the "last updated time" from expiring, the favicon is
240 // never redownloaded from the web. (http://crbug.com/481414)
241 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
242 SC_UpdatingTitleDoesNotUpdateFaviconLastUpdatedTime) {
243 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
245 std::vector<ui::ScaleFactor> supported_scale_factors;
246 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
247 ui::SetSupportedScaleFactors(supported_scale_factors);
249 const GURL page_url(kGenericURL);
250 const GURL icon_url("http://www.google.com/favicon.ico");
252 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
253 ASSERT_TRUE(AllModelsMatchVerifier());
255 const BookmarkNode* bookmark0 = AddURL(0, kGenericURLTitle, page_url);
256 ASSERT_NE(bookmark0, nullptr);
257 gfx::Image favicon0 = CreateFavicon(SK_ColorBLUE);
258 ASSERT_FALSE(favicon0.IsEmpty());
259 SetFavicon(0, bookmark0, icon_url, favicon0, bookmarks_helper::FROM_UI);
261 // Expire the favicon (e.g. as a result of the user "clearing browsing
262 // history from the beginning of time")
263 ExpireFavicon(0, bookmark0);
264 CheckFaviconExpired(0, icon_url);
266 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
267 ASSERT_TRUE(AllModelsMatchVerifier());
269 // Change the bookmark's title for profile 1. Changing the title will cause
270 // the bookmark's favicon data to be synced from profile 1 to profile 0 even
271 // though the favicon data did not change.
272 const std::string kNewTitle = "New Title";
273 ASSERT_NE(kNewTitle, kGenericURLTitle);
274 const BookmarkNode* bookmark1 = GetUniqueNodeByURL(1, page_url);
275 SetTitle(1, bookmark1, kNewTitle);
276 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
277 ASSERT_TRUE(AllModelsMatchVerifier());
279 // The favicon for profile 0 should still be expired.
280 CheckFaviconExpired(0, icon_url);
283 // When two bookmarks use the same icon URL, both bookmarks use the same row
284 // in the favicons table in the Favicons database. Test that when the favicon
285 // is updated for one bookmark it is also updated for the other bookmark. This
286 // ensures that sync has the most up to date data and prevents sync from
287 // reverting the newly updated bookmark favicon back to the old favicon.
288 // crbug.com/485657
289 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
290 SC_SetFaviconTwoBookmarksSameIconURL) {
291 const GURL page_url1("http://www.google.com/a");
292 const GURL page_url2("http://www.google.com/b");
293 const GURL icon_url("http://www.google.com/favicon.ico");
295 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
296 ASSERT_TRUE(AllModelsMatchVerifier());
298 const BookmarkNode* bookmark01 = AddURL(0, kGenericURLTitle, page_url1);
299 ASSERT_TRUE(bookmark01 != nullptr);
300 const BookmarkNode* bookmark02 = AddURL(0, kGenericURLTitle, page_url2);
301 ASSERT_TRUE(bookmark02 != nullptr);
303 SetFavicon(0, bookmark01, icon_url, CreateFavicon(SK_ColorWHITE),
304 bookmarks_helper::FROM_UI);
305 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
306 ASSERT_TRUE(AllModelsMatchVerifier());
308 // Set |page_url2| with the new (blue) favicon at |icon_url|. The sync favicon
309 // for both |page_url1| and |page_url2| should be updated to the blue one.
310 SetFavicon(0, bookmark02, icon_url, CreateFavicon(SK_ColorBLUE),
311 bookmarks_helper::FROM_UI);
312 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
313 ASSERT_TRUE(AllModelsMatchVerifier());
315 // Set the title for |page_url1|. This should not revert either of the
316 // bookmark favicons back to white.
317 const char kNewTitle[] = "New Title";
318 ASSERT_STRNE(kGenericURLTitle, kNewTitle);
319 const BookmarkNode* bookmark11 = GetUniqueNodeByURL(1, page_url1);
320 SetTitle(1, bookmark11, std::string(kNewTitle));
321 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
322 ASSERT_TRUE(AllModelsMatchVerifier());
325 // Test Scribe ID - 370560.
326 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddNonHTTPBMs) {
327 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
328 ASSERT_TRUE(AllModelsMatchVerifier());
330 ASSERT_TRUE(AddURL(
331 0, "FTP UR", GURL("ftp://user:password@host:1234/path")) != NULL);
332 ASSERT_TRUE(AddURL(0, "File UR", GURL("file://host/path")) != NULL);
333 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
334 ASSERT_TRUE(AllModelsMatchVerifier());
337 // Test Scribe ID - 370561.
338 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
339 SC_AddFirstBMUnderFolder) {
340 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
341 ASSERT_TRUE(AllModelsMatchVerifier());
343 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
344 ASSERT_TRUE(folder != NULL);
345 ASSERT_TRUE(AddURL(
346 0, folder, 0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
347 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
348 ASSERT_TRUE(AllModelsMatchVerifier());
351 // Test Scribe ID - 370562.
352 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
353 SC_AddSeveralBMsUnderBMBarAndOtherBM) {
354 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
355 ASSERT_TRUE(AllModelsMatchVerifier());
357 for (int i = 0; i < 20; ++i) {
358 std::string title = IndexedURLTitle(i);
359 GURL url = GURL(IndexedURL(i));
360 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
361 ASSERT_TRUE(AddURL(
362 0, GetOtherNode(0), i, title, url) != NULL);
364 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
365 ASSERT_TRUE(AllModelsMatchVerifier());
368 // Test Scribe ID - 370563.
369 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
370 SC_AddSeveralBMsAndFolders) {
371 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
372 ASSERT_TRUE(AllModelsMatchVerifier());
374 for (int i = 0; i < 15; ++i) {
375 if (base::RandDouble() > 0.6) {
376 std::string title = IndexedURLTitle(i);
377 GURL url = GURL(IndexedURL(i));
378 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
379 } else {
380 std::string title = IndexedFolderName(i);
381 const BookmarkNode* folder = AddFolder(0, i, title);
382 ASSERT_TRUE(folder != NULL);
383 if (base::RandDouble() > 0.4) {
384 for (int i = 0; i < 20; ++i) {
385 std::string title = IndexedURLTitle(i);
386 GURL url = GURL(IndexedURL(i));
387 ASSERT_TRUE(
388 AddURL(0, folder, i, title, url) != NULL);
393 for (int i = 0; i < 10; i++) {
394 std::string title = IndexedURLTitle(i);
395 GURL url = GURL(IndexedURL(i));
396 ASSERT_TRUE(AddURL(0, GetOtherNode(0), i, title, url) != NULL);
398 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
399 ASSERT_TRUE(AllModelsMatchVerifier());
402 // Test Scribe ID - 370641.
403 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
404 SC_DuplicateBMWithDifferentURLSameName) {
405 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
406 ASSERT_TRUE(AllModelsMatchVerifier());
408 GURL url0 = GURL(IndexedURL(0));
409 GURL url1 = GURL(IndexedURL(1));
410 ASSERT_TRUE(AddURL(0, kGenericURLTitle, url0) != NULL);
411 ASSERT_TRUE(AddURL(0, kGenericURLTitle, url1) != NULL);
412 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
413 ASSERT_TRUE(AllModelsMatchVerifier());
416 // Test Scribe ID - 370639 - Add bookmarks with different name and same URL.
417 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
418 SC_DuplicateBookmarksWithSameURL) {
419 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
420 ASSERT_TRUE(AllModelsMatchVerifier());
422 std::string title0 = IndexedURLTitle(0);
423 std::string title1 = IndexedURLTitle(1);
424 ASSERT_TRUE(AddURL(0, title0, GURL(kGenericURL)) != NULL);
425 ASSERT_TRUE(AddURL(0, title1, GURL(kGenericURL)) != NULL);
426 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
427 ASSERT_TRUE(AllModelsMatchVerifier());
430 // Test Scribe ID - 371817.
431 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMName) {
432 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
433 ASSERT_TRUE(AllModelsMatchVerifier());
435 std::string title = IndexedURLTitle(1);
436 const BookmarkNode* bookmark = AddURL(0, title, GURL(kGenericURL));
437 ASSERT_TRUE(bookmark != NULL);
438 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
439 ASSERT_TRUE(AllModelsMatchVerifier());
441 std::string new_title = IndexedURLTitle(2);
442 SetTitle(0, bookmark, new_title);
443 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
444 ASSERT_TRUE(AllModelsMatchVerifier());
447 // Test Scribe ID - 371822.
448 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMURL) {
449 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
450 ASSERT_TRUE(AllModelsMatchVerifier());
452 GURL url = GURL(IndexedURL(1));
453 const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, url);
454 ASSERT_TRUE(bookmark != NULL);
455 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
456 ASSERT_TRUE(AllModelsMatchVerifier());
458 GURL new_url = GURL(IndexedURL(2));
459 ASSERT_TRUE(SetURL(0, bookmark, new_url) != NULL);
460 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
461 ASSERT_TRUE(AllModelsMatchVerifier());
465 // Test Scribe ID - 371818 - Renaming the same bookmark name twice.
466 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
467 SC_TwiceRenamingBookmarkName) {
468 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
469 ASSERT_TRUE(AllModelsMatchVerifier());
471 std::string title = IndexedURLTitle(1);
472 const BookmarkNode* bookmark = AddURL(0, title, GURL(kGenericURL));
473 ASSERT_TRUE(bookmark != NULL);
474 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
475 ASSERT_TRUE(AllModelsMatchVerifier());
477 std::string new_title = IndexedURLTitle(2);
478 SetTitle(0, bookmark, new_title);
479 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
480 ASSERT_TRUE(AllModelsMatchVerifier());
482 SetTitle(0, bookmark, title);
483 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
484 ASSERT_TRUE(AllModelsMatchVerifier());
487 // Test Scribe ID - 371823 - Renaming the same bookmark URL twice.
488 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
489 SC_TwiceRenamingBookmarkURL) {
490 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
491 ASSERT_TRUE(AllModelsMatchVerifier());
493 GURL url = GURL(IndexedURL(1));
494 const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, url);
495 ASSERT_TRUE(bookmark != NULL);
496 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
497 ASSERT_TRUE(AllModelsMatchVerifier());
499 GURL new_url = GURL(IndexedURL(2));
500 ASSERT_TRUE(SetURL(0, bookmark, new_url) != NULL);
501 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
502 ASSERT_TRUE(AllModelsMatchVerifier());
504 ASSERT_TRUE(SetURL(0, bookmark, url) != NULL);
505 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
506 ASSERT_TRUE(AllModelsMatchVerifier());
509 // Test Scribe ID - 371824.
510 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMFolder) {
511 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
512 ASSERT_TRUE(AllModelsMatchVerifier());
514 std::string title = IndexedFolderName(1);
515 const BookmarkNode* folder = AddFolder(0, title);
516 ASSERT_TRUE(AddURL(
517 0, folder, 0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
518 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
519 ASSERT_TRUE(AllModelsMatchVerifier());
521 std::string new_title = IndexedFolderName(2);
522 SetTitle(0, folder, new_title);
523 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
524 ASSERT_TRUE(AllModelsMatchVerifier());
527 // Test Scribe ID - 371825.
528 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameEmptyBMFolder) {
529 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
530 ASSERT_TRUE(AllModelsMatchVerifier());
532 std::string title = IndexedFolderName(1);
533 const BookmarkNode* folder = AddFolder(0, title);
534 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
535 ASSERT_TRUE(AllModelsMatchVerifier());
537 std::string new_title = IndexedFolderName(2);
538 SetTitle(0, folder, new_title);
539 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
540 ASSERT_TRUE(AllModelsMatchVerifier());
543 // Test Scribe ID - 371826.
544 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
545 SC_RenameBMFolderWithLongHierarchy) {
546 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
547 ASSERT_TRUE(AllModelsMatchVerifier());
549 std::string title = IndexedFolderName(1);
550 const BookmarkNode* folder = AddFolder(0, title);
551 ASSERT_TRUE(folder != NULL);
552 for (int i = 0; i < 120; ++i) {
553 if (base::RandDouble() > 0.15) {
554 std::string title = IndexedURLTitle(i);
555 GURL url = GURL(IndexedURL(i));
556 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
557 } else {
558 std::string title = IndexedSubfolderName(i);
559 ASSERT_TRUE(AddFolder(0, folder, i, title) != NULL);
562 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
563 ASSERT_TRUE(AllModelsMatchVerifier());
565 std::string new_title = IndexedFolderName(2);
566 SetTitle(0, folder, new_title);
567 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
568 ASSERT_TRUE(AllModelsMatchVerifier());
571 // Test Scribe ID - 371827.
572 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
573 SC_RenameBMFolderThatHasParentAndChildren) {
574 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
575 ASSERT_TRUE(AllModelsMatchVerifier());
577 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
578 ASSERT_TRUE(folder != NULL);
579 for (int i = 1; i < 15; ++i) {
580 std::string title = IndexedURLTitle(i);
581 GURL url = GURL(IndexedURL(i));
582 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
584 std::string title = IndexedSubfolderName(1);
585 const BookmarkNode* subfolder = AddFolder(0, folder, 0, title);
586 for (int i = 0; i < 120; ++i) {
587 if (base::RandDouble() > 0.15) {
588 std::string title = IndexedURLTitle(i);
589 GURL url = GURL(IndexedURL(i));
590 ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
591 } else {
592 std::string title = IndexedSubsubfolderName(i);
593 ASSERT_TRUE(AddFolder(0, subfolder, i, title) != NULL);
596 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
597 ASSERT_TRUE(AllModelsMatchVerifier());
599 std::string new_title = IndexedSubfolderName(2);
600 SetTitle(0, subfolder, new_title);
601 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
602 ASSERT_TRUE(AllModelsMatchVerifier());
605 // Test Scribe ID - 371828.
606 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMNameAndURL) {
607 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
608 ASSERT_TRUE(AllModelsMatchVerifier());
610 GURL url = GURL(IndexedURL(1));
611 std::string title = IndexedURLTitle(1);
612 const BookmarkNode* bookmark = AddURL(0, title, url);
613 ASSERT_TRUE(bookmark != NULL);
614 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
615 ASSERT_TRUE(AllModelsMatchVerifier());
617 GURL new_url = GURL(IndexedURL(2));
618 std::string new_title = IndexedURLTitle(2);
619 bookmark = SetURL(0, bookmark, new_url);
620 ASSERT_TRUE(bookmark != NULL);
621 SetTitle(0, bookmark, new_title);
622 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
623 ASSERT_TRUE(AllModelsMatchVerifier());
626 // Test Scribe ID - 371832.
627 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
628 SC_DeleteBMEmptyAccountAfterwards) {
629 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
630 ASSERT_TRUE(AllModelsMatchVerifier());
632 ASSERT_TRUE(AddURL(
633 0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
634 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
635 ASSERT_TRUE(AllModelsMatchVerifier());
637 Remove(0, GetBookmarkBarNode(0), 0);
638 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
639 ASSERT_TRUE(AllModelsMatchVerifier());
642 // Test Scribe ID - 371833.
643 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
644 SC_DelBMNonEmptyAccountAfterwards) {
645 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
646 ASSERT_TRUE(AllModelsMatchVerifier());
648 for (int i = 0; i < 20; ++i) {
649 std::string title = IndexedURLTitle(i);
650 GURL url = GURL(IndexedURL(i));
651 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
653 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
654 ASSERT_TRUE(AllModelsMatchVerifier());
656 Remove(0, GetBookmarkBarNode(0), 0);
657 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
658 ASSERT_TRUE(AllModelsMatchVerifier());
661 // Test Scribe ID - 371835.
662 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
663 SC_DelFirstBMUnderBMFoldNonEmptyFoldAfterwards) {
664 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
665 ASSERT_TRUE(AllModelsMatchVerifier());
667 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
668 ASSERT_TRUE(folder != NULL);
669 for (int i = 0; i < 10; ++i) {
670 std::string title = IndexedURLTitle(i);
671 GURL url = GURL(IndexedURL(i));
672 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
674 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
675 ASSERT_TRUE(AllModelsMatchVerifier());
677 Remove(0, folder, 0);
678 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
679 ASSERT_TRUE(AllModelsMatchVerifier());
682 // Test Scribe ID - 371836.
683 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
684 SC_DelLastBMUnderBMFoldNonEmptyFoldAfterwards) {
685 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
686 ASSERT_TRUE(AllModelsMatchVerifier());
688 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
689 ASSERT_TRUE(folder != NULL);
690 for (int i = 0; i < 10; ++i) {
691 std::string title = IndexedURLTitle(i);
692 GURL url = GURL(IndexedURL(i));
693 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
695 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
696 ASSERT_TRUE(AllModelsMatchVerifier());
698 Remove(0, folder, folder->child_count() - 1);
699 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
700 ASSERT_TRUE(AllModelsMatchVerifier());
703 // Test Scribe ID - 371856.
704 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
705 SC_DelMiddleBMUnderBMFoldNonEmptyFoldAfterwards) {
706 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
707 ASSERT_TRUE(AllModelsMatchVerifier());
709 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
710 ASSERT_TRUE(folder != NULL);
711 for (int i = 0; i < 10; ++i) {
712 std::string title = IndexedURLTitle(i);
713 GURL url = GURL(IndexedURL(i));
714 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
716 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
717 ASSERT_TRUE(AllModelsMatchVerifier());
719 Remove(0, folder, 4);
720 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
721 ASSERT_TRUE(AllModelsMatchVerifier());
724 // Test Scribe ID - 371857.
725 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
726 SC_DelBMsUnderBMFoldEmptyFolderAfterwards) {
727 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
728 ASSERT_TRUE(AllModelsMatchVerifier());
730 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
731 ASSERT_TRUE(folder != NULL);
732 for (int i = 0; i < 10; ++i) {
733 std::string title = IndexedURLTitle(i);
734 GURL url = GURL(IndexedURL(i));
735 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
737 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
738 ASSERT_TRUE(AllModelsMatchVerifier());
740 int child_count = folder->child_count();
741 for (int i = 0; i < child_count; ++i) {
742 Remove(0, folder, 0);
744 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
745 ASSERT_TRUE(AllModelsMatchVerifier());
748 // Test Scribe ID - 371858.
749 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
750 SC_DelEmptyBMFoldEmptyAccountAfterwards) {
751 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
752 ASSERT_TRUE(AllModelsMatchVerifier());
754 ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
755 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
756 ASSERT_TRUE(AllModelsMatchVerifier());
758 Remove(0, GetBookmarkBarNode(0), 0);
759 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
760 ASSERT_TRUE(AllModelsMatchVerifier());
763 // Test Scribe ID - 371869.
764 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
765 SC_DelEmptyBMFoldNonEmptyAccountAfterwards) {
766 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
767 ASSERT_TRUE(AllModelsMatchVerifier());
769 ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
770 for (int i = 1; i < 15; ++i) {
771 if (base::RandDouble() > 0.6) {
772 std::string title = IndexedURLTitle(i);
773 GURL url = GURL(IndexedURL(i));
774 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
775 } else {
776 std::string title = IndexedFolderName(i);
777 ASSERT_TRUE(AddFolder(0, i, title) != NULL);
780 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
781 ASSERT_TRUE(AllModelsMatchVerifier());
783 Remove(0, GetBookmarkBarNode(0), 0);
784 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
785 ASSERT_TRUE(AllModelsMatchVerifier());
788 // Test Scribe ID - 371879.
789 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
790 SC_DelBMFoldWithBMsNonEmptyAccountAfterwards) {
791 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
792 ASSERT_TRUE(AllModelsMatchVerifier());
794 ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
795 const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
796 ASSERT_TRUE(folder != NULL);
797 for (int i = 2; i < 10; ++i) {
798 if (base::RandDouble() > 0.6) {
799 std::string title = IndexedURLTitle(i);
800 GURL url = GURL(IndexedURL(i));
801 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
802 } else {
803 std::string title = IndexedFolderName(i);
804 ASSERT_TRUE(AddFolder(0, i, title) != NULL);
807 for (int i = 0; i < 15; ++i) {
808 std::string title = IndexedURLTitle(i);
809 GURL url = GURL(IndexedURL(i));
810 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
812 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
813 ASSERT_TRUE(AllModelsMatchVerifier());
815 Remove(0, GetBookmarkBarNode(0), 1);
816 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
817 ASSERT_TRUE(AllModelsMatchVerifier());
820 // Test Scribe ID - 371880.
821 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
822 SC_DelBMFoldWithBMsAndBMFoldsNonEmptyACAfterwards) {
823 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
824 ASSERT_TRUE(AllModelsMatchVerifier());
826 ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
827 const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
828 ASSERT_TRUE(folder != NULL);
829 for (int i = 2; i < 10; ++i) {
830 if (base::RandDouble() > 0.6) {
831 std::string title = IndexedURLTitle(i);
832 GURL url = GURL(IndexedURL(i));
833 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
834 } else {
835 std::string title = IndexedFolderName(i);
836 ASSERT_TRUE(AddFolder(0, i, title) != NULL);
839 for (int i = 0; i < 10; ++i) {
840 if (base::RandDouble() > 0.6) {
841 std::string title = IndexedURLTitle(i);
842 GURL url = GURL(IndexedURL(i));
843 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
844 } else {
845 std::string title = IndexedSubfolderName(i);
846 const BookmarkNode* subfolder =
847 AddFolder(0, folder, i, title);
848 ASSERT_TRUE(subfolder != NULL);
849 if (base::RandDouble() > 0.3) {
850 for (int j = 0; j < 10; ++j) {
851 if (base::RandDouble() > 0.6) {
852 std::string title = IndexedURLTitle(j);
853 GURL url = GURL(IndexedURL(j));
854 ASSERT_TRUE(AddURL(
855 0, subfolder, j, title, url) != NULL);
856 } else {
857 std::string title = IndexedSubsubfolderName(j);
858 ASSERT_TRUE(AddFolder(
859 0, subfolder, j, title) != NULL);
865 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
866 ASSERT_TRUE(AllModelsMatchVerifier());
868 Remove(0, GetBookmarkBarNode(0), 1);
869 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
870 ASSERT_TRUE(AllModelsMatchVerifier());
873 // Test Scribe ID - 371882.
874 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
875 SC_DelBMFoldWithParentAndChildrenBMsAndBMFolds) {
876 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
877 ASSERT_TRUE(AllModelsMatchVerifier());
879 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
880 ASSERT_TRUE(folder != NULL);
881 for (int i = 1; i < 11; ++i) {
882 std::string title = IndexedURLTitle(i);
883 GURL url = GURL(IndexedURL(i));
884 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
886 const BookmarkNode* subfolder =
887 AddFolder(0, folder, 0, kGenericSubfolderName);
888 ASSERT_TRUE(subfolder != NULL);
889 for (int i = 0; i < 30; ++i) {
890 if (base::RandDouble() > 0.2) {
891 std::string title = IndexedURLTitle(i);
892 GURL url = GURL(IndexedURL(i));
893 ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
894 } else {
895 std::string title = IndexedSubsubfolderName(i);
896 ASSERT_TRUE(AddFolder(0, subfolder, i, title) != NULL);
899 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
900 ASSERT_TRUE(AllModelsMatchVerifier());
902 Remove(0, folder, 0);
903 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
904 ASSERT_TRUE(AllModelsMatchVerifier());
907 // Test Scribe ID - 371931.
908 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
909 SC_ReverseTheOrderOfTwoBMs) {
910 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
911 ASSERT_TRUE(AllModelsMatchVerifier());
913 GURL url0 = GURL(IndexedURL(0));
914 GURL url1 = GURL(IndexedURL(1));
915 std::string title0 = IndexedURLTitle(0);
916 std::string title1 = IndexedURLTitle(1);
917 const BookmarkNode* bookmark0 = AddURL(0, 0, title0, url0);
918 const BookmarkNode* bookmark1 = AddURL(0, 1, title1, url1);
919 ASSERT_TRUE(bookmark0 != NULL);
920 ASSERT_TRUE(bookmark1 != NULL);
921 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
922 ASSERT_TRUE(AllModelsMatchVerifier());
924 Move(0, bookmark0, GetBookmarkBarNode(0), 2);
925 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
926 ASSERT_TRUE(AllModelsMatchVerifier());
929 // Test Scribe ID - 371933.
930 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_ReverseTheOrderOf10BMs) {
931 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
932 ASSERT_TRUE(AllModelsMatchVerifier());
934 for (int i = 0; i < 10; ++i) {
935 std::string title = IndexedURLTitle(i);
936 GURL url = GURL(IndexedURL(i));
937 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
939 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
940 ASSERT_TRUE(AllModelsMatchVerifier());
942 ReverseChildOrder(0, GetBookmarkBarNode(0));
943 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
944 ASSERT_TRUE(AllModelsMatchVerifier());
947 // Test Scribe ID - 371954.
948 // flaky on Windows: http://crbug.com/412169
949 #if defined(OS_WIN) || defined(OS_MACOSX)
950 #define MAYBE_SC_MovingBMsFromBMBarToBMFolder DISABLED_SC_MovingBMsFromBMBarToBMFolder
951 #else
952 #define MAYBE_SC_MovingBMsFromBMBarToBMFolder SC_MovingBMsFromBMBarToBMFolder
953 #endif
954 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
955 MAYBE_SC_MovingBMsFromBMBarToBMFolder) {
956 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
957 ASSERT_TRUE(AllModelsMatchVerifier());
959 ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
960 const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
961 ASSERT_TRUE(folder != NULL);
962 for (int i = 2; i < 10; ++i) {
963 std::string title = IndexedURLTitle(i);
964 GURL url = GURL(IndexedURL(i));
965 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
967 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
968 ASSERT_TRUE(AllModelsMatchVerifier());
970 int num_bookmarks_to_move =
971 GetBookmarkBarNode(0)->child_count() - 2;
972 for (int i = 0; i < num_bookmarks_to_move; ++i) {
973 Move(
974 0, GetBookmarkBarNode(0)->GetChild(2), folder, i);
975 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
976 ASSERT_TRUE(AllModelsMatchVerifier());
980 // Test Scribe ID - 371957.
981 // flaky on Windows and Mac: http://crbug.com/412169
982 #if defined(OS_WIN) || defined(OS_MACOSX)
983 #define MAYBE_SC_MovingBMsFromBMFoldToBMBar DISABLED_SC_MovingBMsFromBMFoldToBMBar
984 #else
985 #define MAYBE_SC_MovingBMsFromBMFoldToBMBar SC_MovingBMsFromBMFoldToBMBar
986 #endif
987 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
988 MAYBE_SC_MovingBMsFromBMFoldToBMBar) {
989 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
990 ASSERT_TRUE(AllModelsMatchVerifier());
992 ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
993 const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
994 ASSERT_TRUE(folder != NULL);
995 for (int i = 0; i < 10; ++i) {
996 std::string title = IndexedURLTitle(i);
997 GURL url = GURL(IndexedURL(i));
998 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1000 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1001 ASSERT_TRUE(AllModelsMatchVerifier());
1003 int num_bookmarks_to_move = folder->child_count() - 2;
1004 for (int i = 0; i < num_bookmarks_to_move; ++i) {
1005 Move(0, folder->GetChild(0), GetBookmarkBarNode(0), i);
1006 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1007 ASSERT_TRUE(AllModelsMatchVerifier());
1011 // Test Scribe ID - 371961.
1012 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1013 SC_MovingBMsFromParentBMFoldToChildBMFold) {
1014 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1015 ASSERT_TRUE(AllModelsMatchVerifier());
1017 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
1018 ASSERT_TRUE(folder != NULL);
1019 for (int i = 0; i < 3; ++i) {
1020 std::string title = IndexedURLTitle(i);
1021 GURL url = GURL(IndexedURL(i));
1022 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1024 const BookmarkNode* subfolder =
1025 AddFolder(0, folder, 3, kGenericSubfolderName);
1026 ASSERT_TRUE(subfolder != NULL);
1027 for (int i = 0; i < 10; ++i) {
1028 std::string title = IndexedURLTitle(i + 3);
1029 GURL url = GURL(IndexedURL(i + 3));
1030 ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
1032 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1033 ASSERT_TRUE(AllModelsMatchVerifier());
1035 for (int i = 0; i < 3; ++i) {
1036 GURL url = GURL(IndexedURL(i));
1037 Move(0, GetUniqueNodeByURL(0, url), subfolder, i + 10);
1039 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1040 ASSERT_TRUE(AllModelsMatchVerifier());
1043 // Test Scribe ID - 371964.
1044 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1045 SC_MovingBMsFromChildBMFoldToParentBMFold) {
1046 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1047 ASSERT_TRUE(AllModelsMatchVerifier());
1049 const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
1050 ASSERT_TRUE(folder != NULL);
1051 for (int i = 0; i < 3; ++i) {
1052 std::string title = IndexedURLTitle(i);
1053 GURL url = GURL(IndexedURL(i));
1054 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1056 const BookmarkNode* subfolder =
1057 AddFolder(0, folder, 3, kGenericSubfolderName);
1058 ASSERT_TRUE(subfolder != NULL);
1059 for (int i = 0; i < 5; ++i) {
1060 std::string title = IndexedURLTitle(i + 3);
1061 GURL url = GURL(IndexedURL(i + 3));
1062 ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
1064 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1065 ASSERT_TRUE(AllModelsMatchVerifier());
1067 for (int i = 0; i < 3; ++i) {
1068 GURL url = GURL(IndexedURL(i + 3));
1069 Move(0, GetUniqueNodeByURL(0, url), folder, i + 4);
1071 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1072 ASSERT_TRUE(AllModelsMatchVerifier());
1075 // Test Scribe ID - 371967.
1076 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_HoistBMs10LevelUp) {
1077 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1078 ASSERT_TRUE(AllModelsMatchVerifier());
1080 const BookmarkNode* folder = GetBookmarkBarNode(0);
1081 const BookmarkNode* folder_L0 = NULL;
1082 const BookmarkNode* folder_L10 = NULL;
1083 for (int level = 0; level < 15; ++level) {
1084 int num_bookmarks = base::RandInt(0, 9);
1085 for (int i = 0; i < num_bookmarks; ++i) {
1086 std::string title = IndexedURLTitle(i);
1087 GURL url = GURL(IndexedURL(i));
1088 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1090 std::string title = IndexedFolderName(level);
1091 folder = AddFolder(0, folder, folder->child_count(), title);
1092 ASSERT_TRUE(folder != NULL);
1093 if (level == 0) folder_L0 = folder;
1094 if (level == 10) folder_L10 = folder;
1096 for (int i = 0; i < 3; ++i) {
1097 std::string title = IndexedURLTitle(i + 10);
1098 GURL url = GURL(IndexedURL(i + 10));
1099 ASSERT_TRUE(AddURL(0, folder_L10, i, title, url) != NULL);
1101 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1102 ASSERT_TRUE(AllModelsMatchVerifier());
1104 GURL url10 = GURL(IndexedURL(10));
1105 Move(0, GetUniqueNodeByURL(
1106 0, url10), folder_L0, folder_L0->child_count());
1107 GURL url11 = GURL(IndexedURL(11));
1108 Move(0, GetUniqueNodeByURL(0, url11), folder_L0, 0);
1109 GURL url12 = GURL(IndexedURL(12));
1110 Move(0, GetUniqueNodeByURL(0, url12), folder_L0, 1);
1111 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1112 ASSERT_TRUE(AllModelsMatchVerifier());
1115 // Test Scribe ID - 371968.
1116 // Flaky. http://crbug.com/107744.
1117 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_SinkBMs10LevelDown) {
1118 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1119 ASSERT_TRUE(AllModelsMatchVerifier());
1121 const BookmarkNode* folder = GetBookmarkBarNode(0);
1122 const BookmarkNode* folder_L0 = NULL;
1123 const BookmarkNode* folder_L10 = NULL;
1124 for (int level = 0; level < 15; ++level) {
1125 int num_bookmarks = base::RandInt(0, 9);
1126 for (int i = 0; i < num_bookmarks; ++i) {
1127 std::string title = IndexedURLTitle(i);
1128 GURL url = GURL(IndexedURL(i));
1129 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1131 std::string title = IndexedFolderName(level);
1132 folder = AddFolder(0, folder, folder->child_count(), title);
1133 ASSERT_TRUE(folder != NULL);
1134 if (level == 0) folder_L0 = folder;
1135 if (level == 10) folder_L10 = folder;
1137 for (int i = 0; i < 3; ++i) {
1138 std::string title = IndexedURLTitle(i + 10);
1139 GURL url = GURL(IndexedURL(i + 10));
1140 ASSERT_TRUE(AddURL(0, folder_L0, 0, title, url) != NULL);
1142 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1143 ASSERT_TRUE(AllModelsMatchVerifier());
1145 GURL url10 = GURL(IndexedURL(10));
1146 Move(0, GetUniqueNodeByURL(0, url10), folder_L10, folder_L10->child_count());
1147 GURL url11 = GURL(IndexedURL(11));
1148 Move(0, GetUniqueNodeByURL(0, url11), folder_L10, 0);
1149 GURL url12 = GURL(IndexedURL(12));
1150 Move(0, GetUniqueNodeByURL(0, url12), folder_L10, 1);
1151 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1152 ASSERT_TRUE(AllModelsMatchVerifier());
1155 // Test Scribe ID - 371980.
1156 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1157 SC_SinkEmptyBMFold5LevelsDown) {
1158 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1159 ASSERT_TRUE(AllModelsMatchVerifier());
1161 const BookmarkNode* folder = GetBookmarkBarNode(0);
1162 const BookmarkNode* folder_L5 = NULL;
1163 for (int level = 0; level < 15; ++level) {
1164 int num_bookmarks = base::RandInt(0, 9);
1165 for (int i = 0; i < num_bookmarks; ++i) {
1166 std::string title = IndexedURLTitle(i);
1167 GURL url = GURL(IndexedURL(i));
1168 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1170 std::string title = IndexedFolderName(level);
1171 folder = AddFolder(
1172 0, folder, folder->child_count(), title);
1173 ASSERT_TRUE(folder != NULL);
1174 if (level == 5) folder_L5 = folder;
1176 folder = AddFolder(
1177 0, GetBookmarkBarNode(0)->child_count(), kGenericFolderName);
1178 ASSERT_TRUE(folder != NULL);
1179 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1180 ASSERT_TRUE(AllModelsMatchVerifier());
1182 Move(0, folder, folder_L5, folder_L5->child_count());
1183 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1184 ASSERT_TRUE(AllModelsMatchVerifier());
1187 // Test Scribe ID - 371997.
1188 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1189 SC_SinkNonEmptyBMFold5LevelsDown) {
1190 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1191 ASSERT_TRUE(AllModelsMatchVerifier());
1193 const BookmarkNode* folder = GetBookmarkBarNode(0);
1194 const BookmarkNode* folder_L5 = NULL;
1195 for (int level = 0; level < 6; ++level) {
1196 int num_bookmarks = base::RandInt(0, 9);
1197 for (int i = 0; i < num_bookmarks; ++i) {
1198 std::string title = IndexedURLTitle(i);
1199 GURL url = GURL(IndexedURL(i));
1200 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1202 std::string title = IndexedFolderName(level);
1203 folder = AddFolder(0, folder, folder->child_count(), title);
1204 ASSERT_TRUE(folder != NULL);
1205 if (level == 5) folder_L5 = folder;
1207 folder = AddFolder(
1208 0, GetBookmarkBarNode(0)->child_count(), kGenericFolderName);
1209 ASSERT_TRUE(folder != NULL);
1210 for (int i = 0; i < 10; ++i) {
1211 std::string title = IndexedURLTitle(i);
1212 GURL url = GURL(IndexedURL(i));
1213 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1215 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1216 ASSERT_TRUE(AllModelsMatchVerifier());
1218 Move(0, folder, folder_L5, folder_L5->child_count());
1219 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1220 ASSERT_TRUE(AllModelsMatchVerifier());
1223 // Test Scribe ID - 372006.
1224 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1225 SC_HoistFolder5LevelsUp) {
1226 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1227 ASSERT_TRUE(AllModelsMatchVerifier());
1229 const BookmarkNode* folder = GetBookmarkBarNode(0);
1230 const BookmarkNode* folder_L5 = NULL;
1231 for (int level = 0; level < 6; ++level) {
1232 int num_bookmarks = base::RandInt(0, 9);
1233 for (int i = 0; i < num_bookmarks; ++i) {
1234 std::string title = IndexedURLTitle(i);
1235 GURL url = GURL(IndexedURL(i));
1236 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1238 std::string title = IndexedFolderName(level);
1239 folder = AddFolder(0, folder, folder->child_count(), title);
1240 ASSERT_TRUE(folder != NULL);
1241 if (level == 5) folder_L5 = folder;
1243 folder = AddFolder(
1244 0, folder_L5, folder_L5->child_count(), kGenericFolderName);
1245 ASSERT_TRUE(folder != NULL);
1246 for (int i = 0; i < 10; ++i) {
1247 std::string title = IndexedURLTitle(i);
1248 GURL url = GURL(IndexedURL(i));
1249 ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
1251 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1252 ASSERT_TRUE(AllModelsMatchVerifier());
1254 Move(0, folder, GetBookmarkBarNode(0), GetBookmarkBarNode(0)->child_count());
1255 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1256 ASSERT_TRUE(AllModelsMatchVerifier());
1259 // Test Scribe ID - 372026.
1260 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1261 SC_ReverseTheOrderOfTwoBMFolders) {
1262 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1263 ASSERT_TRUE(AllModelsMatchVerifier());
1265 for (int i = 0; i < 2; ++i) {
1266 std::string title = IndexedFolderName(i);
1267 const BookmarkNode* folder = AddFolder(0, i, title);
1268 ASSERT_TRUE(folder != NULL);
1269 for (int j = 0; j < 10; ++j) {
1270 std::string title = IndexedURLTitle(j);
1271 GURL url = GURL(IndexedURL(j));
1272 ASSERT_TRUE(AddURL(0, folder, j, title, url) != NULL);
1275 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1276 ASSERT_TRUE(AllModelsMatchVerifier());
1278 ReverseChildOrder(0, GetBookmarkBarNode(0));
1279 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1280 ASSERT_TRUE(AllModelsMatchVerifier());
1283 // Test Scribe ID - 372028.
1284 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1285 SC_ReverseTheOrderOfTenBMFolders) {
1286 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1287 ASSERT_TRUE(AllModelsMatchVerifier());
1289 for (int i = 0; i < 10; ++i) {
1290 std::string title = IndexedFolderName(i);
1291 const BookmarkNode* folder = AddFolder(0, i, title);
1292 ASSERT_TRUE(folder != NULL);
1293 for (int j = 0; j < 10; ++j) {
1294 std::string title = IndexedURLTitle(1000 * i + j);
1295 GURL url = GURL(IndexedURL(j));
1296 ASSERT_TRUE(AddURL(0, folder, j, title, url) != NULL);
1299 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1300 ASSERT_TRUE(AllModelsMatchVerifier());
1302 ReverseChildOrder(0, GetBookmarkBarNode(0));
1303 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1304 ASSERT_TRUE(AllModelsMatchVerifier());
1307 // Test Scribe ID - 373379.
1308 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1309 MC_BiDirectionalPushAddingBM) {
1310 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1311 ASSERT_TRUE(AllModelsMatchVerifier());
1313 DisableVerifier();
1314 for (int i = 0; i < 2; ++i) {
1315 std::string title0 = IndexedURLTitle(2*i);
1316 GURL url0 = GURL(IndexedURL(2*i));
1317 ASSERT_TRUE(AddURL(0, title0, url0) != NULL);
1318 std::string title1 = IndexedURLTitle(2*i+1);
1319 GURL url1 = GURL(IndexedURL(2*i+1));
1320 ASSERT_TRUE(AddURL(1, title1, url1) != NULL);
1322 ASSERT_TRUE(AwaitQuiescence());
1323 ASSERT_TRUE(AllModelsMatch());
1324 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1327 // Test Scribe ID - 373503.
1328 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1329 MC_BiDirectionalPush_AddingSameBMs) {
1330 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1331 ASSERT_TRUE(AllModelsMatchVerifier());
1333 // Note: When a racy commit is done with identical bookmarks, it is possible
1334 // for duplicates to exist after sync completes. See http://crbug.com/19769.
1335 DisableVerifier();
1336 for (int i = 0; i < 2; ++i) {
1337 std::string title = IndexedURLTitle(i);
1338 GURL url = GURL(IndexedURL(i));
1339 ASSERT_TRUE(AddURL(0, title, url) != NULL);
1340 ASSERT_TRUE(AddURL(1, title, url) != NULL);
1342 ASSERT_TRUE(AwaitQuiescence());
1343 ASSERT_TRUE(AllModelsMatch());
1346 // Test Scribe ID - 373506.
1347 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1348 MC_BootStrapEmptyStateEverywhere) {
1349 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1350 ASSERT_TRUE(AwaitQuiescence());
1351 ASSERT_TRUE(AllModelsMatchVerifier());
1354 // Test Scribe ID - 373505.
1355 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1356 MC_Merge_CaseInsensitivity_InNames) {
1357 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1358 DisableVerifier();
1360 const BookmarkNode* folder0 = AddFolder(0, "Folder");
1361 ASSERT_TRUE(folder0 != NULL);
1362 ASSERT_TRUE(AddURL(0, folder0, 0, "Bookmark 0", GURL(kGenericURL)) != NULL);
1363 ASSERT_TRUE(AddURL(0, folder0, 1, "Bookmark 1", GURL(kGenericURL)) != NULL);
1364 ASSERT_TRUE(AddURL(0, folder0, 2, "Bookmark 2", GURL(kGenericURL)) != NULL);
1366 const BookmarkNode* folder1 = AddFolder(1, "fOlDeR");
1367 ASSERT_TRUE(folder1 != NULL);
1368 ASSERT_TRUE(AddURL(1, folder1, 0, "bOoKmArK 0", GURL(kGenericURL)) != NULL);
1369 ASSERT_TRUE(AddURL(1, folder1, 1, "BooKMarK 1", GURL(kGenericURL)) != NULL);
1370 ASSERT_TRUE(AddURL(1, folder1, 2, "bOOKMARK 2", GURL(kGenericURL)) != NULL);
1372 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1373 ASSERT_TRUE(AwaitQuiescence());
1374 ASSERT_TRUE(AllModelsMatch());
1375 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1378 // Test Scribe ID - 373508.
1379 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1380 MC_SimpleMergeOfDifferentBMModels) {
1381 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1382 DisableVerifier();
1384 for (int i = 0; i < 3; ++i) {
1385 std::string title = IndexedURLTitle(i);
1386 GURL url = GURL(IndexedURL(i));
1387 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
1388 ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
1391 for (int i = 3; i < 10; ++i) {
1392 std::string title0 = IndexedURLTitle(i);
1393 GURL url0 = GURL(IndexedURL(i));
1394 ASSERT_TRUE(AddURL(0, i, title0, url0) != NULL);
1395 std::string title1 = IndexedURLTitle(i+7);
1396 GURL url1 = GURL(IndexedURL(i+7));
1397 ASSERT_TRUE(AddURL(1, i, title1, url1) != NULL);
1400 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1401 ASSERT_TRUE(AwaitQuiescence());
1402 ASSERT_TRUE(AllModelsMatch());
1403 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1406 // Test Scribe ID - 386586.
1407 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1408 MC_MergeSimpleBMHierarchyUnderBMBar) {
1409 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1410 DisableVerifier();
1412 for (int i = 0; i < 3; ++i) {
1413 std::string title = IndexedURLTitle(i);
1414 GURL url = GURL(IndexedURL(i));
1415 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
1416 ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
1419 for (int i = 3; i < 10; ++i) {
1420 std::string title = IndexedURLTitle(i);
1421 GURL url = GURL(IndexedURL(i));
1422 ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
1425 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1426 ASSERT_TRUE(AwaitQuiescence());
1427 ASSERT_TRUE(AllModelsMatch());
1428 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1431 // Test Scribe ID - 386589.
1432 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1433 MC_MergeSimpleBMHierarchyEqualSetsUnderBMBar) {
1434 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1435 DisableVerifier();
1437 for (int i = 0; i < 3; ++i) {
1438 std::string title = IndexedURLTitle(i);
1439 GURL url = GURL(IndexedURL(i));
1440 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
1441 ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
1444 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1445 ASSERT_TRUE(AwaitQuiescence());
1446 ASSERT_TRUE(AllModelsMatch());
1447 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1450 // Test Scribe ID - 373504 - Merge bookmark folders with different bookmarks.
1451 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1452 MC_MergeBMFoldersWithDifferentBMs) {
1453 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1454 DisableVerifier();
1456 const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
1457 ASSERT_TRUE(folder0 != NULL);
1458 const BookmarkNode* folder1 = AddFolder(1, kGenericFolderName);
1459 ASSERT_TRUE(folder1 != NULL);
1460 for (int i = 0; i < 2; ++i) {
1461 std::string title0 = IndexedURLTitle(2*i);
1462 GURL url0 = GURL(IndexedURL(2*i));
1463 ASSERT_TRUE(AddURL(0, folder0, i, title0, url0) != NULL);
1464 std::string title1 = IndexedURLTitle(2*i+1);
1465 GURL url1 = GURL(IndexedURL(2*i+1));
1466 ASSERT_TRUE(AddURL(1, folder1, i, title1, url1) != NULL);
1468 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1469 ASSERT_TRUE(AwaitQuiescence());
1470 ASSERT_TRUE(AllModelsMatch());
1471 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1474 // Test Scribe ID - 373509 - Merge moderately complex bookmark models.
1475 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1476 MC_MergeDifferentBMModelsModeratelyComplex) {
1477 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1478 DisableVerifier();
1480 for (int i = 0; i < 25; ++i) {
1481 std::string title0 = IndexedURLTitle(i);
1482 GURL url0 = GURL(IndexedURL(i));
1483 ASSERT_TRUE(AddURL(0, i, title0, url0) != NULL);
1484 std::string title1 = IndexedURLTitle(i+50);
1485 GURL url1 = GURL(IndexedURL(i+50));
1486 ASSERT_TRUE(AddURL(1, i, title1, url1) != NULL);
1488 for (int i = 25; i < 30; ++i) {
1489 std::string title0 = IndexedFolderName(i);
1490 const BookmarkNode* folder0 = AddFolder(0, i, title0);
1491 ASSERT_TRUE(folder0 != NULL);
1492 std::string title1 = IndexedFolderName(i+50);
1493 const BookmarkNode* folder1 = AddFolder(1, i, title1);
1494 ASSERT_TRUE(folder1 != NULL);
1495 for (int j = 0; j < 5; ++j) {
1496 std::string title0 = IndexedURLTitle(i+5*j);
1497 GURL url0 = GURL(IndexedURL(i+5*j));
1498 ASSERT_TRUE(AddURL(0, folder0, j, title0, url0) != NULL);
1499 std::string title1 = IndexedURLTitle(i+5*j+50);
1500 GURL url1 = GURL(IndexedURL(i+5*j+50));
1501 ASSERT_TRUE(AddURL(1, folder1, j, title1, url1) != NULL);
1504 for (int i = 100; i < 125; ++i) {
1505 std::string title = IndexedURLTitle(i);
1506 GURL url = GURL(IndexedURL(i));
1507 ASSERT_TRUE(AddURL(0, title, url) != NULL);
1508 ASSERT_TRUE(AddURL(1, title, url) != NULL);
1510 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1511 ASSERT_TRUE(AwaitQuiescence());
1512 ASSERT_TRUE(AllModelsMatch());
1513 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1516 // TCM ID - 3675271 - Merge simple bookmark subset under bookmark folder.
1517 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1518 MC_MergeSimpleBMHierarchySubsetUnderBMFolder) {
1519 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1520 DisableVerifier();
1522 for (int i = 0; i < 2; ++i) {
1523 const BookmarkNode* folder = AddFolder(i, kGenericFolderName);
1524 ASSERT_TRUE(folder != NULL);
1525 for (int j = 0; j < 4; ++j) {
1526 if (base::RandDouble() < 0.5) {
1527 std::string title = IndexedURLTitle(j);
1528 GURL url = GURL(IndexedURL(j));
1529 ASSERT_TRUE(AddURL(i, folder, j, title, url) != NULL);
1530 } else {
1531 std::string title = IndexedFolderName(j);
1532 ASSERT_TRUE(AddFolder(i, folder, j, title) != NULL);
1536 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1537 ASSERT_TRUE(AwaitQuiescence());
1538 ASSERT_TRUE(AllModelsMatch());
1539 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1542 // TCM ID - 3727284 - Merge subsets of bookmark under bookmark bar.
1543 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1544 MC_MergeSimpleBMHierarchySubsetUnderBookmarkBar) {
1545 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1546 DisableVerifier();
1548 for (int i = 0; i < 4; ++i) {
1549 std::string title = IndexedURLTitle(i);
1550 GURL url = GURL(IndexedURL(i));
1551 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
1554 for (int j = 0; j < 2; ++j) {
1555 std::string title = IndexedURLTitle(j);
1556 GURL url = GURL(IndexedURL(j));
1557 ASSERT_TRUE(AddURL(1, j, title, url) != NULL);
1560 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1561 ASSERT_TRUE(AwaitQuiescence());
1562 ASSERT_TRUE(AllModelsMatch());
1563 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1564 ASSERT_FALSE(ContainsDuplicateBookmarks(1));
1567 // TCM ID - 3659294 - Merge simple bookmark hierarchy under bookmark folder.
1568 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1569 MC_Merge_SimpleBMHierarchy_Under_BMFolder) {
1570 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1571 DisableVerifier();
1573 const BookmarkNode* folder0 = AddFolder(0, 0, kGenericFolderName);
1574 ASSERT_TRUE(folder0 != NULL);
1575 ASSERT_TRUE(AddURL(
1576 0, folder0, 0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1577 ASSERT_TRUE(AddFolder(0, folder0, 1, IndexedSubfolderName(2)) != NULL);
1578 ASSERT_TRUE(AddURL(
1579 0, folder0, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
1580 ASSERT_TRUE(AddFolder(0, folder0, 3, IndexedSubfolderName(4)) != NULL);
1582 const BookmarkNode* folder1 = AddFolder(1, 0, kGenericFolderName);
1583 ASSERT_TRUE(folder1 != NULL);
1584 ASSERT_TRUE(AddFolder(1, folder1, 0, IndexedSubfolderName(0)) != NULL);
1585 ASSERT_TRUE(AddFolder(1, folder1, 1, IndexedSubfolderName(2)) != NULL);
1586 ASSERT_TRUE(AddURL(
1587 1, folder1, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
1588 ASSERT_TRUE(AddFolder(1, folder1, 3, IndexedSubfolderName(5)) != NULL);
1589 ASSERT_TRUE(AddURL(
1590 1, folder1, 4, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1592 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1593 ASSERT_TRUE(AwaitQuiescence());
1594 ASSERT_TRUE(AllModelsMatch());
1595 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1598 // TCM ID - 3711273 - Merge disjoint sets of bookmark hierarchy under bookmark
1599 // folder.
1600 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1601 MC_Merge_SimpleBMHierarchy_DisjointSets_Under_BMFolder) {
1602 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1603 DisableVerifier();
1605 const BookmarkNode* folder0 =
1606 AddFolder(0, 0, kGenericFolderName);
1607 ASSERT_TRUE(folder0 != NULL);
1608 ASSERT_TRUE(AddURL(
1609 0, folder0, 0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1610 ASSERT_TRUE(AddFolder(0, folder0, 1, IndexedSubfolderName(2)) != NULL);
1611 ASSERT_TRUE(AddURL(
1612 0, folder0, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
1613 ASSERT_TRUE(AddFolder(0, folder0, 3, IndexedSubfolderName(4)) != NULL);
1615 const BookmarkNode* folder1 = AddFolder(1, 0, kGenericFolderName);
1616 ASSERT_TRUE(folder1 != NULL);
1617 ASSERT_TRUE(AddFolder(1, folder1, 0, IndexedSubfolderName(5)) != NULL);
1618 ASSERT_TRUE(AddFolder(1, folder1, 1, IndexedSubfolderName(6)) != NULL);
1619 ASSERT_TRUE(AddURL(
1620 1, folder1, 2, IndexedURLTitle(7), GURL(IndexedURL(7))) != NULL);
1621 ASSERT_TRUE(AddURL(
1622 1, folder1, 3, IndexedURLTitle(8), GURL(IndexedURL(8))) != NULL);
1624 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1625 ASSERT_TRUE(AwaitQuiescence());
1626 ASSERT_TRUE(AllModelsMatch());
1627 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1630 // TCM ID - 3639296 - Merge disjoint sets of bookmark hierarchy under bookmark
1631 // bar.
1632 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1633 MC_Merge_SimpleBMHierarchy_DisjointSets_Under_BookmarkBar) {
1634 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1635 DisableVerifier();
1637 for (int i = 0; i < 3; ++i) {
1638 std::string title = IndexedURLTitle(i+1);
1639 GURL url = GURL(IndexedURL(i+1));
1640 ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
1643 for (int j = 0; j < 3; ++j) {
1644 std::string title = IndexedURLTitle(j+4);
1645 GURL url = GURL(IndexedURL(j+4));
1646 ASSERT_TRUE(AddURL(0, j, title, url) != NULL);
1649 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1650 ASSERT_TRUE(AwaitQuiescence());
1651 ASSERT_TRUE(AllModelsMatch());
1652 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1655 // TCM ID - 3616282 - Merge sets of duplicate bookmarks under bookmark bar.
1656 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1657 MC_Merge_SimpleBMHierarchy_DuplicateBMs_Under_BMBar) {
1658 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1659 DisableVerifier();
1661 // Let's add duplicate set of bookmark {1,2,2,3,3,3,4,4,4,4} to client0.
1662 int node_index = 0;
1663 for (int i = 1; i < 5 ; ++i) {
1664 for (int j = 0; j < i; ++j) {
1665 std::string title = IndexedURLTitle(i);
1666 GURL url = GURL(IndexedURL(i));
1667 ASSERT_TRUE(AddURL(0, node_index, title, url) != NULL);
1668 ++node_index;
1671 // Let's add a set of bookmarks {1,2,3,4} to client1.
1672 for (int i = 0; i < 4; ++i) {
1673 std::string title = IndexedURLTitle(i+1);
1674 GURL url = GURL(IndexedURL(i+1));
1675 ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
1678 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1679 ASSERT_TRUE(AwaitQuiescence());
1680 ASSERT_TRUE(AllModelsMatch());
1682 for (int i = 1; i < 5 ; ++i) {
1683 ASSERT_TRUE(CountBookmarksWithTitlesMatching(1, IndexedURLTitle(i)) == i);
1687 // TCM ID - 6593872.
1688 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, DisableBookmarks) {
1689 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1690 ASSERT_TRUE(AllModelsMatchVerifier());
1692 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::BOOKMARKS));
1693 ASSERT_TRUE(AddFolder(1, kGenericFolderName) != NULL);
1694 ASSERT_TRUE(AwaitQuiescence());
1695 ASSERT_FALSE(AllModelsMatch());
1697 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::BOOKMARKS));
1698 ASSERT_TRUE(AwaitQuiescence());
1699 ASSERT_TRUE(AllModelsMatch());
1702 // TCM ID - 7343544.
1703 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, DisableSync) {
1704 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1705 ASSERT_TRUE(AllModelsMatchVerifier());
1707 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
1708 ASSERT_TRUE(AddFolder(0, IndexedFolderName(0)) != NULL);
1709 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
1710 ASSERT_FALSE(AllModelsMatch());
1712 ASSERT_TRUE(AddFolder(1, IndexedFolderName(1)) != NULL);
1713 ASSERT_FALSE(AllModelsMatch());
1715 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
1716 ASSERT_TRUE(AwaitQuiescence());
1717 ASSERT_TRUE(AllModelsMatch());
1720 // TCM ID - 3662298 - Test adding duplicate folder - Both with different BMs
1721 // underneath.
1722 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, MC_DuplicateFolders) {
1723 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1724 DisableVerifier();
1726 const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
1727 ASSERT_TRUE(folder0 != NULL);
1728 const BookmarkNode* folder1 = AddFolder(1, kGenericFolderName);
1729 ASSERT_TRUE(folder1 != NULL);
1730 for (int i = 0; i < 5; ++i) {
1731 std::string title0 = IndexedURLTitle(i);
1732 GURL url0 = GURL(IndexedURL(i));
1733 ASSERT_TRUE(AddURL(0, folder0, i, title0, url0) != NULL);
1734 std::string title1 = IndexedURLTitle(i+5);
1735 GURL url1 = GURL(IndexedURL(i+5));
1736 ASSERT_TRUE(AddURL(1, folder1, i, title1, url1) != NULL);
1739 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1740 ASSERT_TRUE(AwaitQuiescence());
1741 ASSERT_TRUE(AllModelsMatch());
1742 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1745 // This test fails when run with FakeServer and FakeServerInvalidationService.
1746 IN_PROC_BROWSER_TEST_F(LegacyTwoClientBookmarksSyncTest, MC_DeleteBookmark) {
1747 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1748 ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::BOOKMARKS));
1750 const GURL bar_url("http://example.com/bar");
1751 const GURL other_url("http://example.com/other");
1753 ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 0, "bar", bar_url) != NULL);
1754 ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, "other", other_url) != NULL);
1756 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
1758 ASSERT_TRUE(HasNodeWithURL(0, bar_url));
1759 ASSERT_TRUE(HasNodeWithURL(0, other_url));
1760 ASSERT_FALSE(HasNodeWithURL(1, bar_url));
1761 ASSERT_FALSE(HasNodeWithURL(1, other_url));
1763 Remove(0, GetBookmarkBarNode(0), 0);
1764 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0))));
1766 ASSERT_FALSE(HasNodeWithURL(0, bar_url));
1767 ASSERT_TRUE(HasNodeWithURL(0, other_url));
1769 ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::BOOKMARKS));
1770 ASSERT_TRUE(AwaitQuiescence());
1772 ASSERT_FALSE(HasNodeWithURL(0, bar_url));
1773 ASSERT_TRUE(HasNodeWithURL(0, other_url));
1774 ASSERT_FALSE(HasNodeWithURL(1, bar_url));
1775 ASSERT_TRUE(HasNodeWithURL(1, other_url));
1778 // TCM ID - 3719307 - Test a scenario of updating the name of the same bookmark
1779 // from two clients at the same time.
1780 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1781 MC_BookmarkNameChangeConflict) {
1782 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1784 const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
1785 ASSERT_TRUE(folder0 != NULL);
1786 for (int i = 0; i < 3; ++i) {
1787 std::string title = IndexedURLTitle(i);
1788 GURL url = GURL(IndexedURL(i));
1789 ASSERT_TRUE(AddURL(0, folder0, i, title, url) != NULL);
1791 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1792 ASSERT_TRUE(AllModelsMatchVerifier());
1793 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1795 DisableVerifier();
1796 GURL url(IndexedURL(0));
1797 SetTitle(0, GetUniqueNodeByURL(0, url), "Title++");
1798 SetTitle(1, GetUniqueNodeByURL(1, url), "Title--");
1800 ASSERT_TRUE(AwaitQuiescence());
1801 ASSERT_TRUE(AllModelsMatch());
1802 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1805 // TCM ID - 3672299 - Test a scenario of updating the URL of the same bookmark
1806 // from two clients at the same time.
1807 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1808 MC_BookmarkURLChangeConflict) {
1809 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1811 const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
1812 ASSERT_TRUE(folder0 != NULL);
1813 for (int i = 0; i < 3; ++i) {
1814 std::string title = IndexedURLTitle(i);
1815 GURL url = GURL(IndexedURL(i));
1816 ASSERT_TRUE(AddURL(0, folder0, i, title, url) != NULL);
1818 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1819 ASSERT_TRUE(AllModelsMatchVerifier());
1820 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1822 DisableVerifier();
1823 GURL url(IndexedURL(0));
1824 ASSERT_TRUE(SetURL(
1825 0, GetUniqueNodeByURL(0, url), GURL("http://www.google.com/00")));
1826 ASSERT_TRUE(SetURL(
1827 1, GetUniqueNodeByURL(1, url), GURL("http://www.google.com/11")));
1829 ASSERT_TRUE(AwaitQuiescence());
1830 ASSERT_TRUE(AllModelsMatch());
1831 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1834 // TCM ID - 3699290 - Test a scenario of updating the BM Folder name from two
1835 // clients at the same time.
1836 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1837 MC_FolderNameChangeConflict) {
1838 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
1839 DisableVerifier();
1841 const BookmarkNode* folderA[2];
1842 const BookmarkNode* folderB[2];
1843 const BookmarkNode* folderC[2];
1845 // Create empty folder A on both clients.
1846 folderA[0] = AddFolder(0, IndexedFolderName(0));
1847 ASSERT_TRUE(folderA[0] != NULL);
1848 folderA[1] = AddFolder(1, IndexedFolderName(0));
1849 ASSERT_TRUE(folderA[1] != NULL);
1851 // Create folder B with bookmarks on both clients.
1852 folderB[0] = AddFolder(0, IndexedFolderName(1));
1853 ASSERT_TRUE(folderB[0] != NULL);
1854 folderB[1] = AddFolder(1, IndexedFolderName(1));
1855 ASSERT_TRUE(folderB[1] != NULL);
1856 for (int i = 0; i < 3; ++i) {
1857 std::string title = IndexedURLTitle(i);
1858 GURL url = GURL(IndexedURL(i));
1859 ASSERT_TRUE(AddURL(0, folderB[0], i, title, url) != NULL);
1862 // Create folder C with bookmarks and subfolders on both clients.
1863 folderC[0] = AddFolder(0, IndexedFolderName(2));
1864 ASSERT_TRUE(folderC[0] != NULL);
1865 folderC[1] = AddFolder(1, IndexedFolderName(2));
1866 ASSERT_TRUE(folderC[1] != NULL);
1867 for (int i = 0; i < 3; ++i) {
1868 std::string folder_name = IndexedSubfolderName(i);
1869 const BookmarkNode* subfolder = AddFolder(0, folderC[0], i, folder_name);
1870 ASSERT_TRUE(subfolder != NULL);
1871 for (int j = 0; j < 3; ++j) {
1872 std::string title = IndexedURLTitle(j);
1873 GURL url = GURL(IndexedURL(j));
1874 ASSERT_TRUE(AddURL(0, subfolder, j, title, url) != NULL);
1878 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1879 ASSERT_TRUE(AwaitQuiescence());
1880 ASSERT_TRUE(AllModelsMatch());
1881 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1883 // Simultaneously rename folder A on both clients.
1884 SetTitle(0, folderA[0], "Folder A++");
1885 SetTitle(1, folderA[1], "Folder A--");
1886 ASSERT_TRUE(AwaitQuiescence());
1887 ASSERT_TRUE(AllModelsMatch());
1888 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1890 // Simultaneously rename folder B on both clients.
1891 SetTitle(0, folderB[0], "Folder B++");
1892 SetTitle(1, folderB[1], "Folder B--");
1893 ASSERT_TRUE(AwaitQuiescence());
1894 ASSERT_TRUE(AllModelsMatch());
1895 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1897 // Simultaneously rename folder C on both clients.
1898 SetTitle(0, folderC[0], "Folder C++");
1899 SetTitle(1, folderC[1], "Folder C--");
1900 ASSERT_TRUE(AwaitQuiescence());
1901 ASSERT_TRUE(AllModelsMatch());
1902 ASSERT_FALSE(ContainsDuplicateBookmarks(0));
1905 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1906 SingleClientEnabledEncryption) {
1907 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1908 ASSERT_TRUE(AllModelsMatchVerifier());
1910 ASSERT_TRUE(EnableEncryption(0));
1911 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1912 ASSERT_TRUE(IsEncryptionComplete(0));
1913 ASSERT_TRUE(IsEncryptionComplete(1));
1914 ASSERT_TRUE(AllModelsMatchVerifier());
1917 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1918 SingleClientEnabledEncryptionAndChanged) {
1919 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1920 ASSERT_TRUE(AllModelsMatchVerifier());
1922 ASSERT_TRUE(EnableEncryption(0));
1923 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
1924 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1925 ASSERT_TRUE(IsEncryptionComplete(0));
1926 ASSERT_TRUE(IsEncryptionComplete(1));
1927 ASSERT_TRUE(AllModelsMatchVerifier());
1930 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1931 BothClientsEnabledEncryption) {
1932 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1933 ASSERT_TRUE(AllModelsMatchVerifier());
1935 ASSERT_TRUE(EnableEncryption(0));
1936 ASSERT_TRUE(EnableEncryption(1));
1937 ASSERT_TRUE(AwaitQuiescence());
1938 ASSERT_TRUE(IsEncryptionComplete(0));
1939 ASSERT_TRUE(IsEncryptionComplete(1));
1940 ASSERT_TRUE(AllModelsMatchVerifier());
1943 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1944 SingleClientEnabledEncryptionBothChanged) {
1945 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1946 ASSERT_TRUE(AllModelsMatchVerifier());
1948 ASSERT_TRUE(EnableEncryption(0));
1949 ASSERT_TRUE(AwaitQuiescence());
1950 ASSERT_TRUE(IsEncryptionComplete(0));
1951 ASSERT_TRUE(IsEncryptionComplete(1));
1952 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
1953 ASSERT_TRUE(AddURL(0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1954 ASSERT_TRUE(AwaitQuiescence());
1955 ASSERT_TRUE(AllModelsMatchVerifier());
1956 ASSERT_TRUE(IsEncryptionComplete(0));
1957 ASSERT_TRUE(IsEncryptionComplete(1));
1960 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1961 SingleClientEnabledEncryptionAndChangedMultipleTimes) {
1962 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1963 ASSERT_TRUE(AllModelsMatchVerifier());
1965 ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
1966 ASSERT_TRUE(EnableEncryption(0));
1967 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1968 ASSERT_TRUE(IsEncryptionComplete(0));
1969 ASSERT_TRUE(IsEncryptionComplete(1));
1970 ASSERT_TRUE(AllModelsMatchVerifier());
1972 ASSERT_TRUE(AddURL(0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1973 ASSERT_TRUE(AddFolder(0, IndexedFolderName(0)) != NULL);
1974 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1975 ASSERT_TRUE(AllModelsMatchVerifier());
1978 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
1979 FirstClientEnablesEncryptionWithPassSecondChanges) {
1980 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
1981 ASSERT_TRUE(AllModelsMatchVerifier());
1983 // Add initial bookmarks.
1984 ASSERT_TRUE(AddURL(0, 0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
1985 ASSERT_TRUE(AddURL(0, 1, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
1986 ASSERT_TRUE(AddURL(0, 2, IndexedURLTitle(2), GURL(IndexedURL(2))) != NULL);
1987 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1988 ASSERT_TRUE(AllModelsMatchVerifier());
1990 // Set a passphrase and enable encryption on Client 0. Client 1 will not
1991 // understand the bookmark updates.
1992 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
1993 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0))));
1994 ASSERT_TRUE(EnableEncryption(0));
1995 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
1996 ASSERT_TRUE(IsEncryptionComplete(0));
1997 ASSERT_TRUE(IsEncryptionComplete(1));
1998 ASSERT_TRUE(GetSyncService((1))->IsPassphraseRequired());
2000 // Client 1 adds bookmarks between the first two and between the second two.
2001 ASSERT_TRUE(AddURL(0, 1, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
2002 ASSERT_TRUE(AddURL(0, 3, IndexedURLTitle(4), GURL(IndexedURL(4))) != NULL);
2003 EXPECT_FALSE(AllModelsMatchVerifier());
2004 EXPECT_FALSE(AllModelsMatch());
2006 // Set the passphrase. Everything should resolve.
2007 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((1))));
2008 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
2009 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1))));
2010 ASSERT_TRUE(AwaitQuiescence());
2011 EXPECT_TRUE(AllModelsMatch());
2012 ASSERT_EQ(0,
2013 GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts());
2015 // Ensure everything is syncing normally by appending a final bookmark.
2016 ASSERT_TRUE(AddURL(1, 5, IndexedURLTitle(5), GURL(IndexedURL(5))) != NULL);
2017 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
2018 EXPECT_TRUE(AllModelsMatch());
2019 ASSERT_EQ(0,
2020 GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts());
2023 // Deliberately racy rearranging of bookmarks to test that our conflict resolver
2024 // code results in a consistent view across machines (no matter what the final
2025 // order is).
2026 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, RacyPositionChanges) {
2027 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
2028 ASSERT_TRUE(AllModelsMatchVerifier());
2030 // Add initial bookmarks.
2031 size_t num_bookmarks = 5;
2032 for (size_t i = 0; i < num_bookmarks; ++i) {
2033 ASSERT_TRUE(AddURL(0, i, IndexedURLTitle(i), GURL(IndexedURL(i))) != NULL);
2036 // Once we make diverging changes the verifer is helpless.
2037 ASSERT_TRUE(AwaitQuiescence());
2038 ASSERT_TRUE(AllModelsMatchVerifier());
2039 DisableVerifier();
2041 // Make changes on client 0.
2042 for (size_t i = 0; i < num_bookmarks; ++i) {
2043 const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i)));
2044 int rand_pos = base::RandInt(0, num_bookmarks-1);
2045 DVLOG(1) << "Moving client 0's bookmark " << i << " to position "
2046 << rand_pos;
2047 Move(0, node, node->parent(), rand_pos);
2050 // Make changes on client 1.
2051 for (size_t i = 0; i < num_bookmarks; ++i) {
2052 const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i)));
2053 int rand_pos = base::RandInt(0, num_bookmarks-1);
2054 DVLOG(1) << "Moving client 1's bookmark " << i << " to position "
2055 << rand_pos;
2056 Move(1, node, node->parent(), rand_pos);
2059 ASSERT_TRUE(AwaitQuiescence());
2060 ASSERT_TRUE(AllModelsMatch());
2062 // Now make changes to client 1 first.
2063 for (size_t i = 0; i < num_bookmarks; ++i) {
2064 const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i)));
2065 int rand_pos = base::RandInt(0, num_bookmarks-1);
2066 DVLOG(1) << "Moving client 1's bookmark " << i << " to position "
2067 << rand_pos;
2068 Move(1, node, node->parent(), rand_pos);
2071 // Make changes on client 0.
2072 for (size_t i = 0; i < num_bookmarks; ++i) {
2073 const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i)));
2074 int rand_pos = base::RandInt(0, num_bookmarks-1);
2075 DVLOG(1) << "Moving client 0's bookmark " << i << " to position "
2076 << rand_pos;
2077 Move(0, node, node->parent(), rand_pos);
2080 ASSERT_TRUE(AwaitQuiescence());
2081 ASSERT_TRUE(AllModelsMatch());
2084 // Trigger the server side creation of Synced Bookmarks. Ensure both clients
2085 // remain syncing afterwards. Add bookmarks to the synced bookmarks folder
2086 // and ensure both clients receive the boomkmark.
2087 IN_PROC_BROWSER_TEST_F(LegacyTwoClientBookmarksSyncTest,
2088 CreateSyncedBookmarks) {
2089 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
2090 ASSERT_TRUE(AllModelsMatchVerifier());
2092 TriggerCreateSyncedBookmarks();
2094 // Add a bookmark on Client 0 and ensure it syncs over. This will also trigger
2095 // both clients downloading the new Synced Bookmarks folder.
2096 ASSERT_TRUE(AddURL(0, "Google", GURL("http://www.google.com")));
2097 ASSERT_TRUE(AwaitQuiescence());
2098 ASSERT_TRUE(AllModelsMatch());
2100 // Now add a bookmark within the Synced Bookmarks folder and ensure it syncs
2101 // over.
2102 const BookmarkNode* synced_bookmarks = GetSyncedBookmarksNode(0);
2103 ASSERT_TRUE(synced_bookmarks);
2104 ASSERT_TRUE(AddURL(0, synced_bookmarks, 0, "Google2",
2105 GURL("http://www.google2.com")));
2106 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2107 ASSERT_TRUE(AllModelsMatch());
2110 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
2111 BookmarkAllNodesRemovedEvent) {
2113 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
2114 ASSERT_TRUE(AllModelsMatchVerifier());
2116 // Starting state:
2117 // other_node
2118 // -> folder0
2119 // -> tier1_a
2120 // -> http://mail.google.com
2121 // -> http://www.google.com
2122 // -> http://news.google.com
2123 // -> http://yahoo.com
2124 // -> http://www.cnn.com
2125 // bookmark_bar
2126 // -> empty_folder
2127 // -> folder1
2128 // -> http://yahoo.com
2129 // -> http://gmail.com
2131 const BookmarkNode* folder0 = AddFolder(0, GetOtherNode(0), 0, "folder0");
2132 const BookmarkNode* tier1_a = AddFolder(0, folder0, 0, "tier1_a");
2133 ASSERT_TRUE(AddURL(0, folder0, 1, "News", GURL("http://news.google.com")));
2134 ASSERT_TRUE(AddURL(0, folder0, 2, "Yahoo", GURL("http://www.yahoo.com")));
2135 ASSERT_TRUE(AddURL(0, tier1_a, 0, "Gmai", GURL("http://mail.google.com")));
2136 ASSERT_TRUE(AddURL(0, tier1_a, 1, "Google", GURL("http://www.google.com")));
2137 ASSERT_TRUE(
2138 AddURL(0, GetOtherNode(0), 1, "CNN", GURL("http://www.cnn.com")));
2140 ASSERT_TRUE(AddFolder(0, GetBookmarkBarNode(0), 0, "empty_folder"));
2141 const BookmarkNode* folder1 =
2142 AddFolder(0, GetBookmarkBarNode(0), 1, "folder1");
2143 ASSERT_TRUE(AddURL(0, folder1, 0, "Yahoo", GURL("http://www.yahoo.com")));
2144 ASSERT_TRUE(
2145 AddURL(0, GetBookmarkBarNode(0), 2, "Gmai", GURL("http://gmail.com")));
2147 ASSERT_TRUE(AwaitQuiescence());
2148 ASSERT_TRUE(AllModelsMatch());
2150 // Remove all
2151 RemoveAll(0);
2153 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2154 // Verify other node has no children now.
2155 EXPECT_EQ(0, GetOtherNode(0)->child_count());
2156 EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count());
2157 ASSERT_TRUE(AllModelsMatch());
2160 // Verifies that managed bookmarks (installed by policy) don't get synced.
2161 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, ManagedBookmarks) {
2162 // Make sure the first Profile has an overridden policy provider.
2163 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_))
2164 .WillRepeatedly(testing::Return(true));
2165 policy::ProfilePolicyConnectorFactory::GetInstance()->PushProviderForTesting(
2166 &policy_provider_);
2168 // Set up sync.
2169 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
2170 ASSERT_TRUE(AllModelsMatchVerifier());
2172 // Verify that there are no managed bookmarks at startup in either profile.
2173 // The Managed Bookmarks folder should not be visible at this stage.
2174 const BookmarkNode* managed_node0 = GetManagedNode(0);
2175 ASSERT_TRUE(managed_node0->empty());
2176 ASSERT_FALSE(managed_node0->IsVisible());
2177 const BookmarkNode* managed_node1 = GetManagedNode(1);
2178 ASSERT_TRUE(managed_node1->empty());
2179 ASSERT_FALSE(managed_node1->IsVisible());
2181 // Verify that the bookmark bar node is empty on both profiles too.
2182 const BookmarkNode* bar_node0 = GetBookmarkBarNode(0);
2183 ASSERT_TRUE(bar_node0->empty());
2184 ASSERT_TRUE(bar_node0->IsVisible());
2185 const BookmarkNode* bar_node1 = GetBookmarkBarNode(1);
2186 ASSERT_TRUE(bar_node1->empty());
2187 ASSERT_TRUE(bar_node1->IsVisible());
2189 // Verify that adding a bookmark is observed by the second Profile.
2190 GURL google_url("http://www.google.com");
2191 ASSERT_TRUE(AddURL(0, "Google", google_url) != NULL);
2192 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2193 ASSERT_TRUE(AllModelsMatchVerifier());
2194 ASSERT_EQ(1, bar_node0->child_count());
2195 ASSERT_EQ(1, bar_node1->child_count());
2197 // Set the ManagedBookmarks policy for the first Profile,
2198 // which will add one new managed bookmark.
2199 base::DictionaryValue* bookmark = new base::DictionaryValue();
2200 bookmark->SetString("name", "Managed bookmark");
2201 bookmark->SetString("url", "youtube.com");
2202 base::ListValue* list = new base::ListValue();
2203 list->Append(bookmark);
2204 policy::PolicyMap policy;
2205 policy.Set(policy::key::kManagedBookmarks,
2206 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
2207 policy::POLICY_SOURCE_CLOUD, list, nullptr);
2208 policy_provider_.UpdateChromePolicy(policy);
2209 base::RunLoop().RunUntilIdle();
2211 // Now add another user bookmark and wait for it to sync.
2212 ASSERT_TRUE(AddURL(0, "Google 2", google_url) != NULL);
2213 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2214 ASSERT_TRUE(AllModelsMatchVerifier());
2216 EXPECT_FALSE(GetSyncService(0)->HasUnrecoverableError());
2217 EXPECT_FALSE(GetSyncService(1)->HasUnrecoverableError());
2219 // Verify that the managed bookmark exists in the local model of the first
2220 // Profile, and has a child node.
2221 ASSERT_EQ(1, managed_node0->child_count());
2222 ASSERT_TRUE(managed_node0->IsVisible());
2223 EXPECT_EQ(GURL("http://youtube.com/"), managed_node0->GetChild(0)->url());
2225 // Verify that the second Profile didn't get this node.
2226 ASSERT_EQ(0, managed_node1->child_count());