| 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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autofill/autofill_common_test.h" | 7 #include "chrome/browser/autofill/autofill_common_test.h" |
| 8 #include "chrome/browser/sync/profile_sync_service_harness.h" | 8 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 9 #include "chrome/test/live_sync/live_autofill_sync_test.h" | 9 #include "chrome/test/live_sync/autofill_helper.h" |
| 10 #include "chrome/test/live_sync/live_sync_test.h" |
| 10 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | 11 #include "chrome/test/live_sync/performance/sync_timing_helper.h" |
| 11 | 12 |
| 12 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all | 13 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all |
| 13 // datatypes into a performance test base class, once it is possible to do so. | 14 // datatypes into a performance test base class, once it is possible to do so. |
| 14 static const int kNumProfiles = 150; | 15 static const int kNumProfiles = 150; |
| 15 static const int kNumBenchmarkPoints = 18; | 16 static const int kNumBenchmarkPoints = 18; |
| 16 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | 17 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, |
| 17 150, 175, 200, 225, 250, 300, 350, 400, | 18 150, 175, 200, 225, 250, 300, 350, 400, |
| 18 500}; | 19 500}; |
| 19 | 20 |
| 20 class AutofillSyncPerfTest : public TwoClientLiveAutofillSyncTest { | 21 class AutofillSyncPerfTest : public LiveSyncTest { |
| 21 public: | 22 public: |
| 22 AutofillSyncPerfTest() : guid_number_(0), name_number_(0) {} | 23 AutofillSyncPerfTest() |
| 24 : LiveSyncTest(TWO_CLIENT), |
| 25 guid_number_(0), |
| 26 name_number_(0) {} |
| 23 | 27 |
| 24 // Adds |num_profiles| new autofill profiles to the sync profile |profile|. | 28 // Adds |num_profiles| new autofill profiles to the sync profile |profile|. |
| 25 void AddProfiles(int profile, int num_profiles); | 29 void AddProfiles(int profile, int num_profiles); |
| 26 | 30 |
| 27 // Updates all autofill profiles for the sync profile |profile|. | 31 // Updates all autofill profiles for the sync profile |profile|. |
| 28 void UpdateProfiles(int profile); | 32 void UpdateProfiles(int profile); |
| 29 | 33 |
| 30 // Removes all bookmarks in the bookmark bar for |profile|. | 34 // Removes all bookmarks in the bookmark bar for |profile|. |
| 31 void RemoveProfiles(int profile); | 35 void RemoveProfiles(int profile); |
| 32 | 36 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 const std::string NextName(); | 52 const std::string NextName(); |
| 49 | 53 |
| 50 // Returns a unique name based on the input integer |n|. | 54 // Returns a unique name based on the input integer |n|. |
| 51 const std::string IntToName(int n); | 55 const std::string IntToName(int n); |
| 52 | 56 |
| 53 int guid_number_; | 57 int guid_number_; |
| 54 int name_number_; | 58 int name_number_; |
| 55 DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); | 59 DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); |
| 56 }; | 60 }; |
| 57 | 61 |
| 58 void AutofillSyncPerfTest::AddProfiles(int profile, | 62 void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { |
| 59 int num_profiles) { | 63 const std::vector<AutofillProfile*>& all_profiles = |
| 60 const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile); | 64 AutofillHelper::GetAllProfiles(profile); |
| 61 std::vector<AutofillProfile> autofill_profiles; | 65 std::vector<AutofillProfile> autofill_profiles; |
| 62 for (size_t i = 0; i < all_profiles.size(); ++i) { | 66 for (size_t i = 0; i < all_profiles.size(); ++i) { |
| 63 autofill_profiles.push_back(*all_profiles[i]); | 67 autofill_profiles.push_back(*all_profiles[i]); |
| 64 } | 68 } |
| 65 for (int i = 0; i < num_profiles; ++i) { | 69 for (int i = 0; i < num_profiles; ++i) { |
| 66 autofill_profiles.push_back(NextAutofillProfile()); | 70 autofill_profiles.push_back(NextAutofillProfile()); |
| 67 } | 71 } |
| 68 SetProfiles(profile, &autofill_profiles); | 72 AutofillHelper::SetProfiles(profile, &autofill_profiles); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void AutofillSyncPerfTest::UpdateProfiles(int profile) { | 75 void AutofillSyncPerfTest::UpdateProfiles(int profile) { |
| 72 const std::vector<AutofillProfile*>& all_profiles = GetAllProfiles(profile); | 76 const std::vector<AutofillProfile*>& all_profiles = |
| 77 AutofillHelper::GetAllProfiles(profile); |
| 73 std::vector<AutofillProfile> autofill_profiles; | 78 std::vector<AutofillProfile> autofill_profiles; |
| 74 for (size_t i = 0; i < all_profiles.size(); ++i) { | 79 for (size_t i = 0; i < all_profiles.size(); ++i) { |
| 75 autofill_profiles.push_back(*all_profiles[i]); | 80 autofill_profiles.push_back(*all_profiles[i]); |
| 76 autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST), | 81 autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST), |
| 77 UTF8ToUTF16(NextName())); | 82 UTF8ToUTF16(NextName())); |
| 78 } | 83 } |
| 79 SetProfiles(profile, &autofill_profiles); | 84 AutofillHelper::SetProfiles(profile, &autofill_profiles); |
| 80 } | 85 } |
| 81 | 86 |
| 82 void AutofillSyncPerfTest::RemoveProfiles(int profile) { | 87 void AutofillSyncPerfTest::RemoveProfiles(int profile) { |
| 83 std::vector<AutofillProfile> empty; | 88 std::vector<AutofillProfile> empty; |
| 84 SetProfiles(profile, &empty); | 89 AutofillHelper::SetProfiles(profile, &empty); |
| 85 } | 90 } |
| 86 | 91 |
| 87 void AutofillSyncPerfTest::Cleanup() { | 92 void AutofillSyncPerfTest::Cleanup() { |
| 88 for (int i = 0; i < num_clients(); ++i) { | 93 for (int i = 0; i < num_clients(); ++i) { |
| 89 RemoveProfiles(i); | 94 RemoveProfiles(i); |
| 90 } | 95 } |
| 91 ASSERT_TRUE(AwaitQuiescence()); | 96 ASSERT_TRUE(AwaitQuiescence()); |
| 92 } | 97 } |
| 93 | 98 |
| 94 const AutofillProfile AutofillSyncPerfTest::NextAutofillProfile() { | 99 const AutofillProfile AutofillSyncPerfTest::NextAutofillProfile() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 115 return StringPrintf("Name%d" , n); | 120 return StringPrintf("Name%d" , n); |
| 116 } | 121 } |
| 117 | 122 |
| 118 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, P0) { | 123 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, P0) { |
| 119 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 120 | 125 |
| 121 // TCM ID - 7557873. | 126 // TCM ID - 7557873. |
| 122 AddProfiles(0, kNumProfiles); | 127 AddProfiles(0, kNumProfiles); |
| 123 base::TimeDelta dt = | 128 base::TimeDelta dt = |
| 124 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 129 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 125 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | 130 ASSERT_EQ(kNumProfiles, AutofillHelper::GetProfileCount(1)); |
| 126 SyncTimingHelper::PrintResult("autofill", "add", dt); | 131 SyncTimingHelper::PrintResult("autofill", "add", dt); |
| 127 | 132 |
| 128 // TCM ID - 7549835. | 133 // TCM ID - 7549835. |
| 129 UpdateProfiles(0); | 134 UpdateProfiles(0); |
| 130 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 135 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 131 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | 136 ASSERT_EQ(kNumProfiles, AutofillHelper::GetProfileCount(1)); |
| 132 SyncTimingHelper::PrintResult("autofill", "update", dt); | 137 SyncTimingHelper::PrintResult("autofill", "update", dt); |
| 133 | 138 |
| 134 // TCM ID - 7553678. | 139 // TCM ID - 7553678. |
| 135 RemoveProfiles(0); | 140 RemoveProfiles(0); |
| 136 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 141 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 137 ASSERT_EQ(0, GetProfileCount(1)); | 142 ASSERT_EQ(0, AutofillHelper::GetProfileCount(1)); |
| 138 SyncTimingHelper::PrintResult("autofill", "delete", dt); | 143 SyncTimingHelper::PrintResult("autofill", "delete", dt); |
| 139 } | 144 } |
| 140 | 145 |
| 141 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { | 146 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { |
| 142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 147 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 143 | 148 |
| 144 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | 149 for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
| 145 int num_profiles = kBenchmarkPoints[i]; | 150 int num_profiles = kBenchmarkPoints[i]; |
| 146 AddProfiles(0, num_profiles); | 151 AddProfiles(0, num_profiles); |
| 147 base::TimeDelta dt_add = | 152 base::TimeDelta dt_add = |
| 148 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 153 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 149 ASSERT_EQ(num_profiles, GetProfileCount(0)); | 154 ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); |
| 150 ASSERT_TRUE(AllProfilesMatch()); | 155 ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); |
| 151 VLOG(0) << std::endl << "Add: " << num_profiles << " " | 156 VLOG(0) << std::endl << "Add: " << num_profiles << " " |
| 152 << dt_add.InSecondsF(); | 157 << dt_add.InSecondsF(); |
| 153 | 158 |
| 154 UpdateProfiles(0); | 159 UpdateProfiles(0); |
| 155 base::TimeDelta dt_update = | 160 base::TimeDelta dt_update = |
| 156 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 161 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 157 ASSERT_EQ(num_profiles, GetProfileCount(0)); | 162 ASSERT_EQ(num_profiles, AutofillHelper::GetProfileCount(0)); |
| 158 ASSERT_TRUE(AllProfilesMatch()); | 163 ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); |
| 159 VLOG(0) << std::endl << "Update: " << num_profiles << " " | 164 VLOG(0) << std::endl << "Update: " << num_profiles << " " |
| 160 << dt_update.InSecondsF(); | 165 << dt_update.InSecondsF(); |
| 161 | 166 |
| 162 RemoveProfiles(0); | 167 RemoveProfiles(0); |
| 163 base::TimeDelta dt_delete = | 168 base::TimeDelta dt_delete = |
| 164 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 169 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 165 ASSERT_EQ(0, GetProfileCount(0)); | 170 ASSERT_EQ(0, AutofillHelper::GetProfileCount(0)); |
| 166 ASSERT_TRUE(AllProfilesMatch()); | 171 ASSERT_TRUE(AutofillHelper::AllProfilesMatch()); |
| 167 VLOG(0) << std::endl << "Delete: " << num_profiles << " " | 172 VLOG(0) << std::endl << "Delete: " << num_profiles << " " |
| 168 << dt_delete.InSecondsF(); | 173 << dt_delete.InSecondsF(); |
| 169 | 174 |
| 170 Cleanup(); | 175 Cleanup(); |
| 171 } | 176 } |
| 172 } | 177 } |
| OLD | NEW |