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