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

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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 field.autocomplete_attribute = "cc-number"; 207 field.autocomplete_attribute = "cc-number";
202 FormData form_data; 208 FormData form_data;
203 form_data.fields.push_back(field); 209 form_data.fields.push_back(field);
204 210
205 profile()->GetPrefs()->SetBoolean( 211 profile()->GetPrefs()->SetBoolean(
206 prefs::kAutofillDialogPayWithoutWallet, true); 212 prefs::kAutofillDialogPayWithoutWallet, true);
207 profile()->CreateRequestContext(); 213 profile()->CreateRequestContext();
208 test_web_contents_.reset( 214 test_web_contents_.reset(
209 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); 215 content::WebContentsTester::CreateTestWebContents(profile(), NULL));
210 216
211 base::Callback<void(const FormStructure*, const std::string&)> callback; 217 base::Callback<void(const FormStructure*, const std::string&)> callback =
218 base::Bind(&AutofillDialogControllerTest::FinishedCallback,
219 base::Unretained(this));
212 controller_ = new TestAutofillDialogController( 220 controller_ = new TestAutofillDialogController(
213 test_web_contents_.get(), 221 test_web_contents_.get(),
214 form_data, 222 form_data,
215 GURL(), 223 GURL(),
216 metric_logger_, 224 metric_logger_,
217 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 225 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
218 callback); 226 callback);
219 controller_->Init(profile()); 227 controller_->Init(profile());
220 controller_->Show(); 228 controller_->Show();
221 } 229 }
222 230
223 virtual void TearDown() OVERRIDE { 231 virtual void TearDown() OVERRIDE {
224 controller_->ViewClosed(); 232 controller_->ViewClosed();
225 } 233 }
226 234
227 protected: 235 protected:
236 size_t CountNotificationsOfType(DialogNotification::Type type) {
237 size_t count = 0;
238 const std::vector<DialogNotification>& notifications =
239 controller()->CurrentNotifications();
240 for (size_t i = 0; i < notifications.size(); ++i) {
241 if (notifications[i].type() == type)
242 ++count;
243 }
244 return count;
245 }
246
228 TestAutofillDialogController* controller() { return controller_; } 247 TestAutofillDialogController* controller() { return controller_; }
229 248
230 TestingProfile* profile() { return &profile_; } 249 TestingProfile* profile() { return &profile_; }
231 250
232 private: 251 private:
252 void FinishedCallback(const FormStructure* form_structure,
253 const std::string& google_transaction_id) {}
254
233 // A bunch of threads are necessary for classes like TestWebContents and 255 // A bunch of threads are necessary for classes like TestWebContents and
234 // URLRequestContextGetter not to fall over. 256 // URLRequestContextGetter not to fall over.
235 MessageLoopForUI loop_; 257 MessageLoopForUI loop_;
236 content::TestBrowserThread ui_thread_; 258 content::TestBrowserThread ui_thread_;
237 content::TestBrowserThread file_thread_; 259 content::TestBrowserThread file_thread_;
238 content::TestBrowserThread file_blocking_thread_; 260 content::TestBrowserThread file_blocking_thread_;
239 content::TestBrowserThread io_thread_; 261 content::TestBrowserThread io_thread_;
240 TestingProfile profile_; 262 TestingProfile profile_;
241 263
242 // The controller owns itself. 264 // The controller owns itself.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // Respect variants for the email address field only. 339 // Respect variants for the email address field only.
318 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 340 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
319 ui::MenuModel* shipping_model = 341 ui::MenuModel* shipping_model =
320 controller()->MenuModelForSection(SECTION_SHIPPING); 342 controller()->MenuModelForSection(SECTION_SHIPPING);
321 EXPECT_EQ(2, shipping_model->GetItemCount()); 343 EXPECT_EQ(2, shipping_model->GetItemCount());
322 ui::MenuModel* email_model = 344 ui::MenuModel* email_model =
323 controller()->MenuModelForSection(SECTION_EMAIL); 345 controller()->MenuModelForSection(SECTION_EMAIL);
324 EXPECT_EQ(3, email_model->GetItemCount()); 346 EXPECT_EQ(3, email_model->GetItemCount());
325 347
326 email_model->ActivatedAt(0); 348 email_model->ActivatedAt(0);
327 EXPECT_EQ(kEmail1, controller()->SuggestionTextForSection(SECTION_EMAIL)); 349 EXPECT_EQ(kEmail1,
350 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
328 email_model->ActivatedAt(1); 351 email_model->ActivatedAt(1);
329 EXPECT_EQ(kEmail2, controller()->SuggestionTextForSection(SECTION_EMAIL)); 352 EXPECT_EQ(kEmail2,
353 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
330 354
331 controller()->EditClickedForSection(SECTION_EMAIL); 355 controller()->EditClickedForSection(SECTION_EMAIL);
332 const DetailInputs& inputs = 356 const DetailInputs& inputs =
333 controller()->RequestedFieldsForSection(SECTION_EMAIL); 357 controller()->RequestedFieldsForSection(SECTION_EMAIL);
334 EXPECT_EQ(kEmail2, inputs[0].initial_value); 358 EXPECT_EQ(kEmail2, inputs[0].initial_value);
335 } 359 }
336 360
337 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { 361 TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
338 controller()->set_is_paying_with_wallet(true); 362 controller()->set_is_paying_with_wallet(true);
339 363
340 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 364 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
341 EXPECT_CALL(*controller()->GetTestingWalletClient(), 365 EXPECT_CALL(*controller()->GetTestingWalletClient(),
342 AcceptLegalDocuments(_, _, _)).Times(1); 366 AcceptLegalDocuments(_, _, _)).Times(1);
343 EXPECT_CALL(*controller()->GetTestingWalletClient(), 367 EXPECT_CALL(*controller()->GetTestingWalletClient(),
344 GetFullWallet(_)).Times(1); 368 GetFullWallet(_)).Times(1);
345 369
346 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 370 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
347 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); 371 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
348 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 372 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
349 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 373 wallet_items->AddAddress(wallet::GetTestShippingAddress());
350 controller()->OnDidGetWalletItems(wallet_items.Pass()); 374 controller()->OnDidGetWalletItems(wallet_items.Pass());
351 controller()->OnSubmit(); 375 controller()->OnAccept();
352 } 376 }
353 377
354 TEST_F(AutofillDialogControllerTest, SaveAddress) { 378 TEST_F(AutofillDialogControllerTest, SaveAddress) {
355 controller()->set_is_paying_with_wallet(true); 379 controller()->set_is_paying_with_wallet(true);
356 380
357 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 381 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
358 EXPECT_CALL(*controller()->GetTestingWalletClient(), 382 EXPECT_CALL(*controller()->GetTestingWalletClient(),
359 SaveAddress(_, _)).Times(1); 383 SaveAddress(_, _)).Times(1);
360 384
361 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 385 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
362 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 386 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
363 controller()->OnDidGetWalletItems(wallet_items.Pass()); 387 controller()->OnDidGetWalletItems(wallet_items.Pass());
364 controller()->OnSubmit(); 388 controller()->OnAccept();
365 } 389 }
366 390
367 TEST_F(AutofillDialogControllerTest, SaveInstrument) { 391 TEST_F(AutofillDialogControllerTest, SaveInstrument) {
368 controller()->set_is_paying_with_wallet(true); 392 controller()->set_is_paying_with_wallet(true);
369 393
370 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 394 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
371 EXPECT_CALL(*controller()->GetTestingWalletClient(), 395 EXPECT_CALL(*controller()->GetTestingWalletClient(),
372 SaveInstrument(_, _, _)).Times(1); 396 SaveInstrument(_, _, _)).Times(1);
373 397
374 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 398 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
375 wallet_items->AddAddress(wallet::GetTestShippingAddress()); 399 wallet_items->AddAddress(wallet::GetTestShippingAddress());
376 controller()->OnDidGetWalletItems(wallet_items.Pass()); 400 controller()->OnDidGetWalletItems(wallet_items.Pass());
377 controller()->OnSubmit(); 401 controller()->OnAccept();
378 } 402 }
379 403
380 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { 404 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
381 controller()->set_is_paying_with_wallet(true); 405 controller()->set_is_paying_with_wallet(true);
382 406
383 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 407 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
384 EXPECT_CALL(*controller()->GetTestingWalletClient(), 408 EXPECT_CALL(*controller()->GetTestingWalletClient(),
385 SaveInstrumentAndAddress(_, _, _, _)).Times(1); 409 SaveInstrumentAndAddress(_, _, _, _)).Times(1);
386 410
387 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 411 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
388 controller()->OnSubmit(); 412 controller()->OnAccept();
389 } 413 }
390 414
391 TEST_F(AutofillDialogControllerTest, Cancel) { 415 TEST_F(AutofillDialogControllerTest, CancelNoSave) {
392 controller()->set_is_paying_with_wallet(true); 416 controller()->set_is_paying_with_wallet(true);
417 EXPECT_CALL(*controller()->GetTestingWalletClient(),
418 SaveInstrumentAndAddress(_, _, _, _)).Times(0);
393 419
394 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 420 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
395 421
396 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 422 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
397 controller()->OnCancel(); 423 controller()->OnCancel();
398 } 424 }
399 425
400 TEST_F(AutofillDialogControllerTest, EditClickedCancelled) { 426 TEST_F(AutofillDialogControllerTest, EditClickedCancelled) {
401 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 427 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
402 428
403 AutofillProfile full_profile(autofill_test::GetFullProfile()); 429 AutofillProfile full_profile(autofill_test::GetFullProfile());
404 const string16 kEmail = ASCIIToUTF16("first@johndoe.com"); 430 const string16 kEmail = ASCIIToUTF16("first@johndoe.com");
405 full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail); 431 full_profile.SetRawInfo(EMAIL_ADDRESS, kEmail);
406 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 432 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
407 433
408 ui::MenuModel* email_model = 434 ui::MenuModel* email_model =
409 controller()->MenuModelForSection(SECTION_EMAIL); 435 controller()->MenuModelForSection(SECTION_EMAIL);
410 EXPECT_EQ(2, email_model->GetItemCount()); 436 EXPECT_EQ(2, email_model->GetItemCount());
411 437
412 // When unedited, the initial_value should be empty. 438 // When unedited, the initial_value should be empty.
413 email_model->ActivatedAt(0); 439 email_model->ActivatedAt(0);
414 const DetailInputs& inputs0 = 440 const DetailInputs& inputs0 =
415 controller()->RequestedFieldsForSection(SECTION_EMAIL); 441 controller()->RequestedFieldsForSection(SECTION_EMAIL);
416 EXPECT_EQ(string16(), inputs0[0].initial_value); 442 EXPECT_EQ(string16(), inputs0[0].initial_value);
417 EXPECT_EQ(kEmail, controller()->SuggestionTextForSection(SECTION_EMAIL)); 443 EXPECT_EQ(kEmail,
444 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
418 445
419 // When edited, the initial_value should contain the value. 446 // When edited, the initial_value should contain the value.
420 controller()->EditClickedForSection(SECTION_EMAIL); 447 controller()->EditClickedForSection(SECTION_EMAIL);
421 const DetailInputs& inputs1 = 448 const DetailInputs& inputs1 =
422 controller()->RequestedFieldsForSection(SECTION_EMAIL); 449 controller()->RequestedFieldsForSection(SECTION_EMAIL);
423 EXPECT_EQ(kEmail, inputs1[0].initial_value); 450 EXPECT_EQ(kEmail, inputs1[0].initial_value);
424 EXPECT_EQ(string16(), controller()->SuggestionTextForSection(SECTION_EMAIL)); 451 EXPECT_EQ(string16(),
452 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
425 453
426 // When edit is cancelled, the initial_value should be empty. 454 // When edit is cancelled, the initial_value should be empty.
427 controller()->EditCancelledForSection(SECTION_EMAIL); 455 controller()->EditCancelledForSection(SECTION_EMAIL);
428 const DetailInputs& inputs2 = 456 const DetailInputs& inputs2 =
429 controller()->RequestedFieldsForSection(SECTION_EMAIL); 457 controller()->RequestedFieldsForSection(SECTION_EMAIL);
430 EXPECT_EQ(kEmail, controller()->SuggestionTextForSection(SECTION_EMAIL)); 458 EXPECT_EQ(kEmail,
459 controller()->SuggestionStateForSection(SECTION_EMAIL).text);
431 EXPECT_EQ(string16(), inputs2[0].initial_value); 460 EXPECT_EQ(string16(), inputs2[0].initial_value);
432 } 461 }
433 462
463 TEST_F(AutofillDialogControllerTest, VerifyCvv) {
464 controller()->set_is_paying_with_wallet(true);
465
466 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
467 EXPECT_CALL(*controller()->GetTestingWalletClient(),
468 GetFullWallet(_)).Times(1);
469 EXPECT_CALL(*controller()->GetTestingWalletClient(),
470 AuthenticateInstrument(_, _, _)).Times(1);
471
472 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
473 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
474 wallet_items->AddAddress(wallet::GetTestShippingAddress());
475 controller()->OnDidGetWalletItems(wallet_items.Pass());
476 controller()->OnAccept();
477
478 EXPECT_EQ(0U, CountNotificationsOfType(DialogNotification::REQUIRED_ACTION));
479 EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL));
480 EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
481 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
482 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
483 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
484
485 SuggestionState suggestion_state =
486 controller()->SuggestionStateForSection(SECTION_CC_BILLING);
487 EXPECT_TRUE(suggestion_state.extra_text.empty());
488
489 base::DictionaryValue dict;
490 scoped_ptr<base::ListValue> list(new base::ListValue());
491 list->AppendString("verify_cvv");
492 dict.Set("required_action", list.release());
493 controller()->OnDidGetFullWallet(wallet::FullWallet::CreateFullWallet(dict));
494
495 EXPECT_EQ(1U, CountNotificationsOfType(DialogNotification::REQUIRED_ACTION));
496 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
497 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
498 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
499
500 suggestion_state =
501 controller()->SuggestionStateForSection(SECTION_CC_BILLING);
502 EXPECT_FALSE(suggestion_state.extra_text.empty());
503 EXPECT_EQ(
504 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
505
506 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
507 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
508
509 controller()->OnAccept();
510 }
511
434 } // namespace autofill 512 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698