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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ServerFieldType type, | 128 ServerFieldType type, |
129 const string16& value) OVERRIDE { | 129 const string16& value) OVERRIDE { |
130 if (!use_validation_) | 130 if (!use_validation_) |
131 return string16(); | 131 return string16(); |
132 return AutofillDialogControllerImpl::InputValidityMessage( | 132 return AutofillDialogControllerImpl::InputValidityMessage( |
133 section, type, value); | 133 section, type, value); |
134 } | 134 } |
135 | 135 |
136 virtual ValidityMessages InputsAreValid( | 136 virtual ValidityMessages InputsAreValid( |
137 DialogSection section, | 137 DialogSection section, |
138 const DetailOutputMap& inputs) OVERRIDE { | 138 const FieldValueMap& inputs) OVERRIDE { |
139 if (!use_validation_) | 139 if (!use_validation_) |
140 return ValidityMessages(); | 140 return ValidityMessages(); |
141 return AutofillDialogControllerImpl::InputsAreValid(section, inputs); | 141 return AutofillDialogControllerImpl::InputsAreValid(section, inputs); |
142 } | 142 } |
143 | 143 |
144 // Saving to Chrome is tested in AutofillDialogControllerImpl unit tests. | 144 // Saving to Chrome is tested in AutofillDialogControllerImpl unit tests. |
145 // TODO(estade): test that the view defaults to saving to Chrome. | 145 // TODO(estade): test that the view defaults to saving to Chrome. |
146 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE { | 146 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE { |
147 return false; | 147 return false; |
148 } | 148 } |
(...skipping 14 matching lines...) Expand all Loading... |
163 | 163 |
164 void set_notifications(const std::vector<DialogNotification>& notifications) { | 164 void set_notifications(const std::vector<DialogNotification>& notifications) { |
165 notifications_ = notifications; | 165 notifications_ = notifications; |
166 } | 166 } |
167 | 167 |
168 TestPersonalDataManager* GetTestingManager() { | 168 TestPersonalDataManager* GetTestingManager() { |
169 return &test_manager_; | 169 return &test_manager_; |
170 } | 170 } |
171 | 171 |
172 using AutofillDialogControllerImpl::IsEditingExistingData; | 172 using AutofillDialogControllerImpl::IsEditingExistingData; |
173 using AutofillDialogControllerImpl::IsManuallyEditingSection; | 173 using AutofillDialogControllerImpl::IsPayingWithWallet; |
174 using AutofillDialogControllerImpl::IsSubmitPausedOn; | 174 using AutofillDialogControllerImpl::IsSubmitPausedOn; |
175 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 175 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
176 using AutofillDialogControllerImpl::AccountChooserModelForTesting; | 176 using AutofillDialogControllerImpl::AccountChooserModelForTesting; |
177 | 177 |
178 void set_use_validation(bool use_validation) { | 178 void set_use_validation(bool use_validation) { |
179 use_validation_ = use_validation; | 179 use_validation_ = use_validation; |
180 } | 180 } |
181 | 181 |
182 base::WeakPtr<TestAutofillDialogController> AsWeakPtr() { | 182 base::WeakPtr<TestAutofillDialogController> AsWeakPtr() { |
183 return weak_ptr_factory_.GetWeakPtr(); | 183 return weak_ptr_factory_.GetWeakPtr(); |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 | 889 |
890 // Flaky on Win7, WinXP, and Win Aura. http://crbug.com/270314. | 890 // Flaky on Win7, WinXP, and Win Aura. http://crbug.com/270314. |
891 #if defined(OS_WIN) | 891 #if defined(OS_WIN) |
892 #define MAYBE_PreservedSections DISABLED_PreservedSections | 892 #define MAYBE_PreservedSections DISABLED_PreservedSections |
893 #else | 893 #else |
894 #define MAYBE_PreservedSections PreservedSections | 894 #define MAYBE_PreservedSections PreservedSections |
895 #endif | 895 #endif |
896 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { | 896 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { |
897 controller()->set_use_validation(true); | 897 controller()->set_use_validation(true); |
898 | 898 |
899 // Set up some Autofill state. | 899 TestableAutofillDialogView* view = controller()->GetTestableView(); |
900 CreditCard credit_card(test::GetVerifiedCreditCard()); | |
901 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | |
902 | 900 |
903 AutofillProfile profile(test::GetVerifiedProfile()); | 901 { |
904 controller()->GetTestingManager()->AddTestingProfile(&profile); | 902 // Create some valid inputted billing data. |
905 | 903 const DetailInput& cc_number = |
906 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC)); | 904 controller()->RequestedFieldsForSection(SECTION_CC)[0]; |
907 EXPECT_TRUE(controller()->SectionIsActive(SECTION_BILLING)); | 905 DCHECK_EQ(cc_number.type, CREDIT_CARD_NUMBER); |
908 EXPECT_FALSE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 906 view->SetTextContentsOfInput(cc_number, ASCIIToUTF16("4111111111111111")); |
909 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); | 907 } |
910 | |
911 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC)); | |
912 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | |
913 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
914 | |
915 // Set up some Wallet state. | |
916 controller()->OnDidFetchWalletCookieValue(std::string()); | |
917 controller()->OnDidGetWalletItems( | |
918 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | |
919 | |
920 ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser(); | |
921 ASSERT_TRUE(account_chooser->IsItemCheckedAt(0)); | |
922 | |
923 // Check that the view's in the state we expect before starting to simulate | |
924 // user input. | |
925 EXPECT_FALSE(controller()->SectionIsActive(SECTION_CC)); | |
926 EXPECT_FALSE(controller()->SectionIsActive(SECTION_BILLING)); | |
927 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | |
928 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); | |
929 | |
930 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC_BILLING)); | |
931 | |
932 // Create some valid inputted billing data. | |
933 const DetailInput& cc_number = | |
934 controller()->RequestedFieldsForSection(SECTION_CC_BILLING)[0]; | |
935 EXPECT_EQ(CREDIT_CARD_NUMBER, cc_number.type); | |
936 TestableAutofillDialogView* view = controller()->GetTestableView(); | |
937 view->SetTextContentsOfInput(cc_number, ASCIIToUTF16("4111111111111111")); | |
938 | |
939 // Select "Add new shipping info..." from suggestions menu. | |
940 ui::MenuModel* shipping_model = | |
941 controller()->MenuModelForSection(SECTION_SHIPPING); | |
942 shipping_model->ActivatedAt(shipping_model->GetItemCount() - 2); | |
943 | |
944 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
945 | 908 |
946 // Create some invalid, manually inputted shipping data. | 909 // Create some invalid, manually inputted shipping data. |
947 const DetailInput& shipping_zip = | 910 const DetailInput& shipping_zip = |
948 controller()->RequestedFieldsForSection(SECTION_SHIPPING)[5]; | 911 controller()->RequestedFieldsForSection(SECTION_SHIPPING)[5]; |
949 ASSERT_EQ(ADDRESS_HOME_ZIP, shipping_zip.type); | 912 ASSERT_EQ(ADDRESS_HOME_ZIP, shipping_zip.type); |
950 view->SetTextContentsOfInput(shipping_zip, ASCIIToUTF16("shipping zip")); | 913 view->SetTextContentsOfInput(shipping_zip, ASCIIToUTF16("shipping zip")); |
951 | 914 |
952 // Switch to using Autofill. | 915 // Switch to Wallet by simulating a successful server response. |
| 916 controller()->OnDidFetchWalletCookieValue(std::string()); |
| 917 controller()->OnDidGetWalletItems( |
| 918 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
| 919 ASSERT_TRUE(controller()->IsPayingWithWallet()); |
| 920 |
| 921 { |
| 922 // The valid data should be preserved. |
| 923 const DetailInput& cc_number = |
| 924 controller()->RequestedFieldsForSection(SECTION_CC_BILLING)[0]; |
| 925 EXPECT_EQ(cc_number.type, CREDIT_CARD_NUMBER); |
| 926 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), |
| 927 view->GetTextContentsOfInput(cc_number)); |
| 928 } |
| 929 |
| 930 // The invalid data should be dropped. |
| 931 EXPECT_TRUE(view->GetTextContentsOfInput(shipping_zip).empty()); |
| 932 |
| 933 // Switch back to Autofill. |
| 934 ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser(); |
953 account_chooser->ActivatedAt(account_chooser->GetItemCount() - 1); | 935 account_chooser->ActivatedAt(account_chooser->GetItemCount() - 1); |
| 936 ASSERT_FALSE(controller()->IsPayingWithWallet()); |
954 | 937 |
955 // Check that appropriate sections are preserved and in manually editing mode | 938 { |
956 // (or disabled, in the case of the combined cc + billing section). | 939 // The valid data should still be preserved when switched back. |
957 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC)); | 940 const DetailInput& cc_number = |
958 EXPECT_TRUE(controller()->SectionIsActive(SECTION_BILLING)); | 941 controller()->RequestedFieldsForSection(SECTION_CC)[0]; |
959 EXPECT_FALSE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 942 EXPECT_EQ(cc_number.type, CREDIT_CARD_NUMBER); |
960 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); | 943 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), |
961 | 944 view->GetTextContentsOfInput(cc_number)); |
962 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC)); | 945 } |
963 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING)); | |
964 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
965 | |
966 const DetailInput& new_cc_number = | |
967 controller()->RequestedFieldsForSection(SECTION_CC).front(); | |
968 EXPECT_EQ(cc_number.type, new_cc_number.type); | |
969 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), | |
970 view->GetTextContentsOfInput(new_cc_number)); | |
971 | |
972 EXPECT_NE(ASCIIToUTF16("shipping name"), | |
973 view->GetTextContentsOfInput(shipping_zip)); | |
974 } | 946 } |
975 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 947 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
976 | 948 |
977 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 949 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
978 GeneratedCardLastFourAfterVerifyCvv) { | 950 GeneratedCardLastFourAfterVerifyCvv) { |
979 controller()->OnDidFetchWalletCookieValue(std::string()); | 951 controller()->OnDidFetchWalletCookieValue(std::string()); |
980 | 952 |
981 scoped_ptr<wallet::WalletItems> wallet_items = | 953 scoped_ptr<wallet::WalletItems> wallet_items = |
982 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 954 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
983 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 955 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2); | 1219 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2); |
1248 // Tabs should now be: / rAc() \/ manage 2 \/ manage 1 \/ blank \. | 1220 // Tabs should now be: / rAc() \/ manage 2 \/ manage 1 \/ blank \. |
1249 EXPECT_EQ(4, tab_strip->count()); | 1221 EXPECT_EQ(4, tab_strip->count()); |
1250 EXPECT_EQ(0, tab_strip->GetIndexOfWebContents(dialog_invoker)); | 1222 EXPECT_EQ(0, tab_strip->GetIndexOfWebContents(dialog_invoker)); |
1251 EXPECT_EQ(1, tab_strip->active_index()); | 1223 EXPECT_EQ(1, tab_strip->active_index()); |
1252 EXPECT_EQ(2, tab_strip->GetIndexOfWebContents(first_manage_tab)); | 1224 EXPECT_EQ(2, tab_strip->GetIndexOfWebContents(first_manage_tab)); |
1253 EXPECT_EQ(3, tab_strip->GetIndexOfWebContents(blank_tab)); | 1225 EXPECT_EQ(3, tab_strip->GetIndexOfWebContents(blank_tab)); |
1254 } | 1226 } |
1255 | 1227 |
1256 } // namespace autofill | 1228 } // namespace autofill |
OLD | NEW |