| 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/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 Loading... |
| 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<std::string>& document_ids, | 93 void(const std::vector<std::string>& document_ids, |
| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 341 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 336 AcceptLegalDocuments(_, _, _)).Times(1); | 342 AcceptLegalDocuments(_, _, _)).Times(1); |
| 337 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 343 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 338 GetFullWallet(_)).Times(1); | 344 GetFullWallet(_)).Times(1); |
| 339 | 345 |
| 340 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 346 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 341 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); | 347 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); |
| 342 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 348 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 343 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 349 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 344 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 350 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 345 controller()->OnSubmit(); | 351 controller()->OnAccept(); |
| 346 } | 352 } |
| 347 | 353 |
| 348 TEST_F(AutofillDialogControllerTest, SaveAddress) { | 354 TEST_F(AutofillDialogControllerTest, SaveAddress) { |
| 349 controller()->set_is_paying_with_wallet(true); | 355 controller()->set_is_paying_with_wallet(true); |
| 350 | 356 |
| 351 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 357 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 352 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 358 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 353 SaveAddress(_, _)).Times(1); | 359 SaveAddress(_, _)).Times(1); |
| 354 | 360 |
| 355 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 361 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 356 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 362 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 357 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 363 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 358 controller()->OnSubmit(); | 364 controller()->OnAccept(); |
| 359 } | 365 } |
| 360 | 366 |
| 361 TEST_F(AutofillDialogControllerTest, SaveInstrument) { | 367 TEST_F(AutofillDialogControllerTest, SaveInstrument) { |
| 362 controller()->set_is_paying_with_wallet(true); | 368 controller()->set_is_paying_with_wallet(true); |
| 363 | 369 |
| 364 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 370 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 365 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 371 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 366 SaveInstrument(_, _, _)).Times(1); | 372 SaveInstrument(_, _, _)).Times(1); |
| 367 | 373 |
| 368 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 374 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 369 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 375 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 370 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 376 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 371 controller()->OnSubmit(); | 377 controller()->OnAccept(); |
| 372 } | 378 } |
| 373 | 379 |
| 374 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { | 380 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { |
| 375 controller()->set_is_paying_with_wallet(true); | 381 controller()->set_is_paying_with_wallet(true); |
| 376 | 382 |
| 377 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 383 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 378 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 384 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 379 SaveInstrumentAndAddress(_, _, _, _)).Times(1); | 385 SaveInstrumentAndAddress(_, _, _, _)).Times(1); |
| 380 | 386 |
| 381 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); | 387 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); |
| 382 controller()->OnSubmit(); | 388 controller()->OnAccept(); |
| 383 } | 389 } |
| 384 | 390 |
| 385 TEST_F(AutofillDialogControllerTest, Cancel) { | 391 TEST_F(AutofillDialogControllerTest, Cancel) { |
| 386 controller()->set_is_paying_with_wallet(true); | 392 controller()->set_is_paying_with_wallet(true); |
| 387 | 393 |
| 388 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); | 394 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); |
| 389 | 395 |
| 390 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); | 396 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); |
| 391 controller()->OnCancel(); | 397 controller()->OnCancel(); |
| 392 } | 398 } |
| 393 | 399 |
| 400 TEST_F(AutofillDialogControllerTest, VerifyCvv) { |
| 401 controller()->set_is_paying_with_wallet(true); |
| 402 |
| 403 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2); |
| 404 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 405 GetFullWallet(_)).Times(1); |
| 406 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
| 407 AuthenticateInstrument(_, _, _)).Times(1); |
| 408 |
| 409 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 410 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 411 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 412 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 413 controller()->OnAccept(); |
| 414 |
| 415 base::DictionaryValue dict; |
| 416 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 417 list->AppendString("verify_cvv"); |
| 418 dict.Set("required_action", list.release()); |
| 419 controller()->OnDidGetFullWallet(wallet::FullWallet::CreateFullWallet(dict)); |
| 420 |
| 421 EXPECT_TRUE(controller()->IsSubmitPausedOn(wallet::VERIFY_CVV)); |
| 422 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); |
| 423 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); |
| 424 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
| 425 EXPECT_TRUE( |
| 426 !controller()->SuggestionTextForSection(SECTION_CC_BILLING).empty()); |
| 427 EXPECT_EQ( |
| 428 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); |
| 429 |
| 430 controller()->OnAccept(); |
| 431 } |
| 432 |
| 394 } // namespace autofill | 433 } // namespace autofill |
| OLD | NEW |