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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { | 301 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
302 FormFieldData field; | 302 FormFieldData field; |
303 field.autocomplete_attribute = kFieldsFromPage[i]; | 303 field.autocomplete_attribute = kFieldsFromPage[i]; |
304 form_data.fields.push_back(field); | 304 form_data.fields.push_back(field); |
305 } | 305 } |
306 | 306 |
307 profile()->CreateRequestContext(); | 307 profile()->CreateRequestContext(); |
308 test_web_contents_.reset( | 308 test_web_contents_.reset( |
309 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 309 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
310 | 310 |
| 311 SetUpControllerWithFormData(form_data); |
| 312 } |
| 313 |
| 314 virtual void TearDown() OVERRIDE { |
| 315 if (controller_) |
| 316 controller_->ViewClosed(); |
| 317 } |
| 318 |
| 319 protected: |
| 320 void SetUpControllerWithFormData(const FormData& form_data) { |
| 321 if (controller_) |
| 322 controller_->ViewClosed(); |
| 323 |
311 base::Callback<void(const FormStructure*, const std::string&)> callback = | 324 base::Callback<void(const FormStructure*, const std::string&)> callback = |
312 base::Bind(&AutofillDialogControllerTest::FinishedCallback, | 325 base::Bind(&AutofillDialogControllerTest::FinishedCallback, |
313 base::Unretained(this)); | 326 base::Unretained(this)); |
314 controller_ = (new testing::NiceMock<TestAutofillDialogController>( | 327 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
315 test_web_contents_.get(), | 328 test_web_contents_.get(), |
316 form_data, | 329 form_data, |
317 GURL(), | 330 GURL(), |
318 metric_logger_, | 331 metric_logger_, |
319 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, | 332 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, |
320 callback))->AsWeakPtr(); | 333 callback))->AsWeakPtr(); |
321 controller_->Init(profile()); | 334 controller_->Init(profile()); |
322 controller_->Show(); | 335 controller_->Show(); |
323 controller_->OnUserNameFetchSuccess(kFakeEmail); | 336 controller_->OnUserNameFetchSuccess(kFakeEmail); |
324 } | 337 } |
325 | 338 |
326 virtual void TearDown() OVERRIDE { | |
327 if (controller_) | |
328 controller_->ViewClosed(); | |
329 } | |
330 | |
331 protected: | |
332 void FillCreditCardInputs() { | 339 void FillCreditCardInputs() { |
333 DetailOutputMap cc_outputs; | 340 DetailOutputMap cc_outputs; |
334 const DetailInputs& cc_inputs = | 341 const DetailInputs& cc_inputs = |
335 controller()->RequestedFieldsForSection(SECTION_CC); | 342 controller()->RequestedFieldsForSection(SECTION_CC); |
336 for (size_t i = 0; i < cc_inputs.size(); ++i) { | 343 for (size_t i = 0; i < cc_inputs.size(); ++i) { |
337 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); | 344 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); |
338 } | 345 } |
339 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); | 346 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); |
340 } | 347 } |
341 | 348 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 UseBillingForShipping(); | 720 UseBillingForShipping(); |
714 | 721 |
715 controller()->OnAccept(); | 722 controller()->OnAccept(); |
716 ASSERT_EQ(4U, form_structure()->field_count()); | 723 ASSERT_EQ(4U, form_structure()->field_count()); |
717 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(2)->value)); | 724 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(2)->value)); |
718 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); | 725 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); |
719 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); | 726 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); |
720 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); | 727 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); |
721 } | 728 } |
722 | 729 |
| 730 // Tests that shipping and billing telephone fields are supported, and filled |
| 731 // in by their respective profiles. http://crbug.com/244515 |
| 732 TEST_F(AutofillDialogControllerTest, DISABLED_BillingVsShippingPhoneNumber) { |
| 733 FormFieldData shipping_tel; |
| 734 shipping_tel.autocomplete_attribute = "shipping tel"; |
| 735 FormFieldData billing_tel; |
| 736 billing_tel.autocomplete_attribute = "billing tel"; |
| 737 |
| 738 FormData form_data; |
| 739 form_data.fields.push_back(shipping_tel); |
| 740 form_data.fields.push_back(billing_tel); |
| 741 SetUpControllerWithFormData(form_data); |
| 742 |
| 743 // The profile that will be chosen for the shipping section. |
| 744 AutofillProfile shipping_profile(test::GetVerifiedProfile()); |
| 745 // The profile that will be chosen for the billing section. |
| 746 AutofillProfile billing_profile(test::GetVerifiedProfile2()); |
| 747 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 748 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); |
| 749 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); |
| 750 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 751 ui::MenuModel* billing_model = |
| 752 controller()->MenuModelForSection(SECTION_BILLING); |
| 753 billing_model->ActivatedAt(1); |
| 754 |
| 755 controller()->OnAccept(); |
| 756 ASSERT_EQ(2U, form_structure()->field_count()); |
| 757 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, form_structure()->field(0)->type()); |
| 758 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, form_structure()->field(1)->type()); |
| 759 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), |
| 760 form_structure()->field(0)->value); |
| 761 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), |
| 762 form_structure()->field(1)->value); |
| 763 EXPECT_NE(form_structure()->field(1)->value, |
| 764 form_structure()->field(0)->value); |
| 765 } |
| 766 |
723 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { | 767 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { |
724 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 768 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
725 AcceptLegalDocuments(_, _, _)).Times(1); | 769 AcceptLegalDocuments(_, _, _)).Times(1); |
726 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 770 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
727 GetFullWallet(_)).Times(1); | 771 GetFullWallet(_)).Times(1); |
728 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); | 772 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
729 | 773 |
730 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 774 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
731 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 775 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
732 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 776 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 controller()->OnDidGetWalletItems( | 1723 controller()->OnDidGetWalletItems( |
1680 wallet::WalletItems::CreateWalletItems(dict).Pass()); | 1724 wallet::WalletItems::CreateWalletItems(dict).Pass()); |
1681 | 1725 |
1682 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 1726 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
1683 // "Same as billing" and "Add address...". | 1727 // "Same as billing" and "Add address...". |
1684 EXPECT_EQ( | 1728 EXPECT_EQ( |
1685 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 1729 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
1686 } | 1730 } |
1687 | 1731 |
1688 } // namespace autofill | 1732 } // namespace autofill |
OLD | NEW |