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

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: ilya review 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // A full profile should be picked up. 418 // A full profile should be picked up.
419 AutofillProfile full_profile(test::GetFullProfile()); 419 AutofillProfile full_profile(test::GetFullProfile());
420 full_profile.set_origin(kSettingsOrigin); 420 full_profile.set_origin(kSettingsOrigin);
421 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 421 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
422 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 422 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
423 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 423 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
424 EXPECT_EQ(4, shipping_model->GetItemCount()); 424 EXPECT_EQ(4, shipping_model->GetItemCount());
425 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL)); 425 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL));
426 } 426 }
427 427
428 // Makes sure that the choice of which Autofill profile to use for each section
429 // is sticky.
430 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
431 AutofillProfile full_profile(test::GetFullProfile());
432 full_profile.set_origin(kSettingsOrigin);
433 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
434 AutofillProfile full_profile2(test::GetFullProfile2());
435 full_profile2.set_origin(kSettingsOrigin);
436 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
437
438 // Until a selection has been made, the default shipping suggestion is the
439 // first one (after "use billing").
440 SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>(
441 controller()->MenuModelForSection(SECTION_SHIPPING));
442 EXPECT_EQ(1, shipping_model->checked_item());
443
444 for (int i = 2; i >= 0; --i) {
445 shipping_model = static_cast<SuggestionsMenuModel*>(
446 controller()->MenuModelForSection(SECTION_SHIPPING));
447 shipping_model->ExecuteCommand(i, 0);
448 controller()->OnAccept();
449
450 TearDown();
451 SetUp();
452 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
453 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
454 shipping_model = static_cast<SuggestionsMenuModel*>(
455 controller()->MenuModelForSection(SECTION_SHIPPING));
456 EXPECT_EQ(i, shipping_model->checked_item());
457 }
458
459 // Try again, but don't add the default profile to the PDM. The dialog
460 // should fall back to the first profile.
461 shipping_model->ExecuteCommand(2, 0);
462 controller()->OnAccept();
463 TearDown();
464 SetUp();
465 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
466 shipping_model = static_cast<SuggestionsMenuModel*>(
467 controller()->MenuModelForSection(SECTION_SHIPPING));
468 EXPECT_EQ(1, shipping_model->checked_item());
469 }
470
428 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { 471 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
429 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 472 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
430 ui::MenuModel* email_model = 473 ui::MenuModel* email_model =
431 controller()->MenuModelForSection(SECTION_EMAIL); 474 controller()->MenuModelForSection(SECTION_EMAIL);
432 EXPECT_FALSE(email_model); 475 EXPECT_FALSE(email_model);
433 476
434 // Set up some variant data. 477 // Set up some variant data.
435 AutofillProfile full_profile(test::GetFullProfile()); 478 AutofillProfile full_profile(test::GetFullProfile());
436 std::vector<string16> names; 479 std::vector<string16> names;
437 names.push_back(ASCIIToUTF16("John Doe")); 480 names.push_back(ASCIIToUTF16("John Doe"));
438 names.push_back(ASCIIToUTF16("Jane Doe")); 481 names.push_back(ASCIIToUTF16("Jane Doe"));
439 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); 482 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names);
440 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); 483 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail);
441 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); 484 const string16 kEmail2 = ASCIIToUTF16("admin@example.com");
442 std::vector<string16> emails; 485 std::vector<string16> emails;
443 emails.push_back(kEmail1); 486 emails.push_back(kEmail1);
444 emails.push_back(kEmail2); 487 emails.push_back(kEmail2);
445 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); 488 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails);
446 489
447 // Respect variants for the email address field only. 490 // Respect variants for the email address field only.
448 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 491 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
449 ui::MenuModel* shipping_model = 492 ui::MenuModel* shipping_model =
450 controller()->MenuModelForSection(SECTION_SHIPPING); 493 controller()->MenuModelForSection(SECTION_SHIPPING);
451 EXPECT_EQ(4, shipping_model->GetItemCount()); 494 EXPECT_EQ(4, shipping_model->GetItemCount());
452 email_model = controller()->MenuModelForSection(SECTION_EMAIL); 495 email_model = controller()->MenuModelForSection(SECTION_EMAIL);
453 ASSERT_TRUE(!!email_model); 496 ASSERT_TRUE(!!email_model);
454 EXPECT_EQ(4, email_model->GetItemCount()); 497 EXPECT_EQ(4, email_model->GetItemCount());
455 498
499 // The first one is the default.
500 SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>(
501 controller()->MenuModelForSection(SECTION_EMAIL));
502 EXPECT_EQ(0, email_suggestions->checked_item());
503
456 email_model->ActivatedAt(0); 504 email_model->ActivatedAt(0);
457 EXPECT_EQ(kEmail1, 505 EXPECT_EQ(kEmail1,
458 controller()->SuggestionStateForSection(SECTION_EMAIL).text); 506 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
459 email_model->ActivatedAt(1); 507 email_model->ActivatedAt(1);
460 EXPECT_EQ(kEmail2, 508 EXPECT_EQ(kEmail2,
461 controller()->SuggestionStateForSection(SECTION_EMAIL).text); 509 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
462 510
463 controller()->EditClickedForSection(SECTION_EMAIL); 511 controller()->EditClickedForSection(SECTION_EMAIL);
464 const DetailInputs& inputs = 512 const DetailInputs& inputs =
465 controller()->RequestedFieldsForSection(SECTION_EMAIL); 513 controller()->RequestedFieldsForSection(SECTION_EMAIL);
466 EXPECT_EQ(kEmail2, inputs[0].initial_value); 514 EXPECT_EQ(kEmail2, inputs[0].initial_value);
515
516 // The choice of variant is persisted across runs of the dialog.
517 email_model->ActivatedAt(0);
518 email_model->ActivatedAt(1);
519 controller()->OnAccept();
520
521 TearDown();
522 SetUp();
523 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
524 email_suggestions = static_cast<SuggestionsMenuModel*>(
525 controller()->MenuModelForSection(SECTION_EMAIL));
526 EXPECT_EQ(1, email_suggestions->checked_item());
467 } 527 }
468 528
469 // Test selecting a shipping address different from billing as address. 529 // Test selecting a shipping address different from billing as address.
470 TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) { 530 TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) {
471 AutofillProfile full_profile(test::GetFullProfile()); 531 AutofillProfile full_profile(test::GetFullProfile());
472 AutofillProfile full_profile2(test::GetFullProfile2()); 532 AutofillProfile full_profile2(test::GetFullProfile2());
473 CreditCard credit_card; 533 CreditCard credit_card;
474 test::SetCreditCardInfo(&credit_card, "Test User", 534 test::SetCreditCardInfo(&credit_card, "Test User",
475 "4234567890654321", // Visa 535 "4234567890654321", // Visa
476 "11", "2100"); 536 "11", "2100");
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1268 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1209 1269
1210 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1270 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1211 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1271 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1212 1272
1213 profile()->set_incognito(true); 1273 profile()->set_incognito(true);
1214 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1274 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1215 } 1275 }
1216 1276
1217 } // namespace autofill 1277 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698