Home | History | Annotate | Download | only in integration
      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.
      4 
      5 #include "base/rand_util.h"
      6 #include "chrome/browser/profiles/profile.h"
      7 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
      8 #include "chrome/browser/sync/test/integration/passwords_helper.h"
      9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
     10 #include "chrome/browser/sync/test/integration/sync_test.h"
     11 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
     12 #include "ui/base/layout.h"
     13 
     14 using bookmarks_helper::AddFolder;
     15 using bookmarks_helper::AddURL;
     16 using bookmarks_helper::AllModelsMatch;
     17 using bookmarks_helper::AllModelsMatchVerifier;
     18 using bookmarks_helper::ContainsDuplicateBookmarks;
     19 using bookmarks_helper::CountBookmarksWithTitlesMatching;
     20 using bookmarks_helper::CreateFavicon;
     21 using bookmarks_helper::GetBookmarkBarNode;
     22 using bookmarks_helper::GetOtherNode;
     23 using bookmarks_helper::GetSyncedBookmarksNode;
     24 using bookmarks_helper::GetUniqueNodeByURL;
     25 using bookmarks_helper::HasNodeWithURL;
     26 using bookmarks_helper::IndexedFolderName;
     27 using bookmarks_helper::IndexedSubfolderName;
     28 using bookmarks_helper::IndexedSubsubfolderName;
     29 using bookmarks_helper::IndexedURL;
     30 using bookmarks_helper::IndexedURLTitle;
     31 using bookmarks_helper::Move;
     32 using bookmarks_helper::Remove;
     33 using bookmarks_helper::RemoveAll;
     34 using bookmarks_helper::ReverseChildOrder;
     35 using bookmarks_helper::SetFavicon;
     36 using bookmarks_helper::SetTitle;
     37 using bookmarks_helper::SetURL;
     38 using bookmarks_helper::SortChildren;
     39 using passwords_helper::SetDecryptionPassphrase;
     40 using passwords_helper::SetEncryptionPassphrase;
     41 
     42 const std::string kGenericURL = "http://www.host.ext:1234/path/filename";
     43 const std::wstring kGenericURLTitle = L"URL Title";
     44 const std::wstring kGenericFolderName = L"Folder Name";
     45 const std::wstring kGenericSubfolderName = L"Subfolder Name";
     46 const std::wstring kGenericSubsubfolderName = L"Subsubfolder Name";
     47 const char* kValidPassphrase = "passphrase!";
     48 
     49 class TwoClientBookmarksSyncTest : public SyncTest {
     50  public:
     51   TwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT) {}
     52   virtual ~TwoClientBookmarksSyncTest() {}
     53 
     54  private:
     55   DISALLOW_COPY_AND_ASSIGN(TwoClientBookmarksSyncTest);
     56 };
     57 
     58 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, Sanity) {
     59   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
     60   ASSERT_TRUE(AllModelsMatchVerifier());
     61 
     62   GURL google_url("http://www.google.com");
     63   ASSERT_TRUE(AddURL(0, L"Google", google_url) != NULL);
     64   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
     65   ASSERT_TRUE(AddURL(1, L"Yahoo", GURL("http://www.yahoo.com")) != NULL);
     66   ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
     67   ASSERT_TRUE(AllModelsMatchVerifier());
     68 
     69   const BookmarkNode* new_folder = AddFolder(0, 2, L"New Folder");
     70   Move(0, GetUniqueNodeByURL(0, google_url), new_folder, 0);
     71   SetTitle(0, GetBookmarkBarNode(0)->GetChild(0), L"Yahoo!!");
     72   ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 1, L"CNN",
     73       GURL("http://www.cnn.com")) != NULL);
     74   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
     75   ASSERT_TRUE(AllModelsMatchVerifier());
     76 
     77   ASSERT_TRUE(AddURL(1, L"Facebook", GURL("http://www.facebook.com")) != NULL);
     78   ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
     79   ASSERT_TRUE(AllModelsMatchVerifier());
     80 
     81   SortChildren(1, GetBookmarkBarNode(1));
     82   ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
     83   ASSERT_TRUE(AllModelsMatchVerifier());
     84 
     85   DisableVerifier();
     86   SetTitle(0, GetUniqueNodeByURL(0, google_url), L"Google++");
     87   SetTitle(1, GetUniqueNodeByURL(1, google_url), L"Google--");
     88   ASSERT_TRUE(AwaitQuiescence());
     89   ASSERT_TRUE(AllModelsMatch());
     90 }
     91 
     92 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SimultaneousURLChanges) {
     93   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
     94   ASSERT_TRUE(AllModelsMatchVerifier());
     95 
     96   GURL initial_url("http://www.google.com");
     97   GURL second_url("http://www.google.com/abc");
     98   GURL third_url("http://www.google.com/def");
     99   std::wstring title = L"Google";
    100 
    101   ASSERT_TRUE(AddURL(0, title, initial_url) != NULL);
    102   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    103 
    104   DisableVerifier();
    105   ASSERT_TRUE(SetURL(
    106       0, GetUniqueNodeByURL(0, initial_url), second_url) != NULL);
    107   ASSERT_TRUE(SetURL(
    108       1, GetUniqueNodeByURL(1, initial_url), third_url) != NULL);
    109   ASSERT_TRUE(AwaitQuiescence());
    110   ASSERT_TRUE(AllModelsMatch());
    111 
    112   SetTitle(0, GetBookmarkBarNode(0)->GetChild(0), L"Google1");
    113   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    114   ASSERT_TRUE(AllModelsMatch());
    115 }
    116 
    117 // Test Scribe ID - 370558.
    118 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddFirstFolder) {
    119   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    120   ASSERT_TRUE(AllModelsMatchVerifier());
    121 
    122   ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
    123   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    124   ASSERT_TRUE(AllModelsMatchVerifier());
    125 }
    126 
    127 // Test Scribe ID - 370559.
    128 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    129                        SC_AddFirstBMWithoutFavicon) {
    130   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    131   ASSERT_TRUE(AllModelsMatchVerifier());
    132 
    133   ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    134   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    135   ASSERT_TRUE(AllModelsMatchVerifier());
    136 }
    137 
    138 // Test Scribe ID - 370489.
    139 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddFirstBMWithFavicon) {
    140   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    141   ASSERT_TRUE(AllModelsMatchVerifier());
    142 
    143   const GURL page_url(kGenericURL);
    144   const GURL icon_url("http://www.google.com/favicon.ico");
    145 
    146   const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, page_url);
    147 
    148   ASSERT_TRUE(bookmark != NULL);
    149   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    150   SetFavicon(0, bookmark, icon_url, CreateFavicon(SK_ColorWHITE),
    151              bookmarks_helper::FROM_UI);
    152   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    153   ASSERT_TRUE(AllModelsMatchVerifier());
    154 }
    155 
    156 // Test that the history service logic for not losing the hidpi versions of
    157 // favicons as a result of sync does not result in dropping sync updates.
    158 // In particular, the synced 16x16 favicon bitmap should overwrite 16x16
    159 // favicon bitmaps on all clients. (Though non-16x16 favicon bitmaps
    160 // are unchanged).
    161 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_SetFaviconHiDPI) {
    162   // Set the supported scale factors to include 2x such that CreateFavicon()
    163   // creates a favicon with hidpi representations and that methods in the
    164   // FaviconService request hidpi favicons.
    165   std::vector<ui::ScaleFactor> supported_scale_factors;
    166   supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
    167   supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
    168   ui::SetSupportedScaleFactors(supported_scale_factors);
    169 
    170   const GURL page_url(kGenericURL);
    171   const GURL icon_url1("http://www.google.com/favicon1.ico");
    172   const GURL icon_url2("http://www.google.com/favicon2.ico");
    173 
    174   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    175   ASSERT_TRUE(AllModelsMatchVerifier());
    176 
    177   const BookmarkNode* bookmark0 = AddURL(0, kGenericURLTitle, page_url);
    178   ASSERT_TRUE(bookmark0 != NULL);
    179   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    180   SetFavicon(0, bookmark0, icon_url1, CreateFavicon(SK_ColorWHITE),
    181              bookmarks_helper::FROM_UI);
    182   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    183   ASSERT_TRUE(AllModelsMatchVerifier());
    184 
    185   const BookmarkNode* bookmark1 = GetUniqueNodeByURL(1, page_url);
    186   SetFavicon(1, bookmark1, icon_url1, CreateFavicon(SK_ColorBLUE),
    187              bookmarks_helper::FROM_UI);
    188   ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
    189   ASSERT_TRUE(AllModelsMatchVerifier());
    190 
    191   SetFavicon(0, bookmark0, icon_url2, CreateFavicon(SK_ColorGREEN),
    192              bookmarks_helper::FROM_UI);
    193   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    194   ASSERT_TRUE(AllModelsMatchVerifier());
    195 }
    196 
    197 // Test Scribe ID - 370560.
    198 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_AddNonHTTPBMs) {
    199   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    200   ASSERT_TRUE(AllModelsMatchVerifier());
    201 
    202   ASSERT_TRUE(AddURL(
    203       0, L"FTP URL", GURL("ftp://user:password@host:1234/path")) != NULL);
    204   ASSERT_TRUE(AddURL(0, L"File URL", GURL("file://host/path")) != NULL);
    205   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    206   ASSERT_TRUE(AllModelsMatchVerifier());
    207 }
    208 
    209 // Test Scribe ID - 370561.
    210 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    211                        SC_AddFirstBMUnderFolder) {
    212   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    213   ASSERT_TRUE(AllModelsMatchVerifier());
    214 
    215   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    216   ASSERT_TRUE(folder != NULL);
    217   ASSERT_TRUE(AddURL(
    218       0, folder, 0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    219   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    220   ASSERT_TRUE(AllModelsMatchVerifier());
    221 }
    222 
    223 // Test Scribe ID - 370562.
    224 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    225                        SC_AddSeveralBMsUnderBMBarAndOtherBM) {
    226   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    227   ASSERT_TRUE(AllModelsMatchVerifier());
    228 
    229   for (int i = 0; i < 20; ++i) {
    230     std::wstring title = IndexedURLTitle(i);
    231     GURL url = GURL(IndexedURL(i));
    232     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    233     ASSERT_TRUE(AddURL(
    234         0, GetOtherNode(0), i, title, url) != NULL);
    235   }
    236   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    237   ASSERT_TRUE(AllModelsMatchVerifier());
    238 }
    239 
    240 // Test Scribe ID - 370563.
    241 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    242                        SC_AddSeveralBMsAndFolders) {
    243   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    244   ASSERT_TRUE(AllModelsMatchVerifier());
    245 
    246   for (int i = 0; i < 15; ++i) {
    247     if (base::RandDouble() > 0.6) {
    248       std::wstring title = IndexedURLTitle(i);
    249       GURL url = GURL(IndexedURL(i));
    250       ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    251     } else {
    252       std::wstring title = IndexedFolderName(i);
    253       const BookmarkNode* folder = AddFolder(0, i, title);
    254       ASSERT_TRUE(folder != NULL);
    255       if (base::RandDouble() > 0.4) {
    256         for (int i = 0; i < 20; ++i) {
    257           std::wstring title = IndexedURLTitle(i);
    258           GURL url = GURL(IndexedURL(i));
    259           ASSERT_TRUE(
    260               AddURL(0, folder, i, title, url) != NULL);
    261         }
    262       }
    263     }
    264   }
    265   for (int i = 0; i < 10; i++) {
    266     std::wstring title = IndexedURLTitle(i);
    267     GURL url = GURL(IndexedURL(i));
    268     ASSERT_TRUE(AddURL(0, GetOtherNode(0), i, title, url) != NULL);
    269   }
    270   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    271   ASSERT_TRUE(AllModelsMatchVerifier());
    272 }
    273 
    274 // Test Scribe ID - 370641.
    275 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    276                        SC_DuplicateBMWithDifferentURLSameName) {
    277   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    278   ASSERT_TRUE(AllModelsMatchVerifier());
    279 
    280   GURL url0 = GURL(IndexedURL(0));
    281   GURL url1 = GURL(IndexedURL(1));
    282   ASSERT_TRUE(AddURL(0, kGenericURLTitle, url0) != NULL);
    283   ASSERT_TRUE(AddURL(0, kGenericURLTitle, url1) != NULL);
    284   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    285   ASSERT_TRUE(AllModelsMatchVerifier());
    286 }
    287 
    288 // Test Scribe ID - 370639 - Add bookmarks with different name and same URL.
    289 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    290                        SC_DuplicateBookmarksWithSameURL) {
    291   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    292   ASSERT_TRUE(AllModelsMatchVerifier());
    293 
    294   std::wstring title0 = IndexedURLTitle(0);
    295   std::wstring title1 = IndexedURLTitle(1);
    296   ASSERT_TRUE(AddURL(0, title0, GURL(kGenericURL)) != NULL);
    297   ASSERT_TRUE(AddURL(0, title1, GURL(kGenericURL)) != NULL);
    298   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    299   ASSERT_TRUE(AllModelsMatchVerifier());
    300 }
    301 
    302 // Test Scribe ID - 371817.
    303 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMName) {
    304   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    305   ASSERT_TRUE(AllModelsMatchVerifier());
    306 
    307   std::wstring title = IndexedURLTitle(1);
    308   const BookmarkNode* bookmark = AddURL(0, title, GURL(kGenericURL));
    309   ASSERT_TRUE(bookmark != NULL);
    310   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    311   ASSERT_TRUE(AllModelsMatchVerifier());
    312 
    313   std::wstring new_title = IndexedURLTitle(2);
    314   SetTitle(0, bookmark, new_title);
    315   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    316   ASSERT_TRUE(AllModelsMatchVerifier());
    317 }
    318 
    319 // Test Scribe ID - 371822.
    320 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMURL) {
    321   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    322   ASSERT_TRUE(AllModelsMatchVerifier());
    323 
    324   GURL url = GURL(IndexedURL(1));
    325   const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, url);
    326   ASSERT_TRUE(bookmark != NULL);
    327   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    328   ASSERT_TRUE(AllModelsMatchVerifier());
    329 
    330   GURL new_url = GURL(IndexedURL(2));
    331   ASSERT_TRUE(SetURL(0, bookmark, new_url) != NULL);
    332   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    333   ASSERT_TRUE(AllModelsMatchVerifier());
    334 }
    335 
    336 
    337 // Test Scribe ID - 371818 - Renaming the same bookmark name twice.
    338 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    339                        SC_TwiceRenamingBookmarkName) {
    340   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    341   ASSERT_TRUE(AllModelsMatchVerifier());
    342 
    343   std::wstring title = IndexedURLTitle(1);
    344   const BookmarkNode* bookmark = AddURL(0, title, GURL(kGenericURL));
    345   ASSERT_TRUE(bookmark != NULL);
    346   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    347   ASSERT_TRUE(AllModelsMatchVerifier());
    348 
    349   std::wstring new_title = IndexedURLTitle(2);
    350   SetTitle(0, bookmark, new_title);
    351   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    352   ASSERT_TRUE(AllModelsMatchVerifier());
    353 
    354   SetTitle(0, bookmark, title);
    355   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    356   ASSERT_TRUE(AllModelsMatchVerifier());
    357 }
    358 
    359 // Test Scribe ID - 371823 - Renaming the same bookmark URL twice.
    360 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    361                        SC_TwiceRenamingBookmarkURL) {
    362   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    363   ASSERT_TRUE(AllModelsMatchVerifier());
    364 
    365   GURL url = GURL(IndexedURL(1));
    366   const BookmarkNode* bookmark = AddURL(0, kGenericURLTitle, url);
    367   ASSERT_TRUE(bookmark != NULL);
    368   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    369   ASSERT_TRUE(AllModelsMatchVerifier());
    370 
    371   GURL new_url = GURL(IndexedURL(2));
    372   ASSERT_TRUE(SetURL(0, bookmark, new_url) != NULL);
    373   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    374   ASSERT_TRUE(AllModelsMatchVerifier());
    375 
    376   ASSERT_TRUE(SetURL(0, bookmark, url) != NULL);
    377   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    378   ASSERT_TRUE(AllModelsMatchVerifier());
    379 }
    380 
    381 // Test Scribe ID - 371824.
    382 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMFolder) {
    383   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    384   ASSERT_TRUE(AllModelsMatchVerifier());
    385 
    386   std::wstring title = IndexedFolderName(1);
    387   const BookmarkNode* folder = AddFolder(0, title);
    388   ASSERT_TRUE(AddURL(
    389       0, folder, 0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    390   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    391   ASSERT_TRUE(AllModelsMatchVerifier());
    392 
    393   std::wstring new_title = IndexedFolderName(2);
    394   SetTitle(0, folder, new_title);
    395   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    396   ASSERT_TRUE(AllModelsMatchVerifier());
    397 }
    398 
    399 // Test Scribe ID - 371825.
    400 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameEmptyBMFolder) {
    401   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    402   ASSERT_TRUE(AllModelsMatchVerifier());
    403 
    404   std::wstring title = IndexedFolderName(1);
    405   const BookmarkNode* folder = AddFolder(0, title);
    406   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    407   ASSERT_TRUE(AllModelsMatchVerifier());
    408 
    409   std::wstring new_title = IndexedFolderName(2);
    410   SetTitle(0, folder, new_title);
    411   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    412   ASSERT_TRUE(AllModelsMatchVerifier());
    413 }
    414 
    415 // Test Scribe ID - 371826.
    416 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    417                        SC_RenameBMFolderWithLongHierarchy) {
    418   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    419   ASSERT_TRUE(AllModelsMatchVerifier());
    420 
    421   std::wstring title = IndexedFolderName(1);
    422   const BookmarkNode* folder = AddFolder(0, title);
    423   ASSERT_TRUE(folder != NULL);
    424   for (int i = 0; i < 120; ++i) {
    425     if (base::RandDouble() > 0.15) {
    426       std::wstring title = IndexedURLTitle(i);
    427       GURL url = GURL(IndexedURL(i));
    428       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    429     } else {
    430       std::wstring title = IndexedSubfolderName(i);
    431       ASSERT_TRUE(AddFolder(0, folder, i, title) != NULL);
    432     }
    433   }
    434   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    435   ASSERT_TRUE(AllModelsMatchVerifier());
    436 
    437   std::wstring new_title = IndexedFolderName(2);
    438   SetTitle(0, folder, new_title);
    439   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    440   ASSERT_TRUE(AllModelsMatchVerifier());
    441 }
    442 
    443 // Test Scribe ID - 371827.
    444 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    445                        SC_RenameBMFolderThatHasParentAndChildren) {
    446   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    447   ASSERT_TRUE(AllModelsMatchVerifier());
    448 
    449   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    450   ASSERT_TRUE(folder != NULL);
    451   for (int i = 1; i < 15; ++i) {
    452     std::wstring title = IndexedURLTitle(i);
    453     GURL url = GURL(IndexedURL(i));
    454     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    455   }
    456   std::wstring title = IndexedSubfolderName(1);
    457   const BookmarkNode* subfolder = AddFolder(0, folder, 0, title);
    458   for (int i = 0; i < 120; ++i) {
    459     if (base::RandDouble() > 0.15) {
    460       std::wstring title = IndexedURLTitle(i);
    461       GURL url = GURL(IndexedURL(i));
    462       ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
    463     } else {
    464       std::wstring title = IndexedSubsubfolderName(i);
    465       ASSERT_TRUE(AddFolder(0, subfolder, i, title) != NULL);
    466     }
    467   }
    468   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    469   ASSERT_TRUE(AllModelsMatchVerifier());
    470 
    471   std::wstring new_title = IndexedSubfolderName(2);
    472   SetTitle(0, subfolder, new_title);
    473   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    474   ASSERT_TRUE(AllModelsMatchVerifier());
    475 }
    476 
    477 // Test Scribe ID - 371828.
    478 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_RenameBMNameAndURL) {
    479   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    480   ASSERT_TRUE(AllModelsMatchVerifier());
    481 
    482   GURL url = GURL(IndexedURL(1));
    483   std::wstring title = IndexedURLTitle(1);
    484   const BookmarkNode* bookmark = AddURL(0, title, url);
    485   ASSERT_TRUE(bookmark != NULL);
    486   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    487   ASSERT_TRUE(AllModelsMatchVerifier());
    488 
    489   GURL new_url = GURL(IndexedURL(2));
    490   std::wstring new_title = IndexedURLTitle(2);
    491   bookmark = SetURL(0, bookmark, new_url);
    492   ASSERT_TRUE(bookmark != NULL);
    493   SetTitle(0, bookmark, new_title);
    494   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    495   ASSERT_TRUE(AllModelsMatchVerifier());
    496 }
    497 
    498 // Test Scribe ID - 371832.
    499 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    500                        SC_DeleteBMEmptyAccountAfterwards) {
    501   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    502   ASSERT_TRUE(AllModelsMatchVerifier());
    503 
    504   ASSERT_TRUE(AddURL(
    505       0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    506   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    507   ASSERT_TRUE(AllModelsMatchVerifier());
    508 
    509   Remove(0, GetBookmarkBarNode(0), 0);
    510   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    511   ASSERT_TRUE(AllModelsMatchVerifier());
    512 }
    513 
    514 // Test Scribe ID - 371833.
    515 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    516                        SC_DelBMNonEmptyAccountAfterwards) {
    517   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    518   ASSERT_TRUE(AllModelsMatchVerifier());
    519 
    520   for (int i = 0; i < 20; ++i) {
    521     std::wstring title = IndexedURLTitle(i);
    522     GURL url = GURL(IndexedURL(i));
    523     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    524   }
    525   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    526   ASSERT_TRUE(AllModelsMatchVerifier());
    527 
    528   Remove(0, GetBookmarkBarNode(0), 0);
    529   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    530   ASSERT_TRUE(AllModelsMatchVerifier());
    531 }
    532 
    533 // Test Scribe ID - 371835.
    534 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    535                        SC_DelFirstBMUnderBMFoldNonEmptyFoldAfterwards) {
    536   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    537   ASSERT_TRUE(AllModelsMatchVerifier());
    538 
    539   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    540   ASSERT_TRUE(folder != NULL);
    541   for (int i = 0; i < 10; ++i) {
    542     std::wstring title = IndexedURLTitle(i);
    543     GURL url = GURL(IndexedURL(i));
    544     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    545   }
    546   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    547   ASSERT_TRUE(AllModelsMatchVerifier());
    548 
    549   Remove(0, folder, 0);
    550   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    551   ASSERT_TRUE(AllModelsMatchVerifier());
    552 }
    553 
    554 // Test Scribe ID - 371836.
    555 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    556                        SC_DelLastBMUnderBMFoldNonEmptyFoldAfterwards) {
    557   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    558   ASSERT_TRUE(AllModelsMatchVerifier());
    559 
    560   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    561   ASSERT_TRUE(folder != NULL);
    562   for (int i = 0; i < 10; ++i) {
    563     std::wstring title = IndexedURLTitle(i);
    564     GURL url = GURL(IndexedURL(i));
    565     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    566   }
    567   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    568   ASSERT_TRUE(AllModelsMatchVerifier());
    569 
    570   Remove(0, folder, folder->child_count() - 1);
    571   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    572   ASSERT_TRUE(AllModelsMatchVerifier());
    573 }
    574 
    575 // Test Scribe ID - 371856.
    576 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    577                        SC_DelMiddleBMUnderBMFoldNonEmptyFoldAfterwards) {
    578   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    579   ASSERT_TRUE(AllModelsMatchVerifier());
    580 
    581   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    582   ASSERT_TRUE(folder != NULL);
    583   for (int i = 0; i < 10; ++i) {
    584     std::wstring title = IndexedURLTitle(i);
    585     GURL url = GURL(IndexedURL(i));
    586     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    587   }
    588   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    589   ASSERT_TRUE(AllModelsMatchVerifier());
    590 
    591   Remove(0, folder, 4);
    592   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    593   ASSERT_TRUE(AllModelsMatchVerifier());
    594 }
    595 
    596 // Test Scribe ID - 371857.
    597 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    598                        SC_DelBMsUnderBMFoldEmptyFolderAfterwards) {
    599   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    600   ASSERT_TRUE(AllModelsMatchVerifier());
    601 
    602   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    603   ASSERT_TRUE(folder != NULL);
    604   for (int i = 0; i < 10; ++i) {
    605     std::wstring title = IndexedURLTitle(i);
    606     GURL url = GURL(IndexedURL(i));
    607     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    608   }
    609   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    610   ASSERT_TRUE(AllModelsMatchVerifier());
    611 
    612   int child_count = folder->child_count();
    613   for (int i = 0; i < child_count; ++i) {
    614     Remove(0, folder, 0);
    615   }
    616   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    617   ASSERT_TRUE(AllModelsMatchVerifier());
    618 }
    619 
    620 // Test Scribe ID - 371858.
    621 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    622                        SC_DelEmptyBMFoldEmptyAccountAfterwards) {
    623   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    624   ASSERT_TRUE(AllModelsMatchVerifier());
    625 
    626   ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
    627   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    628   ASSERT_TRUE(AllModelsMatchVerifier());
    629 
    630   Remove(0, GetBookmarkBarNode(0), 0);
    631   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    632   ASSERT_TRUE(AllModelsMatchVerifier());
    633 }
    634 
    635 // Test Scribe ID - 371869.
    636 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    637                        SC_DelEmptyBMFoldNonEmptyAccountAfterwards) {
    638   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    639   ASSERT_TRUE(AllModelsMatchVerifier());
    640 
    641   ASSERT_TRUE(AddFolder(0, kGenericFolderName) != NULL);
    642   for (int i = 1; i < 15; ++i) {
    643     if (base::RandDouble() > 0.6) {
    644       std::wstring title = IndexedURLTitle(i);
    645       GURL url = GURL(IndexedURL(i));
    646       ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    647     } else {
    648       std::wstring title = IndexedFolderName(i);
    649       ASSERT_TRUE(AddFolder(0, i, title) != NULL);
    650     }
    651   }
    652   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    653   ASSERT_TRUE(AllModelsMatchVerifier());
    654 
    655   Remove(0, GetBookmarkBarNode(0), 0);
    656   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    657   ASSERT_TRUE(AllModelsMatchVerifier());
    658 }
    659 
    660 // Test Scribe ID - 371879.
    661 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    662                        SC_DelBMFoldWithBMsNonEmptyAccountAfterwards) {
    663   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    664   ASSERT_TRUE(AllModelsMatchVerifier());
    665 
    666   ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    667   const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
    668   ASSERT_TRUE(folder != NULL);
    669   for (int i = 2; i < 10; ++i) {
    670     if (base::RandDouble() > 0.6) {
    671       std::wstring title = IndexedURLTitle(i);
    672       GURL url = GURL(IndexedURL(i));
    673       ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    674     } else {
    675       std::wstring title = IndexedFolderName(i);
    676       ASSERT_TRUE(AddFolder(0, i, title) != NULL);
    677     }
    678   }
    679   for (int i = 0; i < 15; ++i) {
    680     std::wstring title = IndexedURLTitle(i);
    681     GURL url = GURL(IndexedURL(i));
    682     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    683   }
    684   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    685   ASSERT_TRUE(AllModelsMatchVerifier());
    686 
    687   Remove(0, GetBookmarkBarNode(0), 1);
    688   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    689   ASSERT_TRUE(AllModelsMatchVerifier());
    690 }
    691 
    692 // Test Scribe ID - 371880.
    693 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    694                        SC_DelBMFoldWithBMsAndBMFoldsNonEmptyACAfterwards) {
    695   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    696   ASSERT_TRUE(AllModelsMatchVerifier());
    697 
    698   ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    699   const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
    700   ASSERT_TRUE(folder != NULL);
    701   for (int i = 2; i < 10; ++i) {
    702     if (base::RandDouble() > 0.6) {
    703       std::wstring title = IndexedURLTitle(i);
    704       GURL url = GURL(IndexedURL(i));
    705       ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    706     } else {
    707       std::wstring title = IndexedFolderName(i);
    708       ASSERT_TRUE(AddFolder(0, i, title) != NULL);
    709     }
    710   }
    711   for (int i = 0; i < 10; ++i) {
    712     if (base::RandDouble() > 0.6) {
    713       std::wstring title = IndexedURLTitle(i);
    714       GURL url = GURL(IndexedURL(i));
    715       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    716     } else {
    717       std::wstring title = IndexedSubfolderName(i);
    718       const BookmarkNode* subfolder =
    719           AddFolder(0, folder, i, title);
    720       ASSERT_TRUE(subfolder != NULL);
    721       if (base::RandDouble() > 0.3) {
    722         for (int j = 0; j < 10; ++j) {
    723           if (base::RandDouble() > 0.6) {
    724             std::wstring title = IndexedURLTitle(j);
    725             GURL url = GURL(IndexedURL(j));
    726             ASSERT_TRUE(AddURL(
    727                 0, subfolder, j, title, url) != NULL);
    728           } else {
    729             std::wstring title = IndexedSubsubfolderName(j);
    730             ASSERT_TRUE(AddFolder(
    731                 0, subfolder, j, title) != NULL);
    732           }
    733         }
    734       }
    735     }
    736   }
    737   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    738   ASSERT_TRUE(AllModelsMatchVerifier());
    739 
    740   Remove(0, GetBookmarkBarNode(0), 1);
    741   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    742   ASSERT_TRUE(AllModelsMatchVerifier());
    743 }
    744 
    745 // Test Scribe ID - 371882.
    746 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    747                        SC_DelBMFoldWithParentAndChildrenBMsAndBMFolds) {
    748   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    749   ASSERT_TRUE(AllModelsMatchVerifier());
    750 
    751   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    752   ASSERT_TRUE(folder != NULL);
    753   for (int i = 1; i < 11; ++i) {
    754     std::wstring title = IndexedURLTitle(i);
    755     GURL url = GURL(IndexedURL(i));
    756     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    757   }
    758   const BookmarkNode* subfolder =
    759       AddFolder(0, folder, 0, kGenericSubfolderName);
    760   ASSERT_TRUE(subfolder != NULL);
    761   for (int i = 0; i < 30; ++i) {
    762     if (base::RandDouble() > 0.2) {
    763       std::wstring title = IndexedURLTitle(i);
    764       GURL url = GURL(IndexedURL(i));
    765       ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
    766     } else {
    767       std::wstring title = IndexedSubsubfolderName(i);
    768       ASSERT_TRUE(AddFolder(0, subfolder, i, title) != NULL);
    769     }
    770   }
    771   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    772   ASSERT_TRUE(AllModelsMatchVerifier());
    773 
    774   Remove(0, folder, 0);
    775   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    776   ASSERT_TRUE(AllModelsMatchVerifier());
    777 }
    778 
    779 // Test Scribe ID - 371931.
    780 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    781                        SC_ReverseTheOrderOfTwoBMs) {
    782   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    783   ASSERT_TRUE(AllModelsMatchVerifier());
    784 
    785   GURL url0 = GURL(IndexedURL(0));
    786   GURL url1 = GURL(IndexedURL(1));
    787   std::wstring title0 = IndexedURLTitle(0);
    788   std::wstring title1 = IndexedURLTitle(1);
    789   const BookmarkNode* bookmark0 = AddURL(0, 0, title0, url0);
    790   const BookmarkNode* bookmark1 = AddURL(0, 1, title1, url1);
    791   ASSERT_TRUE(bookmark0 != NULL);
    792   ASSERT_TRUE(bookmark1 != NULL);
    793   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    794   ASSERT_TRUE(AllModelsMatchVerifier());
    795 
    796   Move(0, bookmark0, GetBookmarkBarNode(0), 2);
    797   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    798   ASSERT_TRUE(AllModelsMatchVerifier());
    799 }
    800 
    801 // Test Scribe ID - 371933.
    802 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_ReverseTheOrderOf10BMs) {
    803   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    804   ASSERT_TRUE(AllModelsMatchVerifier());
    805 
    806   for (int i = 0; i < 10; ++i) {
    807     std::wstring title = IndexedURLTitle(i);
    808     GURL url = GURL(IndexedURL(i));
    809     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    810   }
    811   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    812   ASSERT_TRUE(AllModelsMatchVerifier());
    813 
    814   ReverseChildOrder(0, GetBookmarkBarNode(0));
    815   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    816   ASSERT_TRUE(AllModelsMatchVerifier());
    817 }
    818 
    819 // Test Scribe ID - 371954.
    820 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    821                        SC_MovingBMsFromBMBarToBMFolder) {
    822   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    823   ASSERT_TRUE(AllModelsMatchVerifier());
    824 
    825   ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    826   const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
    827   ASSERT_TRUE(folder != NULL);
    828   for (int i = 2; i < 10; ++i) {
    829     std::wstring title = IndexedURLTitle(i);
    830     GURL url = GURL(IndexedURL(i));
    831     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
    832   }
    833   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    834   ASSERT_TRUE(AllModelsMatchVerifier());
    835 
    836   int num_bookmarks_to_move =
    837       GetBookmarkBarNode(0)->child_count() - 2;
    838   for (int i = 0; i < num_bookmarks_to_move; ++i) {
    839     Move(
    840         0, GetBookmarkBarNode(0)->GetChild(2), folder, i);
    841     ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    842     ASSERT_TRUE(AllModelsMatchVerifier());
    843   }
    844 }
    845 
    846 // Test Scribe ID - 371957.
    847 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    848                        SC_MovingBMsFromBMFoldToBMBar) {
    849   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    850   ASSERT_TRUE(AllModelsMatchVerifier());
    851 
    852   ASSERT_TRUE(AddURL(0, kGenericURLTitle, GURL(kGenericURL)) != NULL);
    853   const BookmarkNode* folder = AddFolder(0, 1, kGenericFolderName);
    854   ASSERT_TRUE(folder != NULL);
    855   for (int i = 0; i < 10; ++i) {
    856     std::wstring title = IndexedURLTitle(i);
    857     GURL url = GURL(IndexedURL(i));
    858     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    859   }
    860   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    861   ASSERT_TRUE(AllModelsMatchVerifier());
    862 
    863   int num_bookmarks_to_move = folder->child_count() - 2;
    864   for (int i = 0; i < num_bookmarks_to_move; ++i) {
    865     Move(0, folder->GetChild(0), GetBookmarkBarNode(0), i);
    866     ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    867     ASSERT_TRUE(AllModelsMatchVerifier());
    868   }
    869 }
    870 
    871 // Test Scribe ID - 371961.
    872 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    873                        SC_MovingBMsFromParentBMFoldToChildBMFold) {
    874   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    875   ASSERT_TRUE(AllModelsMatchVerifier());
    876 
    877   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    878   ASSERT_TRUE(folder != NULL);
    879   for (int i = 0; i < 3; ++i) {
    880     std::wstring title = IndexedURLTitle(i);
    881     GURL url = GURL(IndexedURL(i));
    882     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    883   }
    884   const BookmarkNode* subfolder =
    885       AddFolder(0, folder, 3, kGenericSubfolderName);
    886   ASSERT_TRUE(subfolder != NULL);
    887   for (int i = 0; i < 10; ++i) {
    888     std::wstring title = IndexedURLTitle(i + 3);
    889     GURL url = GURL(IndexedURL(i + 3));
    890     ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
    891   }
    892   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    893   ASSERT_TRUE(AllModelsMatchVerifier());
    894 
    895   for (int i = 0; i < 3; ++i) {
    896     GURL url = GURL(IndexedURL(i));
    897     Move(0, GetUniqueNodeByURL(0, url), subfolder, i + 10);
    898   }
    899   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    900   ASSERT_TRUE(AllModelsMatchVerifier());
    901 }
    902 
    903 // Test Scribe ID - 371964.
    904 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
    905                        SC_MovingBMsFromChildBMFoldToParentBMFold) {
    906   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    907   ASSERT_TRUE(AllModelsMatchVerifier());
    908 
    909   const BookmarkNode* folder = AddFolder(0, kGenericFolderName);
    910   ASSERT_TRUE(folder != NULL);
    911   for (int i = 0; i < 3; ++i) {
    912     std::wstring title = IndexedURLTitle(i);
    913     GURL url = GURL(IndexedURL(i));
    914     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    915   }
    916   const BookmarkNode* subfolder =
    917       AddFolder(0, folder, 3, kGenericSubfolderName);
    918   ASSERT_TRUE(subfolder != NULL);
    919   for (int i = 0; i < 5; ++i) {
    920     std::wstring title = IndexedURLTitle(i + 3);
    921     GURL url = GURL(IndexedURL(i + 3));
    922     ASSERT_TRUE(AddURL(0, subfolder, i, title, url) != NULL);
    923   }
    924   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    925   ASSERT_TRUE(AllModelsMatchVerifier());
    926 
    927   for (int i = 0; i < 3; ++i) {
    928     GURL url = GURL(IndexedURL(i + 3));
    929     Move(0, GetUniqueNodeByURL(0, url), folder, i + 4);
    930   }
    931   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    932   ASSERT_TRUE(AllModelsMatchVerifier());
    933 }
    934 
    935 // Test Scribe ID - 371967.
    936 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_HoistBMs10LevelUp) {
    937   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    938   ASSERT_TRUE(AllModelsMatchVerifier());
    939 
    940   const BookmarkNode* folder = GetBookmarkBarNode(0);
    941   const BookmarkNode* folder_L0 = NULL;
    942   const BookmarkNode* folder_L10 = NULL;
    943   for (int level = 0; level < 15; ++level) {
    944     int num_bookmarks = base::RandInt(0, 9);
    945     for (int i = 0; i < num_bookmarks; ++i) {
    946       std::wstring title = IndexedURLTitle(i);
    947       GURL url = GURL(IndexedURL(i));
    948       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    949     }
    950     std::wstring title = IndexedFolderName(level);
    951     folder = AddFolder(0, folder, folder->child_count(), title);
    952     ASSERT_TRUE(folder != NULL);
    953     if (level == 0) folder_L0 = folder;
    954     if (level == 10) folder_L10 = folder;
    955   }
    956   for (int i = 0; i < 3; ++i) {
    957     std::wstring title = IndexedURLTitle(i + 10);
    958     GURL url = GURL(IndexedURL(i + 10));
    959     ASSERT_TRUE(AddURL(0, folder_L10, i, title, url) != NULL);
    960   }
    961   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    962   ASSERT_TRUE(AllModelsMatchVerifier());
    963 
    964   GURL url10 = GURL(IndexedURL(10));
    965   Move(0, GetUniqueNodeByURL(
    966       0, url10), folder_L0, folder_L0->child_count());
    967   GURL url11 = GURL(IndexedURL(11));
    968   Move(0, GetUniqueNodeByURL(0, url11), folder_L0, 0);
    969   GURL url12 = GURL(IndexedURL(12));
    970   Move(0, GetUniqueNodeByURL(0, url12), folder_L0, 1);
    971   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
    972   ASSERT_TRUE(AllModelsMatchVerifier());
    973 }
    974 
    975 // Test Scribe ID - 371968.
    976 // Flaky. http://crbug.com/107744.
    977 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, SC_SinkBMs10LevelDown) {
    978   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
    979   ASSERT_TRUE(AllModelsMatchVerifier());
    980 
    981   const BookmarkNode* folder = GetBookmarkBarNode(0);
    982   const BookmarkNode* folder_L0 = NULL;
    983   const BookmarkNode* folder_L10 = NULL;
    984   for (int level = 0; level < 15; ++level) {
    985     int num_bookmarks = base::RandInt(0, 9);
    986     for (int i = 0; i < num_bookmarks; ++i) {
    987       std::wstring title = IndexedURLTitle(i);
    988       GURL url = GURL(IndexedURL(i));
    989       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
    990     }
    991     std::wstring title = IndexedFolderName(level);
    992     folder = AddFolder(0, folder, folder->child_count(), title);
    993     ASSERT_TRUE(folder != NULL);
    994     if (level == 0) folder_L0 = folder;
    995     if (level == 10) folder_L10 = folder;
    996   }
    997   for (int i = 0; i < 3; ++i) {
    998     std::wstring title = IndexedURLTitle(i + 10);
    999     GURL url = GURL(IndexedURL(i + 10));
   1000     ASSERT_TRUE(AddURL(0, folder_L0, 0, title, url) != NULL);
   1001   }
   1002   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1003   ASSERT_TRUE(AllModelsMatchVerifier());
   1004 
   1005   GURL url10 = GURL(IndexedURL(10));
   1006   Move(0, GetUniqueNodeByURL(0, url10), folder_L10, folder_L10->child_count());
   1007   GURL url11 = GURL(IndexedURL(11));
   1008   Move(0, GetUniqueNodeByURL(0, url11), folder_L10, 0);
   1009   GURL url12 = GURL(IndexedURL(12));
   1010   Move(0, GetUniqueNodeByURL(0, url12), folder_L10, 1);
   1011   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1012   ASSERT_TRUE(AllModelsMatchVerifier());
   1013 }
   1014 
   1015 // Test Scribe ID - 371980.
   1016 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1017                        SC_SinkEmptyBMFold5LevelsDown) {
   1018   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1019   ASSERT_TRUE(AllModelsMatchVerifier());
   1020 
   1021   const BookmarkNode* folder = GetBookmarkBarNode(0);
   1022   const BookmarkNode* folder_L5 = NULL;
   1023   for (int level = 0; level < 15; ++level) {
   1024     int num_bookmarks = base::RandInt(0, 9);
   1025     for (int i = 0; i < num_bookmarks; ++i) {
   1026       std::wstring title = IndexedURLTitle(i);
   1027       GURL url = GURL(IndexedURL(i));
   1028       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
   1029     }
   1030     std::wstring title = IndexedFolderName(level);
   1031     folder = AddFolder(
   1032         0, folder, folder->child_count(), title);
   1033     ASSERT_TRUE(folder != NULL);
   1034     if (level == 5) folder_L5 = folder;
   1035   }
   1036   folder = AddFolder(
   1037       0, GetBookmarkBarNode(0)->child_count(), kGenericFolderName);
   1038   ASSERT_TRUE(folder != NULL);
   1039   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1040   ASSERT_TRUE(AllModelsMatchVerifier());
   1041 
   1042   Move(0, folder, folder_L5, folder_L5->child_count());
   1043   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1044   ASSERT_TRUE(AllModelsMatchVerifier());
   1045 }
   1046 
   1047 // Test Scribe ID - 371997.
   1048 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1049                        SC_SinkNonEmptyBMFold5LevelsDown) {
   1050   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1051   ASSERT_TRUE(AllModelsMatchVerifier());
   1052 
   1053   const BookmarkNode* folder = GetBookmarkBarNode(0);
   1054   const BookmarkNode* folder_L5 = NULL;
   1055   for (int level = 0; level < 6; ++level) {
   1056     int num_bookmarks = base::RandInt(0, 9);
   1057     for (int i = 0; i < num_bookmarks; ++i) {
   1058       std::wstring title = IndexedURLTitle(i);
   1059       GURL url = GURL(IndexedURL(i));
   1060       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
   1061     }
   1062     std::wstring title = IndexedFolderName(level);
   1063     folder = AddFolder(0, folder, folder->child_count(), title);
   1064     ASSERT_TRUE(folder != NULL);
   1065     if (level == 5) folder_L5 = folder;
   1066   }
   1067   folder = AddFolder(
   1068       0, GetBookmarkBarNode(0)->child_count(), kGenericFolderName);
   1069   ASSERT_TRUE(folder != NULL);
   1070   for (int i = 0; i < 10; ++i) {
   1071     std::wstring title = IndexedURLTitle(i);
   1072     GURL url = GURL(IndexedURL(i));
   1073     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
   1074   }
   1075   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1076   ASSERT_TRUE(AllModelsMatchVerifier());
   1077 
   1078   Move(0, folder, folder_L5, folder_L5->child_count());
   1079   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1080   ASSERT_TRUE(AllModelsMatchVerifier());
   1081 }
   1082 
   1083 // Test Scribe ID - 372006.
   1084 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1085                        SC_HoistFolder5LevelsUp) {
   1086   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1087   ASSERT_TRUE(AllModelsMatchVerifier());
   1088 
   1089   const BookmarkNode* folder = GetBookmarkBarNode(0);
   1090   const BookmarkNode* folder_L5 = NULL;
   1091   for (int level = 0; level < 6; ++level) {
   1092     int num_bookmarks = base::RandInt(0, 9);
   1093     for (int i = 0; i < num_bookmarks; ++i) {
   1094       std::wstring title = IndexedURLTitle(i);
   1095       GURL url = GURL(IndexedURL(i));
   1096       ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
   1097     }
   1098     std::wstring title = IndexedFolderName(level);
   1099     folder = AddFolder(
   1100         0, folder, folder->child_count(), title);
   1101     ASSERT_TRUE(folder != NULL);
   1102     if (level == 5) folder_L5 = folder;
   1103   }
   1104   folder = AddFolder(
   1105       0, folder_L5, folder_L5->child_count(), kGenericFolderName);
   1106   ASSERT_TRUE(folder != NULL);
   1107   for (int i = 0; i < 10; ++i) {
   1108     std::wstring title = IndexedURLTitle(i);
   1109     GURL url = GURL(IndexedURL(i));
   1110     ASSERT_TRUE(AddURL(0, folder, i, title, url) != NULL);
   1111   }
   1112   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1113   ASSERT_TRUE(AllModelsMatchVerifier());
   1114 
   1115   Move(0, folder, GetBookmarkBarNode(0), GetBookmarkBarNode(0)->child_count());
   1116   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1117   ASSERT_TRUE(AllModelsMatchVerifier());
   1118 }
   1119 
   1120 // Test Scribe ID - 372026.
   1121 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1122                        SC_ReverseTheOrderOfTwoBMFolders) {
   1123   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1124   ASSERT_TRUE(AllModelsMatchVerifier());
   1125 
   1126   for (int i = 0; i < 2; ++i) {
   1127     std::wstring title = IndexedFolderName(i);
   1128     const BookmarkNode* folder = AddFolder(0, i, title);
   1129     ASSERT_TRUE(folder != NULL);
   1130     for (int j = 0; j < 10; ++j) {
   1131       std::wstring title = IndexedURLTitle(j);
   1132       GURL url = GURL(IndexedURL(j));
   1133       ASSERT_TRUE(AddURL(0, folder, j, title, url) != NULL);
   1134     }
   1135   }
   1136   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1137   ASSERT_TRUE(AllModelsMatchVerifier());
   1138 
   1139   ReverseChildOrder(0, GetBookmarkBarNode(0));
   1140   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1141   ASSERT_TRUE(AllModelsMatchVerifier());
   1142 }
   1143 
   1144 // Test Scribe ID - 372028.
   1145 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1146                        SC_ReverseTheOrderOfTenBMFolders) {
   1147   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1148   ASSERT_TRUE(AllModelsMatchVerifier());
   1149 
   1150   for (int i = 0; i < 10; ++i) {
   1151     std::wstring title = IndexedFolderName(i);
   1152     const BookmarkNode* folder = AddFolder(0, i, title);
   1153     ASSERT_TRUE(folder != NULL);
   1154     for (int j = 0; j < 10; ++j) {
   1155       std::wstring title = IndexedURLTitle(1000 * i + j);
   1156       GURL url = GURL(IndexedURL(j));
   1157       ASSERT_TRUE(AddURL(0, folder, j, title, url) != NULL);
   1158     }
   1159   }
   1160   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1161   ASSERT_TRUE(AllModelsMatchVerifier());
   1162 
   1163   ReverseChildOrder(0, GetBookmarkBarNode(0));
   1164   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1165   ASSERT_TRUE(AllModelsMatchVerifier());
   1166 }
   1167 
   1168 // Test Scribe ID - 373379.
   1169 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1170                        MC_BiDirectionalPushAddingBM) {
   1171   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1172   ASSERT_TRUE(AllModelsMatchVerifier());
   1173 
   1174   DisableVerifier();
   1175   for (int i = 0; i < 2; ++i) {
   1176     std::wstring title0 = IndexedURLTitle(2*i);
   1177     GURL url0 = GURL(IndexedURL(2*i));
   1178     ASSERT_TRUE(AddURL(0, title0, url0) != NULL);
   1179     std::wstring title1 = IndexedURLTitle(2*i+1);
   1180     GURL url1 = GURL(IndexedURL(2*i+1));
   1181     ASSERT_TRUE(AddURL(1, title1, url1) != NULL);
   1182   }
   1183   ASSERT_TRUE(AwaitQuiescence());
   1184   ASSERT_TRUE(AllModelsMatch());
   1185   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1186 }
   1187 
   1188 // Test Scribe ID - 373503.
   1189 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1190                        MC_BiDirectionalPush_AddingSameBMs) {
   1191   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1192   ASSERT_TRUE(AllModelsMatchVerifier());
   1193 
   1194   // Note: When a racy commit is done with identical bookmarks, it is possible
   1195   // for duplicates to exist after sync completes. See http://crbug.com/19769.
   1196   DisableVerifier();
   1197   for (int i = 0; i < 2; ++i) {
   1198     std::wstring title = IndexedURLTitle(i);
   1199     GURL url = GURL(IndexedURL(i));
   1200     ASSERT_TRUE(AddURL(0, title, url) != NULL);
   1201     ASSERT_TRUE(AddURL(1, title, url) != NULL);
   1202   }
   1203   ASSERT_TRUE(AwaitQuiescence());
   1204   ASSERT_TRUE(AllModelsMatch());
   1205 }
   1206 
   1207 // Test Scribe ID - 373506.
   1208 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1209                        MC_BootStrapEmptyStateEverywhere) {
   1210   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1211   ASSERT_TRUE(AwaitQuiescence());
   1212   ASSERT_TRUE(AllModelsMatchVerifier());
   1213 }
   1214 
   1215 // Test Scribe ID - 373505.
   1216 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1217                        MC_Merge_CaseInsensitivity_InNames) {
   1218   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1219   DisableVerifier();
   1220 
   1221   const BookmarkNode* folder0 = AddFolder(0, L"Folder");
   1222   ASSERT_TRUE(folder0 != NULL);
   1223   ASSERT_TRUE(AddURL(0, folder0, 0, L"Bookmark 0", GURL(kGenericURL)) != NULL);
   1224   ASSERT_TRUE(AddURL(0, folder0, 1, L"Bookmark 1", GURL(kGenericURL)) != NULL);
   1225   ASSERT_TRUE(AddURL(0, folder0, 2, L"Bookmark 2", GURL(kGenericURL)) != NULL);
   1226 
   1227   const BookmarkNode* folder1 = AddFolder(1, L"fOlDeR");
   1228   ASSERT_TRUE(folder1 != NULL);
   1229   ASSERT_TRUE(AddURL(1, folder1, 0, L"bOoKmArK 0", GURL(kGenericURL)) != NULL);
   1230   ASSERT_TRUE(AddURL(1, folder1, 1, L"BooKMarK 1", GURL(kGenericURL)) != NULL);
   1231   ASSERT_TRUE(AddURL(1, folder1, 2, L"bOOKMARK 2", GURL(kGenericURL)) != NULL);
   1232 
   1233   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1234   ASSERT_TRUE(AwaitQuiescence());
   1235   ASSERT_TRUE(AllModelsMatch());
   1236   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1237 }
   1238 
   1239 // Test Scribe ID - 373508.
   1240 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1241                        MC_SimpleMergeOfDifferentBMModels) {
   1242   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1243   DisableVerifier();
   1244 
   1245   for (int i = 0; i < 3; ++i) {
   1246     std::wstring title = IndexedURLTitle(i);
   1247     GURL url = GURL(IndexedURL(i));
   1248     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
   1249     ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
   1250   }
   1251 
   1252   for (int i = 3; i < 10; ++i) {
   1253     std::wstring title0 = IndexedURLTitle(i);
   1254     GURL url0 = GURL(IndexedURL(i));
   1255     ASSERT_TRUE(AddURL(0, i, title0, url0) != NULL);
   1256     std::wstring title1 = IndexedURLTitle(i+7);
   1257     GURL url1 = GURL(IndexedURL(i+7));
   1258     ASSERT_TRUE(AddURL(1, i, title1, url1) != NULL);
   1259   }
   1260 
   1261   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1262   ASSERT_TRUE(AwaitQuiescence());
   1263   ASSERT_TRUE(AllModelsMatch());
   1264   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1265 }
   1266 
   1267 // Test Scribe ID - 386586.
   1268 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1269                        MC_MergeSimpleBMHierarchyUnderBMBar) {
   1270   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1271   DisableVerifier();
   1272 
   1273   for (int i = 0; i < 3; ++i) {
   1274     std::wstring title = IndexedURLTitle(i);
   1275     GURL url = GURL(IndexedURL(i));
   1276     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
   1277     ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
   1278   }
   1279 
   1280   for (int i = 3; i < 10; ++i) {
   1281     std::wstring title = IndexedURLTitle(i);
   1282     GURL url = GURL(IndexedURL(i));
   1283     ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
   1284   }
   1285 
   1286   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1287   ASSERT_TRUE(AwaitQuiescence());
   1288   ASSERT_TRUE(AllModelsMatch());
   1289   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1290 }
   1291 
   1292 // Test Scribe ID - 386589.
   1293 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1294                        MC_MergeSimpleBMHierarchyEqualSetsUnderBMBar) {
   1295   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1296   DisableVerifier();
   1297 
   1298   for (int i = 0; i < 3; ++i) {
   1299     std::wstring title = IndexedURLTitle(i);
   1300     GURL url = GURL(IndexedURL(i));
   1301     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
   1302     ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
   1303   }
   1304 
   1305   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1306   ASSERT_TRUE(AwaitQuiescence());
   1307   ASSERT_TRUE(AllModelsMatch());
   1308   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1309 }
   1310 
   1311 // Test Scribe ID - 373504 - Merge bookmark folders with different bookmarks.
   1312 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1313                        MC_MergeBMFoldersWithDifferentBMs) {
   1314   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1315   DisableVerifier();
   1316 
   1317   const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
   1318   ASSERT_TRUE(folder0 != NULL);
   1319   const BookmarkNode* folder1 = AddFolder(1, kGenericFolderName);
   1320   ASSERT_TRUE(folder1 != NULL);
   1321   for (int i = 0; i < 2; ++i) {
   1322     std::wstring title0 = IndexedURLTitle(2*i);
   1323     GURL url0 = GURL(IndexedURL(2*i));
   1324     ASSERT_TRUE(AddURL(0, folder0, i, title0, url0) != NULL);
   1325     std::wstring title1 = IndexedURLTitle(2*i+1);
   1326     GURL url1 = GURL(IndexedURL(2*i+1));
   1327     ASSERT_TRUE(AddURL(1, folder1, i, title1, url1) != NULL);
   1328   }
   1329   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1330   ASSERT_TRUE(AwaitQuiescence());
   1331   ASSERT_TRUE(AllModelsMatch());
   1332   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1333 }
   1334 
   1335 // Test Scribe ID - 373509 - Merge moderately complex bookmark models.
   1336 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1337                        MC_MergeDifferentBMModelsModeratelyComplex) {
   1338   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1339   DisableVerifier();
   1340 
   1341   for (int i = 0; i < 25; ++i) {
   1342     std::wstring title0 = IndexedURLTitle(i);
   1343     GURL url0 = GURL(IndexedURL(i));
   1344     ASSERT_TRUE(AddURL(0, i, title0, url0) != NULL);
   1345     std::wstring title1 = IndexedURLTitle(i+50);
   1346     GURL url1 = GURL(IndexedURL(i+50));
   1347     ASSERT_TRUE(AddURL(1, i, title1, url1) != NULL);
   1348   }
   1349   for (int i = 25; i < 30; ++i) {
   1350     std::wstring title0 = IndexedFolderName(i);
   1351     const BookmarkNode* folder0 = AddFolder(0, i, title0);
   1352     ASSERT_TRUE(folder0 != NULL);
   1353     std::wstring title1 = IndexedFolderName(i+50);
   1354     const BookmarkNode* folder1 = AddFolder(1, i, title1);
   1355     ASSERT_TRUE(folder1 != NULL);
   1356     for (int j = 0; j < 5; ++j) {
   1357       std::wstring title0 = IndexedURLTitle(i+5*j);
   1358       GURL url0 = GURL(IndexedURL(i+5*j));
   1359       ASSERT_TRUE(AddURL(0, folder0, j, title0, url0) != NULL);
   1360       std::wstring title1 = IndexedURLTitle(i+5*j+50);
   1361       GURL url1 = GURL(IndexedURL(i+5*j+50));
   1362       ASSERT_TRUE(AddURL(1, folder1, j, title1, url1) != NULL);
   1363     }
   1364   }
   1365   for (int i = 100; i < 125; ++i) {
   1366     std::wstring title = IndexedURLTitle(i);
   1367     GURL url = GURL(IndexedURL(i));
   1368     ASSERT_TRUE(AddURL(0, title, url) != NULL);
   1369     ASSERT_TRUE(AddURL(1, title, url) != NULL);
   1370   }
   1371   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1372   ASSERT_TRUE(AwaitQuiescence());
   1373   ASSERT_TRUE(AllModelsMatch());
   1374   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1375 }
   1376 
   1377 // TCM ID - 3675271 - Merge simple bookmark subset under bookmark folder.
   1378 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1379                        MC_MergeSimpleBMHierarchySubsetUnderBMFolder) {
   1380   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1381   DisableVerifier();
   1382 
   1383   for (int i = 0; i < 2; ++i) {
   1384     const BookmarkNode* folder = AddFolder(i, kGenericFolderName);
   1385     ASSERT_TRUE(folder != NULL);
   1386     for (int j = 0; j < 4; ++j) {
   1387       if (base::RandDouble() < 0.5) {
   1388         std::wstring title = IndexedURLTitle(j);
   1389         GURL url = GURL(IndexedURL(j));
   1390         ASSERT_TRUE(AddURL(i, folder, j, title, url) != NULL);
   1391       } else {
   1392         std::wstring title = IndexedFolderName(j);
   1393         ASSERT_TRUE(AddFolder(i, folder, j, title) != NULL);
   1394       }
   1395     }
   1396   }
   1397   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1398   ASSERT_TRUE(AwaitQuiescence());
   1399   ASSERT_TRUE(AllModelsMatch());
   1400   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1401 }
   1402 
   1403 // TCM ID - 3727284 - Merge subsets of bookmark under bookmark bar.
   1404 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1405                        MC_MergeSimpleBMHierarchySubsetUnderBookmarkBar) {
   1406   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1407   DisableVerifier();
   1408 
   1409   for (int i = 0; i < 4; ++i) {
   1410     std::wstring title = IndexedURLTitle(i);
   1411     GURL url = GURL(IndexedURL(i));
   1412     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
   1413   }
   1414 
   1415   for (int j = 0; j < 2; ++j) {
   1416     std::wstring title = IndexedURLTitle(j);
   1417     GURL url = GURL(IndexedURL(j));
   1418     ASSERT_TRUE(AddURL(1, j, title, url) != NULL);
   1419   }
   1420 
   1421   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1422   ASSERT_TRUE(AwaitQuiescence());
   1423   ASSERT_TRUE(AllModelsMatch());
   1424   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1425   ASSERT_FALSE(ContainsDuplicateBookmarks(1));
   1426 }
   1427 
   1428 // TCM ID - 3659294 - Merge simple bookmark hierarchy under bookmark folder.
   1429 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1430                        MC_Merge_SimpleBMHierarchy_Under_BMFolder) {
   1431   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1432   DisableVerifier();
   1433 
   1434   const BookmarkNode* folder0 = AddFolder(0, 0, kGenericFolderName);
   1435   ASSERT_TRUE(folder0 != NULL);
   1436   ASSERT_TRUE(AddURL(
   1437       0, folder0, 0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1438   ASSERT_TRUE(AddFolder(0, folder0, 1, IndexedSubfolderName(2)) != NULL);
   1439   ASSERT_TRUE(AddURL(
   1440       0, folder0, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
   1441   ASSERT_TRUE(AddFolder(0, folder0, 3, IndexedSubfolderName(4)) != NULL);
   1442 
   1443   const BookmarkNode* folder1 = AddFolder(1, 0, kGenericFolderName);
   1444   ASSERT_TRUE(folder1 != NULL);
   1445   ASSERT_TRUE(AddFolder(1, folder1, 0, IndexedSubfolderName(0)) != NULL);
   1446   ASSERT_TRUE(AddFolder(1, folder1, 1, IndexedSubfolderName(2)) != NULL);
   1447   ASSERT_TRUE(AddURL(
   1448       1, folder1, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
   1449   ASSERT_TRUE(AddFolder(1, folder1, 3, IndexedSubfolderName(5)) != NULL);
   1450   ASSERT_TRUE(AddURL(
   1451       1, folder1, 4, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1452 
   1453   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1454   ASSERT_TRUE(AwaitQuiescence());
   1455   ASSERT_TRUE(AllModelsMatch());
   1456   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1457 }
   1458 
   1459 // TCM ID - 3711273 - Merge disjoint sets of bookmark hierarchy under bookmark
   1460 // folder.
   1461 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1462                        MC_Merge_SimpleBMHierarchy_DisjointSets_Under_BMFolder) {
   1463   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1464   DisableVerifier();
   1465 
   1466   const BookmarkNode* folder0 =
   1467       AddFolder(0, 0, kGenericFolderName);
   1468   ASSERT_TRUE(folder0 != NULL);
   1469   ASSERT_TRUE(AddURL(
   1470       0, folder0, 0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1471   ASSERT_TRUE(AddFolder(0, folder0, 1, IndexedSubfolderName(2)) != NULL);
   1472   ASSERT_TRUE(AddURL(
   1473       0, folder0, 2, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
   1474   ASSERT_TRUE(AddFolder(0, folder0, 3, IndexedSubfolderName(4)) != NULL);
   1475 
   1476   const BookmarkNode* folder1 = AddFolder(1, 0, kGenericFolderName);
   1477   ASSERT_TRUE(folder1 != NULL);
   1478   ASSERT_TRUE(AddFolder(1, folder1, 0, IndexedSubfolderName(5)) != NULL);
   1479   ASSERT_TRUE(AddFolder(1, folder1, 1, IndexedSubfolderName(6)) != NULL);
   1480   ASSERT_TRUE(AddURL(
   1481       1, folder1, 2, IndexedURLTitle(7), GURL(IndexedURL(7))) != NULL);
   1482   ASSERT_TRUE(AddURL(
   1483       1, folder1, 3, IndexedURLTitle(8), GURL(IndexedURL(8))) != NULL);
   1484 
   1485   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1486   ASSERT_TRUE(AwaitQuiescence());
   1487   ASSERT_TRUE(AllModelsMatch());
   1488   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1489 }
   1490 
   1491 // TCM ID - 3639296 - Merge disjoint sets of bookmark hierarchy under bookmark
   1492 // bar.
   1493 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1494     MC_Merge_SimpleBMHierarchy_DisjointSets_Under_BookmarkBar) {
   1495   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1496   DisableVerifier();
   1497 
   1498   for (int i = 0; i < 3; ++i) {
   1499     std::wstring title = IndexedURLTitle(i+1);
   1500     GURL url = GURL(IndexedURL(i+1));
   1501     ASSERT_TRUE(AddURL(0, i, title, url) != NULL);
   1502   }
   1503 
   1504   for (int j = 0; j < 3; ++j) {
   1505     std::wstring title = IndexedURLTitle(j+4);
   1506     GURL url = GURL(IndexedURL(j+4));
   1507     ASSERT_TRUE(AddURL(0, j, title, url) != NULL);
   1508   }
   1509 
   1510   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1511   ASSERT_TRUE(AwaitQuiescence());
   1512   ASSERT_TRUE(AllModelsMatch());
   1513   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1514 }
   1515 
   1516 // TCM ID - 3616282 - Merge sets of duplicate bookmarks under bookmark bar.
   1517 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1518                        MC_Merge_SimpleBMHierarchy_DuplicateBMs_Under_BMBar) {
   1519   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1520   DisableVerifier();
   1521 
   1522   // Let's add duplicate set of bookmark {1,2,2,3,3,3,4,4,4,4} to client0.
   1523   int node_index = 0;
   1524   for (int i = 1; i < 5 ; ++i) {
   1525     for (int j = 0; j < i; ++j) {
   1526       std::wstring title = IndexedURLTitle(i);
   1527       GURL url = GURL(IndexedURL(i));
   1528       ASSERT_TRUE(AddURL(0, node_index, title, url) != NULL);
   1529       ++node_index;
   1530     }
   1531   }
   1532   // Let's add a set of bookmarks {1,2,3,4} to client1.
   1533   for (int i = 0; i < 4; ++i) {
   1534     std::wstring title = IndexedURLTitle(i+1);
   1535     GURL url = GURL(IndexedURL(i+1));
   1536     ASSERT_TRUE(AddURL(1, i, title, url) != NULL);
   1537   }
   1538 
   1539   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1540   ASSERT_TRUE(AwaitQuiescence());
   1541   ASSERT_TRUE(AllModelsMatch());
   1542 
   1543   for (int i = 1; i < 5 ; ++i) {
   1544     ASSERT_TRUE(CountBookmarksWithTitlesMatching(1, IndexedURLTitle(i)) == i);
   1545   }
   1546 }
   1547 
   1548 // TCM ID - 6593872.
   1549 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, DisableBookmarks) {
   1550   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1551   ASSERT_TRUE(AllModelsMatchVerifier());
   1552 
   1553   ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::BOOKMARKS));
   1554   ASSERT_TRUE(AddFolder(1, kGenericFolderName) != NULL);
   1555   ASSERT_TRUE(AwaitQuiescence());
   1556   ASSERT_FALSE(AllModelsMatch());
   1557 
   1558   ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::BOOKMARKS));
   1559   ASSERT_TRUE(AwaitQuiescence());
   1560   ASSERT_TRUE(AllModelsMatch());
   1561 }
   1562 
   1563 // TCM ID - 7343544.
   1564 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, DisableSync) {
   1565   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1566   ASSERT_TRUE(AllModelsMatchVerifier());
   1567 
   1568   ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
   1569   ASSERT_TRUE(AddFolder(0, IndexedFolderName(0)) != NULL);
   1570   ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
   1571   ASSERT_FALSE(AllModelsMatch());
   1572 
   1573   ASSERT_TRUE(AddFolder(1, IndexedFolderName(1)) != NULL);
   1574   ASSERT_FALSE(AllModelsMatch());
   1575 
   1576   ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
   1577   ASSERT_TRUE(AwaitQuiescence());
   1578   ASSERT_TRUE(AllModelsMatch());
   1579 }
   1580 
   1581 // TCM ID - 3662298 - Test adding duplicate folder - Both with different BMs
   1582 // underneath.
   1583 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, MC_DuplicateFolders) {
   1584   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1585   DisableVerifier();
   1586 
   1587   const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
   1588   ASSERT_TRUE(folder0 != NULL);
   1589   const BookmarkNode* folder1 = AddFolder(1, kGenericFolderName);
   1590   ASSERT_TRUE(folder1 != NULL);
   1591   for (int i = 0; i < 5; ++i) {
   1592     std::wstring title0 = IndexedURLTitle(i);
   1593     GURL url0 = GURL(IndexedURL(i));
   1594     ASSERT_TRUE(AddURL(0, folder0, i, title0, url0) != NULL);
   1595     std::wstring title1 = IndexedURLTitle(i+5);
   1596     GURL url1 = GURL(IndexedURL(i+5));
   1597     ASSERT_TRUE(AddURL(1, folder1, i, title1, url1) != NULL);
   1598   }
   1599 
   1600   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1601   ASSERT_TRUE(AwaitQuiescence());
   1602   ASSERT_TRUE(AllModelsMatch());
   1603   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1604 }
   1605 
   1606 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, MC_DeleteBookmark) {
   1607   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1608   ASSERT_TRUE(GetClient(1)->DisableSyncForDatatype(syncer::BOOKMARKS));
   1609 
   1610   const GURL bar_url("http://example.com/bar");
   1611   const GURL other_url("http://example.com/other");
   1612 
   1613   ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 0, L"bar", bar_url) != NULL);
   1614   ASSERT_TRUE(AddURL(0, GetOtherNode(0), 0, L"other", other_url) != NULL);
   1615 
   1616   ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
   1617 
   1618   ASSERT_TRUE(HasNodeWithURL(0, bar_url));
   1619   ASSERT_TRUE(HasNodeWithURL(0, other_url));
   1620   ASSERT_FALSE(HasNodeWithURL(1, bar_url));
   1621   ASSERT_FALSE(HasNodeWithURL(1, other_url));
   1622 
   1623   Remove(0, GetBookmarkBarNode(0), 0);
   1624   ASSERT_TRUE(GetClient(0)->AwaitFullSyncCompletion());
   1625 
   1626   ASSERT_FALSE(HasNodeWithURL(0, bar_url));
   1627   ASSERT_TRUE(HasNodeWithURL(0, other_url));
   1628 
   1629   ASSERT_TRUE(GetClient(1)->EnableSyncForDatatype(syncer::BOOKMARKS));
   1630   ASSERT_TRUE(AwaitQuiescence());
   1631 
   1632   ASSERT_FALSE(HasNodeWithURL(0, bar_url));
   1633   ASSERT_TRUE(HasNodeWithURL(0, other_url));
   1634   ASSERT_FALSE(HasNodeWithURL(1, bar_url));
   1635   ASSERT_TRUE(HasNodeWithURL(1, other_url));
   1636 }
   1637 
   1638 // TCM ID - 3719307 - Test a scenario of updating the name of the same bookmark
   1639 // from two clients at the same time.
   1640 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1641                        MC_BookmarkNameChangeConflict) {
   1642   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1643 
   1644   const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
   1645   ASSERT_TRUE(folder0 != NULL);
   1646   for (int i = 0; i < 3; ++i) {
   1647     std::wstring title = IndexedURLTitle(i);
   1648     GURL url = GURL(IndexedURL(i));
   1649     ASSERT_TRUE(AddURL(0, folder0, i, title, url) != NULL);
   1650   }
   1651   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1652   ASSERT_TRUE(AllModelsMatchVerifier());
   1653   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1654 
   1655   DisableVerifier();
   1656   GURL url(IndexedURL(0));
   1657   SetTitle(0, GetUniqueNodeByURL(0, url), L"Title++");
   1658   SetTitle(1, GetUniqueNodeByURL(1, url), L"Title--");
   1659 
   1660   ASSERT_TRUE(AwaitQuiescence());
   1661   ASSERT_TRUE(AllModelsMatch());
   1662   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1663 }
   1664 
   1665 // TCM ID - 3672299 - Test a scenario of updating the URL of the same bookmark
   1666 // from two clients at the same time.
   1667 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1668                        MC_BookmarkURLChangeConflict) {
   1669   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1670 
   1671   const BookmarkNode* folder0 = AddFolder(0, kGenericFolderName);
   1672   ASSERT_TRUE(folder0 != NULL);
   1673   for (int i = 0; i < 3; ++i) {
   1674     std::wstring title = IndexedURLTitle(i);
   1675     GURL url = GURL(IndexedURL(i));
   1676     ASSERT_TRUE(AddURL(0, folder0, i, title, url) != NULL);
   1677   }
   1678   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1679   ASSERT_TRUE(AllModelsMatchVerifier());
   1680   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1681 
   1682   DisableVerifier();
   1683   GURL url(IndexedURL(0));
   1684   ASSERT_TRUE(SetURL(
   1685       0, GetUniqueNodeByURL(0, url), GURL("http://www.google.com/00")));
   1686   ASSERT_TRUE(SetURL(
   1687       1, GetUniqueNodeByURL(1, url), GURL("http://www.google.com/11")));
   1688 
   1689   ASSERT_TRUE(AwaitQuiescence());
   1690   ASSERT_TRUE(AllModelsMatch());
   1691   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1692 }
   1693 
   1694 // TCM ID - 3699290 - Test a scenario of updating the BM Folder name from two
   1695 // clients at the same time.
   1696 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1697                        MC_FolderNameChangeConflict) {
   1698   ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
   1699   DisableVerifier();
   1700 
   1701   const BookmarkNode* folderA[2];
   1702   const BookmarkNode* folderB[2];
   1703   const BookmarkNode* folderC[2];
   1704 
   1705   // Create empty folder A on both clients.
   1706   folderA[0] = AddFolder(0, IndexedFolderName(0));
   1707   ASSERT_TRUE(folderA[0] != NULL);
   1708   folderA[1] = AddFolder(1, IndexedFolderName(0));
   1709   ASSERT_TRUE(folderA[1] != NULL);
   1710 
   1711   // Create folder B with bookmarks on both clients.
   1712   folderB[0] = AddFolder(0, IndexedFolderName(1));
   1713   ASSERT_TRUE(folderB[0] != NULL);
   1714   folderB[1] = AddFolder(1, IndexedFolderName(1));
   1715   ASSERT_TRUE(folderB[1] != NULL);
   1716   for (int i = 0; i < 3; ++i) {
   1717     std::wstring title = IndexedURLTitle(i);
   1718     GURL url = GURL(IndexedURL(i));
   1719     ASSERT_TRUE(AddURL(0, folderB[0], i, title, url) != NULL);
   1720   }
   1721 
   1722   // Create folder C with bookmarks and subfolders on both clients.
   1723   folderC[0] = AddFolder(0, IndexedFolderName(2));
   1724   ASSERT_TRUE(folderC[0] != NULL);
   1725   folderC[1] = AddFolder(1, IndexedFolderName(2));
   1726   ASSERT_TRUE(folderC[1] != NULL);
   1727   for (int i = 0; i < 3; ++i) {
   1728     std::wstring folder_name = IndexedSubfolderName(i);
   1729     const BookmarkNode* subfolder = AddFolder(0, folderC[0], i, folder_name);
   1730     ASSERT_TRUE(subfolder != NULL);
   1731     for (int j = 0; j < 3; ++j) {
   1732       std::wstring title = IndexedURLTitle(j);
   1733       GURL url = GURL(IndexedURL(j));
   1734       ASSERT_TRUE(AddURL(0, subfolder, j, title, url) != NULL);
   1735     }
   1736   }
   1737 
   1738   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1739   ASSERT_TRUE(AwaitQuiescence());
   1740   ASSERT_TRUE(AllModelsMatch());
   1741   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1742 
   1743   // Simultaneously rename folder A on both clients.
   1744   SetTitle(0, folderA[0], L"Folder A++");
   1745   SetTitle(1, folderA[1], L"Folder A--");
   1746   ASSERT_TRUE(AwaitQuiescence());
   1747   ASSERT_TRUE(AllModelsMatch());
   1748   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1749 
   1750   // Simultaneously rename folder B on both clients.
   1751   SetTitle(0, folderB[0], L"Folder B++");
   1752   SetTitle(1, folderB[1], L"Folder B--");
   1753   ASSERT_TRUE(AwaitQuiescence());
   1754   ASSERT_TRUE(AllModelsMatch());
   1755   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1756 
   1757   // Simultaneously rename folder C on both clients.
   1758   SetTitle(0, folderC[0], L"Folder C++");
   1759   SetTitle(1, folderC[1], L"Folder C--");
   1760   ASSERT_TRUE(AwaitQuiescence());
   1761   ASSERT_TRUE(AllModelsMatch());
   1762   ASSERT_FALSE(ContainsDuplicateBookmarks(0));
   1763 }
   1764 
   1765 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1766                        SingleClientEnabledEncryption) {
   1767   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1768   ASSERT_TRUE(AllModelsMatchVerifier());
   1769 
   1770   ASSERT_TRUE(EnableEncryption(0));
   1771   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1772   ASSERT_TRUE(IsEncryptionComplete(0));
   1773   ASSERT_TRUE(IsEncryptionComplete(1));
   1774   ASSERT_TRUE(AllModelsMatchVerifier());
   1775 }
   1776 
   1777 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1778                        SingleClientEnabledEncryptionAndChanged) {
   1779   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1780   ASSERT_TRUE(AllModelsMatchVerifier());
   1781 
   1782   ASSERT_TRUE(EnableEncryption(0));
   1783   ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
   1784   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1785   ASSERT_TRUE(IsEncryptionComplete(0));
   1786   ASSERT_TRUE(IsEncryptionComplete(1));
   1787   ASSERT_TRUE(AllModelsMatchVerifier());
   1788 }
   1789 
   1790 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1791                        BothClientsEnabledEncryption) {
   1792   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1793   ASSERT_TRUE(AllModelsMatchVerifier());
   1794 
   1795   ASSERT_TRUE(EnableEncryption(0));
   1796   ASSERT_TRUE(EnableEncryption(1));
   1797   ASSERT_TRUE(AwaitQuiescence());
   1798   ASSERT_TRUE(IsEncryptionComplete(0));
   1799   ASSERT_TRUE(IsEncryptionComplete(1));
   1800   ASSERT_TRUE(AllModelsMatchVerifier());
   1801 }
   1802 
   1803 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1804                        SingleClientEnabledEncryptionBothChanged) {
   1805   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1806   ASSERT_TRUE(AllModelsMatchVerifier());
   1807 
   1808   ASSERT_TRUE(EnableEncryption(0));
   1809   ASSERT_TRUE(AwaitQuiescence());
   1810   ASSERT_TRUE(IsEncryptionComplete(0));
   1811   ASSERT_TRUE(IsEncryptionComplete(1));
   1812   ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
   1813   ASSERT_TRUE(AddURL(0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1814   ASSERT_TRUE(AwaitQuiescence());
   1815   ASSERT_TRUE(AllModelsMatchVerifier());
   1816   ASSERT_TRUE(IsEncryptionComplete(0));
   1817   ASSERT_TRUE(IsEncryptionComplete(1));
   1818 }
   1819 
   1820 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1821                        SingleClientEnabledEncryptionAndChangedMultipleTimes) {
   1822   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1823   ASSERT_TRUE(AllModelsMatchVerifier());
   1824 
   1825   ASSERT_TRUE(AddURL(0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
   1826   ASSERT_TRUE(EnableEncryption(0));
   1827   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1828   ASSERT_TRUE(IsEncryptionComplete(0));
   1829   ASSERT_TRUE(IsEncryptionComplete(1));
   1830   ASSERT_TRUE(AllModelsMatchVerifier());
   1831 
   1832   ASSERT_TRUE(AddURL(0, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1833   ASSERT_TRUE(AddFolder(0, IndexedFolderName(0)) != NULL);
   1834   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1835   ASSERT_TRUE(AllModelsMatchVerifier());
   1836 }
   1837 
   1838 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1839                        FirstClientEnablesEncryptionWithPassSecondChanges) {
   1840   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1841   ASSERT_TRUE(AllModelsMatchVerifier());
   1842 
   1843   // Add initial bookmarks.
   1844   ASSERT_TRUE(AddURL(0, 0, IndexedURLTitle(0), GURL(IndexedURL(0))) != NULL);
   1845   ASSERT_TRUE(AddURL(0, 1, IndexedURLTitle(1), GURL(IndexedURL(1))) != NULL);
   1846   ASSERT_TRUE(AddURL(0, 2, IndexedURLTitle(2), GURL(IndexedURL(2))) != NULL);
   1847   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1848   ASSERT_TRUE(AllModelsMatchVerifier());
   1849 
   1850   // Set a passphrase and enable encryption on Client 0. Client 1 will not
   1851   // understand the bookmark updates.
   1852   SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
   1853   ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted());
   1854   ASSERT_TRUE(EnableEncryption(0));
   1855   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1856   ASSERT_TRUE(IsEncryptionComplete(0));
   1857   ASSERT_TRUE(IsEncryptionComplete(1));
   1858   ASSERT_TRUE(GetClient(1)->service()->IsPassphraseRequired());
   1859 
   1860   // Client 1 adds bookmarks between the first two and between the second two.
   1861   ASSERT_TRUE(AddURL(0, 1, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL);
   1862   ASSERT_TRUE(AddURL(0, 3, IndexedURLTitle(4), GURL(IndexedURL(4))) != NULL);
   1863   EXPECT_FALSE(AllModelsMatchVerifier());
   1864   EXPECT_FALSE(AllModelsMatch());
   1865 
   1866   // Set the passphrase. Everything should resolve.
   1867   ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired());
   1868   ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
   1869   ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted());
   1870   ASSERT_TRUE(AwaitQuiescence());
   1871   EXPECT_TRUE(AllModelsMatch());
   1872   ASSERT_EQ(0,
   1873             GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts());
   1874 
   1875   // Ensure everything is syncing normally by appending a final bookmark.
   1876   ASSERT_TRUE(AddURL(1, 5, IndexedURLTitle(5), GURL(IndexedURL(5))) != NULL);
   1877   ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
   1878   EXPECT_TRUE(AllModelsMatch());
   1879   ASSERT_EQ(0,
   1880             GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts());
   1881 }
   1882 
   1883 // Deliberately racy rearranging of bookmarks to test that our conflict resolver
   1884 // code results in a consistent view across machines (no matter what the final
   1885 // order is).
   1886 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, RacyPositionChanges) {
   1887   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1888   ASSERT_TRUE(AllModelsMatchVerifier());
   1889 
   1890   // Add initial bookmarks.
   1891   size_t num_bookmarks = 5;
   1892   for (size_t i = 0; i < num_bookmarks; ++i) {
   1893     ASSERT_TRUE(AddURL(0, i, IndexedURLTitle(i), GURL(IndexedURL(i))) != NULL);
   1894   }
   1895 
   1896   // Once we make diverging changes the verifer is helpless.
   1897   ASSERT_TRUE(AwaitQuiescence());
   1898   ASSERT_TRUE(AllModelsMatchVerifier());
   1899   DisableVerifier();
   1900 
   1901   // Make changes on client 0.
   1902   for (size_t i = 0; i < num_bookmarks; ++i) {
   1903     const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i)));
   1904     int rand_pos = base::RandInt(0, num_bookmarks-1);
   1905     DVLOG(1) << "Moving client 0's bookmark " << i << " to position "
   1906              << rand_pos;
   1907     Move(0, node, node->parent(), rand_pos);
   1908   }
   1909 
   1910   // Make changes on client 1.
   1911   for (size_t i = 0; i < num_bookmarks; ++i) {
   1912     const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i)));
   1913     int rand_pos = base::RandInt(0, num_bookmarks-1);
   1914     DVLOG(1) << "Moving client 1's bookmark " << i << " to position "
   1915              << rand_pos;
   1916     Move(1, node, node->parent(), rand_pos);
   1917   }
   1918 
   1919   ASSERT_TRUE(AwaitQuiescence());
   1920   ASSERT_TRUE(AllModelsMatch());
   1921 
   1922   // Now make changes to client 1 first.
   1923   for (size_t i = 0; i < num_bookmarks; ++i) {
   1924     const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i)));
   1925     int rand_pos = base::RandInt(0, num_bookmarks-1);
   1926     DVLOG(1) << "Moving client 1's bookmark " << i << " to position "
   1927              << rand_pos;
   1928     Move(1, node, node->parent(), rand_pos);
   1929   }
   1930 
   1931   // Make changes on client 0.
   1932   for (size_t i = 0; i < num_bookmarks; ++i) {
   1933     const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i)));
   1934     int rand_pos = base::RandInt(0, num_bookmarks-1);
   1935     DVLOG(1) << "Moving client 0's bookmark " << i << " to position "
   1936              << rand_pos;
   1937     Move(0, node, node->parent(), rand_pos);
   1938   }
   1939 
   1940   ASSERT_TRUE(AwaitQuiescence());
   1941   ASSERT_TRUE(AllModelsMatch());
   1942 }
   1943 
   1944 // Trigger the server side creation of Synced Bookmarks. Ensure both clients
   1945 // remain syncing afterwards. Add bookmarks to the synced bookmarks folder
   1946 // and ensure both clients receive the boomkmark.
   1947 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, CreateSyncedBookmarks) {
   1948   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1949   ASSERT_TRUE(AllModelsMatchVerifier());
   1950 
   1951   TriggerCreateSyncedBookmarks();
   1952 
   1953   // Add a bookmark on Client 0 and ensure it syncs over. This will also trigger
   1954   // both clients downloading the new Synced Bookmarks folder.
   1955   ASSERT_TRUE(AddURL(0, L"Google", GURL("http://www.google.com")));
   1956   ASSERT_TRUE(AwaitQuiescence());
   1957   ASSERT_TRUE(AllModelsMatch());
   1958 
   1959   // Now add a bookmark within the Synced Bookmarks folder and ensure it syncs
   1960   // over.
   1961   const BookmarkNode* synced_bookmarks = GetSyncedBookmarksNode(0);
   1962   ASSERT_TRUE(synced_bookmarks);
   1963   ASSERT_TRUE(AddURL(0, synced_bookmarks, 0, L"Google2",
   1964                      GURL("http://www.google2.com")));
   1965   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   1966   ASSERT_TRUE(AllModelsMatch());
   1967 }
   1968 
   1969 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest,
   1970                        BookmarkAllNodesRemovedEvent) {
   1971 
   1972   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
   1973   ASSERT_TRUE(AllModelsMatchVerifier());
   1974 
   1975   // Starting state:
   1976   // other_node
   1977   //    -> folder0
   1978   //      -> tier1_a
   1979   //        -> http://mail.google.com
   1980   //        -> http://www.google.com
   1981   //      -> http://news.google.com
   1982   //      -> http://yahoo.com
   1983   //    -> http://www.cnn.com
   1984   // bookmark_bar
   1985   // -> empty_folder
   1986   // -> folder1
   1987   //    -> http://yahoo.com
   1988   // -> http://gmail.com
   1989 
   1990   const BookmarkNode* folder0 = AddFolder(0, GetOtherNode(0), 0, L"folder0");
   1991   const BookmarkNode* tier1_a = AddFolder(0, folder0, 0, L"tier1_a");
   1992   ASSERT_TRUE(AddURL(0, folder0, 1, L"News", GURL("http://news.google.com")));
   1993   ASSERT_TRUE(AddURL(0, folder0, 2, L"Yahoo", GURL("http://www.yahoo.com")));
   1994   ASSERT_TRUE(AddURL(0, tier1_a, 0, L"Gmail", GURL("http://mail.google.com")));
   1995   ASSERT_TRUE(AddURL(0, tier1_a, 1, L"Google", GURL("http://www.google.com")));
   1996   ASSERT_TRUE(
   1997       AddURL(0, GetOtherNode(0), 1, L"CNN", GURL("http://www.cnn.com")));
   1998 
   1999   ASSERT_TRUE(AddFolder(0, GetBookmarkBarNode(0), 0, L"empty_folder"));
   2000   const BookmarkNode* folder1 =
   2001       AddFolder(0, GetBookmarkBarNode(0), 1, L"folder1");
   2002   ASSERT_TRUE(AddURL(0, folder1, 0, L"Yahoo", GURL("http://www.yahoo.com")));
   2003   ASSERT_TRUE(
   2004       AddURL(0, GetBookmarkBarNode(0), 2, L"Gmail", GURL("http://gmail.com")));
   2005 
   2006   ASSERT_TRUE(AwaitQuiescence());
   2007   ASSERT_TRUE(AllModelsMatch());
   2008 
   2009   // Remove all
   2010   RemoveAll(0);
   2011 
   2012   ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
   2013   // Verify other node has no children now.
   2014   EXPECT_EQ(0, GetOtherNode(0)->child_count());
   2015   EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count());
   2016   ASSERT_TRUE(AllModelsMatch());
   2017 }
   2018