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

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

Issue 12893007: Implementing VERIFY_CVV required action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/autofill/browser/autofill_common_test.h" 13 #include "components/autofill/browser/autofill_common_test.h"
14 #include "components/autofill/browser/autofill_metrics.h" 14 #include "components/autofill/browser/autofill_metrics.h"
15 #include "components/autofill/browser/wallet/full_wallet.h"
15 #include "components/autofill/browser/wallet/instrument.h" 16 #include "components/autofill/browser/wallet/instrument.h"
16 #include "components/autofill/browser/wallet/wallet_address.h" 17 #include "components/autofill/browser/wallet/wallet_address.h"
17 #include "components/autofill/browser/wallet/wallet_client.h" 18 #include "components/autofill/browser/wallet/wallet_client.h"
18 #include "components/autofill/browser/wallet/wallet_test_util.h" 19 #include "components/autofill/browser/wallet/wallet_test_util.h"
19 #include "components/autofill/common/form_data.h" 20 #include "components/autofill/common/form_data.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
22 #include "content/public/test/web_contents_tester.h" 23 #include "content/public/test/web_contents_tester.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 TestWalletClient(net::URLRequestContextGetter* context, 87 TestWalletClient(net::URLRequestContextGetter* context,
87 wallet::WalletClientDelegate* delegate) 88 wallet::WalletClientDelegate* delegate)
88 : wallet::WalletClient(context, delegate) {} 89 : wallet::WalletClient(context, delegate) {}
89 virtual ~TestWalletClient() {} 90 virtual ~TestWalletClient() {}
90 91
91 MOCK_METHOD3(AcceptLegalDocuments, 92 MOCK_METHOD3(AcceptLegalDocuments,
92 void(const std::vector<wallet::WalletItems::LegalDocument*>& documents, 93 void(const std::vector<wallet::WalletItems::LegalDocument*>& documents,
93 const std::string& google_transaction_id, 94 const std::string& google_transaction_id,
94 const GURL& source_url)); 95 const GURL& source_url));
95 96
97 MOCK_METHOD3(AuthenticateInstrument,
98 void(const std::string& instrument_id,
99 const std::string& card_verification_number,
100 const std::string& obfuscated_gaia_id));
101
96 MOCK_METHOD1(GetFullWallet, 102 MOCK_METHOD1(GetFullWallet,
97 void(const wallet::WalletClient::FullWalletRequest& request)); 103 void(const wallet::WalletClient::FullWalletRequest& request));
98 104
99 MOCK_METHOD2(SaveAddress, 105 MOCK_METHOD2(SaveAddress,
100 void(const wallet::Address& address, const GURL& source_url)); 106 void(const wallet::Address& address, const GURL& source_url));
101 107
102 MOCK_METHOD3(SaveInstrument, 108 MOCK_METHOD3(SaveInstrument,
103 void(const wallet::Instrument& instrument, 109 void(const wallet::Instrument& instrument,
104 const std::string& obfuscated_gaia_id, 110 const std::string& obfuscated_gaia_id,
105 const GURL& source_url)); 111 const GURL& source_url));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 218 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
213 callback); 219 callback);
214 controller_->Show(); 220 controller_->Show();
215 } 221 }
216 222
217 virtual void TearDown() OVERRIDE { 223 virtual void TearDown() OVERRIDE {
218 controller_->ViewClosed(); 224 controller_->ViewClosed();
219 } 225 }
220 226
221 protected: 227 protected:
228 size_t CountNotificationsOfType(DialogNotification::Type type) {
229 size_t count = 0;
230 const std::vector<DialogNotification>& notifications =
231 controller()->CurrentNotifications();
232 for (size_t i = 0; i < notifications.size(); ++i) {
233 if (notifications[i].type() == type)
234 ++count;
235 }
236 return count;
237 }
238
222 TestAutofillDialogController* controller() { return controller_; } 239 TestAutofillDialogController* controller() { return controller_; }
223 240
224 TestingProfile* profile() { return &profile_; } 241 TestingProfile* profile() { return &profile_; }
225 242
226 private: 243 private:
227 // A bunch of threads are necessary for classes like TestWebContents and 244 // A bunch of threads are necessary for classes like TestWebContents and
228 // URLRequestContextGetter not to fall over. 245 // URLRequestContextGetter not to fall over.
229 MessageLoopForUI loop_; 246 MessageLoopForUI loop_;
230 content::TestBrowserThread ui_thread_; 247 content::TestBrowserThread ui_thread_;
231 content::TestBrowserThread file_thread_; 248 content::TestBrowserThread file_thread_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 EXPECT_CALL(*controller()->GetTestingWalletClient(), 352 EXPECT_CALL(*controller()->GetTestingWalletClient(),
336 AcceptLegalDocuments(_, _, _)).Times(1); 353 AcceptLegalDocuments(_, _, _)).Times(1);
337 EXPECT_CALL(*controller()->GetTestingWalletClient(), 354 EXPECT_CALL(*controller()->GetTestingWalletClient(),
338 GetFullWallet(_)).Times(1); 355 GetFullWallet(_)).Times(1);
339 356
340 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 357 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
341 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 358 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
342 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 359 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
343 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 360 wallet_items->AddAddress(wallet::GetTestShippingAddress());
344 controller()->OnDidGetWalletItems(wallet_items.Pass()); 361 controller()->OnDidGetWalletItems(wallet_items.Pass());
345 controller()->OnSubmit(); 362 controller()->OnAccept();
346 } 363 }
347 364
348 TEST_F(AutofillDialogControllerTest, SaveAddress) { 365 TEST_F(AutofillDialogControllerTest, SaveAddress) {
349 controller()->set_is_paying_with_wallet(true); 366 controller()->set_is_paying_with_wallet(true);
350 367
351 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 368 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
352 EXPECT_CALL(*controller()->GetTestingWalletClient(), 369 EXPECT_CALL(*controller()->GetTestingWalletClient(),
353 SaveAddress(_, _)).Times(1); 370 SaveAddress(_, _)).Times(1);
354 371
355 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 372 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
356 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 373 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
357 controller()->OnDidGetWalletItems(wallet_items.Pass()); 374 controller()->OnDidGetWalletItems(wallet_items.Pass());
358 controller()->OnSubmit(); 375 controller()->OnAccept();
359 } 376 }
360 377
361 TEST_F(AutofillDialogControllerTest, SaveInstrument) { 378 TEST_F(AutofillDialogControllerTest, SaveInstrument) {
362 controller()->set_is_paying_with_wallet(true); 379 controller()->set_is_paying_with_wallet(true);
363 380
364 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 381 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
365 EXPECT_CALL(*controller()->GetTestingWalletClient(), 382 EXPECT_CALL(*controller()->GetTestingWalletClient(),
366 SaveInstrument(_, _, _)).Times(1); 383 SaveInstrument(_, _, _)).Times(1);
367 384
368 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 385 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
369 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 386 wallet_items->AddAddress(wallet::GetTestShippingAddress());
370 controller()->OnDidGetWalletItems(wallet_items.Pass()); 387 controller()->OnDidGetWalletItems(wallet_items.Pass());
371 controller()->OnSubmit(); 388 controller()->OnAccept();
372 } 389 }
373 390
374 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { 391 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
375 controller()->set_is_paying_with_wallet(true); 392 controller()->set_is_paying_with_wallet(true);
376 393
377 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 394 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
378 EXPECT_CALL(*controller()->GetTestingWalletClient(), 395 EXPECT_CALL(*controller()->GetTestingWalletClient(),
379 SaveInstrumentAndAddress(_, _, _, _)).Times(1); 396 SaveInstrumentAndAddress(_, _, _, _)).Times(1);
380 397
381 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 398 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
382 controller()->OnSubmit(); 399 controller()->OnAccept();
383 } 400 }
384 401
385 TEST_F(AutofillDialogControllerTest, Cancel) { 402 TEST_F(AutofillDialogControllerTest, CancelNoSave) {
386 controller()->set_is_paying_with_wallet(true); 403 controller()->set_is_paying_with_wallet(true);
404 EXPECT_CALL(*controller()->GetTestingWalletClient(),
405 SaveInstrumentAndAddress(_, _, _, _)).Times(0);
387 406
388 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 407 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
389 408
390 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 409 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
391 controller()->OnCancel(); 410 controller()->OnCancel();
392 } 411 }
393 412
413 TEST_F(AutofillDialogControllerTest, VerifyCvv) {
414 controller()->set_is_paying_with_wallet(true);
415
416 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
417 EXPECT_CALL(*controller()->GetTestingWalletClient(),
418 GetFullWallet(_)).Times(1);
419 EXPECT_CALL(*controller()->GetTestingWalletClient(),
420 AuthenticateInstrument(_, _, _)).Times(1);
421
422 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
423 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
424 wallet_items->AddAddress(wallet::GetTestShippingAddress());
425 controller()->OnDidGetWalletItems(wallet_items.Pass());
426 controller()->OnAccept();
427
428 base::DictionaryValue dict;
429 scoped_ptr<base::ListValue> list(new base::ListValue());
430 list->AppendString("verify_cvv");
431 dict.Set("required_action", list.release());
432 controller()->OnDidGetFullWallet(wallet::FullWallet::CreateFullWallet(dict));
433
434 EXPECT_TRUE(controller()->IsSubmitPausedOn(wallet::VERIFY_CVV));
435 EXPECT_EQ(1U, CountNotificationsOfType(DialogNotification::REQUIRED_ACTION));
436
437 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
438 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
439
440 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
441 EXPECT_TRUE(
442 !controller()->SuggestionTextForSection(SECTION_CC_BILLING).empty());
443 EXPECT_EQ(
444 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
445
446 controller()->OnAccept();
447 }
448
394 } // namespace autofill 449 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698