Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 15500008: Persist the choice of AutofillDataModel when using the requestAutocomplete dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad merge resolution Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/guid.h" 5 #include "base/guid.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 AutofillProfile verified_profile(test::GetFullProfile()); 519 AutofillProfile verified_profile(test::GetFullProfile());
520 verified_profile.set_origin(kSettingsOrigin); 520 verified_profile.set_origin(kSettingsOrigin);
521 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 521 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
522 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 522 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
523 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 523 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
524 ASSERT_TRUE(shipping_model); 524 ASSERT_TRUE(shipping_model);
525 EXPECT_EQ(4, shipping_model->GetItemCount()); 525 EXPECT_EQ(4, shipping_model->GetItemCount());
526 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL)); 526 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL));
527 } 527 }
528 528
529 // Makes sure that the choice of which Autofill profile to use for each section
530 // is sticky.
531 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
532 AutofillProfile full_profile(test::GetFullProfile());
533 full_profile.set_origin(kSettingsOrigin);
534 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
535 AutofillProfile full_profile2(test::GetFullProfile2());
536 full_profile2.set_origin(kSettingsOrigin);
537 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
538
539 // Until a selection has been made, the default shipping suggestion is the
540 // first one (after "use billing").
541 SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>(
542 controller()->MenuModelForSection(SECTION_SHIPPING));
543 EXPECT_EQ(1, shipping_model->checked_item());
544
545 for (int i = 2; i >= 0; --i) {
546 shipping_model = static_cast<SuggestionsMenuModel*>(
547 controller()->MenuModelForSection(SECTION_SHIPPING));
548 shipping_model->ExecuteCommand(i, 0);
549 FillCreditCardInputs();
550 controller()->OnAccept();
551
552 TearDown();
553 SetUp();
554 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
555 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
556 shipping_model = static_cast<SuggestionsMenuModel*>(
557 controller()->MenuModelForSection(SECTION_SHIPPING));
558 EXPECT_EQ(i, shipping_model->checked_item());
559 }
560
561 // Try again, but don't add the default profile to the PDM. The dialog
562 // should fall back to the first profile.
563 shipping_model->ExecuteCommand(2, 0);
564 FillCreditCardInputs();
565 controller()->OnAccept();
566 TearDown();
567 SetUp();
568 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
569 shipping_model = static_cast<SuggestionsMenuModel*>(
570 controller()->MenuModelForSection(SECTION_SHIPPING));
571 EXPECT_EQ(1, shipping_model->checked_item());
572 }
573
529 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { 574 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
530 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 575 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
531 ui::MenuModel* email_model = 576 ui::MenuModel* email_model =
532 controller()->MenuModelForSection(SECTION_EMAIL); 577 controller()->MenuModelForSection(SECTION_EMAIL);
533 EXPECT_FALSE(email_model); 578 EXPECT_FALSE(email_model);
534 579
535 // Set up some variant data. 580 // Set up some variant data.
536 AutofillProfile full_profile(test::GetVerifiedProfile()); 581 AutofillProfile full_profile(test::GetVerifiedProfile());
537 std::vector<string16> names; 582 std::vector<string16> names;
538 names.push_back(ASCIIToUTF16("John Doe")); 583 names.push_back(ASCIIToUTF16("John Doe"));
539 names.push_back(ASCIIToUTF16("Jane Doe")); 584 names.push_back(ASCIIToUTF16("Jane Doe"));
540 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); 585 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names);
541 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); 586 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail);
542 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); 587 const string16 kEmail2 = ASCIIToUTF16("admin@example.com");
543 std::vector<string16> emails; 588 std::vector<string16> emails;
544 emails.push_back(kEmail1); 589 emails.push_back(kEmail1);
545 emails.push_back(kEmail2); 590 emails.push_back(kEmail2);
546 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); 591 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails);
547 592
548 // Respect variants for the email address field only. 593 // Respect variants for the email address field only.
549 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 594 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
550 ui::MenuModel* shipping_model = 595 ui::MenuModel* shipping_model =
551 controller()->MenuModelForSection(SECTION_SHIPPING); 596 controller()->MenuModelForSection(SECTION_SHIPPING);
552 EXPECT_EQ(4, shipping_model->GetItemCount()); 597 EXPECT_EQ(4, shipping_model->GetItemCount());
553 email_model = controller()->MenuModelForSection(SECTION_EMAIL); 598 email_model = controller()->MenuModelForSection(SECTION_EMAIL);
554 ASSERT_TRUE(!!email_model); 599 ASSERT_TRUE(!!email_model);
555 EXPECT_EQ(4, email_model->GetItemCount()); 600 EXPECT_EQ(4, email_model->GetItemCount());
556 601
602 // The first one is the default.
603 SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>(
604 controller()->MenuModelForSection(SECTION_EMAIL));
605 EXPECT_EQ(0, email_suggestions->checked_item());
606
557 email_model->ActivatedAt(0); 607 email_model->ActivatedAt(0);
558 EXPECT_EQ(kEmail1, 608 EXPECT_EQ(kEmail1,
559 controller()->SuggestionStateForSection(SECTION_EMAIL).text); 609 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
560 email_model->ActivatedAt(1); 610 email_model->ActivatedAt(1);
561 EXPECT_EQ(kEmail2, 611 EXPECT_EQ(kEmail2,
562 controller()->SuggestionStateForSection(SECTION_EMAIL).text); 612 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
563 613
564 controller()->EditClickedForSection(SECTION_EMAIL); 614 controller()->EditClickedForSection(SECTION_EMAIL);
565 const DetailInputs& inputs = 615 const DetailInputs& inputs =
566 controller()->RequestedFieldsForSection(SECTION_EMAIL); 616 controller()->RequestedFieldsForSection(SECTION_EMAIL);
567 EXPECT_EQ(kEmail2, inputs[0].initial_value); 617 EXPECT_EQ(kEmail2, inputs[0].initial_value);
618
619 // The choice of variant is persisted across runs of the dialog.
620 email_model->ActivatedAt(0);
621 email_model->ActivatedAt(1);
622 FillCreditCardInputs();
623 controller()->OnAccept();
624
625 TearDown();
626 SetUp();
627 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
628 email_suggestions = static_cast<SuggestionsMenuModel*>(
629 controller()->MenuModelForSection(SECTION_EMAIL));
630 EXPECT_EQ(1, email_suggestions->checked_item());
568 } 631 }
569 632
570 TEST_F(AutofillDialogControllerTest, AutofillCreditCards) { 633 TEST_F(AutofillDialogControllerTest, AutofillCreditCards) {
571 // Since the PersonalDataManager is empty, this should only have the 634 // Since the PersonalDataManager is empty, this should only have the
572 // default menu items. 635 // default menu items.
573 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 636 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
574 637
575 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3); 638 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(3);
576 639
577 // Empty cards are ignored. 640 // Empty cards are ignored.
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1461 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1399 1462
1400 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1463 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1401 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1464 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1402 1465
1403 profile()->set_incognito(true); 1466 profile()->set_incognito(true);
1404 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1467 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1405 } 1468 }
1406 1469
1407 } // namespace autofill 1470 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_models.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698