Chromium Code Reviews

Side by Side Diff: chrome/browser/autofill/personal_data_manager_unittest.cc

Issue 2818033: AutoFill: Aggregate profile data. Remove the AutoFill InfoBar. (Closed)
Patch Set: Comment. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "chrome/browser/autofill/autofill_common_unittest.h" 9 #include "chrome/browser/autofill/autofill_common_unittest.h"
10 #include "chrome/browser/autofill/autofill_profile.h" 10 #include "chrome/browser/autofill/autofill_profile.h"
11 #include "chrome/browser/autofill/form_structure.h" 11 #include "chrome/browser/autofill/form_structure.h"
12 #include "chrome/browser/autofill/personal_data_manager.h" 12 #include "chrome/browser/autofill/personal_data_manager.h"
13 #include "chrome/browser/chrome_thread.h" 13 #include "chrome/browser/chrome_thread.h"
14 #include "chrome/browser/pref_service.h" 14 #include "chrome/browser/pref_service.h"
15 #include "chrome/common/notification_details.h" 15 #include "chrome/common/notification_details.h"
16 #include "chrome/common/notification_observer_mock.h" 16 #include "chrome/common/notification_observer_mock.h"
17 #include "chrome/common/notification_registrar.h" 17 #include "chrome/common/notification_registrar.h"
18 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
19 #include "chrome/common/notification_type.h" 19 #include "chrome/common/notification_type.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/testing_profile.h" 21 #include "chrome/test/testing_profile.h"
22 #include "webkit/glue/form_data.h" 22 #include "webkit/glue/form_data.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 using webkit_glue::FormData;
27
26 ACTION(QuitUIMessageLoop) { 28 ACTION(QuitUIMessageLoop) {
27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 29 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
28 MessageLoop::current()->Quit(); 30 MessageLoop::current()->Quit();
29 } 31 }
30 32
31 class PersonalDataLoadedObserverMock : public PersonalDataManager::Observer { 33 class PersonalDataLoadedObserverMock : public PersonalDataManager::Observer {
32 public: 34 public:
33 PersonalDataLoadedObserverMock() {} 35 PersonalDataLoadedObserverMock() {}
34 virtual ~PersonalDataLoadedObserverMock() {} 36 virtual ~PersonalDataLoadedObserverMock() {}
35 37
(...skipping 135 matching lines...)
171 // Verify that we've loaded the profiles from the web database. 173 // Verify that we've loaded the profiles from the web database.
172 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); 174 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles();
173 ASSERT_EQ(2U, results3.size()); 175 ASSERT_EQ(2U, results3.size());
174 EXPECT_EQ(profile0, *results3.at(0)); 176 EXPECT_EQ(profile0, *results3.at(0));
175 EXPECT_EQ(profile2, *results3.at(1)); 177 EXPECT_EQ(profile2, *results3.at(1));
176 } 178 }
177 179
178 // TODO(jhawkins): Test SetCreditCards w/out a WebDataService in the profile. 180 // TODO(jhawkins): Test SetCreditCards w/out a WebDataService in the profile.
179 TEST_F(PersonalDataManagerTest, SetCreditCards) { 181 TEST_F(PersonalDataManagerTest, SetCreditCards) {
180 CreditCard creditcard0(string16(), 0); 182 CreditCard creditcard0(string16(), 0);
181 autofill_unittest::SetCreditCardInfo(&creditcard0, 183 autofill_unittest::SetCreditCardInfo(&creditcard0, "Corporate",
182 "Corporate", "John Dillinger", "Visa", 184 "John Dillinger", "Visa", "123456789012", "01", "2010", "Chicago");
183 "123456789012", "01", "2010", "123", "Chicago", "Indianapolis");
184 185
185 CreditCard creditcard1(string16(), 0); 186 CreditCard creditcard1(string16(), 0);
186 autofill_unittest::SetCreditCardInfo(&creditcard1, 187 autofill_unittest::SetCreditCardInfo(&creditcard1, "Personal",
187 "Personal", "Bonnie Parker", "Mastercard", 188 "Bonnie Parker", "Mastercard", "098765432109", "12", "2012", "Dallas");
188 "098765432109", "12", "2012", "987", "Dallas", "");
189 189
190 CreditCard creditcard2(string16(), 0); 190 CreditCard creditcard2(string16(), 0);
191 autofill_unittest::SetCreditCardInfo(&creditcard2, 191 autofill_unittest::SetCreditCardInfo(&creditcard2, "Savings", "Clyde Barrow",
192 "Savings", "Clyde Barrow", "American Express", 192 "American Express", "777666888555", "04", "2015", "Home");
193 "777666888555", "04", "2015", "445", "Home", "Farm");
194 193
195 // This will verify that the web database has been loaded and the notification 194 // This will verify that the web database has been loaded and the notification
196 // sent out. 195 // sent out.
197 EXPECT_CALL(personal_data_observer_, 196 EXPECT_CALL(personal_data_observer_,
198 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); 197 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
199 198
200 // The message loop will exit when the mock observer is notified. 199 // The message loop will exit when the mock observer is notified.
201 MessageLoop::current()->Run(); 200 MessageLoop::current()->Run();
202 201
203 // Add the three test credit cards to the database. 202 // Add the three test credit cards to the database.
(...skipping 136 matching lines...)
340 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); 339 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
341 340
342 MessageLoop::current()->Run(); 341 MessageLoop::current()->Run();
343 342
344 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); 343 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles();
345 ASSERT_EQ(1U, results3.size()); 344 ASSERT_EQ(1U, results3.size());
346 EXPECT_EQ(profile0, *results2.at(0)); 345 EXPECT_EQ(profile0, *results2.at(0));
347 } 346 }
348 347
349 TEST_F(PersonalDataManagerTest, ImportFormData) { 348 TEST_F(PersonalDataManagerTest, ImportFormData) {
350 webkit_glue::FormData form; 349 FormData form;
350 webkit_glue::FormField field;
351 autofill_unittest::CreateTestFormField(
352 "First name:", "first_name", "George", "text", &field);
353 form.fields.push_back(field);
354 autofill_unittest::CreateTestFormField(
355 "Last name:", "last_name", "Washington", "text", &field);
356 form.fields.push_back(field);
357 autofill_unittest::CreateTestFormField(
358 "Email:", "email", "theprez@gmail.com", "text", &field);
359 form.fields.push_back(field);
351 FormStructure form_structure(form); 360 FormStructure form_structure(form);
352 std::vector<FormStructure*> forms; 361 std::vector<FormStructure*> forms;
353 forms.push_back(&form_structure); 362 forms.push_back(&form_structure);
354 personal_data_->ImportFormData(forms, NULL); 363 personal_data_->ImportFormData(forms, NULL);
355 personal_data_->SaveImportedFormData();
356 364
357 // And wait for the refresh. 365 // And wait for the refresh.
358 EXPECT_CALL(personal_data_observer_, 366 EXPECT_CALL(personal_data_observer_,
359 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); 367 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
360 368
361 MessageLoop::current()->Run(); 369 MessageLoop::current()->Run();
362 370
363 AutoFillProfile expected(ASCIIToUTF16("Unlabeled"), 1); 371 AutoFillProfile expected(ASCIIToUTF16("Unlabeled"), 1);
372 autofill_unittest::SetProfileInfo(&expected, "Unlabeled", "George", NULL,
373 "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
374 NULL, NULL, NULL);
364 const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); 375 const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
365 ASSERT_EQ(1U, results.size()); 376 ASSERT_EQ(1U, results.size());
366 ASSERT_EQ(expected, *results[0]); 377 EXPECT_EQ(expected, *results[0]);
367 } 378 }
368 379
369 TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) { 380 TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) {
370 AutoFillProfile profile0(ASCIIToUTF16("Home"), 0); 381 AutoFillProfile profile0(ASCIIToUTF16("Home"), 0);
371 AutoFillProfile profile1(ASCIIToUTF16("Home"), 0); 382 AutoFillProfile profile1(ASCIIToUTF16("Home"), 0);
372 AutoFillProfile profile2(ASCIIToUTF16("Home"), 0); 383 AutoFillProfile profile2(ASCIIToUTF16("Home"), 0);
373 AutoFillProfile profile3(ASCIIToUTF16("NotHome"), 0); 384 AutoFillProfile profile3(ASCIIToUTF16("NotHome"), 0);
374 AutoFillProfile profile4(ASCIIToUTF16("Work"), 0); 385 AutoFillProfile profile4(ASCIIToUTF16("Work"), 0);
375 AutoFillProfile profile5(ASCIIToUTF16("Work"), 0); 386 AutoFillProfile profile5(ASCIIToUTF16("Work"), 0);
376 387
(...skipping 59 matching lines...)
436 447
437 const std::vector<CreditCard*>& results = personal_data_->credit_cards(); 448 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
438 ASSERT_EQ(6U, results.size()); 449 ASSERT_EQ(6U, results.size());
439 EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label()); 450 EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label());
440 EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label()); 451 EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label());
441 EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label()); 452 EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label());
442 EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label()); 453 EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label());
443 EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label()); 454 EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label());
444 EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label()); 455 EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label());
445 } 456 }
457
458 TEST_F(PersonalDataManagerTest, AggregateProfileData) {
459 scoped_ptr<FormData> form(new FormData);
460
461 webkit_glue::FormField field;
462 autofill_unittest::CreateTestFormField(
463 "First name:", "first_name", "George", "text", &field);
464 form->fields.push_back(field);
465 autofill_unittest::CreateTestFormField(
466 "Last name:", "last_name", "Washington", "text", &field);
467 form->fields.push_back(field);
468 autofill_unittest::CreateTestFormField(
469 "Email:", "email", "theprez@gmail.com", "text", &field);
470 form->fields.push_back(field);
471
472 scoped_ptr<FormStructure> form_structure(new FormStructure(*form));
473 scoped_ptr<std::vector<FormStructure*> > forms(
474 new std::vector<FormStructure*>);
475 forms->push_back(form_structure.get());
476 personal_data_->ImportFormData(*forms, NULL);
477
478 // And wait for the refresh.
479 EXPECT_CALL(personal_data_observer_,
480 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
481
482 MessageLoop::current()->Run();
483
484 scoped_ptr<AutoFillProfile> expected(
485 new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
486 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
487 "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
488 NULL, NULL, NULL);
489 const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
490 ASSERT_EQ(1U, results.size());
491 EXPECT_EQ(*expected, *results[0]);
492
493 // Now create a completely different profile.
494 form.reset(new FormData);
495 autofill_unittest::CreateTestFormField(
496 "First name:", "first_name", "John", "text", &field);
497 form->fields.push_back(field);
498 autofill_unittest::CreateTestFormField(
499 "Last name:", "last_name", "Adams", "text", &field);
500 form->fields.push_back(field);
501 autofill_unittest::CreateTestFormField(
502 "Email:", "email", "second@gmail.com", "text", &field);
503 form->fields.push_back(field);
504
505 form_structure.reset(new FormStructure(*form));
506 forms.reset(new std::vector<FormStructure*>);
507 forms->push_back(form_structure.get());
508 personal_data_->ImportFormData(*forms, NULL);
509
510 // And wait for the refresh.
511 EXPECT_CALL(personal_data_observer_,
512 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
513
514 MessageLoop::current()->Run();
515
516 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles();
517 ASSERT_EQ(2U, results2.size());
518
519 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
520 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
521 "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
522 NULL, NULL, NULL);
523 EXPECT_EQ(*expected, *results2[0]);
524
525 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2));
526 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL,
527 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
528 NULL, NULL);
529 EXPECT_EQ(*expected, *results2[1]);
530
531 // Submit a form with new data for the first profile.
532 form.reset(new FormData);
533 autofill_unittest::CreateTestFormField(
534 "First name:", "first_name", "George", "text", &field);
535 form->fields.push_back(field);
536 autofill_unittest::CreateTestFormField(
537 "Last name:", "last_name", "Washington", "text", &field);
538 form->fields.push_back(field);
539 autofill_unittest::CreateTestFormField(
540 "Address Line 1:", "address", "190 High Street", "text", &field);
541 form->fields.push_back(field);
542 autofill_unittest::CreateTestFormField(
543 "City:", "city", "Philadelphia", "text", &field);
544 form->fields.push_back(field);
545 autofill_unittest::CreateTestFormField(
546 "State:", "state", "Pennsylvania", "text", &field);
547 form->fields.push_back(field);
548 autofill_unittest::CreateTestFormField(
549 "Zip:", "zipcode", "19106", "text", &field);
550 form->fields.push_back(field);
551
552 form_structure.reset(new FormStructure(*form));
553 forms.reset(new std::vector<FormStructure*>);
554 forms->push_back(form_structure.get());
555 personal_data_->ImportFormData(*forms, NULL);
556
557 // And wait for the refresh.
558 EXPECT_CALL(personal_data_observer_,
559 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
560
561 MessageLoop::current()->Run();
562
563 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles();
564 ASSERT_EQ(2U, results3.size());
565
566 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
567 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
568 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL,
569 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL);
570 EXPECT_EQ(*expected, *results3[0]);
571
572 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2));
573 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL,
574 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
575 NULL, NULL);
576 EXPECT_EQ(*expected, *results3[1]);
577 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.cc ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine