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