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 "base/stringprintf.h" | |
6 #include "base/utf_string_conversions.h" | |
7 #include "chrome/browser/autofill/autofill_common_test.h" | |
8 #include "chrome/browser/autofill/autofill_profile.h" | |
9 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
10 #include "chrome/browser/webdata/autofill_entry.h" | |
11 #include "chrome/test/live_sync/autofill_helper.h" | |
12 #include "chrome/test/live_sync/live_sync_test.h" | |
13 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | |
14 | |
15 using autofill_helper::AllProfilesMatch; | |
16 using autofill_helper::GetAllKeys; | |
17 using autofill_helper::GetAllProfiles; | |
18 using autofill_helper::GetKeyCount; | |
19 using autofill_helper::GetProfileCount; | |
20 using autofill_helper::RemoveKey; | |
21 using autofill_helper::SetProfiles; | |
22 | |
23 static const int kNumKeys = 150; | |
24 static const int kNumProfiles = 150; | |
25 | |
26 class AutofillSyncPerfTest : public LiveSyncTest { | |
27 public: | |
28 AutofillSyncPerfTest() | |
29 : LiveSyncTest(TWO_CLIENT), | |
30 guid_number_(0), | |
31 name_number_(0), | |
32 value_number_(0) {} | |
33 | |
34 // Adds |num_profiles| new autofill profiles to the sync profile |profile|. | |
35 void AddProfiles(int profile, int num_profiles); | |
36 | |
37 // Updates all autofill profiles for the sync profile |profile|. | |
38 void UpdateProfiles(int profile); | |
39 | |
40 // Removes all autofill profiles from |profile|. | |
41 void RemoveProfiles(int profile); | |
42 | |
43 // Adds |num_keys| new autofill keys to the sync profile |profile|. | |
44 void AddKeys(int profile, int num_keys); | |
45 | |
46 // Removes all autofill keys from |profile|. | |
47 void RemoveKeys(int profile); | |
48 | |
49 private: | |
50 // Returns a new unique autofill profile. | |
51 const AutofillProfile NextAutofillProfile(); | |
52 | |
53 // Returns a new unique autofill key. | |
54 const AutofillKey NextAutofillKey(); | |
55 | |
56 // Returns an unused unique guid. | |
57 const std::string NextGUID(); | |
58 | |
59 // Returns a unique guid based on the input integer |n|. | |
60 const std::string IntToGUID(int n); | |
61 | |
62 // Returns a new unused unique name. | |
63 const std::string NextName(); | |
64 | |
65 // Returns a unique name based on the input integer |n|. | |
66 const std::string IntToName(int n); | |
67 | |
68 // Returns a new unused unique value for autofill entries. | |
69 const std::string NextValue(); | |
70 | |
71 // Returnes a unique value based on the input integer |n|. | |
72 const std::string IntToValue(int n); | |
73 | |
74 int guid_number_; | |
75 int name_number_; | |
76 int value_number_; | |
77 DISALLOW_COPY_AND_ASSIGN(AutofillSyncPerfTest); | |
78 }; | |
79 | |
80 void AutofillSyncPerfTest::AddProfiles(int profile, int num_profiles) { | |
81 const std::vector<AutofillProfile*>& all_profiles = | |
82 GetAllProfiles(profile); | |
83 std::vector<AutofillProfile> autofill_profiles; | |
84 for (size_t i = 0; i < all_profiles.size(); ++i) { | |
85 autofill_profiles.push_back(*all_profiles[i]); | |
86 } | |
87 for (int i = 0; i < num_profiles; ++i) { | |
88 autofill_profiles.push_back(NextAutofillProfile()); | |
89 } | |
90 SetProfiles(profile, &autofill_profiles); | |
91 } | |
92 | |
93 void AutofillSyncPerfTest::UpdateProfiles(int profile) { | |
94 const std::vector<AutofillProfile*>& all_profiles = | |
95 GetAllProfiles(profile); | |
96 std::vector<AutofillProfile> autofill_profiles; | |
97 for (size_t i = 0; i < all_profiles.size(); ++i) { | |
98 autofill_profiles.push_back(*all_profiles[i]); | |
99 autofill_profiles.back().SetInfo(AutofillFieldType(NAME_FIRST), | |
100 UTF8ToUTF16(NextName())); | |
101 } | |
102 SetProfiles(profile, &autofill_profiles); | |
103 } | |
104 | |
105 void AutofillSyncPerfTest::RemoveProfiles(int profile) { | |
106 std::vector<AutofillProfile> empty; | |
107 SetProfiles(profile, &empty); | |
108 } | |
109 | |
110 void AutofillSyncPerfTest::AddKeys(int profile, int num_keys) { | |
111 std::set<AutofillKey> keys; | |
112 for (int i = 0; i < num_keys; ++i) { | |
113 keys.insert(NextAutofillKey()); | |
114 } | |
115 autofill_helper::AddKeys(profile, keys); | |
116 } | |
117 | |
118 void AutofillSyncPerfTest::RemoveKeys(int profile) { | |
119 std::set<AutofillEntry> keys = GetAllKeys(profile); | |
120 for (std::set<AutofillEntry>::const_iterator it = keys.begin(); | |
121 it != keys.end(); ++it) { | |
122 RemoveKey(profile, it->key()); | |
123 } | |
124 } | |
125 | |
126 const AutofillProfile AutofillSyncPerfTest::NextAutofillProfile() { | |
127 AutofillProfile profile; | |
128 autofill_test::SetProfileInfoWithGuid(&profile, NextGUID().c_str(), | |
129 NextName().c_str(), "", "", "", "", "", | |
130 "", "", "", "", "", "", ""); | |
131 return profile; | |
132 } | |
133 | |
134 const AutofillKey AutofillSyncPerfTest::NextAutofillKey() { | |
135 return AutofillKey(NextName().c_str(), NextName().c_str()); | |
136 } | |
137 | |
138 const std::string AutofillSyncPerfTest::NextGUID() { | |
139 return IntToGUID(guid_number_++); | |
140 } | |
141 | |
142 const std::string AutofillSyncPerfTest::IntToGUID(int n) { | |
143 return StringPrintf("00000000-0000-0000-0000-%012X", n); | |
144 } | |
145 | |
146 const std::string AutofillSyncPerfTest::NextName() { | |
147 return IntToName(name_number_++); | |
148 } | |
149 | |
150 const std::string AutofillSyncPerfTest::IntToName(int n) { | |
151 return StringPrintf("Name%d", n); | |
152 } | |
153 | |
154 const std::string AutofillSyncPerfTest::NextValue() { | |
155 return IntToValue(value_number_++); | |
156 } | |
157 | |
158 const std::string AutofillSyncPerfTest::IntToValue(int n) { | |
159 return StringPrintf("Value%d", n); | |
160 } | |
161 | |
162 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, AutofillProfiles_P0) { | |
163 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
164 | |
165 // TCM ID - 7557873. | |
166 AddProfiles(0, kNumProfiles); | |
167 base::TimeDelta dt = | |
168 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
169 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | |
170 SyncTimingHelper::PrintResult("autofill", "add_autofill_profiles", dt); | |
171 | |
172 // TCM ID - 7549835. | |
173 UpdateProfiles(0); | |
174 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
175 ASSERT_EQ(kNumProfiles, GetProfileCount(1)); | |
176 SyncTimingHelper::PrintResult("autofill", "update_autofill_profiles", dt); | |
177 | |
178 // TCM ID - 7553678. | |
179 RemoveProfiles(0); | |
180 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
181 ASSERT_EQ(0, GetProfileCount(1)); | |
182 SyncTimingHelper::PrintResult("autofill", "delete_autofill_profiles", dt); | |
183 } | |
184 | |
185 IN_PROC_BROWSER_TEST_F(AutofillSyncPerfTest, Autofill_P0) { | |
186 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
187 | |
188 AddKeys(0, kNumKeys); | |
189 base::TimeDelta dt = | |
190 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
191 ASSERT_EQ(kNumKeys, GetKeyCount(1)); | |
192 SyncTimingHelper::PrintResult("autofill", "add_autofill_keys", dt); | |
193 | |
194 RemoveKeys(0); | |
195 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
196 ASSERT_EQ(0, GetKeyCount(1)); | |
197 SyncTimingHelper::PrintResult("autofill", "delete_autofill_keys", dt); | |
198 } | |
OLD | NEW |