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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 EXPECT_EQ(4, | 1421 EXPECT_EQ(4, |
1422 controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); | 1422 controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); |
1423 // "add" | 1423 // "add" |
1424 EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> | 1424 EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> |
1425 IsItemCheckedAt(2)); | 1425 IsItemCheckedAt(2)); |
1426 } | 1426 } |
1427 | 1427 |
1428 TEST_F(AutofillDialogControllerTest, SaveAddress) { | 1428 TEST_F(AutofillDialogControllerTest, SaveAddress) { |
1429 EXPECT_CALL(*controller()->GetView(), ModelChanged()); | 1429 EXPECT_CALL(*controller()->GetView(), ModelChanged()); |
1430 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1430 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1431 SaveToWalletMock(testing::IsNull(), testing::NotNull())); | 1431 SaveToWalletMock(testing::IsNull(), |
| 1432 testing::NotNull(), |
| 1433 testing::IsNull(), |
| 1434 testing::IsNull())); |
1432 | 1435 |
1433 scoped_ptr<wallet::WalletItems> wallet_items = | 1436 scoped_ptr<wallet::WalletItems> wallet_items = |
1434 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1437 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1435 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1438 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1436 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1439 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1437 // If there is no shipping address in wallet, it will default to | 1440 // If there is no shipping address in wallet, it will default to |
1438 // "same-as-billing" instead of "add-new-item". "same-as-billing" is covered | 1441 // "same-as-billing" instead of "add-new-item". "same-as-billing" is covered |
1439 // by the following tests. The penultimate item in the menu is "add-new-item". | 1442 // by the following tests. The penultimate item in the menu is "add-new-item". |
1440 ui::MenuModel* shipping_model = | 1443 ui::MenuModel* shipping_model = |
1441 controller()->MenuModelForSection(SECTION_SHIPPING); | 1444 controller()->MenuModelForSection(SECTION_SHIPPING); |
1442 shipping_model->ActivatedAt(shipping_model->GetItemCount() - 2); | 1445 shipping_model->ActivatedAt(shipping_model->GetItemCount() - 2); |
1443 | 1446 |
1444 AutofillProfile test_profile(test::GetVerifiedProfile()); | 1447 AutofillProfile test_profile(test::GetVerifiedProfile()); |
1445 FillInputs(SECTION_SHIPPING, test_profile); | 1448 FillInputs(SECTION_SHIPPING, test_profile); |
1446 | 1449 |
1447 AcceptAndLoadFakeFingerprint(); | 1450 AcceptAndLoadFakeFingerprint(); |
1448 } | 1451 } |
1449 | 1452 |
1450 TEST_F(AutofillDialogControllerTest, SaveInstrument) { | 1453 TEST_F(AutofillDialogControllerTest, SaveInstrument) { |
1451 EXPECT_CALL(*controller()->GetView(), ModelChanged()); | 1454 EXPECT_CALL(*controller()->GetView(), ModelChanged()); |
1452 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1455 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1453 SaveToWalletMock(testing::NotNull(), testing::IsNull())); | 1456 SaveToWalletMock(testing::NotNull(), |
| 1457 testing::IsNull(), |
| 1458 testing::IsNull(), |
| 1459 testing::IsNull())); |
1454 | 1460 |
1455 FillCCBillingInputs(); | 1461 FillCCBillingInputs(); |
1456 scoped_ptr<wallet::WalletItems> wallet_items = | 1462 scoped_ptr<wallet::WalletItems> wallet_items = |
1457 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1463 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1458 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1464 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1459 SubmitWithWalletItems(wallet_items.Pass()); | 1465 SubmitWithWalletItems(wallet_items.Pass()); |
1460 } | 1466 } |
1461 | 1467 |
1462 TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) { | 1468 TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) { |
1463 EXPECT_CALL(*controller()->GetView(), ModelChanged()); | 1469 EXPECT_CALL(*controller()->GetView(), ModelChanged()); |
1464 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1470 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1465 SaveToWalletMock(testing::NotNull(), testing::IsNull())); | 1471 SaveToWalletMock(testing::NotNull(), |
| 1472 testing::IsNull(), |
| 1473 testing::IsNull(), |
| 1474 testing::IsNull())); |
1466 | 1475 |
1467 FillCCBillingInputs(); | 1476 FillCCBillingInputs(); |
1468 scoped_ptr<wallet::WalletItems> wallet_items = | 1477 scoped_ptr<wallet::WalletItems> wallet_items = |
1469 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1478 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1470 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 1479 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
1471 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); | 1480 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); |
1472 SubmitWithWalletItems(wallet_items.Pass()); | 1481 SubmitWithWalletItems(wallet_items.Pass()); |
1473 } | 1482 } |
1474 | 1483 |
1475 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { | 1484 TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { |
1476 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1485 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1477 SaveToWalletMock(testing::NotNull(), testing::NotNull())); | 1486 SaveToWalletMock(testing::NotNull(), |
| 1487 testing::NotNull(), |
| 1488 testing::IsNull(), |
| 1489 testing::IsNull())); |
1478 | 1490 |
1479 FillCCBillingInputs(); | 1491 FillCCBillingInputs(); |
1480 scoped_ptr<wallet::WalletItems> wallet_items = | 1492 scoped_ptr<wallet::WalletItems> wallet_items = |
1481 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1493 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1482 SubmitWithWalletItems(wallet_items.Pass()); | 1494 SubmitWithWalletItems(wallet_items.Pass()); |
1483 } | 1495 } |
1484 | 1496 |
1485 MATCHER(IsUpdatingExistingData, "updating existing Wallet data") { | 1497 MATCHER(IsUpdatingExistingData, "updating existing Wallet data") { |
1486 return !arg->object_id().empty(); | 1498 return !arg->object_id().empty(); |
1487 } | 1499 } |
1488 | 1500 |
1489 MATCHER(UsesLocalBillingAddress, "uses the local billing address") { | 1501 MATCHER(UsesLocalBillingAddress, "uses the local billing address") { |
1490 return arg->address_line_1() == ASCIIToUTF16(kEditedBillingAddress); | 1502 return arg->address_line_1() == ASCIIToUTF16(kEditedBillingAddress); |
1491 } | 1503 } |
1492 | 1504 |
1493 // Tests that when using billing address for shipping, and there is no exact | 1505 // Tests that when using billing address for shipping, and there is no exact |
1494 // matched shipping address, then a shipping address should be added. | 1506 // matched shipping address, then a shipping address should be added. |
1495 TEST_F(AutofillDialogControllerTest, BillingForShipping) { | 1507 TEST_F(AutofillDialogControllerTest, BillingForShipping) { |
1496 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1508 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1497 SaveToWalletMock(testing::IsNull(), testing::NotNull())); | 1509 SaveToWalletMock(testing::IsNull(), |
| 1510 testing::NotNull(), |
| 1511 testing::IsNull(), |
| 1512 testing::IsNull())); |
1498 | 1513 |
1499 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 1514 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
1500 // Select "Same as billing" in the address menu. | 1515 // Select "Same as billing" in the address menu. |
1501 UseBillingForShipping(); | 1516 UseBillingForShipping(); |
1502 | 1517 |
1503 AcceptAndLoadFakeFingerprint(); | 1518 AcceptAndLoadFakeFingerprint(); |
1504 } | 1519 } |
1505 | 1520 |
1506 // Tests that when using billing address for shipping, and there is an exact | 1521 // Tests that when using billing address for shipping, and there is an exact |
1507 // matched shipping address, then a shipping address should not be added. | 1522 // matched shipping address, then a shipping address should not be added. |
1508 TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) { | 1523 TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) { |
1509 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1524 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1510 SaveToWalletMock(_, _)).Times(0); | 1525 SaveToWalletMock(_, _, _, _)).Times(0); |
1511 | 1526 |
1512 scoped_ptr<wallet::WalletItems> wallet_items = | 1527 scoped_ptr<wallet::WalletItems> wallet_items = |
1513 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 1528 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
1514 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument = | 1529 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument = |
1515 wallet::GetTestMaskedInstrument(); | 1530 wallet::GetTestMaskedInstrument(); |
1516 // Copy billing address as shipping address, and assign an id to it. | 1531 // Copy billing address as shipping address, and assign an id to it. |
1517 scoped_ptr<wallet::Address> shipping_address( | 1532 scoped_ptr<wallet::Address> shipping_address( |
1518 new wallet::Address(instrument->address())); | 1533 new wallet::Address(instrument->address())); |
1519 shipping_address->set_object_id("shipping_address_id"); | 1534 shipping_address->set_object_id("shipping_address_id"); |
1520 wallet_items->AddAddress(shipping_address.Pass()); | 1535 wallet_items->AddAddress(shipping_address.Pass()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); | 1567 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
1553 | 1568 |
1554 if (outputs[type].empty()) | 1569 if (outputs[type].empty()) |
1555 outputs[type] = full_card.GetInfo(AutofillType(type), "en-US"); | 1570 outputs[type] = full_card.GetInfo(AutofillType(type), "en-US"); |
1556 } | 1571 } |
1557 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 1572 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
1558 | 1573 |
1559 controller()->OnAccept(); | 1574 controller()->OnAccept(); |
1560 | 1575 |
1561 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1576 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1562 SaveToWalletMock(testing::NotNull(), UsesLocalBillingAddress())); | 1577 SaveToWalletMock(testing::NotNull(), |
| 1578 UsesLocalBillingAddress(), |
| 1579 testing::IsNull(), |
| 1580 testing::IsNull())); |
1563 AcceptAndLoadFakeFingerprint(); | 1581 AcceptAndLoadFakeFingerprint(); |
1564 } | 1582 } |
1565 | 1583 |
1566 TEST_F(AutofillDialogControllerTest, CancelNoSave) { | 1584 TEST_F(AutofillDialogControllerTest, CancelNoSave) { |
1567 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 1585 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
1568 SaveToWalletMock(_, _)).Times(0); | 1586 SaveToWalletMock(_, _, _, _)).Times(0); |
1569 | 1587 |
1570 EXPECT_CALL(*controller()->GetView(), ModelChanged()); | 1588 EXPECT_CALL(*controller()->GetView(), ModelChanged()); |
1571 | 1589 |
1572 controller()->OnDidGetWalletItems( | 1590 controller()->OnDidGetWalletItems( |
1573 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | 1591 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
1574 controller()->OnCancel(); | 1592 controller()->OnCancel(); |
1575 } | 1593 } |
1576 | 1594 |
1577 // Checks that clicking the Manage menu item opens a new tab with a different | 1595 // Checks that clicking the Manage menu item opens a new tab with a different |
1578 // URL for Wallet and Autofill. | 1596 // URL for Wallet and Autofill. |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2646 controller()->OnDidGetWalletItems( | 2664 controller()->OnDidGetWalletItems( |
2647 wallet::GetTestWalletItemsWithRequiredAction( | 2665 wallet::GetTestWalletItemsWithRequiredAction( |
2648 wallet::PASSIVE_GAIA_AUTH)); | 2666 wallet::PASSIVE_GAIA_AUTH)); |
2649 EXPECT_TRUE(controller()->ShouldShowSpinner()); | 2667 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
2650 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( | 2668 controller()->OnPassiveSigninFailure(GoogleServiceAuthError( |
2651 GoogleServiceAuthError::NONE)); | 2669 GoogleServiceAuthError::NONE)); |
2652 EXPECT_FALSE(controller()->ShouldShowSpinner()); | 2670 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
2653 } | 2671 } |
2654 | 2672 |
2655 } // namespace autofill | 2673 } // namespace autofill |
OLD | NEW |