Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 14904002: Load and send Wallet Risk params after user has agreed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} 160 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {}
161 virtual ~TestAccountChooserModel() {} 161 virtual ~TestAccountChooserModel() {}
162 162
163 using AccountChooserModel::kActiveWalletItemId; 163 using AccountChooserModel::kActiveWalletItemId;
164 using AccountChooserModel::kAutofillItemId; 164 using AccountChooserModel::kAutofillItemId;
165 165
166 private: 166 private:
167 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); 167 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel);
168 }; 168 };
169 169
170 FORWARD_DECLARE_TEST(AutofillDialogControllerTest, AcceptLegalDocuments);
171 FORWARD_DECLARE_TEST(AutofillDialogControllerTest, VerifyCvv);
172 FORWARD_DECLARE_TEST(AutofillDialogControllerTest, ErrorDuringSubmit);
173 FORWARD_DECLARE_TEST(AutofillDialogControllerTest, ErrorDuringVerifyCvv);
174 FORWARD_DECLARE_TEST(AutofillDialogControllerTest, ChangeAccountDuringSubmit);
175 FORWARD_DECLARE_TEST(AutofillDialogControllerTest,
176 ChangeAccountDuringVerifyCvv);
177 FORWARD_DECLARE_TEST(AutofillDialogControllerTest,
178 RiskNeverLoadsWithPendingLegalDocuments);
179 FORWARD_DECLARE_TEST(AutofillDialogControllerTest,
180 RiskLoadsWithoutPendingLegalDocuments);
181 FORWARD_DECLARE_TEST(AutofillDialogControllerTest,
182 RiskLoadsAfterAcceptingLegalDocuments);
183
170 class TestAutofillDialogController 184 class TestAutofillDialogController
171 : public AutofillDialogControllerImpl, 185 : public AutofillDialogControllerImpl,
172 public base::SupportsWeakPtr<TestAutofillDialogController> { 186 public base::SupportsWeakPtr<TestAutofillDialogController> {
173 public: 187 public:
174 TestAutofillDialogController( 188 TestAutofillDialogController(
175 content::WebContents* contents, 189 content::WebContents* contents,
176 const FormData& form_structure, 190 const FormData& form_structure,
177 const GURL& source_url, 191 const GURL& source_url,
178 const AutofillMetrics& metric_logger, 192 const AutofillMetrics& metric_logger,
179 const DialogType dialog_type, 193 const DialogType dialog_type,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 242 }
229 243
230 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 244 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
231 return &test_wallet_client_; 245 return &test_wallet_client_;
232 } 246 }
233 247
234 virtual bool IsFirstRun() const OVERRIDE { 248 virtual bool IsFirstRun() const OVERRIDE {
235 return is_first_run_; 249 return is_first_run_;
236 } 250 }
237 251
252 MOCK_METHOD0(LoadRiskFingerprintData, void());
253
238 virtual void OpenTabWithUrl(const GURL& url) OVERRIDE { 254 virtual void OpenTabWithUrl(const GURL& url) OVERRIDE {
239 open_tab_url_ = url; 255 open_tab_url_ = url;
240 } 256 }
241 257
242 private: 258 private:
259 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest, AcceptLegalDocuments);
260 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest, VerifyCvv);
261 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest, ErrorDuringSubmit);
262 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest, ErrorDuringVerifyCvv);
263 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest,
264 ChangeAccountDuringSubmit);
265 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest,
266 ChangeAccountDuringVerifyCvv);
267 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest,
268 RiskNeverLoadsWithPendingLegalDocuments);
269 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest,
270 RiskLoadsWithoutPendingLegalDocuments);
271 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest,
272 RiskLoadsAfterAcceptingLegalDocuments);
Ilya Sherman 2013/05/22 22:34:24 Why not just make the relevant method public? The
Dan Beam 2013/05/22 23:25:20 Done.
273
243 // To specify our own metric logger. 274 // To specify our own metric logger.
244 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 275 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
245 return metric_logger_; 276 return metric_logger_;
246 } 277 }
247 278
248 const AutofillMetrics& metric_logger_; 279 const AutofillMetrics& metric_logger_;
249 TestPersonalDataManager test_manager_; 280 TestPersonalDataManager test_manager_;
250 testing::NiceMock<TestWalletClient> test_wallet_client_; 281 testing::NiceMock<TestWalletClient> test_wallet_client_;
251 bool is_first_run_; 282 bool is_first_run_;
252 GURL open_tab_url_; 283 GURL open_tab_url_;
(...skipping 25 matching lines...) Expand all
278 form_data.fields.push_back(field); 309 form_data.fields.push_back(field);
279 } 310 }
280 311
281 profile()->CreateRequestContext(); 312 profile()->CreateRequestContext();
282 test_web_contents_.reset( 313 test_web_contents_.reset(
283 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); 314 content::WebContentsTester::CreateTestWebContents(profile(), NULL));
284 315
285 base::Callback<void(const FormStructure*, const std::string&)> callback = 316 base::Callback<void(const FormStructure*, const std::string&)> callback =
286 base::Bind(&AutofillDialogControllerTest::FinishedCallback, 317 base::Bind(&AutofillDialogControllerTest::FinishedCallback,
287 base::Unretained(this)); 318 base::Unretained(this));
288 controller_ = (new TestAutofillDialogController( 319 controller_ = (new testing::NiceMock<TestAutofillDialogController>(
289 test_web_contents_.get(), 320 test_web_contents_.get(),
290 form_data, 321 form_data,
291 GURL(), 322 GURL(),
292 metric_logger_, 323 metric_logger_,
293 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 324 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
294 callback))->AsWeakPtr(); 325 callback))->AsWeakPtr();
295 controller_->Init(profile()); 326 controller_->Init(profile());
296 controller_->Show(); 327 controller_->Show();
297 controller_->OnUserNameFetchSuccess(kFakeEmail); 328 controller_->OnUserNameFetchSuccess(kFakeEmail);
298 } 329 }
299 330
300 virtual void TearDown() OVERRIDE { 331 virtual void TearDown() OVERRIDE {
301 if (controller_) 332 if (controller_)
302 controller_->ViewClosed(); 333 controller_->ViewClosed();
303 } 334 }
304 335
305 protected: 336 protected:
306 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { 337 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() {
307 base::DictionaryValue dict; 338 base::DictionaryValue dict;
308 scoped_ptr<base::ListValue> list(new base::ListValue()); 339 scoped_ptr<base::ListValue> list(new base::ListValue());
309 list->AppendString("verify_cvv"); 340 list->AppendString("verify_cvv");
310 dict.Set("required_action", list.release()); 341 dict.Set("required_action", list.release());
311 return wallet::FullWallet::CreateFullWallet(dict); 342 return wallet::FullWallet::CreateFullWallet(dict);
312 } 343 }
313 344
345 static scoped_ptr<risk::Fingerprint> GetFakeFingerprint() {
346 scoped_ptr<risk::Fingerprint> fingerprint(new risk::Fingerprint());
347 // Add some data to the proto, else the encoded content is empty.
348 fingerprint->mutable_machine_characteristics()->mutable_screen_size()->
349 set_width(1024);
350 return fingerprint.Pass();
351 }
352
314 void FillCreditCardInputs() { 353 void FillCreditCardInputs() {
315 DetailOutputMap cc_outputs; 354 DetailOutputMap cc_outputs;
316 const DetailInputs& cc_inputs = 355 const DetailInputs& cc_inputs =
317 controller()->RequestedFieldsForSection(SECTION_CC); 356 controller()->RequestedFieldsForSection(SECTION_CC);
318 for (size_t i = 0; i < cc_inputs.size(); ++i) { 357 for (size_t i = 0; i < cc_inputs.size(); ++i) {
319 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11"); 358 cc_outputs[&cc_inputs[i]] = ASCIIToUTF16("11");
320 } 359 }
321 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); 360 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);
322 } 361 }
323 362
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 415
377 // Must outlive the controller. 416 // Must outlive the controller.
378 AutofillMetrics metric_logger_; 417 AutofillMetrics metric_logger_;
379 418
380 // Returned when the dialog closes successfully. 419 // Returned when the dialog closes successfully.
381 const FormStructure* form_structure_; 420 const FormStructure* form_structure_;
382 421
383 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); 422 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
384 }; 423 };
385 424
386 } // namespace
387
388 // This test makes sure nothing falls over when fields are being validity- 425 // This test makes sure nothing falls over when fields are being validity-
389 // checked. 426 // checked.
390 TEST_F(AutofillDialogControllerTest, ValidityCheck) { 427 TEST_F(AutofillDialogControllerTest, ValidityCheck) {
391 const DialogSection sections[] = { 428 const DialogSection sections[] = {
392 SECTION_EMAIL, 429 SECTION_EMAIL,
393 SECTION_CC, 430 SECTION_CC,
394 SECTION_BILLING, 431 SECTION_BILLING,
395 SECTION_CC_BILLING, 432 SECTION_CC_BILLING,
396 SECTION_SHIPPING 433 SECTION_SHIPPING
397 }; 434 };
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value)); 637 EXPECT_EQ("CA", UTF16ToUTF8(form_structure()->field(3)->value));
601 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type()); 638 EXPECT_EQ(ADDRESS_BILLING_STATE, form_structure()->field(2)->type());
602 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type()); 639 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure()->field(3)->type());
603 } 640 }
604 641
605 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { 642 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
606 EXPECT_CALL(*controller()->GetTestingWalletClient(), 643 EXPECT_CALL(*controller()->GetTestingWalletClient(),
607 AcceptLegalDocuments(_, _, _)).Times(1); 644 AcceptLegalDocuments(_, _, _)).Times(1);
608 EXPECT_CALL(*controller()->GetTestingWalletClient(), 645 EXPECT_CALL(*controller()->GetTestingWalletClient(),
609 GetFullWallet(_)).Times(1); 646 GetFullWallet(_)).Times(1);
647 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
610 648
611 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 649 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
612 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 650 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
613 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 651 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
614 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 652 wallet_items->AddAddress(wallet::GetTestShippingAddress());
615 controller()->OnDidGetWalletItems(wallet_items.Pass()); 653 controller()->OnDidGetWalletItems(wallet_items.Pass());
616 controller()->OnAccept(); 654 controller()->OnAccept();
655 controller()->OnDidAcceptLegalDocuments();
656 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
617 } 657 }
618 658
619 // Makes sure the default object IDs are respected. 659 // Makes sure the default object IDs are respected.
620 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { 660 TEST_F(AutofillDialogControllerTest, WalletDefaultItems) {
621 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 661 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
622 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 662 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
623 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 663 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
624 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 664 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
625 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 665 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
626 666
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 EXPECT_CALL(*controller()->GetTestingWalletClient(), 975 EXPECT_CALL(*controller()->GetTestingWalletClient(),
936 GetFullWallet(_)).Times(1); 976 GetFullWallet(_)).Times(1);
937 EXPECT_CALL(*controller()->GetTestingWalletClient(), 977 EXPECT_CALL(*controller()->GetTestingWalletClient(),
938 AuthenticateInstrument(_, _, _)).Times(1); 978 AuthenticateInstrument(_, _, _)).Times(1);
939 979
940 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 980 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
941 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 981 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
942 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 982 wallet_items->AddAddress(wallet::GetTestShippingAddress());
943 controller()->OnDidGetWalletItems(wallet_items.Pass()); 983 controller()->OnDidGetWalletItems(wallet_items.Pass());
944 controller()->OnAccept(); 984 controller()->OnAccept();
985 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
945 986
946 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); 987 EXPECT_TRUE(NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty());
947 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING)); 988 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
948 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); 989 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
949 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 990 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
950 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 991 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
951 992
952 SuggestionState suggestion_state = 993 SuggestionState suggestion_state =
953 controller()->SuggestionStateForSection(SECTION_CC_BILLING); 994 controller()->SuggestionStateForSection(SECTION_CC_BILLING);
954 EXPECT_TRUE(suggestion_state.extra_text.empty()); 995 EXPECT_TRUE(suggestion_state.extra_text.empty());
(...skipping 18 matching lines...) Expand all
973 1014
974 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) { 1015 TEST_F(AutofillDialogControllerTest, ErrorDuringSubmit) {
975 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1016 EXPECT_CALL(*controller()->GetTestingWalletClient(),
976 GetFullWallet(_)).Times(1); 1017 GetFullWallet(_)).Times(1);
977 1018
978 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1019 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
979 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1020 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
980 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1021 wallet_items->AddAddress(wallet::GetTestShippingAddress());
981 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1022 controller()->OnDidGetWalletItems(wallet_items.Pass());
982 controller()->OnAccept(); 1023 controller()->OnAccept();
1024 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
983 1025
984 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1026 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
985 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1027 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
986 1028
987 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 1029 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
988 1030
989 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1031 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
990 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1032 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
991 } 1033 }
992 1034
993 // TODO(dbeam): disallow changing accounts instead and remove this test. 1035 // TODO(dbeam): disallow changing accounts instead and remove this test.
994 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { 1036 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) {
995 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1037 EXPECT_CALL(*controller()->GetTestingWalletClient(),
996 GetFullWallet(_)).Times(1); 1038 GetFullWallet(_)).Times(1);
997 1039
998 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1040 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
999 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1041 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1000 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1042 wallet_items->AddAddress(wallet::GetTestShippingAddress());
1001 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1043 controller()->OnDidGetWalletItems(wallet_items.Pass());
1002 controller()->OnAccept(); 1044 controller()->OnAccept();
1045 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
1003 1046
1004 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1047 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1005 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1048 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1006 1049
1007 SwitchToWallet(); 1050 SwitchToWallet();
1008 SwitchToAutofill(); 1051 SwitchToAutofill();
1009 1052
1010 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1053 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1011 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1054 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1012 } 1055 }
1013 1056
1014 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { 1057 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) {
1015 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1058 EXPECT_CALL(*controller()->GetTestingWalletClient(),
1016 GetFullWallet(_)).Times(1); 1059 GetFullWallet(_)).Times(1);
1017 1060
1018 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1061 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1019 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1062 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1020 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1063 wallet_items->AddAddress(wallet::GetTestShippingAddress());
1021 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1064 controller()->OnDidGetWalletItems(wallet_items.Pass());
1022 controller()->OnAccept(); 1065 controller()->OnAccept();
1066 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
1023 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); 1067 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
1024 1068
1025 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1069 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1026 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1070 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1027 1071
1028 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); 1072 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR);
1029 1073
1030 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1074 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1031 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1075 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1032 } 1076 }
1033 1077
1034 // TODO(dbeam): disallow changing accounts instead and remove this test. 1078 // TODO(dbeam): disallow changing accounts instead and remove this test.
1035 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { 1079 TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) {
1036 EXPECT_CALL(*controller()->GetTestingWalletClient(), 1080 EXPECT_CALL(*controller()->GetTestingWalletClient(),
1037 GetFullWallet(_)).Times(1); 1081 GetFullWallet(_)).Times(1);
1038 1082
1039 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1083 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1040 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1084 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1041 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 1085 wallet_items->AddAddress(wallet::GetTestShippingAddress());
1042 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1086 controller()->OnDidGetWalletItems(wallet_items.Pass());
1043 controller()->OnAccept(); 1087 controller()->OnAccept();
1088 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
1044 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); 1089 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv());
1045 1090
1046 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1091 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1047 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1092 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
1048 1093
1049 SwitchToWallet(); 1094 SwitchToWallet();
1050 SwitchToAutofill(); 1095 SwitchToAutofill();
1051 1096
1052 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 1097 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
1053 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 1098 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 controller()->EditCancelledForSection(SECTION_EMAIL); 1350 controller()->EditCancelledForSection(SECTION_EMAIL);
1306 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1351 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1307 1352
1308 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1353 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1309 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1354 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1310 1355
1311 profile()->set_incognito(true); 1356 profile()->set_incognito(true);
1312 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1357 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1313 } 1358 }
1314 1359
1360 TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) {
1361 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
1362
1363 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1364 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
1365 controller()->OnDidGetWalletItems(wallet_items.Pass());
1366
1367 EXPECT_EQ("risky business", controller()->GetRiskData());
1368 }
1369
1370 TEST_F(AutofillDialogControllerTest, RiskLoadsWithoutPendingLegalDocuments) {
1371 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
1372
1373 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1374 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1375 wallet_items->AddAddress(wallet::GetTestShippingAddress());
1376 controller()->OnDidGetWalletItems(wallet_items.Pass());
1377 controller()->OnAccept();
1378
1379 EXPECT_EQ("risky business", controller()->GetRiskData());
1380
1381 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
1382 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
1383 }
1384
1385 TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) {
1386 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
1387
1388 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1389 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
1390 controller()->OnDidGetWalletItems(wallet_items.Pass());
1391
1392 testing::Mock::VerifyAndClear(controller());
1393 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
1394
1395 controller()->OnAccept();
1396 EXPECT_EQ("risky business", controller()->GetRiskData());
1397
1398 // Simulate a risk load and verify |GetRiskData()| matches the encoded value.
1399 controller()->OnDidAcceptLegalDocuments();
1400 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass());
1401 EXPECT_EQ(kFakeFingerprintEncoded, controller()->GetRiskData());
1402 }
1403
1315 } // namespace autofill 1404 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698