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 { | |
Ilya Sherman
2013/05/22 23:53:59
Why did you remove this? It should wrap everythin
Dan Beam
2013/05/23 00:30:40
look at newer patchsets
| |
38 | |
39 const char kFakeEmail[] = "user@example.com"; | 38 const char kFakeEmail[] = "user@example.com"; |
39 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | |
40 const char kEditedBillingAddress[] = "123 edited billing address"; | 40 const char kEditedBillingAddress[] = "123 edited billing address"; |
41 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region", | 41 const char* kFieldsFromPage[] = |
42 "shipping region" }; | 42 { "email", "cc-number", "billing region", "shipping region" }; |
43 const char kSettingsOrigin[] = "Chrome settings"; | 43 const char kSettingsOrigin[] = "Chrome settings"; |
44 | 44 |
45 using content::BrowserThread; | 45 using content::BrowserThread; |
46 | 46 |
47 void SetOutputValue(const DetailInputs& inputs, | 47 void SetOutputValue(const DetailInputs& inputs, |
48 DetailOutputMap* outputs, | 48 DetailOutputMap* outputs, |
49 AutofillFieldType type, | 49 AutofillFieldType type, |
50 const std::string& value) { | 50 const std::string& value) { |
51 for (size_t i = 0; i < inputs.size(); ++i) { | 51 for (size_t i = 0; i < inputs.size(); ++i) { |
52 const DetailInput& input = inputs[i]; | 52 const DetailInput& input = inputs[i]; |
(...skipping 162 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; } | 215 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } |
216 | 216 |
217 const GURL& open_tab_url() { return open_tab_url_; } | 217 const GURL& open_tab_url() { return open_tab_url_; } |
218 | 218 |
219 virtual DialogType GetDialogType() const OVERRIDE { | 219 virtual DialogType GetDialogType() const OVERRIDE { |
220 return dialog_type_; | 220 return dialog_type_; |
221 } | 221 } |
222 | 222 |
223 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } | 223 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } |
224 | 224 |
225 MOCK_METHOD0(LoadRiskFingerprintData, void()); | |
226 | |
227 virtual void OnDidLoadRiskFingerprintData( | |
228 scoped_ptr<risk::Fingerprint> fingerprint) OVERRIDE { | |
229 AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( | |
230 fingerprint.Pass()); | |
231 } | |
Ilya Sherman
2013/05/22 23:53:59
Optional nit: I think you can just write "using Au
Dan Beam
2013/05/23 00:30:40
Done.
| |
232 | |
225 protected: | 233 protected: |
226 virtual PersonalDataManager* GetManager() OVERRIDE { | 234 virtual PersonalDataManager* GetManager() OVERRIDE { |
227 return &test_manager_; | 235 return &test_manager_; |
228 } | 236 } |
229 | 237 |
230 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 238 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
231 return &test_wallet_client_; | 239 return &test_wallet_client_; |
232 } | 240 } |
233 | 241 |
234 virtual bool IsFirstRun() const OVERRIDE { | 242 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); | 286 form_data.fields.push_back(field); |
279 } | 287 } |
280 | 288 |
281 profile()->CreateRequestContext(); | 289 profile()->CreateRequestContext(); |
282 test_web_contents_.reset( | 290 test_web_contents_.reset( |
283 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 291 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
284 | 292 |
285 base::Callback<void(const FormStructure*, const std::string&)> callback = | 293 base::Callback<void(const FormStructure*, const std::string&)> callback = |
286 base::Bind(&AutofillDialogControllerTest::FinishedCallback, | 294 base::Bind(&AutofillDialogControllerTest::FinishedCallback, |
287 base::Unretained(this)); | 295 base::Unretained(this)); |
288 controller_ = (new TestAutofillDialogController( | 296 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
289 test_web_contents_.get(), | 297 test_web_contents_.get(), |
290 form_data, | 298 form_data, |
291 GURL(), | 299 GURL(), |
292 metric_logger_, | 300 metric_logger_, |
293 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, | 301 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, |
294 callback))->AsWeakPtr(); | 302 callback))->AsWeakPtr(); |
295 controller_->Init(profile()); | 303 controller_->Init(profile()); |
296 controller_->Show(); | 304 controller_->Show(); |
297 controller_->OnUserNameFetchSuccess(kFakeEmail); | 305 controller_->OnUserNameFetchSuccess(kFakeEmail); |
298 } | 306 } |
299 | 307 |
300 virtual void TearDown() OVERRIDE { | 308 virtual void TearDown() OVERRIDE { |
301 if (controller_) | 309 if (controller_) |
302 controller_->ViewClosed(); | 310 controller_->ViewClosed(); |
303 } | 311 } |
304 | 312 |
305 protected: | 313 protected: |
306 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { | 314 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { |
307 base::DictionaryValue dict; | 315 base::DictionaryValue dict; |
308 scoped_ptr<base::ListValue> list(new base::ListValue()); | 316 scoped_ptr<base::ListValue> list(new base::ListValue()); |
309 list->AppendString("verify_cvv"); | 317 list->AppendString("verify_cvv"); |
310 dict.Set("required_action", list.release()); | 318 dict.Set("required_action", list.release()); |
311 return wallet::FullWallet::CreateFullWallet(dict); | 319 return wallet::FullWallet::CreateFullWallet(dict); |
312 } | 320 } |
313 | 321 |
322 static scoped_ptr<risk::Fingerprint> GetFakeFingerprint() { | |
323 scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint()); | |
324 // Add some data to the proto, else the encoded content is empty. | |
325 fingerprint->mutable_machine_characteristics()->mutable_screen_size()-> | |
326 set_width(1024); | |
327 return fingerprint.Pass(); | |
328 } | |
Ilya Sherman
2013/05/22 23:53:59
nit: Please define this as a free function rather
Dan Beam
2013/05/23 00:30:40
Done.
| |
329 | |
314 void FillCreditCardInputs() { | 330 void FillCreditCardInputs() { |
315 DetailOutputMap cc_outputs; | 331 DetailOutputMap cc_outputs; |
316 const DetailInputs& cc_inputs = | 332 const DetailInputs& cc_inputs = |
317 controller()->RequestedFieldsForSection(SECTION_CC); | 333 controller()->RequestedFieldsForSection(SECTION_CC); |
318 for (size_t i = 0; i < cc_inputs.size(); ++i) { | 334 for (size_t i = 0; i < cc_inputs.size(); ++i) { |
319 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); | 335 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); |
320 } | 336 } |
321 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); | 337 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); |
322 } | 338 } |
323 | 339 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 392 |
377 // Must outlive the controller. | 393 // Must outlive the controller. |
378 AutofillMetrics metric_logger_; | 394 AutofillMetrics metric_logger_; |
379 | 395 |
380 // Returned when the dialog closes successfully. | 396 // Returned when the dialog closes successfully. |
381 const FormStructure* form_structure_; | 397 const FormStructure* form_structure_; |
382 | 398 |
383 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | 399 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); |
384 }; | 400 }; |
385 | 401 |
386 } // namespace | |
387 | |
388 // This test makes sure nothing falls over when fields are being validity- | 402 // This test makes sure nothing falls over when fields are being validity- |
389 // checked. | 403 // checked. |
390 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 404 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
391 const DialogSection sections[] = { | 405 const DialogSection sections[] = { |
392 SECTION_EMAIL, | 406 SECTION_EMAIL, |
393 SECTION_CC, | 407 SECTION_CC, |
394 SECTION_BILLING, | 408 SECTION_BILLING, |
395 SECTION_CC_BILLING, | 409 SECTION_CC_BILLING, |
396 SECTION_SHIPPING | 410 SECTION_SHIPPING |
397 }; | 411 }; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); | 614 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); |
601 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); | 615 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); |
602 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); | 616 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); |
603 } | 617 } |
604 | 618 |
605 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { | 619 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { |
606 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 620 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
607 AcceptLegalDocuments(_, _, _)).Times(1); | 621 AcceptLegalDocuments(_, _, _)).Times(1); |
608 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 622 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
609 GetFullWallet(_)).Times(1); | 623 GetFullWallet(_)).Times(1); |
624 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); | |
610 | 625 |
611 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 626 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
612 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 627 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
613 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 628 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
614 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 629 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
615 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 630 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
616 controller()->OnAccept(); | 631 controller()->OnAccept(); |
632 controller()->OnDidAcceptLegalDocuments(); | |
633 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
617 } | 634 } |
618 | 635 |
619 // Makes sure the default object IDs are respected. | 636 // Makes sure the default object IDs are respected. |
620 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { | 637 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { |
621 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 638 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
622 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 639 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
623 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 640 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
624 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 641 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
625 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 642 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
626 | 643 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 952 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
936 GetFullWallet(_)).Times(1); | 953 GetFullWallet(_)).Times(1); |
937 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 954 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
938 AuthenticateInstrument(_, _, _)).Times(1); | 955 AuthenticateInstrument(_, _, _)).Times(1); |
939 | 956 |
940 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 957 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
941 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 958 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
942 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 959 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
943 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 960 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
944 controller()->OnAccept(); | 961 controller()->OnAccept(); |
962 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
945 | 963 |
946 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); | 964 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
947 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); | 965 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); |
948 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 966 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
949 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 967 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
950 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 968 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
951 | 969 |
952 SuggestionState suggestion_state = | 970 SuggestionState suggestion_state = |
953 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 971 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
954 EXPECT_TRUE(suggestion_state.extra_text.empty()); | 972 EXPECT_TRUE(suggestion_state.extra_text.empty()); |
(...skipping 18 matching lines...) Expand all Loading... | |
973 | 991 |
974 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { | 992 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { |
975 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 993 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
976 GetFullWallet(_)).Times(1); | 994 GetFullWallet(_)).Times(1); |
977 | 995 |
978 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 996 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
979 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 997 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
980 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 998 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
981 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 999 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
982 controller()->OnAccept(); | 1000 controller()->OnAccept(); |
1001 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
983 | 1002 |
984 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1003 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
985 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1004 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
986 | 1005 |
987 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); | 1006 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
988 | 1007 |
989 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1008 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
990 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1009 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
991 } | 1010 } |
992 | 1011 |
993 // TODO(dbeam): disallow changing accounts instead and remove this test. | 1012 // TODO(dbeam): disallow changing accounts instead and remove this test. |
994 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { | 1013 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { |
995 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1014 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
996 GetFullWallet(_)).Times(1); | 1015 GetFullWallet(_)).Times(1); |
997 | 1016 |
998 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1017 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
999 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1018 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1000 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1019 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1001 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1020 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1002 controller()->OnAccept(); | 1021 controller()->OnAccept(); |
1022 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
1003 | 1023 |
1004 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1024 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1005 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1025 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1006 | 1026 |
1007 SwitchToWallet(); | 1027 SwitchToWallet(); |
1008 SwitchToAutofill(); | 1028 SwitchToAutofill(); |
1009 | 1029 |
1010 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1030 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1011 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1031 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1012 } | 1032 } |
1013 | 1033 |
1014 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { | 1034 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { |
1015 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1035 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1016 GetFullWallet(_)).Times(1); | 1036 GetFullWallet(_)).Times(1); |
1017 | 1037 |
1018 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1038 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1019 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1039 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1020 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1040 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1021 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1041 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1022 controller()->OnAccept(); | 1042 controller()->OnAccept(); |
1043 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
1023 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 1044 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
1024 | 1045 |
1025 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1046 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1026 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1047 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1027 | 1048 |
1028 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); | 1049 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
1029 | 1050 |
1030 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1051 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1031 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1052 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1032 } | 1053 } |
1033 | 1054 |
1034 // TODO(dbeam): disallow changing accounts instead and remove this test. | 1055 // TODO(dbeam): disallow changing accounts instead and remove this test. |
1035 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { | 1056 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { |
1036 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1057 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1037 GetFullWallet(_)).Times(1); | 1058 GetFullWallet(_)).Times(1); |
1038 | 1059 |
1039 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 1060 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
1040 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1061 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1041 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1062 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1042 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1063 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1043 controller()->OnAccept(); | 1064 controller()->OnAccept(); |
1065 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
1044 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 1066 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
1045 | 1067 |
1046 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1068 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1047 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1069 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
1048 | 1070 |
1049 SwitchToWallet(); | 1071 SwitchToWallet(); |
1050 SwitchToAutofill(); | 1072 SwitchToAutofill(); |
1051 | 1073 |
1052 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 1074 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
1053 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 1075 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1305 controller()->EditCancelledForSection(SECTION_EMAIL); | 1327 controller()->EditCancelledForSection(SECTION_EMAIL); |
1306 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1328 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1307 | 1329 |
1308 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 1330 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
1309 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 1331 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
1310 | 1332 |
1311 profile()->set_incognito(true); | 1333 profile()->set_incognito(true); |
1312 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1334 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
1313 } | 1335 } |
1314 | 1336 |
1337 TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) { | |
1338 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); | |
1339 | |
1340 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | |
1341 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | |
1342 controller()->OnDidGetWalletItems(wallet_items.Pass()); | |
1343 | |
1344 EXPECT_EQ("risky business", controller()->GetRiskData()); | |
Ilya Sherman
2013/05/22 23:53:59
Should this test call controller()->OnAccept(); be
Dan Beam
2013/05/23 00:30:40
Done.
| |
1345 } | |
1346 | |
1347 TEST_F(AutofillDialogControllerTest, RiskLoadsWithoutPendingLegalDocuments) { | |
1348 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); | |
1349 | |
1350 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | |
1351 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | |
1352 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | |
1353 controller()->OnDidGetWalletItems(wallet_items.Pass()); | |
1354 controller()->OnAccept(); | |
1355 | |
1356 EXPECT_EQ("risky business", controller()->GetRiskData()); | |
1357 | |
1358 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
1359 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); | |
1360 } | |
1361 | |
1362 TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { | |
1363 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); | |
1364 | |
1365 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | |
1366 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | |
1367 controller()->OnDidGetWalletItems(wallet_items.Pass()); | |
1368 | |
1369 testing::Mock::VerifyAndClear(controller()); | |
1370 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1); | |
1371 | |
1372 controller()->OnAccept(); | |
1373 EXPECT_EQ("risky business", controller()->GetRiskData()); | |
1374 | |
1375 // Simulate a risk load and verify |GetRiskData()| matches the encoded value. | |
1376 controller()->OnDidAcceptLegalDocuments(); | |
1377 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
1378 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData()); | |
1379 } | |
1380 | |
1315 } // namespace autofill | 1381 } // namespace autofill |
OLD | NEW |