BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_autofill_sync_test.cc
blob77d45da4c5201951c470e423fe7d4f5d31d8617d
1 // Copyright (c) 2012 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.
5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/sync/test/integration/autofill_helper.h"
7 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/autofill/core/browser/webdata/autofill_entry.h"
15 #include "components/autofill/core/browser/webdata/autofill_table.h"
17 // The E2E tests are designed to run only against real backend servers. They are
18 // disabled on regular bots. TODO(shadi): consolidate this into a common macro.
19 #define E2E_ONLY(x) DISABLED_E2ETest_##x
21 using autofill::AutofillKey;
22 using autofill::AutofillTable;
23 using autofill::AutofillProfile;
24 using autofill::AutofillType;
25 using autofill::CreditCard;
26 using autofill::PersonalDataManager;
27 using autofill_helper::AddKeys;
28 using autofill_helper::AddProfile;
29 using autofill_helper::AwaitKeysMatch;
30 using autofill_helper::AwaitProfilesMatch;
31 using autofill_helper::CreateAutofillProfile;
32 using autofill_helper::CreateUniqueAutofillProfile;
33 using autofill_helper::GetAllKeys;
34 using autofill_helper::GetAllProfiles;
35 using autofill_helper::GetPersonalDataManager;
36 using autofill_helper::GetProfileCount;
37 using autofill_helper::KeysMatch;
38 using autofill_helper::ProfilesMatch;
39 using autofill_helper::PROFILE_FRASIER;
40 using autofill_helper::PROFILE_HOMER;
41 using autofill_helper::PROFILE_MARION;
42 using autofill_helper::PROFILE_NULL;
43 using autofill_helper::RemoveKey;
44 using autofill_helper::RemoveProfile;
45 using autofill_helper::SetCreditCards;
46 using autofill_helper::UpdateProfile;
47 using bookmarks_helper::AddFolder;
48 using bookmarks_helper::AddURL;
49 using bookmarks_helper::IndexedURL;
50 using bookmarks_helper::IndexedURLTitle;
51 using sync_integration_test_util::AwaitCommitActivityCompletion;
53 class TwoClientAutofillSyncTest : public SyncTest {
54 public:
55 TwoClientAutofillSyncTest() : SyncTest(TWO_CLIENT) { count = 0; }
56 ~TwoClientAutofillSyncTest() override {}
58 bool TestUsesSelfNotifications() override { return false; }
60 // We do this so as to make a change that will trigger the autofill to sync.
61 // By default autofill does not sync unless there is some other change.
62 void MakeABookmarkChange(int profile) {
63 ASSERT_TRUE(
64 AddURL(profile, IndexedURLTitle(count), GURL(IndexedURL(count))));
65 ++count;
67 private:
68 int count;
69 DISALLOW_COPY_AND_ASSIGN(TwoClientAutofillSyncTest);
72 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, WebDataServiceSanity) {
73 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
75 // Client0 adds a key.
76 std::set<AutofillKey> keys;
77 keys.insert(AutofillKey("name0", "value0"));
78 AddKeys(0, keys);
79 MakeABookmarkChange(0);
80 ASSERT_TRUE(AwaitKeysMatch(0, 1));
81 ASSERT_EQ(1U, GetAllKeys(0).size());
83 // Client1 adds a key.
84 keys.clear();
85 keys.insert(AutofillKey("name1", "value1-0"));
86 AddKeys(1, keys);
87 MakeABookmarkChange(1);
88 ASSERT_TRUE(AwaitKeysMatch(0, 1));
89 ASSERT_EQ(2U, GetAllKeys(0).size());
91 // Client0 adds a key with the same name.
92 keys.clear();
93 keys.insert(AutofillKey("name1", "value1-1"));
94 AddKeys(0, keys);
95 MakeABookmarkChange(0);
96 ASSERT_TRUE(AwaitKeysMatch(0, 1));
97 ASSERT_EQ(3U, GetAllKeys(0).size());
99 // Client1 removes a key.
100 RemoveKey(1, AutofillKey("name1", "value1-0"));
101 MakeABookmarkChange(1);
102 ASSERT_TRUE(AwaitKeysMatch(0, 1));
103 ASSERT_EQ(2U, GetAllKeys(0).size());
105 // Client0 removes the rest.
106 RemoveKey(0, AutofillKey("name0", "value0"));
107 RemoveKey(0, AutofillKey("name1", "value1-1"));
108 MakeABookmarkChange(0);
109 ASSERT_TRUE(AwaitKeysMatch(0, 1));
110 ASSERT_EQ(0U, GetAllKeys(0).size());
113 // TCM ID - 3678296.
114 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddUnicodeProfile) {
115 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
117 std::set<AutofillKey> keys;
118 keys.insert(AutofillKey(base::WideToUTF16(L"Sigur R\u00F3s"),
119 base::WideToUTF16(L"\u00C1g\u00E6tis byrjun")));
120 AddKeys(0, keys);
121 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
122 ASSERT_TRUE(AwaitKeysMatch(0, 1));
125 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest,
126 AddDuplicateNamesToSameProfile) {
127 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
129 std::set<AutofillKey> keys;
130 keys.insert(AutofillKey("name0", "value0-0"));
131 keys.insert(AutofillKey("name0", "value0-1"));
132 keys.insert(AutofillKey("name1", "value1"));
133 AddKeys(0, keys);
134 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
135 ASSERT_TRUE(AwaitKeysMatch(0, 1));
136 ASSERT_EQ(2U, GetAllKeys(0).size());
139 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest,
140 AddDuplicateNamesToDifferentProfiles) {
141 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
143 std::set<AutofillKey> keys0;
144 keys0.insert(AutofillKey("name0", "value0-0"));
145 keys0.insert(AutofillKey("name1", "value1"));
146 AddKeys(0, keys0);
148 std::set<AutofillKey> keys1;
149 keys1.insert(AutofillKey("name0", "value0-1"));
150 keys1.insert(AutofillKey("name2", "value2"));
151 keys1.insert(AutofillKey("name3", "value3"));
152 AddKeys(1, keys1);
154 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
155 ASSERT_TRUE(AwaitKeysMatch(0, 1));
156 ASSERT_EQ(5U, GetAllKeys(0).size());
159 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest,
160 PersonalDataManagerSanity) {
161 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
163 // Client0 adds a profile.
164 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
165 MakeABookmarkChange(0);
166 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
167 ASSERT_EQ(1U, GetAllProfiles(0).size());
169 // Client1 adds a profile.
170 AddProfile(1, CreateAutofillProfile(PROFILE_MARION));
171 MakeABookmarkChange(1);
172 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
173 ASSERT_EQ(2U, GetAllProfiles(0).size());
175 // Client0 adds the same profile.
176 AddProfile(0, CreateAutofillProfile(PROFILE_MARION));
177 MakeABookmarkChange(0);
178 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
179 ASSERT_EQ(2U, GetAllProfiles(0).size());
181 // Client1 removes a profile.
182 RemoveProfile(1, GetAllProfiles(1)[0]->guid());
183 MakeABookmarkChange(1);
184 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
185 ASSERT_EQ(1U, GetAllProfiles(0).size());
187 // Client0 updates a profile.
188 UpdateProfile(0,
189 GetAllProfiles(0)[0]->guid(),
190 AutofillType(autofill::NAME_FIRST),
191 base::ASCIIToUTF16("Bart"));
192 MakeABookmarkChange(0);
193 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
194 ASSERT_EQ(1U, GetAllProfiles(0).size());
196 // Client1 removes remaining profile.
197 RemoveProfile(1, GetAllProfiles(1)[0]->guid());
198 MakeABookmarkChange(1);
199 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
200 ASSERT_EQ(0U, GetAllProfiles(0).size());
203 // TCM ID - 7261786.
204 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddDuplicateProfiles) {
205 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
207 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
208 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
209 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
210 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
211 ASSERT_EQ(1U, GetAllProfiles(0).size());
214 // TCM ID - 3636294.
215 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, SameProfileWithConflict) {
216 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
218 AutofillProfile profile0 = CreateAutofillProfile(PROFILE_HOMER);
219 AutofillProfile profile1 = CreateAutofillProfile(PROFILE_HOMER);
220 profile1.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
221 base::ASCIIToUTF16("1234567890"));
223 AddProfile(0, profile0);
224 AddProfile(1, profile1);
225 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
226 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
227 ASSERT_EQ(1U, GetAllProfiles(0).size());
230 // TCM ID - 3626291.
231 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddEmptyProfile) {
232 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
234 AddProfile(0, CreateAutofillProfile(PROFILE_NULL));
235 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
236 ASSERT_EQ(0U, GetAllProfiles(0).size());
239 // TCM ID - 3616283.
240 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddProfile) {
241 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
243 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
244 MakeABookmarkChange(0);
245 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
246 ASSERT_EQ(1U, GetAllProfiles(0).size());
249 // TCM ID - 3632260.
250 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, AddMultipleProfiles) {
251 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
253 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
254 AddProfile(0, CreateAutofillProfile(PROFILE_MARION));
255 AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER));
256 MakeABookmarkChange(0);
257 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
258 ASSERT_EQ(3U, GetAllProfiles(0).size());
261 // TCM ID - 3602257.
262 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, DeleteProfile) {
263 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
265 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
266 MakeABookmarkChange(0);
267 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
268 ASSERT_EQ(1U, GetAllProfiles(0).size());
270 RemoveProfile(1, GetAllProfiles(1)[0]->guid());
271 MakeABookmarkChange(1);
272 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
273 ASSERT_EQ(0U, GetAllProfiles(0).size());
276 // TCM ID - 3627300.
277 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MergeProfiles) {
278 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
280 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
281 AddProfile(1, CreateAutofillProfile(PROFILE_MARION));
282 AddProfile(1, CreateAutofillProfile(PROFILE_FRASIER));
283 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
284 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
285 ASSERT_EQ(3U, GetAllProfiles(0).size());
288 // TCM ID - 3665264.
289 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, UpdateFields) {
290 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
292 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
293 MakeABookmarkChange(0);
294 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
295 ASSERT_EQ(1U, GetAllProfiles(0).size());
297 UpdateProfile(0,
298 GetAllProfiles(0)[0]->guid(),
299 AutofillType(autofill::NAME_FIRST),
300 base::ASCIIToUTF16("Lisa"));
301 UpdateProfile(0,
302 GetAllProfiles(0)[0]->guid(),
303 AutofillType(autofill::EMAIL_ADDRESS),
304 base::ASCIIToUTF16("grrrl@TV.com"));
305 MakeABookmarkChange(0);
306 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
307 ASSERT_EQ(1U, GetAllProfiles(0).size());
310 // TCM ID - 3628299.
311 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, ConflictingFields) {
312 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
314 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
315 MakeABookmarkChange(0);
316 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
317 ASSERT_EQ(1U, GetAllProfiles(0).size());
318 UpdateProfile(0,
319 GetAllProfiles(0)[0]->guid(),
320 AutofillType(autofill::NAME_FIRST),
321 base::ASCIIToUTF16("Lisa"));
322 MakeABookmarkChange(0);
323 UpdateProfile(1,
324 GetAllProfiles(1)[0]->guid(),
325 AutofillType(autofill::NAME_FIRST),
326 base::ASCIIToUTF16("Bart"));
327 MakeABookmarkChange(1);
328 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
329 ASSERT_EQ(1U, GetAllProfiles(0).size());
332 // TCM ID - 3608295.
333 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, MaxLength) {
334 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
336 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
337 MakeABookmarkChange(0);
338 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
339 ASSERT_EQ(1U, GetAllProfiles(0).size());
341 base::string16 max_length_string(AutofillTable::kMaxDataLength, '.');
342 UpdateProfile(0,
343 GetAllProfiles(0)[0]->guid(),
344 AutofillType(autofill::NAME_FULL),
345 max_length_string);
346 UpdateProfile(0,
347 GetAllProfiles(0)[0]->guid(),
348 AutofillType(autofill::EMAIL_ADDRESS),
349 max_length_string);
350 UpdateProfile(0,
351 GetAllProfiles(0)[0]->guid(),
352 AutofillType(autofill::ADDRESS_HOME_LINE1),
353 max_length_string);
355 MakeABookmarkChange(0);
356 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
359 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, ExceedsMaxLength) {
360 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
362 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
363 MakeABookmarkChange(0);
364 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
365 ASSERT_EQ(1U, GetAllProfiles(0).size());
367 base::string16 exceeds_max_length_string(
368 AutofillTable::kMaxDataLength + 1, '.');
369 UpdateProfile(0,
370 GetAllProfiles(0)[0]->guid(),
371 AutofillType(autofill::NAME_FIRST),
372 exceeds_max_length_string);
373 UpdateProfile(0,
374 GetAllProfiles(0)[0]->guid(),
375 AutofillType(autofill::NAME_LAST),
376 exceeds_max_length_string);
377 UpdateProfile(0,
378 GetAllProfiles(0)[0]->guid(),
379 AutofillType(autofill::EMAIL_ADDRESS),
380 exceeds_max_length_string);
381 UpdateProfile(0,
382 GetAllProfiles(0)[0]->guid(),
383 AutofillType(autofill::ADDRESS_HOME_LINE1),
384 exceeds_max_length_string);
386 MakeABookmarkChange(0);
387 ASSERT_TRUE(bookmarks_helper::AwaitAllModelsMatch());
388 EXPECT_FALSE(ProfilesMatch(0, 1));
391 // Test credit cards don't sync.
392 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest, NoCreditCardSync) {
393 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
395 AddProfile(0, CreateAutofillProfile(PROFILE_HOMER));
397 CreditCard card;
398 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
399 base::ASCIIToUTF16("6011111111111117"));
400 std::vector<CreditCard> credit_cards;
401 credit_cards.push_back(card);
402 SetCreditCards(0, &credit_cards);
404 MakeABookmarkChange(0);
405 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
406 ASSERT_EQ(1U, GetAllProfiles(0).size());
408 PersonalDataManager* pdm = GetPersonalDataManager(1);
409 ASSERT_EQ(0U, pdm->GetCreditCards().size());
412 IN_PROC_BROWSER_TEST_F(TwoClientAutofillSyncTest,
413 E2E_ONLY(TwoClientsAddAutofillProfiles)) {
414 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
416 // All profiles should sync same autofill profiles.
417 ASSERT_TRUE(AwaitProfilesMatch(0, 1)) <<
418 "Initial autofill profiles did not match for all profiles.";
420 // For clean profiles, the autofill profiles count should be zero. We are not
421 // enforcing this, we only check that the final count is equal to initial
422 // count plus new autofill profiles count.
423 int init_autofill_profiles_count = GetProfileCount(0);
425 // Add a new autofill profile to the first client.
426 AddProfile(0, CreateUniqueAutofillProfile());
428 ASSERT_TRUE(AwaitProfilesMatch(0, 1));
430 // Check that the total number of autofill profiles is as expected
431 for (int i = 0; i < num_clients(); ++i) {
432 ASSERT_EQ(GetProfileCount(i), init_autofill_profiles_count + 1) <<
433 "Total autofill profile count is wrong.";