OLD | NEW |
---|---|
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 Loading... | |
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 defauilt shipping suggestion is the | |
Ilya Sherman
2013/05/21 03:54:35
nit: "default"
Evan Stade
2013/05/21 17:34:41
Done.
| |
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 SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>( | |
446 controller()->MenuModelForSection(SECTION_SHIPPING)); | |
447 shipping_model->ExecuteCommand(i, 0); | |
448 controller()->OnAccept(); | |
449 | |
450 TearDown(); | |
451 SetUp(); | |
Ilya Sherman
2013/05/21 03:54:35
Hmm, these methods aren't really meant to be calle
Evan Stade
2013/05/21 17:34:41
If the contents of SetUp and TearDown evolve, we p
| |
452 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | |
453 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); | |
Ilya Sherman
2013/05/21 03:54:35
Please add a test verifying the behavior when the
Evan Stade
2013/05/21 17:34:41
Done. Also improved the behavior in that case (ins
| |
454 shipping_model = static_cast<SuggestionsMenuModel*>( | |
455 controller()->MenuModelForSection(SECTION_SHIPPING)); | |
456 EXPECT_EQ(i, shipping_model->checked_item()); | |
457 } | |
458 } | |
459 | |
428 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { | 460 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { |
429 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 461 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
430 ui::MenuModel* email_model = | 462 ui::MenuModel* email_model = |
431 controller()->MenuModelForSection(SECTION_EMAIL); | 463 controller()->MenuModelForSection(SECTION_EMAIL); |
432 EXPECT_FALSE(email_model); | 464 EXPECT_FALSE(email_model); |
433 | 465 |
434 // Set up some variant data. | 466 // Set up some variant data. |
435 AutofillProfile full_profile(test::GetFullProfile()); | 467 AutofillProfile full_profile(test::GetFullProfile()); |
436 std::vector<string16> names; | 468 std::vector<string16> names; |
437 names.push_back(ASCIIToUTF16("John Doe")); | 469 names.push_back(ASCIIToUTF16("John Doe")); |
438 names.push_back(ASCIIToUTF16("Jane Doe")); | 470 names.push_back(ASCIIToUTF16("Jane Doe")); |
439 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); | 471 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); |
440 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); | 472 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); |
441 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); | 473 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); |
442 std::vector<string16> emails; | 474 std::vector<string16> emails; |
443 emails.push_back(kEmail1); | 475 emails.push_back(kEmail1); |
444 emails.push_back(kEmail2); | 476 emails.push_back(kEmail2); |
445 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); | 477 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); |
446 | 478 |
447 // Respect variants for the email address field only. | 479 // Respect variants for the email address field only. |
448 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 480 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
449 ui::MenuModel* shipping_model = | 481 ui::MenuModel* shipping_model = |
450 controller()->MenuModelForSection(SECTION_SHIPPING); | 482 controller()->MenuModelForSection(SECTION_SHIPPING); |
451 EXPECT_EQ(4, shipping_model->GetItemCount()); | 483 EXPECT_EQ(4, shipping_model->GetItemCount()); |
452 email_model = controller()->MenuModelForSection(SECTION_EMAIL); | 484 email_model = controller()->MenuModelForSection(SECTION_EMAIL); |
453 ASSERT_TRUE(!!email_model); | 485 ASSERT_TRUE(!!email_model); |
454 EXPECT_EQ(4, email_model->GetItemCount()); | 486 EXPECT_EQ(4, email_model->GetItemCount()); |
455 | 487 |
488 // The first one is the default. | |
489 SuggestionsMenuModel* email_suggestions = static_cast<SuggestionsMenuModel*>( | |
490 controller()->MenuModelForSection(SECTION_EMAIL)); | |
491 EXPECT_EQ(0, email_suggestions->checked_item()); | |
492 | |
456 email_model->ActivatedAt(0); | 493 email_model->ActivatedAt(0); |
457 EXPECT_EQ(kEmail1, | 494 EXPECT_EQ(kEmail1, |
458 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 495 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
459 email_model->ActivatedAt(1); | 496 email_model->ActivatedAt(1); |
460 EXPECT_EQ(kEmail2, | 497 EXPECT_EQ(kEmail2, |
461 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 498 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
462 | 499 |
463 controller()->EditClickedForSection(SECTION_EMAIL); | 500 controller()->EditClickedForSection(SECTION_EMAIL); |
464 const DetailInputs& inputs = | 501 const DetailInputs& inputs = |
465 controller()->RequestedFieldsForSection(SECTION_EMAIL); | 502 controller()->RequestedFieldsForSection(SECTION_EMAIL); |
466 EXPECT_EQ(kEmail2, inputs[0].initial_value); | 503 EXPECT_EQ(kEmail2, inputs[0].initial_value); |
504 | |
505 // The choice of variant is persisted across runs of the dialog. | |
506 email_model->ActivatedAt(0); | |
507 email_model->ActivatedAt(1); | |
508 controller()->OnAccept(); | |
509 | |
510 TearDown(); | |
511 SetUp(); | |
512 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | |
513 email_suggestions = static_cast<SuggestionsMenuModel*>( | |
514 controller()->MenuModelForSection(SECTION_EMAIL)); | |
515 EXPECT_EQ(1, email_suggestions->checked_item()); | |
467 } | 516 } |
468 | 517 |
469 // Test selecting a shipping address different from billing as address. | 518 // Test selecting a shipping address different from billing as address. |
470 TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) { | 519 TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) { |
471 AutofillProfile full_profile(test::GetFullProfile()); | 520 AutofillProfile full_profile(test::GetFullProfile()); |
472 AutofillProfile full_profile2(test::GetFullProfile2()); | 521 AutofillProfile full_profile2(test::GetFullProfile2()); |
473 CreditCard credit_card; | 522 CreditCard credit_card; |
474 test::SetCreditCardInfo(&credit_card, "Test User", | 523 test::SetCreditCardInfo(&credit_card, "Test User", |
475 "4234567890654321", // Visa | 524 "4234567890654321", // Visa |
476 "11", "2100"); | 525 "11", "2100"); |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1257 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1209 | 1258 |
1210 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 1259 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
1211 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 1260 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
1212 | 1261 |
1213 profile()->set_incognito(true); | 1262 profile()->set_incognito(true); |
1214 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1263 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1215 } | 1264 } |
1216 | 1265 |
1217 } // namespace autofill | 1266 } // namespace autofill |
OLD | NEW |