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