| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { | 360 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { |
| 361 ui::MenuModel* shipping_model = | 361 ui::MenuModel* shipping_model = |
| 362 controller()->MenuModelForSection(SECTION_SHIPPING); | 362 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 363 // Since the PersonalDataManager is empty, this should only have the | 363 // Since the PersonalDataManager is empty, this should only have the |
| 364 // "use billing", "add new" and "manage" menu items. | 364 // "use billing", "add new" and "manage" menu items. |
| 365 EXPECT_EQ(3, shipping_model->GetItemCount()); | 365 EXPECT_EQ(3, shipping_model->GetItemCount()); |
| 366 // On the other hand, the other models should be NULL when there's no |
| 367 // suggestion. |
| 368 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); |
| 369 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); |
| 370 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); |
| 366 | 371 |
| 367 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); | 372 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); |
| 368 | 373 |
| 369 // Empty profiles are ignored. | 374 // Empty profiles are ignored. |
| 370 AutofillProfile empty_profile(base::GenerateGUID()); | 375 AutofillProfile empty_profile(base::GenerateGUID()); |
| 371 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); | 376 empty_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
| 372 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); | 377 controller()->GetTestingManager()->AddTestingProfile(&empty_profile); |
| 373 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 378 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 374 EXPECT_EQ(3, shipping_model->GetItemCount()); | 379 EXPECT_EQ(3, shipping_model->GetItemCount()); |
| 380 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_EMAIL)); |
| 375 | 381 |
| 376 // A full profile should be picked up. | 382 // A full profile should be picked up. |
| 377 AutofillProfile full_profile(test::GetFullProfile()); | 383 AutofillProfile full_profile(test::GetFullProfile()); |
| 378 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); | 384 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); |
| 379 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 385 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 380 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); | 386 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 381 EXPECT_EQ(4, shipping_model->GetItemCount()); | 387 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 388 EXPECT_TRUE(!!controller()->MenuModelForSection(SECTION_EMAIL)); |
| 382 } | 389 } |
| 383 | 390 |
| 384 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { | 391 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { |
| 385 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 392 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 386 ui::MenuModel* email_model = | 393 ui::MenuModel* email_model = |
| 387 controller()->MenuModelForSection(SECTION_EMAIL); | 394 controller()->MenuModelForSection(SECTION_EMAIL); |
| 388 EXPECT_EQ(2, email_model->GetItemCount()); | 395 EXPECT_FALSE(email_model); |
| 389 | 396 |
| 390 // Set up some variant data. | 397 // Set up some variant data. |
| 391 AutofillProfile full_profile(test::GetFullProfile()); | 398 AutofillProfile full_profile(test::GetFullProfile()); |
| 392 std::vector<string16> names; | 399 std::vector<string16> names; |
| 393 names.push_back(ASCIIToUTF16("John Doe")); | 400 names.push_back(ASCIIToUTF16("John Doe")); |
| 394 names.push_back(ASCIIToUTF16("Jane Doe")); | 401 names.push_back(ASCIIToUTF16("Jane Doe")); |
| 395 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); | 402 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, names); |
| 396 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); | 403 const string16 kEmail1 = ASCIIToUTF16(kFakeEmail); |
| 397 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); | 404 const string16 kEmail2 = ASCIIToUTF16("admin@example.com"); |
| 398 std::vector<string16> emails; | 405 std::vector<string16> emails; |
| 399 emails.push_back(kEmail1); | 406 emails.push_back(kEmail1); |
| 400 emails.push_back(kEmail2); | 407 emails.push_back(kEmail2); |
| 401 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); | 408 full_profile.SetRawMultiInfo(EMAIL_ADDRESS, emails); |
| 402 | 409 |
| 403 // Respect variants for the email address field only. | 410 // Respect variants for the email address field only. |
| 404 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 411 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 405 ui::MenuModel* shipping_model = | 412 ui::MenuModel* shipping_model = |
| 406 controller()->MenuModelForSection(SECTION_SHIPPING); | 413 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 407 EXPECT_EQ(4, shipping_model->GetItemCount()); | 414 EXPECT_EQ(4, shipping_model->GetItemCount()); |
| 408 email_model = controller()->MenuModelForSection(SECTION_EMAIL); | 415 email_model = controller()->MenuModelForSection(SECTION_EMAIL); |
| 416 ASSERT_TRUE(!!email_model); |
| 409 EXPECT_EQ(4, email_model->GetItemCount()); | 417 EXPECT_EQ(4, email_model->GetItemCount()); |
| 410 | 418 |
| 411 email_model->ActivatedAt(0); | 419 email_model->ActivatedAt(0); |
| 412 EXPECT_EQ(kEmail1, | 420 EXPECT_EQ(kEmail1, |
| 413 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 421 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
| 414 email_model->ActivatedAt(1); | 422 email_model->ActivatedAt(1); |
| 415 EXPECT_EQ(kEmail2, | 423 EXPECT_EQ(kEmail2, |
| 416 controller()->SuggestionStateForSection(SECTION_EMAIL).text); | 424 controller()->SuggestionStateForSection(SECTION_EMAIL).text); |
| 417 | 425 |
| 418 controller()->EditClickedForSection(SECTION_EMAIL); | 426 controller()->EditClickedForSection(SECTION_EMAIL); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 638 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
| 631 | 639 |
| 632 EXPECT_FALSE( | 640 EXPECT_FALSE( |
| 633 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); | 641 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
| 634 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); | 642 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); |
| 635 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 643 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
| 636 | 644 |
| 637 suggestion_state = | 645 suggestion_state = |
| 638 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 646 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
| 639 EXPECT_FALSE(suggestion_state.extra_text.empty()); | 647 EXPECT_FALSE(suggestion_state.extra_text.empty()); |
| 640 EXPECT_EQ( | 648 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
| 641 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); | |
| 642 | 649 |
| 643 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 650 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 644 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 651 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
| 645 | 652 |
| 646 controller()->OnAccept(); | 653 controller()->OnAccept(); |
| 647 } | 654 } |
| 648 | 655 |
| 649 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { | 656 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { |
| 650 SetUpWallet(); | 657 SetUpWallet(); |
| 651 | 658 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 952 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 946 | 953 |
| 947 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 954 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
| 948 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 955 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
| 949 | 956 |
| 950 profile()->set_incognito(true); | 957 profile()->set_incognito(true); |
| 951 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 958 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 952 } | 959 } |
| 953 | 960 |
| 954 } // namespace autofill | 961 } // namespace autofill |
| OLD | NEW |