| 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/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 6 #include "chrome/test/live_sync/live_bookmarks_sync_test.h" | 6 #include "chrome/test/live_sync/bookmarks_helper.h" |
| 7 #include "chrome/test/live_sync/live_sync_test.h" |
| 7 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | 8 #include "chrome/test/live_sync/performance/sync_timing_helper.h" |
| 8 | 9 |
| 9 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all | 10 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all |
| 10 // datatypes into a performance test base class, once it is possible to do so. | 11 // datatypes into a performance test base class, once it is possible to do so. |
| 11 static const int kNumBookmarks = 150; | 12 static const int kNumBookmarks = 150; |
| 12 static const int kNumBenchmarkPoints = 18; | 13 static const int kNumBenchmarkPoints = 18; |
| 13 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | 14 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, |
| 14 150, 175, 200, 225, 250, 300, 350, 400, | 15 150, 175, 200, 225, 250, 300, 350, 400, |
| 15 500}; | 16 500}; |
| 16 | 17 |
| 17 class BookmarksSyncPerfTest | 18 class BookmarksSyncPerfTest : public LiveSyncTest { |
| 18 : public TwoClientLiveBookmarksSyncTest { | |
| 19 public: | 19 public: |
| 20 BookmarksSyncPerfTest() : url_number(0), url_title_number(0) {} | 20 BookmarksSyncPerfTest() |
| 21 : LiveSyncTest(TWO_CLIENT), |
| 22 url_number(0), |
| 23 url_title_number(0) {} |
| 21 | 24 |
| 22 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. | 25 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. |
| 23 void AddURLs(int profile, int num_urls); | 26 void AddURLs(int profile, int num_urls); |
| 24 | 27 |
| 25 // Updates the URL for all bookmarks in the bookmark bar for |profile|. | 28 // Updates the URL for all bookmarks in the bookmark bar for |profile|. |
| 26 void UpdateURLs(int profile); | 29 void UpdateURLs(int profile); |
| 27 | 30 |
| 28 // Removes all bookmarks in the bookmark bar for |profile|. | 31 // Removes all bookmarks in the bookmark bar for |profile|. |
| 29 void RemoveURLs(int profile); | 32 void RemoveURLs(int profile); |
| 30 | 33 |
| 31 // Remvoes all bookmarks in the bookmark bars for all profiles. Called | 34 // Remvoes all bookmarks in the bookmark bars for all profiles. Called |
| 32 // between benchmark iterations. | 35 // between benchmark iterations. |
| 33 void Cleanup(); | 36 void Cleanup(); |
| 34 | 37 |
| 35 private: | 38 private: |
| 36 // Returns a new unique bookmark URL. | 39 // Returns a new unique bookmark URL. |
| 37 std::string NextIndexedURL(); | 40 std::string NextIndexedURL(); |
| 38 | 41 |
| 39 // Returns a new unique bookmark title. | 42 // Returns a new unique bookmark title. |
| 40 std::wstring NextIndexedURLTitle(); | 43 std::wstring NextIndexedURLTitle(); |
| 41 | 44 |
| 42 int url_number; | 45 int url_number; |
| 43 int url_title_number; | 46 int url_title_number; |
| 44 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); | 47 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) { | 50 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) { |
| 48 for (int i = 0; i < num_urls; ++i) { | 51 for (int i = 0; i < num_urls; ++i) { |
| 49 ASSERT_TRUE(AddURL( | 52 ASSERT_TRUE(BookmarksHelper::AddURL( |
| 50 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); | 53 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 | 56 |
| 54 void BookmarksSyncPerfTest::UpdateURLs(int profile) { | 57 void BookmarksSyncPerfTest::UpdateURLs(int profile) { |
| 55 for (int i = 0; i < GetBookmarkBarNode(profile)->child_count(); ++i) { | 58 for (int i = 0; |
| 56 ASSERT_TRUE(SetURL(profile, GetBookmarkBarNode(profile)->GetChild(i), | 59 i < BookmarksHelper::GetBookmarkBarNode(profile)->child_count(); |
| 57 GURL(NextIndexedURL()))); | 60 ++i) { |
| 61 ASSERT_TRUE(BookmarksHelper::SetURL( |
| 62 profile, BookmarksHelper::GetBookmarkBarNode(profile)->GetChild(i), |
| 63 GURL(NextIndexedURL()))); |
| 58 } | 64 } |
| 59 } | 65 } |
| 60 | 66 |
| 61 void BookmarksSyncPerfTest::RemoveURLs(int profile) { | 67 void BookmarksSyncPerfTest::RemoveURLs(int profile) { |
| 62 while (GetBookmarkBarNode(profile)->child_count()) { | 68 while (!BookmarksHelper::GetBookmarkBarNode(profile)->empty()) { |
| 63 Remove(profile, GetBookmarkBarNode(profile), 0); | 69 BookmarksHelper::Remove( |
| 70 profile, BookmarksHelper::GetBookmarkBarNode(profile), 0); |
| 64 } | 71 } |
| 65 } | 72 } |
| 66 | 73 |
| 67 void BookmarksSyncPerfTest::Cleanup() { | 74 void BookmarksSyncPerfTest::Cleanup() { |
| 68 for (int i = 0; i < num_clients(); ++i) { | 75 for (int i = 0; i < num_clients(); ++i) { |
| 69 RemoveURLs(i); | 76 RemoveURLs(i); |
| 70 } | 77 } |
| 71 ASSERT_TRUE(AwaitQuiescence()); | 78 ASSERT_TRUE(AwaitQuiescence()); |
| 72 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 79 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 73 ASSERT_TRUE(AllModelsMatch()); | 80 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 74 } | 81 } |
| 75 | 82 |
| 76 std::string BookmarksSyncPerfTest::NextIndexedURL() { | 83 std::string BookmarksSyncPerfTest::NextIndexedURL() { |
| 77 return IndexedURL(url_number++); | 84 return BookmarksHelper::IndexedURL(url_number++); |
| 78 } | 85 } |
| 79 | 86 |
| 80 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { | 87 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { |
| 81 return IndexedURLTitle(url_title_number++); | 88 return BookmarksHelper::IndexedURLTitle(url_title_number++); |
| 82 } | 89 } |
| 83 | 90 |
| 84 // TCM ID - 7556828. | 91 // TCM ID - 7556828. |
| 85 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Add) { | 92 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Add) { |
| 86 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 93 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 87 DisableVerifier(); | 94 DisableVerifier(); |
| 88 | 95 |
| 89 AddURLs(0, kNumBookmarks); | 96 AddURLs(0, kNumBookmarks); |
| 90 base::TimeDelta dt = | 97 base::TimeDelta dt = |
| 91 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 98 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 92 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | 99 ASSERT_EQ(kNumBookmarks, |
| 93 ASSERT_TRUE(AllModelsMatch()); | 100 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 101 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 94 | 102 |
| 95 SyncTimingHelper::PrintResult("bookmarks", "add", dt); | 103 SyncTimingHelper::PrintResult("bookmarks", "add", dt); |
| 96 } | 104 } |
| 97 | 105 |
| 98 // TCM ID - 7564762. | 106 // TCM ID - 7564762. |
| 99 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Update) { | 107 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Update) { |
| 100 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 108 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 101 DisableVerifier(); | 109 DisableVerifier(); |
| 102 | 110 |
| 103 AddURLs(0, kNumBookmarks); | 111 AddURLs(0, kNumBookmarks); |
| 104 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 112 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 105 | 113 |
| 106 UpdateURLs(0); | 114 UpdateURLs(0); |
| 107 base::TimeDelta dt = | 115 base::TimeDelta dt = |
| 108 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 116 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 109 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | 117 ASSERT_EQ(kNumBookmarks, |
| 110 ASSERT_TRUE(AllModelsMatch()); | 118 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 119 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 111 | 120 |
| 112 SyncTimingHelper::PrintResult("bookmarks", "update", dt); | 121 SyncTimingHelper::PrintResult("bookmarks", "update", dt); |
| 113 } | 122 } |
| 114 | 123 |
| 115 // TCM ID - 7566626. | 124 // TCM ID - 7566626. |
| 116 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Delete) { | 125 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Delete) { |
| 117 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 118 DisableVerifier(); | 127 DisableVerifier(); |
| 119 | 128 |
| 120 AddURLs(0, kNumBookmarks); | 129 AddURLs(0, kNumBookmarks); |
| 121 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 130 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 122 | 131 |
| 123 RemoveURLs(0); | 132 RemoveURLs(0); |
| 124 base::TimeDelta dt = | 133 base::TimeDelta dt = |
| 125 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 134 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 126 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 135 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 127 ASSERT_TRUE(AllModelsMatch()); | 136 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 128 | 137 |
| 129 SyncTimingHelper::PrintResult("bookmarks", "delete", dt); | 138 SyncTimingHelper::PrintResult("bookmarks", "delete", dt); |
| 130 } | 139 } |
| 131 | 140 |
| 132 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { | 141 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { |
| 133 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 134 DisableVerifier(); | 143 DisableVerifier(); |
| 135 | 144 |
| 136 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | 145 for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
| 137 int num_bookmarks = kBenchmarkPoints[i]; | 146 int num_bookmarks = kBenchmarkPoints[i]; |
| 138 AddURLs(0, num_bookmarks); | 147 AddURLs(0, num_bookmarks); |
| 139 base::TimeDelta dt_add = | 148 base::TimeDelta dt_add = |
| 140 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 149 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 141 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | 150 ASSERT_EQ(num_bookmarks, |
| 142 ASSERT_TRUE(AllModelsMatch()); | 151 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 152 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 143 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " | 153 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " |
| 144 << dt_add.InSecondsF(); | 154 << dt_add.InSecondsF(); |
| 145 | 155 |
| 146 UpdateURLs(0); | 156 UpdateURLs(0); |
| 147 base::TimeDelta dt_update = | 157 base::TimeDelta dt_update = |
| 148 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 158 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 149 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | 159 ASSERT_EQ(num_bookmarks, |
| 150 ASSERT_TRUE(AllModelsMatch()); | 160 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 161 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 151 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " | 162 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " |
| 152 << dt_update.InSecondsF(); | 163 << dt_update.InSecondsF(); |
| 153 | 164 |
| 154 RemoveURLs(0); | 165 RemoveURLs(0); |
| 155 base::TimeDelta dt_delete = | 166 base::TimeDelta dt_delete = |
| 156 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 167 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 157 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 168 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 158 ASSERT_TRUE(AllModelsMatch()); | 169 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 159 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " | 170 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " |
| 160 << dt_delete.InSecondsF(); | 171 << dt_delete.InSecondsF(); |
| 161 | 172 |
| 162 Cleanup(); | 173 Cleanup(); |
| 163 } | 174 } |
| 164 } | 175 } |
| OLD | NEW |