| 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 | 362 |
| 363 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { | 363 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { |
| 364 ui::MenuModel* shipping_model = | 364 ui::MenuModel* shipping_model = |
| 365 controller()->MenuModelForSection(SECTION_SHIPPING); | 365 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 366 // Since the PersonalDataManager is empty, this should only have the | 366 // Since the PersonalDataManager is empty, this should only have the |
| 367 // "use billing", "add new" and "manage" menu items. | 367 // "use billing", "add new" and "manage" menu items. |
| 368 EXPECT_EQ(3, shipping_model->GetItemCount()); | 368 EXPECT_EQ(3, shipping_model->GetItemCount()); |
| 369 // On the other hand, the other models should be NULL when there's no |
| 370 // suggestion. |
| 371 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); |
| 372 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); |
| 373 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); |
| 369 | 374 |
| 370 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); | 375 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); |
| 371 | 376 |
| 372 // Empty profiles are ignored. | 377 // Empty profiles are ignored. |
| 373 AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin); | 378 AutofillProfile empty_profile(base::GenerateGUID(), kSettingsOrigin); |
| 374 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); | 379 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
| 375 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); | 380 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); |
| 376 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 381 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 377 EXPECT_EQ(3, shipping_model->GetItemCount()); | 382 EXPECT_EQ(3, shipping_model->GetItemCount()); |
| 383 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); |
| 378 | 384 |
| 379 // A full profile should be picked up. | 385 // A full profile should be picked up. |
| 380 AutofillProfile full_profile(test::GetFullProfile()); | 386 AutofillProfile full_profile(test::GetFullProfile()); |
| 381 full_profile.set_origin(kSettingsOrigin); | 387 full_profile.set_origin(kSettingsOrigin); |
| 382 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); | 388 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); |
| 383 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 389 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 384 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 390 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 385 EXPECT_EQ(4, shipping_model->GetItemCount()); | 391 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 392 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL)); |
| 386 } | 393 } |
| 387 | 394 |
| 388 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { | 395 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { |
| 389 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 396 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 390 ui::MenuModel* email_model = | 397 ui::MenuModel* email_model = |
| 391 controller()->MenuModelForSection(SECTION_EMAIL); | 398 controller()->MenuModelForSection(SECTION_EMAIL); |
| 392 EXPECT_EQ(2, email_model->GetItemCount()); | 399 EXPECT_FALSE(email_model); |
| 393 | 400 |
| 394 // Set up some variant data. | 401 // Set up some variant data. |
| 395 AutofillProfile full_profile(test::GetFullProfile()); | 402 AutofillProfile full_profile(test::GetFullProfile()); |
| 396 std::vector<string16> names; | 403 std::vector<string16> names; |
| 397 names.push_back(ASCIIToUTF16("John Doe")); | 404 names.push_back(ASCIIToUTF16("John Doe")); |
| 398 names.push_back(ASCIIToUTF16("Jane Doe")); | 405 names.push_back(ASCIIToUTF16("Jane Doe")); |
| 399 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); | 406 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); |
| 400 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); | 407 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); |
| 401 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); | 408 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); |
| 402 std::vector<string16> emails; | 409 std::vector<string16> emails; |
| 403 emails.push_back(kEmail1); | 410 emails.push_back(kEmail1); |
| 404 emails.push_back(kEmail2); | 411 emails.push_back(kEmail2); |
| 405 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); | 412 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); |
| 406 | 413 |
| 407 // Respect variants for the email address field only. | 414 // Respect variants for the email address field only. |
| 408 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 415 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 409 ui::MenuModel* shipping_model = | 416 ui::MenuModel* shipping_model = |
| 410 controller()->MenuModelForSection(SECTION_SHIPPING); | 417 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 411 EXPECT_EQ(4, shipping_model->GetItemCount()); | 418 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 412 email_model = controller()->MenuModelForSection(SECTION_EMAIL); | 419 email_model = controller()->MenuModelForSection(SECTION_EMAIL); |
| 420 ASSERT_TRUE(!!email_model); |
| 413 EXPECT_EQ(4, email_model->GetItemCount()); | 421 EXPECT_EQ(4, email_model->GetItemCount()); |
| 414 | 422 |
| 415 email_model->ActivatedAt(0); | 423 email_model->ActivatedAt(0); |
| 416 EXPECT_EQ(kEmail1, | 424 EXPECT_EQ(kEmail1, |
| 417 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 425 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
| 418 email_model->ActivatedAt(1); | 426 email_model->ActivatedAt(1); |
| 419 EXPECT_EQ(kEmail2, | 427 EXPECT_EQ(kEmail2, |
| 420 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 428 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
| 421 | 429 |
| 422 controller()->EditClickedForSection(SECTION_EMAIL); | 430 controller()->EditClickedForSection(SECTION_EMAIL); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 632 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
| 625 | 633 |
| 626 EXPECT_FALSE( | 634 EXPECT_FALSE( |
| 627 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); | 635 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
| 628 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); | 636 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); |
| 629 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 637 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
| 630 | 638 |
| 631 suggestion_state = | 639 suggestion_state = |
| 632 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 640 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
| 633 EXPECT_FALSE(suggestion_state.extra_text.empty()); | 641 EXPECT_FALSE(suggestion_state.extra_text.empty()); |
| 634 EXPECT_EQ( | 642 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
| 635 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); | |
| 636 | 643 |
| 637 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 644 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 638 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 645 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
| 639 | 646 |
| 640 controller()->OnAccept(); | 647 controller()->OnAccept(); |
| 641 } | 648 } |
| 642 | 649 |
| 643 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { | 650 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { |
| 644 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 651 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 645 GetFullWallet(_)).Times(1); | 652 GetFullWallet(_)).Times(1); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 916 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 910 | 917 |
| 911 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 918 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
| 912 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 919 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
| 913 | 920 |
| 914 profile()->set_incognito(true); | 921 profile()->set_incognito(true); |
| 915 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 922 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 916 } | 923 } |
| 917 | 924 |
| 918 } // namespace autofill | 925 } // namespace autofill |
| OLD | NEW |