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/autofill/autofill_profile.h" | 8 #include "chrome/browser/autofill/autofill_profile.h" |
9 #include "chrome/browser/sync/profile_sync_service_harness.h" | 9 #include "chrome/browser/sync/profile_sync_service_harness.h" |
10 #include "chrome/browser/webdata/autofill_entry.h" | |
10 #include "chrome/test/live_sync/autofill_helper.h" | 11 #include "chrome/test/live_sync/autofill_helper.h" |
11 #include "chrome/test/live_sync/live_sync_test.h" | 12 #include "chrome/test/live_sync/live_sync_test.h" |
12 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | 13 #include "chrome/test/live_sync/performance/sync_timing_helper.h" |
13 | 14 |
14 using autofill_helper::AllProfilesMatch; | 15 using autofill_helper::AllProfilesMatch; |
16 using autofill_helper::GetAllKeys; | |
15 using autofill_helper::GetAllProfiles; | 17 using autofill_helper::GetAllProfiles; |
18 using autofill_helper::GetKeyCount; | |
16 using autofill_helper::GetProfileCount; | 19 using autofill_helper::GetProfileCount; |
20 using autofill_helper::RemoveKey; | |
17 using autofill_helper::SetProfiles; | 21 using autofill_helper::SetProfiles; |
18 | 22 |
19 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all | 23 // TODO(braffert): Move kNumBenchmarkPoints and kBenchmarkPoints for all |
20 // datatypes into a performance test base class, once it is possible to do so. | 24 // datatypes into a performance test base class, once it is possible to do so. |
25 static const int kNumKeys = 150; | |
21 static const int kNumProfiles = 150; | 26 static const int kNumProfiles = 150; |
22 static const int kNumBenchmarkPoints = 18; | 27 static const int kNumBenchmarkPoints = 18; |
23 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | 28 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, |
24 150, 175, 200, 225, 250, 300, 350, 400, | 29 150, 175, 200, 225, 250, 300, 350, 400, |
25 500}; | 30 500}; |
26 | 31 |
27 class AutofillSyncPerfTest : public LiveSyncTest { | 32 class AutofillSyncPerfTest : public LiveSyncTest { |
28 public: | 33 public: |
29 AutofillSyncPerfTest() | 34 AutofillSyncPerfTest() |
30 : LiveSyncTest(TWO_CLIENT), | 35 : LiveSyncTest(TWO_CLIENT), |
31 guid_number_(0), | 36 guid_number_(0), |
32 name_number_(0) {} | 37 name_number_(0), |
38 value_number_(0) {} | |
33 | 39 |
34 // Adds |num_profiles| new autofill profiles to the sync profile |profile|. | 40 // Adds |num_profiles| new autofill profiles to the sync profile |profile|. |
35 void AddProfiles(int profile, int num_profiles); | 41 void AddProfiles(int profile, int num_profiles); |
36 | 42 |
37 // Updates all autofill profiles for the sync profile |profile|. | 43 // Updates all autofill profiles for the sync profile |profile|. |
38 void UpdateProfiles(int profile); | 44 void UpdateProfiles(int profile); |
39 | 45 |
40 // Removes all bookmarks in the bookmark bar for |profile|. | 46 // Removes all autofill profiles for |profile|. |
Raghu Simha
2011/08/10 19:43:38
nit: s/for/from/
braffert
2011/08/10 19:52:35
Done.
| |
41 void RemoveProfiles(int profile); | 47 void RemoveProfiles(int profile); |
42 | 48 |
49 // Adds |num_keys| new autofill keys to the sync profile |profile|. | |
50 void AddKeys(int profile, int num_keys); | |
51 | |
52 // Removes all autofill keys for |profile|. | |
Raghu Simha
2011/08/10 19:43:38
nit: s/for/from/
braffert
2011/08/10 19:52:35
Done.
| |
53 void RemoveKeys(int profile); | |
54 | |
43 // Removes all autofill profiles in all sync profiles. Called between | 55 // Removes all autofill profiles in all sync profiles. Called between |
44 // benchmark iterations. | 56 // benchmark iterations. |
45 void Cleanup(); | 57 void Cleanup(); |
46 | 58 |
47 private: | 59 private: |
48 // Returns a new unique autofill profile. | 60 // Returns a new unique autofill profile. |
49 const AutofillProfile NextAutofillProfile(); | 61 const AutofillProfile NextAutofillProfile(); |
50 | 62 |
63 // Returns a new unique autofill key. | |
64 const AutofillKey NextAutofillKey(); | |
65 | |
51 // Returns an unused unique guid. | 66 // Returns an unused unique guid. |
52 const std::string NextGUID(); | 67 const std::string NextGUID(); |
53 | 68 |
54 // Returns a unique guid based on the input integer |n|. | 69 // Returns a unique guid based on the input integer |n|. |
55 const std::string IntToGUID(int n); | 70 const std::string IntToGUID(int n); |
56 | 71 |
57 // Returns a new unused unique name. | 72 // Returns a new unused unique name. |
58 const std::string NextName(); | 73 const std::string NextName(); |
59 | 74 |
60 // Returns a unique name based on the input integer |n|. | 75 // Returns a unique name based on the input integer |n|. |
61 const std::string IntToName(int n); | 76 const std::string IntToName(int n); |
62 | 77 |
78 // Returns a new unused unique value for autofill entries. | |
79 const std::string NextValue(); | |
80 | |
81 // Returnes a unique value based on the input integer |n|. | |
82 const std::string IntToValue(int n); | |
83 | |
63 int guid_number_; | 84 int guid_number_; |
64 int name_number_; | 85 int name_number_; |
86 int value_number_; | |
65 DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); | 87 DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); |
66 }; | 88 }; |
67 | 89 |
68 void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { | 90 void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { |
69 const std::vector<AutofillProfile*>& all_profiles = | 91 const std::vector<AutofillProfile*>& all_profiles = |
70 GetAllProfiles(profile); | 92 GetAllProfiles(profile); |
71 std::vector<AutofillProfile> autofill_profiles; | 93 std::vector<AutofillProfile> autofill_profiles; |
72 for (size_t i = 0; i < all_profiles.size(); ++i) { | 94 for (size_t i = 0; i < all_profiles.size(); ++i) { |
73 autofill_profiles.push_back(*all_profiles[i]); | 95 autofill_profiles.push_back(*all_profiles[i]); |
74 } | 96 } |
(...skipping 13 matching lines...) Expand all Loading... | |
88 UTF8ToUTF16(NextName())); | 110 UTF8ToUTF16(NextName())); |
89 } | 111 } |
90 SetProfiles(profile, &autofill_profiles); | 112 SetProfiles(profile, &autofill_profiles); |
91 } | 113 } |
92 | 114 |
93 void AutofillSyncPerfTest::RemoveProfiles(int profile) { | 115 void AutofillSyncPerfTest::RemoveProfiles(int profile) { |
94 std::vector<AutofillProfile> empty; | 116 std::vector<AutofillProfile> empty; |
95 SetProfiles(profile, &empty); | 117 SetProfiles(profile, &empty); |
96 } | 118 } |
97 | 119 |
120 void AutofillSyncPerfTest::AddKeys(int profile, int num_profiles) { | |
Raghu Simha
2011/08/10 19:43:38
s/num_profiles/num_keys/
braffert
2011/08/10 19:52:35
Done.
| |
121 std::set<AutofillKey> keys; | |
122 for (int i = 0; i < num_profiles; ++i) { | |
123 keys.insert(NextAutofillKey()); | |
124 }; | |
Raghu Simha
2011/08/10 19:43:38
Remove semicolon.
braffert
2011/08/10 19:52:35
Done. Don't know how that got in there.
| |
125 autofill_helper::AddKeys(profile, keys); | |
126 } | |
127 | |
128 void AutofillSyncPerfTest::RemoveKeys(int profile) { | |
Raghu Simha
2011/08/10 19:43:38
Perhaps name this RemoveAllKeys, since that's what
braffert
2011/08/10 19:52:35
This is a good suggestion, but I will leave it as
| |
129 std::set<AutofillEntry> keys = GetAllKeys(profile); | |
130 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | |
131 it != keys.end(); ++it) { | |
132 RemoveKey(profile, it->key()); | |
133 } | |
134 } | |
135 | |
98 void AutofillSyncPerfTest::Cleanup() { | 136 void AutofillSyncPerfTest::Cleanup() { |
99 for (int i = 0; i < num_clients(); ++i) { | 137 for (int i = 0; i < num_clients(); ++i) { |
100 RemoveProfiles(i); | 138 RemoveProfiles(i); |
101 } | 139 } |
102 ASSERT_TRUE(AwaitQuiescence()); | 140 ASSERT_TRUE(AwaitQuiescence()); |
103 } | 141 } |
104 | 142 |
105 const AutofillProfile AutofillSyncPerfTest::NextAutofillProfile() { | 143 const AutofillProfile AutofillSyncPerfTest::NextAutofillProfile() { |
106 AutofillProfile profile; | 144 AutofillProfile profile; |
107 autofill_test::SetProfileInfoWithGuid(&profile, NextGUID().c_str(), | 145 autofill_test::SetProfileInfoWithGuid(&profile, NextGUID().c_str(), |
108 NextName().c_str(), "", "", "", "", "", | 146 NextName().c_str(), "", "", "", "", "", |
109 "", "", "", "", "", "", ""); | 147 "", "", "", "", "", "", ""); |
110 return profile; | 148 return profile; |
111 } | 149 } |
112 | 150 |
151 const AutofillKey AutofillSyncPerfTest::NextAutofillKey() { | |
152 return AutofillKey(NextName().c_str(), NextName().c_str()); | |
153 } | |
154 | |
113 const std::string AutofillSyncPerfTest::NextGUID() { | 155 const std::string AutofillSyncPerfTest::NextGUID() { |
114 return IntToGUID(guid_number_++); | 156 return IntToGUID(guid_number_++); |
115 } | 157 } |
116 | 158 |
117 const std::string AutofillSyncPerfTest::IntToGUID(int n) { | 159 const std::string AutofillSyncPerfTest::IntToGUID(int n) { |
118 return StringPrintf("00000000-0000-0000-0000-%012X", n); | 160 return StringPrintf("00000000-0000-0000-0000-%012X", n); |
119 } | 161 } |
120 | 162 |
121 const std::string AutofillSyncPerfTest::NextName() { | 163 const std::string AutofillSyncPerfTest::NextName() { |
122 return IntToName(name_number_++); | 164 return IntToName(name_number_++); |
123 } | 165 } |
124 | 166 |
125 const std::string AutofillSyncPerfTest::IntToName(int n) { | 167 const std::string AutofillSyncPerfTest::IntToName(int n) { |
126 return StringPrintf("Name%d" , n); | 168 return StringPrintf("Name%d", n); |
127 } | 169 } |
128 | 170 |
129 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, P0) { | 171 const std::string AutofillSyncPerfTest::NextValue() { |
172 return IntToValue(value_number_++); | |
173 } | |
174 | |
175 const std::string AutofillSyncPerfTest::IntToValue(int n) { | |
176 return StringPrintf("Value%d", n); | |
177 } | |
178 | |
179 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, AutofillProfiles_P0) { | |
130 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 180 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
131 | 181 |
132 // TCM ID - 7557873. | 182 // TCM ID - 7557873. |
133 AddProfiles(0, kNumProfiles); | 183 AddProfiles(0, kNumProfiles); |
134 base::TimeDelta dt = | 184 base::TimeDelta dt = |
135 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 185 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
136 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | 186 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); |
137 SyncTimingHelper::PrintResult("autofill", "add", dt); | 187 SyncTimingHelper::PrintResult("autofill", "add_autofill_profiles", dt); |
138 | 188 |
139 // TCM ID - 7549835. | 189 // TCM ID - 7549835. |
140 UpdateProfiles(0); | 190 UpdateProfiles(0); |
141 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 191 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
142 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | 192 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); |
143 SyncTimingHelper::PrintResult("autofill", "update", dt); | 193 SyncTimingHelper::PrintResult("autofill", "update_autofill_profiles", dt); |
144 | 194 |
145 // TCM ID - 7553678. | 195 // TCM ID - 7553678. |
146 RemoveProfiles(0); | 196 RemoveProfiles(0); |
147 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 197 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
148 ASSERT_EQ(0, GetProfileCount(1)); | 198 ASSERT_EQ(0, GetProfileCount(1)); |
149 SyncTimingHelper::PrintResult("autofill", "delete", dt); | 199 SyncTimingHelper::PrintResult("autofill", "delete_autofill_profiles", dt); |
200 } | |
201 | |
202 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, Autofill_P0) { | |
Raghu Simha
2011/08/10 19:43:38
Perhaps name this test AutofillKeys_P0?
braffert
2011/08/10 19:52:35
Anna suggested using only Autofill as the name her
| |
203 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
204 | |
205 AddKeys(0, kNumKeys); | |
206 base::TimeDelta dt = | |
207 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
208 ASSERT_EQ(kNumKeys, GetKeyCount(1)); | |
209 SyncTimingHelper::PrintResult("autofill", "add_autofill_keys", dt); | |
210 | |
211 RemoveKeys(0); | |
212 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
213 ASSERT_EQ(0, GetKeyCount(1)); | |
214 SyncTimingHelper::PrintResult("autofill", "delete_autofill_keys", dt); | |
150 } | 215 } |
151 | 216 |
152 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { | 217 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, DISABLED_Benchmark) { |
153 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 218 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
154 | 219 |
155 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | 220 for (int i = 0; i < kNumBenchmarkPoints; ++i) { |
156 int num_profiles = kBenchmarkPoints[i]; | 221 int num_profiles = kBenchmarkPoints[i]; |
157 AddProfiles(0, num_profiles); | 222 AddProfiles(0, num_profiles); |
158 base::TimeDelta dt_add = | 223 base::TimeDelta dt_add = |
159 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 224 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
(...skipping 14 matching lines...) Expand all Loading... | |
174 base::TimeDelta dt_delete = | 239 base::TimeDelta dt_delete = |
175 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 240 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
176 ASSERT_EQ(0, GetProfileCount(0)); | 241 ASSERT_EQ(0, GetProfileCount(0)); |
177 ASSERT_TRUE(AllProfilesMatch()); | 242 ASSERT_TRUE(AllProfilesMatch()); |
178 VLOG(0) << std::endl << "Delete: " << num_profiles << " " | 243 VLOG(0) << std::endl << "Delete: " << num_profiles << " " |
179 << dt_delete.InSecondsF(); | 244 << dt_delete.InSecondsF(); |
180 | 245 |
181 Cleanup(); | 246 Cleanup(); |
182 } | 247 } |
183 } | 248 } |
OLD | NEW |