| 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 static const int kNumBookmarks = 150; | 10 static const int kNumBookmarks = 150; |
| 10 | 11 |
| 11 // TODO(braffert): Consider the range / resolution of these test points. | 12 // TODO(braffert): Consider the range / resolution of these test points. |
| 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 // TODO(braffert): Move this class into its own .h/.cc files. What should the | 18 // TODO(braffert): Move this class into its own .h/.cc files. What should the |
| 18 // class files be named as opposed to the file containing the tests themselves? | 19 // class files be named as opposed to the file containing the tests themselves? |
| 19 class BookmarksSyncPerfTest | 20 class BookmarksSyncPerfTest : public LiveSyncTest { |
| 20 : public TwoClientLiveBookmarksSyncTest { | |
| 21 public: | 21 public: |
| 22 BookmarksSyncPerfTest() : url_number(0), url_title_number(0) {} | 22 BookmarksSyncPerfTest() |
| 23 : LiveSyncTest(TWO_CLIENT), |
| 24 url_number(0), |
| 25 url_title_number(0) {} |
| 23 | 26 |
| 24 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. | 27 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. |
| 25 void AddURLs(int profile, int num_urls); | 28 void AddURLs(int profile, int num_urls); |
| 26 | 29 |
| 27 // Updates the URL for all bookmarks in the bookmark bar for |profile|. | 30 // Updates the URL for all bookmarks in the bookmark bar for |profile|. |
| 28 void UpdateURLs(int profile); | 31 void UpdateURLs(int profile); |
| 29 | 32 |
| 30 // Removes all bookmarks in the bookmark bar for |profile|. | 33 // Removes all bookmarks in the bookmark bar for |profile|. |
| 31 void RemoveURLs(int profile); | 34 void RemoveURLs(int profile); |
| 32 | 35 |
| 33 // Remvoes all bookmarks in the bookmark bars for all profiles. Called | 36 // Remvoes all bookmarks in the bookmark bars for all profiles. Called |
| 34 // between benchmark iterations. | 37 // between benchmark iterations. |
| 35 void Cleanup(); | 38 void Cleanup(); |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 // Returns a new unique bookmark URL. | 41 // Returns a new unique bookmark URL. |
| 39 std::string NextIndexedURL(); | 42 std::string NextIndexedURL(); |
| 40 | 43 |
| 41 // Returns a new unique bookmark title. | 44 // Returns a new unique bookmark title. |
| 42 std::wstring NextIndexedURLTitle(); | 45 std::wstring NextIndexedURLTitle(); |
| 43 | 46 |
| 44 int url_number; | 47 int url_number; |
| 45 int url_title_number; | 48 int url_title_number; |
| 46 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); | 49 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest); |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) { | 52 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) { |
| 50 for (int i = 0; i < num_urls; ++i) { | 53 for (int i = 0; i < num_urls; ++i) { |
| 51 ASSERT_TRUE(AddURL( | 54 ASSERT_TRUE(BookmarksHelper::AddURL( |
| 52 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); | 55 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); |
| 53 } | 56 } |
| 54 } | 57 } |
| 55 | 58 |
| 56 void BookmarksSyncPerfTest::UpdateURLs(int profile) { | 59 void BookmarksSyncPerfTest::UpdateURLs(int profile) { |
| 57 for (int i = 0; i < GetBookmarkBarNode(profile)->child_count(); ++i) { | 60 for (int i = 0; |
| 58 ASSERT_TRUE(SetURL(profile, GetBookmarkBarNode(profile)->GetChild(i), | 61 i < BookmarksHelper::GetBookmarkBarNode(profile)->child_count(); |
| 59 GURL(NextIndexedURL()))); | 62 ++i) { |
| 63 ASSERT_TRUE(BookmarksHelper::SetURL( |
| 64 profile, BookmarksHelper::GetBookmarkBarNode(profile)->GetChild(i), |
| 65 GURL(NextIndexedURL()))); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 void BookmarksSyncPerfTest::RemoveURLs(int profile) { | 69 void BookmarksSyncPerfTest::RemoveURLs(int profile) { |
| 64 while (GetBookmarkBarNode(profile)->child_count()) { | 70 while (!BookmarksHelper::GetBookmarkBarNode(profile)->empty()) { |
| 65 Remove(profile, GetBookmarkBarNode(profile), 0); | 71 BookmarksHelper::Remove( |
| 72 profile, BookmarksHelper::GetBookmarkBarNode(profile), 0); |
| 66 } | 73 } |
| 67 } | 74 } |
| 68 | 75 |
| 69 void BookmarksSyncPerfTest::Cleanup() { | 76 void BookmarksSyncPerfTest::Cleanup() { |
| 70 for (int i = 0; i < num_clients(); ++i) { | 77 for (int i = 0; i < num_clients(); ++i) { |
| 71 RemoveURLs(i); | 78 RemoveURLs(i); |
| 72 } | 79 } |
| 73 ASSERT_TRUE(AwaitQuiescence()); | 80 ASSERT_TRUE(AwaitQuiescence()); |
| 74 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 81 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 75 ASSERT_TRUE(AllModelsMatch()); | 82 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 76 } | 83 } |
| 77 | 84 |
| 78 std::string BookmarksSyncPerfTest::NextIndexedURL() { | 85 std::string BookmarksSyncPerfTest::NextIndexedURL() { |
| 79 return IndexedURL(url_number++); | 86 return BookmarksHelper::IndexedURL(url_number++); |
| 80 } | 87 } |
| 81 | 88 |
| 82 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { | 89 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() { |
| 83 return IndexedURLTitle(url_title_number++); | 90 return BookmarksHelper::IndexedURLTitle(url_title_number++); |
| 84 } | 91 } |
| 85 | 92 |
| 86 // TCM ID - 7556828. | 93 // TCM ID - 7556828. |
| 87 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Add) { | 94 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Add) { |
| 88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 95 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 89 DisableVerifier(); | 96 DisableVerifier(); |
| 90 | 97 |
| 91 AddURLs(0, kNumBookmarks); | 98 AddURLs(0, kNumBookmarks); |
| 92 base::TimeDelta dt = | 99 base::TimeDelta dt = |
| 93 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 100 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 94 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | 101 ASSERT_EQ(kNumBookmarks, |
| 95 ASSERT_TRUE(AllModelsMatch()); | 102 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 103 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 96 | 104 |
| 97 // TODO(braffert): Compare timings against some target value. | 105 // TODO(braffert): Compare timings against some target value. |
| 98 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | 106 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; |
| 99 } | 107 } |
| 100 | 108 |
| 101 // TCM ID - 7564762. | 109 // TCM ID - 7564762. |
| 102 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Update) { | 110 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Update) { |
| 103 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 111 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 104 DisableVerifier(); | 112 DisableVerifier(); |
| 105 | 113 |
| 106 AddURLs(0, kNumBookmarks); | 114 AddURLs(0, kNumBookmarks); |
| 107 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 115 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 108 | 116 |
| 109 UpdateURLs(0); | 117 UpdateURLs(0); |
| 110 base::TimeDelta dt = | 118 base::TimeDelta dt = |
| 111 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 119 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 112 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | 120 ASSERT_EQ(kNumBookmarks, |
| 113 ASSERT_TRUE(AllModelsMatch()); | 121 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 122 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 114 | 123 |
| 115 // TODO(braffert): Compare timings against some target value. | 124 // TODO(braffert): Compare timings against some target value. |
| 116 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | 125 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; |
| 117 } | 126 } |
| 118 | 127 |
| 119 // TCM ID - 7566626. | 128 // TCM ID - 7566626. |
| 120 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Delete) { | 129 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, Delete) { |
| 121 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 130 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 122 DisableVerifier(); | 131 DisableVerifier(); |
| 123 | 132 |
| 124 AddURLs(0, kNumBookmarks); | 133 AddURLs(0, kNumBookmarks); |
| 125 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 134 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 126 | 135 |
| 127 RemoveURLs(0); | 136 RemoveURLs(0); |
| 128 base::TimeDelta dt = | 137 base::TimeDelta dt = |
| 129 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 138 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 130 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 139 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 131 ASSERT_TRUE(AllModelsMatch()); | 140 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 132 | 141 |
| 133 // TODO(braffert): Compare timings against some target value. | 142 // TODO(braffert): Compare timings against some target value. |
| 134 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | 143 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; |
| 135 } | 144 } |
| 136 | 145 |
| 137 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { | 146 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, DISABLED_Benchmark) { |
| 138 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 147 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 139 DisableVerifier(); | 148 DisableVerifier(); |
| 140 | 149 |
| 141 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | 150 for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
| 142 int num_bookmarks = kBenchmarkPoints[i]; | 151 int num_bookmarks = kBenchmarkPoints[i]; |
| 143 AddURLs(0, num_bookmarks); | 152 AddURLs(0, num_bookmarks); |
| 144 base::TimeDelta dt_add = | 153 base::TimeDelta dt_add = |
| 145 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 154 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 146 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | 155 ASSERT_EQ(num_bookmarks, |
| 147 ASSERT_TRUE(AllModelsMatch()); | 156 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 157 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 148 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " | 158 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " |
| 149 << dt_add.InSecondsF(); | 159 << dt_add.InSecondsF(); |
| 150 | 160 |
| 151 UpdateURLs(0); | 161 UpdateURLs(0); |
| 152 base::TimeDelta dt_update = | 162 base::TimeDelta dt_update = |
| 153 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 163 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 154 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | 164 ASSERT_EQ(num_bookmarks, |
| 155 ASSERT_TRUE(AllModelsMatch()); | 165 BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 166 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 156 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " | 167 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " |
| 157 << dt_update.InSecondsF(); | 168 << dt_update.InSecondsF(); |
| 158 | 169 |
| 159 RemoveURLs(0); | 170 RemoveURLs(0); |
| 160 base::TimeDelta dt_delete = | 171 base::TimeDelta dt_delete = |
| 161 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 172 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 162 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | 173 ASSERT_EQ(0, BookmarksHelper::GetBookmarkBarNode(0)->child_count()); |
| 163 ASSERT_TRUE(AllModelsMatch()); | 174 ASSERT_TRUE(BookmarksHelper::AllModelsMatch()); |
| 164 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " | 175 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " |
| 165 << dt_delete.InSecondsF(); | 176 << dt_delete.InSecondsF(); |
| 166 | 177 |
| 167 Cleanup(); | 178 Cleanup(); |
| 168 } | 179 } |
| 169 } | 180 } |
| OLD | NEW |