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/sync/profile_sync_service_harness.h" |
| 6 #include "chrome/test/live_sync/live_bookmarks_sync_test.h" |
| 7 #include "chrome/test/live_sync/live_sync_timing_helper.h" |
| 8 |
| 9 static const int kNumBookmarks = 150; |
| 10 |
| 11 // TODO(braffert): Consider the range / resolution of these test points. |
| 12 static const int kNumBenchmarkPoints = 18; |
| 13 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, |
| 14 150, 175, 200, 225, 250, 300, 350, 400, |
| 15 500}; |
| 16 |
| 17 // 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 PerformanceLiveBookmarksSyncTest |
| 20 : public TwoClientLiveBookmarksSyncTest { |
| 21 public: |
| 22 PerformanceLiveBookmarksSyncTest() : url_number(0), url_title_number(0) {} |
| 23 |
| 24 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|. |
| 25 void AddURLs(int profile, int num_urls); |
| 26 |
| 27 // Updates the URL for all bookmarks in the bookmark bar for |profile|. |
| 28 void UpdateURLs(int profile); |
| 29 |
| 30 // Removes all bookmarks in the bookmark bar for |profile|. |
| 31 void RemoveURLs(int profile); |
| 32 |
| 33 // Remvoes all bookmarks in the bookmark bars for all profiles. Called |
| 34 // between benchmark iterations. |
| 35 void Cleanup(); |
| 36 |
| 37 private: |
| 38 // Returns a new unique bookmark URL. |
| 39 std::string NextIndexedURL(); |
| 40 |
| 41 // Returns a new unique bookmark title. |
| 42 std::wstring NextIndexedURLTitle(); |
| 43 |
| 44 int url_number; |
| 45 int url_title_number; |
| 46 DISALLOW_COPY_AND_ASSIGN(PerformanceLiveBookmarksSyncTest); |
| 47 }; |
| 48 |
| 49 void PerformanceLiveBookmarksSyncTest::AddURLs(int profile, int num_urls) { |
| 50 for (int i = 0; i < num_urls; ++i) { |
| 51 ASSERT_TRUE(AddURL( |
| 52 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL); |
| 53 } |
| 54 } |
| 55 |
| 56 void PerformanceLiveBookmarksSyncTest::UpdateURLs(int profile) { |
| 57 for (int i = 0; i < GetBookmarkBarNode(profile)->child_count(); ++i) { |
| 58 ASSERT_TRUE(SetURL(profile, GetBookmarkBarNode(profile)->GetChild(i), |
| 59 GURL(NextIndexedURL()))); |
| 60 } |
| 61 } |
| 62 |
| 63 void PerformanceLiveBookmarksSyncTest::RemoveURLs(int profile) { |
| 64 while (GetBookmarkBarNode(profile)->child_count()) { |
| 65 Remove(profile, GetBookmarkBarNode(profile), 0); |
| 66 } |
| 67 } |
| 68 |
| 69 void PerformanceLiveBookmarksSyncTest::Cleanup() { |
| 70 for (int i = 0; i < num_clients(); ++i) { |
| 71 RemoveURLs(i); |
| 72 } |
| 73 ASSERT_TRUE(AwaitQuiescence()); |
| 74 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
| 75 ASSERT_TRUE(AllModelsMatch()); |
| 76 } |
| 77 |
| 78 std::string PerformanceLiveBookmarksSyncTest::NextIndexedURL() { |
| 79 return IndexedURL(url_number++); |
| 80 } |
| 81 |
| 82 std::wstring PerformanceLiveBookmarksSyncTest::NextIndexedURLTitle() { |
| 83 return IndexedURLTitle(url_title_number++); |
| 84 } |
| 85 |
| 86 // TODO(braffert): Possibly split each of these into separate up / down test |
| 87 // cases? |
| 88 // TCM ID - 7556828. |
| 89 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Add) { |
| 90 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 91 DisableVerifier(); |
| 92 |
| 93 DisableNetwork(GetProfile(1)); |
| 94 AddURLs(0, kNumBookmarks); |
| 95 base::TimeDelta dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 96 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); |
| 97 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); |
| 98 |
| 99 EnableNetwork(GetProfile(1)); |
| 100 base::TimeDelta dt_down = |
| 101 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 102 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); |
| 103 ASSERT_TRUE(AllModelsMatch()); |
| 104 |
| 105 // TODO(braffert): Compare timings against some target value. |
| 106 } |
| 107 |
| 108 // TCM ID - 7564762. |
| 109 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Update) { |
| 110 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 111 DisableVerifier(); |
| 112 |
| 113 AddURLs(0, kNumBookmarks); |
| 114 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 115 ASSERT_TRUE(AllModelsMatch()); |
| 116 |
| 117 DisableNetwork(GetProfile(1)); |
| 118 UpdateURLs(0); |
| 119 base::TimeDelta dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 120 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); |
| 121 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); |
| 122 ASSERT_FALSE(AllModelsMatch()); |
| 123 |
| 124 EnableNetwork(GetProfile(1)); |
| 125 base::TimeDelta dt_down = |
| 126 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 127 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); |
| 128 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); |
| 129 |
| 130 // TODO(braffert): Compare timings against some target value. |
| 131 } |
| 132 |
| 133 // TCM ID - 7566626. |
| 134 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Delete) { |
| 135 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 136 DisableVerifier(); |
| 137 |
| 138 AddURLs(0, kNumBookmarks); |
| 139 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
| 140 ASSERT_TRUE(AllModelsMatch()); |
| 141 |
| 142 DisableNetwork(GetProfile(1)); |
| 143 RemoveURLs(0); |
| 144 base::TimeDelta dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 145 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
| 146 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); |
| 147 |
| 148 EnableNetwork(GetProfile(1)); |
| 149 base::TimeDelta dt_down = |
| 150 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 151 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
| 152 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); |
| 153 |
| 154 // TODO(braffert): Compare timings against some target value. |
| 155 } |
| 156 |
| 157 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, DISABLED_Benchmark) { |
| 158 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 159 DisableVerifier(); |
| 160 |
| 161 for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
| 162 int num_bookmarks = kBenchmarkPoints[i]; |
| 163 |
| 164 // Disable client 1. Add bookmarks and time commit by client 0. |
| 165 DisableNetwork(GetProfile(1)); |
| 166 AddURLs(0, num_bookmarks); |
| 167 base::TimeDelta dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 168 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); |
| 169 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); |
| 170 |
| 171 // Enable client 1 and time update (new bookmarks). |
| 172 EnableNetwork(GetProfile(1)); |
| 173 base::TimeDelta dt_down = |
| 174 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 175 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); |
| 176 ASSERT_TRUE(AllModelsMatch()); |
| 177 |
| 178 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " |
| 179 << dt_up.InSecondsF() << " " << dt_down.InSecondsF(); |
| 180 |
| 181 // Disable client 1. Modify bookmarks and time commit by client 0. |
| 182 DisableNetwork(GetProfile(1)); |
| 183 UpdateURLs(0); |
| 184 dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 185 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); |
| 186 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(1)->child_count()); |
| 187 ASSERT_FALSE(AllModelsMatch()); |
| 188 |
| 189 // Enable client 1 and time update (changed bookmarks). |
| 190 EnableNetwork(GetProfile(1)); |
| 191 dt_down = |
| 192 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 193 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); |
| 194 ASSERT_TRUE(AllModelsMatch()); |
| 195 |
| 196 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " |
| 197 << dt_up.InSecondsF() << " " << dt_down.InSecondsF(); |
| 198 |
| 199 // Disable client 1. Delete bookmarks and time commit by client 0. |
| 200 DisableNetwork(GetProfile(1)); |
| 201 RemoveURLs(0); |
| 202 dt_up = LiveSyncTimingHelper::TimeSyncCycle(GetClient(0)); |
| 203 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
| 204 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(1)->child_count()); |
| 205 |
| 206 // Enable client 1 and time update (deleted bookmarks). |
| 207 EnableNetwork(GetProfile(1)); |
| 208 dt_down = |
| 209 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 210 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); |
| 211 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); |
| 212 |
| 213 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " |
| 214 << dt_up.InSecondsF() << " " << dt_down.InSecondsF(); |
| 215 |
| 216 Cleanup(); |
| 217 } |
| 218 } |
OLD | NEW |