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" |
11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "components/autofill/browser/autofill_common_test.h" | 14 #include "components/autofill/browser/autofill_common_test.h" |
15 #include "components/autofill/browser/autofill_metrics.h" | 15 #include "components/autofill/browser/autofill_metrics.h" |
| 16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" |
16 #include "components/autofill/browser/test_personal_data_manager.h" | 17 #include "components/autofill/browser/test_personal_data_manager.h" |
17 #include "components/autofill/browser/wallet/full_wallet.h" | 18 #include "components/autofill/browser/wallet/full_wallet.h" |
18 #include "components/autofill/browser/wallet/instrument.h" | 19 #include "components/autofill/browser/wallet/instrument.h" |
19 #include "components/autofill/browser/wallet/wallet_address.h" | 20 #include "components/autofill/browser/wallet/wallet_address.h" |
20 #include "components/autofill/browser/wallet/wallet_client.h" | 21 #include "components/autofill/browser/wallet/wallet_client.h" |
21 #include "components/autofill/browser/wallet/wallet_test_util.h" | 22 #include "components/autofill/browser/wallet/wallet_test_util.h" |
22 #include "components/autofill/common/form_data.h" | 23 #include "components/autofill/common/form_data.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
25 #include "content/public/test/web_contents_tester.h" | 26 #include "content/public/test/web_contents_tester.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
30 #include "ui/base/win/scoped_ole_initializer.h" | 31 #include "ui/base/win/scoped_ole_initializer.h" |
31 #endif | 32 #endif |
32 | 33 |
33 using testing::_; | 34 using testing::_; |
34 | 35 |
35 namespace autofill { | 36 namespace autofill { |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 const char kFakeEmail[] = "user@example.com"; | 40 const char kFakeEmail[] = "user@example.com"; |
| 41 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; |
40 const char kEditedBillingAddress[] = "123 edited billing address"; | 42 const char kEditedBillingAddress[] = "123 edited billing address"; |
41 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region", | 43 const char* kFieldsFromPage[] = |
42 "shipping region" }; | 44 { "email", "cc-number", "billing region", "shipping region" }; |
43 const char kSettingsOrigin[] = "Chrome settings"; | 45 const char kSettingsOrigin[] = "Chrome settings"; |
44 | 46 |
45 using content::BrowserThread; | 47 using content::BrowserThread; |
46 | 48 |
47 void SetOutputValue(const DetailInputs& inputs, | 49 void SetOutputValue(const DetailInputs& inputs, |
48 DetailOutputMap* outputs, | 50 DetailOutputMap* outputs, |
49 AutofillFieldType type, | 51 AutofillFieldType type, |
50 const std::string& value) { | 52 const std::string& value) { |
51 for (size_t i = 0; i < inputs.size(); ++i) { | 53 for (size_t i = 0; i < inputs.size(); ++i) { |
52 const DetailInput& input = inputs[i]; | 54 const DetailInput& input = inputs[i]; |
53 (*outputs)[&input] = input.type == type ? | 55 (*outputs)[&input] = input.type == type ? |
54 ASCIIToUTF16(value) : | 56 ASCIIToUTF16(value) : |
55 input.initial_value; | 57 input.initial_value; |
56 } | 58 } |
57 } | 59 } |
58 | 60 |
| 61 scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { |
| 62 base::DictionaryValue dict; |
| 63 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 64 list->AppendString("verify_cvv"); |
| 65 dict.Set("required_action", list.release()); |
| 66 return wallet::FullWallet::CreateFullWallet(dict); |
| 67 } |
| 68 |
| 69 scoped_ptr<risk::Fingerprint> GetFakeFingerprint() { |
| 70 scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint()); |
| 71 // Add some data to the proto, else the encoded content is empty. |
| 72 fingerprint->mutable_machine_characteristics()->mutable_screen_size()-> |
| 73 set_width(1024); |
| 74 return fingerprint.Pass(); |
| 75 } |
| 76 |
59 class TestAutofillDialogView : public AutofillDialogView { | 77 class TestAutofillDialogView : public AutofillDialogView { |
60 public: | 78 public: |
61 TestAutofillDialogView() {} | 79 TestAutofillDialogView() {} |
62 virtual ~TestAutofillDialogView() {} | 80 virtual ~TestAutofillDialogView() {} |
63 | 81 |
64 virtual void Show() OVERRIDE {} | 82 virtual void Show() OVERRIDE {} |
65 virtual void Hide() OVERRIDE {} | 83 virtual void Hide() OVERRIDE {} |
66 virtual void UpdateNotificationArea() OVERRIDE {} | 84 virtual void UpdateNotificationArea() OVERRIDE {} |
67 virtual void UpdateAccountChooser() OVERRIDE {} | 85 virtual void UpdateAccountChooser() OVERRIDE {} |
68 virtual void UpdateButtonStrip() OVERRIDE {} | 86 virtual void UpdateButtonStrip() OVERRIDE {} |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } | 233 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } |
216 | 234 |
217 const GURL& open_tab_url() { return open_tab_url_; } | 235 const GURL& open_tab_url() { return open_tab_url_; } |
218 | 236 |
219 virtual DialogType GetDialogType() const OVERRIDE { | 237 virtual DialogType GetDialogType() const OVERRIDE { |
220 return dialog_type_; | 238 return dialog_type_; |
221 } | 239 } |
222 | 240 |
223 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } | 241 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } |
224 | 242 |
| 243 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| 244 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 245 |
225 protected: | 246 protected: |
226 virtual PersonalDataManager* GetManager() OVERRIDE { | 247 virtual PersonalDataManager* GetManager() OVERRIDE { |
227 return &test_manager_; | 248 return &test_manager_; |
228 } | 249 } |
229 | 250 |
230 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 251 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
231 return &test_wallet_client_; | 252 return &test_wallet_client_; |
232 } | 253 } |
233 | 254 |
234 virtual bool IsFirstRun() const OVERRIDE { | 255 virtual bool IsFirstRun() const OVERRIDE { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 form_data.fields.push_back(field); | 299 form_data.fields.push_back(field); |
279 } | 300 } |
280 | 301 |
281 profile()->CreateRequestContext(); | 302 profile()->CreateRequestContext(); |
282 test_web_contents_.reset( | 303 test_web_contents_.reset( |
283 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 304 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
284 | 305 |
285 base::Callback<void(const FormStructure*, const std::string&)> callback = | 306 base::Callback<void(const FormStructure*, const std::string&)> callback = |
286 base::Bind(&AutofillDialogControllerTest::FinishedCallback, | 307 base::Bind(&AutofillDialogControllerTest::FinishedCallback, |
287 base::Unretained(this)); | 308 base::Unretained(this)); |
288 controller_ = (new TestAutofillDialogController( | 309 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
289 test_web_contents_.get(), | 310 test_web_contents_.get(), |
290 form_data, | 311 form_data, |
291 GURL(), | 312 GURL(), |
292 metric_logger_, | 313 metric_logger_, |
293 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, | 314 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, |
294 callback))->AsWeakPtr(); | 315 callback))->AsWeakPtr(); |
295 controller_->Init(profile()); | 316 controller_->Init(profile()); |
296 controller_->Show(); | 317 controller_->Show(); |
297 controller_->OnUserNameFetchSuccess(kFakeEmail); | 318 controller_->OnUserNameFetchSuccess(kFakeEmail); |
298 } | 319 } |
299 | 320 |
300 virtual void TearDown() OVERRIDE { | 321 virtual void TearDown() OVERRIDE { |
301 if (controller_) | 322 if (controller_) |
302 controller_->ViewClosed(); | 323 controller_->ViewClosed(); |
303 } | 324 } |
304 | 325 |
305 protected: | 326 protected: |
306 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { | |
307 base::DictionaryValue dict; | |
308 scoped_ptr<base::ListValue> list(new base::ListValue()); | |
309 list->AppendString("verify_cvv"); | |
310 dict.Set("required_action", list.release()); | |
311 return wallet::FullWallet::CreateFullWallet(dict); | |
312 } | |
313 | |
314 void FillCreditCardInputs() { | 327 void FillCreditCardInputs() { |
315 DetailOutputMap cc_outputs; | 328 DetailOutputMap cc_outputs; |
316 const DetailInputs& cc_inputs = | 329 const DetailInputs& cc_inputs = |
317 controller()->RequestedFieldsForSection(SECTION_CC); | 330 controller()->RequestedFieldsForSection(SECTION_CC); |
318 for (size_t i = 0; i < cc_inputs.size(); ++i) { | 331 for (size_t i = 0; i < cc_inputs.size(); ++i) { |
319 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); | 332 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); |
320 } | 333 } |
321 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); | 334 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); |
322 } | 335 } |
323 | 336 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); | 649 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); |
637 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); | 650 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); |
638 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); | 651 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); |
639 } | 652 } |
640 | 653 |
641 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { | 654 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { |
642 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 655 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
643 AcceptLegalDocuments(_, _, _)).Times(1); | 656 AcceptLegalDocuments(_, _, _)).Times(1); |
644 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 657 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
645 GetFullWallet(_)).Times(1); | 658 GetFullWallet(_)).Times(1); |
| 659 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
646 | 660 |
647 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 661 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
648 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 662 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
649 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 663 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
650 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 664 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
651 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 665 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
652 controller()->OnAccept(); | 666 controller()->OnAccept(); |
| 667 controller()->OnDidAcceptLegalDocuments(); |
| 668 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
653 } | 669 } |
654 | 670 |
655 // Makes sure the default object IDs are respected. | 671 // Makes sure the default object IDs are respected. |
656 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { | 672 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { |
657 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 673 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
658 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 674 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
659 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 675 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
660 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 676 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
661 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 677 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
662 | 678 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1045 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1030 GetFullWallet(_)).Times(1); | 1046 GetFullWallet(_)).Times(1); |
1031 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1047 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1032 AuthenticateInstrument(_, _, _)).Times(1); | 1048 AuthenticateInstrument(_, _, _)).Times(1); |
1033 | 1049 |
1034 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1050 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1035 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1051 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1036 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1052 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1037 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1053 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1038 controller()->OnAccept(); | 1054 controller()->OnAccept(); |
| 1055 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
1039 | 1056 |
1040 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); | 1057 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
1041 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); | 1058 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); |
1042 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 1059 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
1043 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1060 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1044 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1061 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1045 | 1062 |
1046 SuggestionState suggestion_state = | 1063 SuggestionState suggestion_state = |
1047 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 1064 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
1048 EXPECT_TRUE(suggestion_state.extra_text.empty()); | 1065 EXPECT_TRUE(suggestion_state.extra_text.empty()); |
(...skipping 18 matching lines...) Expand all Loading... |
1067 | 1084 |
1068 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { | 1085 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { |
1069 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1086 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1070 GetFullWallet(_)).Times(1); | 1087 GetFullWallet(_)).Times(1); |
1071 | 1088 |
1072 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1089 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1073 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1090 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1074 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1091 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1075 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1092 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1076 controller()->OnAccept(); | 1093 controller()->OnAccept(); |
| 1094 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
1077 | 1095 |
1078 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1096 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1079 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1097 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1080 | 1098 |
1081 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); | 1099 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
1082 | 1100 |
1083 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1101 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1084 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1102 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1085 } | 1103 } |
1086 | 1104 |
1087 // TODO(dbeam): disallow changing accounts instead and remove this test. | 1105 // TODO(dbeam): disallow changing accounts instead and remove this test. |
1088 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { | 1106 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { |
1089 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1107 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1090 GetFullWallet(_)).Times(1); | 1108 GetFullWallet(_)).Times(1); |
1091 | 1109 |
1092 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1110 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1093 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1111 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1094 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1112 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1095 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1113 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1096 controller()->OnAccept(); | 1114 controller()->OnAccept(); |
| 1115 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
1097 | 1116 |
1098 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1117 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1099 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1118 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1100 | 1119 |
1101 SwitchToWallet(); | 1120 SwitchToWallet(); |
1102 SwitchToAutofill(); | 1121 SwitchToAutofill(); |
1103 | 1122 |
1104 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1123 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1105 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1124 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1106 } | 1125 } |
1107 | 1126 |
1108 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { | 1127 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { |
1109 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1128 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1110 GetFullWallet(_)).Times(1); | 1129 GetFullWallet(_)).Times(1); |
1111 | 1130 |
1112 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1131 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1113 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1132 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1114 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1133 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1115 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1134 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1116 controller()->OnAccept(); | 1135 controller()->OnAccept(); |
| 1136 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
1117 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 1137 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
1118 | 1138 |
1119 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1139 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1120 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1140 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1121 | 1141 |
1122 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); | 1142 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
1123 | 1143 |
1124 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1144 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1125 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1145 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1126 } | 1146 } |
1127 | 1147 |
1128 // TODO(dbeam): disallow changing accounts instead and remove this test. | 1148 // TODO(dbeam): disallow changing accounts instead and remove this test. |
1129 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { | 1149 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { |
1130 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1150 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1131 GetFullWallet(_)).Times(1); | 1151 GetFullWallet(_)).Times(1); |
1132 | 1152 |
1133 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1153 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1134 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1154 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1135 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1155 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1136 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1156 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1137 controller()->OnAccept(); | 1157 controller()->OnAccept(); |
| 1158 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
1138 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 1159 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
1139 | 1160 |
1140 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1161 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1141 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1162 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1142 | 1163 |
1143 SwitchToWallet(); | 1164 SwitchToWallet(); |
1144 SwitchToAutofill(); | 1165 SwitchToAutofill(); |
1145 | 1166 |
1146 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1167 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1147 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1168 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 controller()->EditCancelledForSection(SECTION_EMAIL); | 1418 controller()->EditCancelledForSection(SECTION_EMAIL); |
1398 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1419 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1399 | 1420 |
1400 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 1421 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
1401 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 1422 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
1402 | 1423 |
1403 profile()->set_incognito(true); | 1424 profile()->set_incognito(true); |
1404 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1425 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1405 } | 1426 } |
1406 | 1427 |
| 1428 TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) { |
| 1429 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); |
| 1430 |
| 1431 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 1432 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 1433 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 1434 controller()->OnAccept(); |
| 1435 |
| 1436 EXPECT_TRUE(controller()->GetRiskData().empty()); |
| 1437 } |
| 1438 |
| 1439 TEST_F(AutofillDialogControllerTest, RiskLoadsWithoutPendingLegalDocuments) { |
| 1440 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
| 1441 |
| 1442 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 1443 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 1444 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 1445 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 1446 controller()->OnAccept(); |
| 1447 |
| 1448 EXPECT_TRUE(controller()->GetRiskData().empty()); |
| 1449 |
| 1450 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
| 1451 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); |
| 1452 } |
| 1453 |
| 1454 TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { |
| 1455 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); |
| 1456 |
| 1457 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 1458 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 1459 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 1460 |
| 1461 testing::Mock::VerifyAndClear(controller()); |
| 1462 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); |
| 1463 |
| 1464 controller()->OnAccept(); |
| 1465 EXPECT_TRUE(controller()->GetRiskData().empty()); |
| 1466 |
| 1467 // Simulate a risk load and verify |GetRiskData()| matches the encoded value. |
| 1468 controller()->OnDidAcceptLegalDocuments(); |
| 1469 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); |
| 1470 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); |
| 1471 } |
| 1472 |
1407 } // namespace autofill | 1473 } // namespace autofill |
OLD | NEW |