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/utf_string_conversions.h" | |
6 #include "chrome/browser/autofill/autofill_profile.h" | |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
8 #include "chrome/browser/sync/test/live_sync/autofill_helper.h" | |
9 #include "chrome/browser/sync/test/live_sync/live_sync_test.h" | |
10 #include "chrome/browser/webdata/autofill_entry.h" | |
11 | |
12 using autofill_helper::AddKeys; | |
13 using autofill_helper::AddProfile; | |
14 using autofill_helper::CreateAutofillProfile; | |
15 using autofill_helper::GetAllKeys; | |
16 using autofill_helper::GetAllProfiles; | |
17 using autofill_helper::KeysMatch; | |
18 using autofill_helper::ProfilesMatch; | |
19 using autofill_helper::PROFILE_FRASIER; | |
20 using autofill_helper::PROFILE_HOMER; | |
21 using autofill_helper::PROFILE_MARION; | |
22 using autofill_helper::PROFILE_NULL; | |
23 using autofill_helper::RemoveKey; | |
24 using autofill_helper::RemoveProfile; | |
25 using autofill_helper::UpdateProfile; | |
26 | |
27 // Autofill entry length is limited to 1024. See http://crbug.com/49332. | |
28 const size_t kMaxDataLength = 1024; | |
29 | |
30 class TwoClientAutofillSyncTest : public LiveSyncTest { | |
31 public: | |
32 TwoClientAutofillSyncTest() : LiveSyncTest(TWO_CLIENT) {} | |
33 virtual ~TwoClientAutofillSyncTest() {} | |
34 | |
35 private: | |
36 DISALLOW_COPY_AND_ASSIGN(TwoClientAutofillSyncTest); | |
37 }; | |
38 | |
39 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, WebDataServiceSanity) { | |
40 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
41 | |
42 // Client0 adds a key. | |
43 std::set<AutofillKey> keys; | |
44 keys.insert(AutofillKey("name0", "value0")); | |
45 AddKeys(0, keys); | |
46 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
47 ASSERT_TRUE(KeysMatch(0, 1)); | |
48 ASSERT_EQ(1U, GetAllKeys(0).size()); | |
49 | |
50 // Client1 adds a key. | |
51 keys.clear(); | |
52 keys.insert(AutofillKey("name1", "value1-0")); | |
53 AddKeys(1, keys); | |
54 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
55 ASSERT_TRUE(KeysMatch(0, 1)); | |
56 ASSERT_EQ(2U, GetAllKeys(0).size()); | |
57 | |
58 // Client0 adds a key with the same name. | |
59 keys.clear(); | |
60 keys.insert(AutofillKey("name1", "value1-1")); | |
61 AddKeys(0, keys); | |
62 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
63 ASSERT_TRUE(KeysMatch(0, 1)); | |
64 ASSERT_EQ(3U, GetAllKeys(0).size()); | |
65 | |
66 // Client1 removes a key. | |
67 RemoveKey(1, AutofillKey("name1", "value1-0")); | |
68 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
69 ASSERT_TRUE(KeysMatch(0, 1)); | |
70 ASSERT_EQ(2U, GetAllKeys(0).size()); | |
71 | |
72 // Client0 removes the rest. | |
73 RemoveKey(0, AutofillKey("name0", "value0")); | |
74 RemoveKey(0, AutofillKey("name1", "value1-1")); | |
75 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
76 ASSERT_TRUE(KeysMatch(0, 1)); | |
77 ASSERT_EQ(0U, GetAllKeys(0).size()); | |
78 } | |
79 | |
80 // TCM ID - 3678296. | |
81 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddUnicodeProfile) { | |
82 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
83 | |
84 std::set<AutofillKey> keys; | |
85 keys.insert(AutofillKey(WideToUTF16(L"Sigur R\u00F3s"), | |
86 WideToUTF16(L"\u00C1g\u00E6tis byrjun"))); | |
87 AddKeys(0, keys); | |
88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
89 ASSERT_TRUE(AwaitQuiescence()); | |
90 ASSERT_TRUE(KeysMatch(0, 1)); | |
91 } | |
92 | |
93 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, | |
94 AddDuplicateNamesToSameProfile) { | |
95 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
96 | |
97 std::set<AutofillKey> keys; | |
98 keys.insert(AutofillKey("name0", "value0-0")); | |
99 keys.insert(AutofillKey("name0", "value0-1")); | |
100 keys.insert(AutofillKey("name1", "value1")); | |
101 AddKeys(0, keys); | |
102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
103 ASSERT_TRUE(AwaitQuiescence()); | |
104 ASSERT_TRUE(KeysMatch(0, 1)); | |
105 ASSERT_EQ(2U, GetAllKeys(0).size()); | |
106 } | |
107 | |
108 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, | |
109 AddDuplicateNamesToDifferentProfiles) { | |
110 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
111 | |
112 std::set<AutofillKey> keys0; | |
113 keys0.insert(AutofillKey("name0", "value0-0")); | |
114 keys0.insert(AutofillKey("name1", "value1")); | |
115 AddKeys(0, keys0); | |
116 | |
117 std::set<AutofillKey> keys1; | |
118 keys1.insert(AutofillKey("name0", "value0-1")); | |
119 keys1.insert(AutofillKey("name2", "value2")); | |
120 keys1.insert(AutofillKey("name3", "value3")); | |
121 AddKeys(1, keys1); | |
122 | |
123 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
124 ASSERT_TRUE(AwaitQuiescence()); | |
125 ASSERT_TRUE(KeysMatch(0, 1)); | |
126 ASSERT_EQ(5U, GetAllKeys(0).size()); | |
127 } | |
128 | |
129 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, | |
130 PersonalDataManagerSanity) { | |
131 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
132 | |
133 // Client0 adds a profile. | |
134 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
135 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
136 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
137 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
138 | |
139 // Client1 adds a profile. | |
140 AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); | |
141 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
142 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
143 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
144 | |
145 // Client0 adds the same profile. | |
146 AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); | |
147 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
148 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
149 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
150 | |
151 // Client1 removes a profile. | |
152 RemoveProfile(1, GetAllProfiles(1)[0]->guid()); | |
153 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
154 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
155 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
156 | |
157 // Client0 updates a profile. | |
158 UpdateProfile(0, | |
159 GetAllProfiles(0)[0]->guid(), | |
160 AutofillType(NAME_FIRST), | |
161 ASCIIToUTF16("Bart")); | |
162 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
163 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
164 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
165 | |
166 // Client1 removes remaining profile. | |
167 RemoveProfile(1, GetAllProfiles(1)[0]->guid()); | |
168 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
169 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
170 ASSERT_EQ(0U, GetAllProfiles(0).size()); | |
171 } | |
172 | |
173 // TCM ID - 7261786. | |
174 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddDuplicateProfiles) { | |
175 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
176 | |
177 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
178 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
179 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
180 ASSERT_TRUE(AwaitQuiescence()); | |
181 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
182 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
183 } | |
184 | |
185 // TCM ID - 3636294. | |
186 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, SameProfileWithConflict) { | |
187 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
188 | |
189 AutofillProfile profile0 = CreateAutofillProfile(PROFILE_HOMER); | |
190 AutofillProfile profile1 = CreateAutofillProfile(PROFILE_HOMER); | |
191 profile1.SetInfo(PHONE_FAX_WHOLE_NUMBER, ASCIIToUTF16("1234567890")); | |
192 | |
193 AddProfile(0, profile0); | |
194 AddProfile(1, profile1); | |
195 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
196 ASSERT_TRUE(AwaitQuiescence()); | |
197 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
198 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
199 } | |
200 | |
201 // TCM ID - 3626291. | |
202 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddEmptyProfile) { | |
203 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
204 | |
205 AddProfile(0, CreateAutofillProfile(PROFILE_NULL)); | |
206 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
207 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
208 ASSERT_EQ(0U, GetAllProfiles(0).size()); | |
209 } | |
210 | |
211 // TCM ID - 3616283. | |
212 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddProfile) { | |
213 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
214 | |
215 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
216 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
217 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
218 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
219 } | |
220 | |
221 // TCM ID - 3632260. | |
222 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddMultipleProfiles) { | |
223 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
224 | |
225 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
226 AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); | |
227 AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER)); | |
228 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
229 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
230 ASSERT_EQ(3U, GetAllProfiles(0).size()); | |
231 } | |
232 | |
233 // TCM ID - 3602257. | |
234 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DeleteProfile) { | |
235 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
236 | |
237 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
238 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
239 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
240 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
241 | |
242 RemoveProfile(1, GetAllProfiles(1)[0]->guid()); | |
243 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
244 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
245 ASSERT_EQ(0U, GetAllProfiles(0).size()); | |
246 } | |
247 | |
248 // TCM ID - 3627300. | |
249 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MergeProfiles) { | |
250 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
251 | |
252 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
253 AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); | |
254 AddProfile(1, CreateAutofillProfile(PROFILE_FRASIER)); | |
255 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
256 ASSERT_TRUE(AwaitQuiescence()); | |
257 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
258 ASSERT_EQ(3U, GetAllProfiles(0).size()); | |
259 } | |
260 | |
261 // TCM ID - 3665264. | |
262 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, UpdateFields) { | |
263 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
264 | |
265 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
266 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
267 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
268 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
269 | |
270 UpdateProfile(0, | |
271 GetAllProfiles(0)[0]->guid(), | |
272 AutofillType(NAME_FIRST), | |
273 ASCIIToUTF16("Lisa")); | |
274 UpdateProfile(0, | |
275 GetAllProfiles(0)[0]->guid(), | |
276 AutofillType(EMAIL_ADDRESS), | |
277 ASCIIToUTF16("grrrl@TV.com")); | |
278 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
279 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
280 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
281 } | |
282 | |
283 // TCM ID - 3628299. | |
284 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, ConflictingFields) { | |
285 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
286 | |
287 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
288 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
289 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
290 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
291 UpdateProfile(0, | |
292 GetAllProfiles(0)[0]->guid(), | |
293 AutofillType(NAME_FIRST), | |
294 ASCIIToUTF16("Lisa")); | |
295 UpdateProfile(1, | |
296 GetAllProfiles(1)[0]->guid(), | |
297 AutofillType(NAME_FIRST), | |
298 ASCIIToUTF16("Bart")); | |
299 ASSERT_TRUE(AwaitQuiescence()); | |
300 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
301 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
302 } | |
303 | |
304 // TCM ID - 3663293. | |
305 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DisableAutofill) { | |
306 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
307 | |
308 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
309 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
310 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
311 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
312 | |
313 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncable::AUTOFILL)); | |
314 AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER)); | |
315 ASSERT_TRUE(AwaitQuiescence()); | |
316 ASSERT_FALSE(ProfilesMatch(0, 1)); | |
317 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
318 ASSERT_EQ(1U, GetAllProfiles(1).size()); | |
319 | |
320 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncable::AUTOFILL)); | |
321 ASSERT_TRUE(AwaitQuiescence()); | |
322 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
323 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
324 } | |
325 | |
326 // TCM ID - 3661291. | |
327 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DisableSync) { | |
328 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
329 | |
330 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
331 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
332 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
333 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
334 | |
335 ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes()); | |
336 AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER)); | |
337 ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Added a profile.")); | |
338 ASSERT_FALSE(ProfilesMatch(0, 1)); | |
339 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
340 ASSERT_EQ(1U, GetAllProfiles(1).size()); | |
341 | |
342 ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes()); | |
343 ASSERT_TRUE(AwaitQuiescence()); | |
344 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
345 ASSERT_EQ(2U, GetAllProfiles(0).size()); | |
346 } | |
347 | |
348 // TCM ID - 3608295. | |
349 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MaxLength) { | |
350 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
351 | |
352 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
353 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
354 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
355 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
356 | |
357 string16 max_length_string(kMaxDataLength, '.'); | |
358 UpdateProfile(0, | |
359 GetAllProfiles(0)[0]->guid(), | |
360 AutofillType(NAME_FIRST), | |
361 max_length_string); | |
362 UpdateProfile(0, | |
363 GetAllProfiles(0)[0]->guid(), | |
364 AutofillType(NAME_LAST), | |
365 max_length_string); | |
366 UpdateProfile(0, | |
367 GetAllProfiles(0)[0]->guid(), | |
368 AutofillType(EMAIL_ADDRESS), | |
369 max_length_string); | |
370 UpdateProfile(0, | |
371 GetAllProfiles(0)[0]->guid(), | |
372 AutofillType(ADDRESS_HOME_LINE1), | |
373 max_length_string); | |
374 | |
375 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
376 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
377 } | |
378 | |
379 // TODO(braffert): Remove FAILS annotation when crbug.com/85769 is resolved. | |
380 // TCM ID - 7735472. | |
381 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, FAILS_ExceedsMaxLength) { | |
382 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
383 | |
384 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); | |
385 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
386 ASSERT_TRUE(ProfilesMatch(0, 1)); | |
387 ASSERT_EQ(1U, GetAllProfiles(0).size()); | |
388 | |
389 string16 exceeds_max_length_string(kMaxDataLength + 1, '.'); | |
390 UpdateProfile(0, | |
391 GetAllProfiles(0)[0]->guid(), | |
392 AutofillType(NAME_FIRST), | |
393 exceeds_max_length_string); | |
394 UpdateProfile(0, | |
395 GetAllProfiles(0)[0]->guid(), | |
396 AutofillType(NAME_LAST), | |
397 exceeds_max_length_string); | |
398 UpdateProfile(0, | |
399 GetAllProfiles(0)[0]->guid(), | |
400 AutofillType(EMAIL_ADDRESS), | |
401 exceeds_max_length_string); | |
402 UpdateProfile(0, | |
403 GetAllProfiles(0)[0]->guid(), | |
404 AutofillType(ADDRESS_HOME_LINE1), | |
405 exceeds_max_length_string); | |
406 | |
407 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
408 ASSERT_FALSE(ProfilesMatch(0, 1)); | |
409 } | |
OLD | NEW |