| 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)->empty()) | |
| 65 Remove(profile, GetBookmarkBarNode(profile), 0); | |
| 66 } | |
| 67 | |
| 68 void PerformanceLiveBookmarksSyncTest::Cleanup() { | |
| 69 for (int i = 0; i < num_clients(); ++i) { | |
| 70 RemoveURLs(i); | |
| 71 } | |
| 72 ASSERT_TRUE(AwaitQuiescence()); | |
| 73 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 74 ASSERT_TRUE(AllModelsMatch()); | |
| 75 } | |
| 76 | |
| 77 std::string PerformanceLiveBookmarksSyncTest::NextIndexedURL() { | |
| 78 return IndexedURL(url_number++); | |
| 79 } | |
| 80 | |
| 81 std::wstring PerformanceLiveBookmarksSyncTest::NextIndexedURLTitle() { | |
| 82 return IndexedURLTitle(url_title_number++); | |
| 83 } | |
| 84 | |
| 85 // TCM ID - 7556828. | |
| 86 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Add) { | |
| 87 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 88 DisableVerifier(); | |
| 89 | |
| 90 AddURLs(0, kNumBookmarks); | |
| 91 base::TimeDelta dt = | |
| 92 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 93 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 94 ASSERT_TRUE(AllModelsMatch()); | |
| 95 | |
| 96 // TODO(braffert): Compare timings against some target value. | |
| 97 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 98 } | |
| 99 | |
| 100 // TCM ID - 7564762. | |
| 101 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Update) { | |
| 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 103 DisableVerifier(); | |
| 104 | |
| 105 AddURLs(0, kNumBookmarks); | |
| 106 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 107 | |
| 108 UpdateURLs(0); | |
| 109 base::TimeDelta dt = | |
| 110 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 111 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 112 ASSERT_TRUE(AllModelsMatch()); | |
| 113 | |
| 114 // TODO(braffert): Compare timings against some target value. | |
| 115 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 116 } | |
| 117 | |
| 118 // TCM ID - 7566626. | |
| 119 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Delete) { | |
| 120 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 121 DisableVerifier(); | |
| 122 | |
| 123 AddURLs(0, kNumBookmarks); | |
| 124 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 125 | |
| 126 RemoveURLs(0); | |
| 127 base::TimeDelta dt = | |
| 128 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 129 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 130 ASSERT_TRUE(AllModelsMatch()); | |
| 131 | |
| 132 // TODO(braffert): Compare timings against some target value. | |
| 133 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 134 } | |
| 135 | |
| 136 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, DISABLED_Benchmark) { | |
| 137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 138 DisableVerifier(); | |
| 139 | |
| 140 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | |
| 141 int num_bookmarks = kBenchmarkPoints[i]; | |
| 142 AddURLs(0, num_bookmarks); | |
| 143 base::TimeDelta dt_add = | |
| 144 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 145 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 146 ASSERT_TRUE(AllModelsMatch()); | |
| 147 VLOG(0) << std::endl << "Add: " << num_bookmarks << " " | |
| 148 << dt_add.InSecondsF(); | |
| 149 | |
| 150 UpdateURLs(0); | |
| 151 base::TimeDelta dt_update = | |
| 152 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 153 ASSERT_EQ(num_bookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 154 ASSERT_TRUE(AllModelsMatch()); | |
| 155 VLOG(0) << std::endl << "Update: " << num_bookmarks << " " | |
| 156 << dt_update.InSecondsF(); | |
| 157 | |
| 158 RemoveURLs(0); | |
| 159 base::TimeDelta dt_delete = | |
| 160 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 161 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 162 ASSERT_TRUE(AllModelsMatch()); | |
| 163 VLOG(0) << std::endl << "Delete: " << num_bookmarks << " " | |
| 164 << dt_delete.InSecondsF(); | |
| 165 | |
| 166 Cleanup(); | |
| 167 } | |
| 168 } | |
| OLD | NEW |