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