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

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

Powered by Google App Engine
This is Rietveld 408576698