Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
index 00b17ffde6d9e2730087e6fd88b7154b05896d66..a304df6596aa106041947c594172d083578a91cb 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
@@ -2285,6 +2285,9 @@ TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) { |
EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); |
} |
+// Verify that new Wallet data is fetched when the user switches away from the |
+// tab hosting the Autofill dialog and back. Also verify that the user's |
+// selection is preserved across this re-fetch. |
TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { |
// Switch into Wallet mode and initialize some Wallet data. |
SwitchToWallet(); |
@@ -2311,10 +2314,10 @@ TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { |
// Select entries other than the defaults. |
cc_billing_model->ActivatedAt(1); |
shipping_model->ActivatedAt(1); |
- // "add", "manage", and 2 suggestions. |
+ // 2 suggestions, "add", and "manage". |
ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); |
- // "use billing", "add", "manage", and 2 suggestions. |
+ // "use billing", 2 suggestions, "add", "manage". |
ASSERT_EQ(5, shipping_model->GetItemCount()); |
EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); |
@@ -2332,14 +2335,72 @@ TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { |
controller()->OnDidGetWalletItems(wallet_items.Pass()); |
// The previously selected entries should still be selected. |
- // "add", "manage", and 3 suggestions. |
+ // 3 suggestions, "add", and "manage". |
ASSERT_EQ(5, cc_billing_model->GetItemCount()); |
EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(2)); |
- // "use billing", "add", "manage", and 1 suggestion. |
+ // "use billing", 1 suggestion, "add", and "manage". |
ASSERT_EQ(4, shipping_model->GetItemCount()); |
EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); |
} |
+// Verify that if the default values change when re-fetching Wallet data, these |
+// new default values are selected in the dialog. |
+TEST_F(AutofillDialogControllerTest, |
+ ReloadWalletItemsOnActivationWithNewDefaults) { |
+ // Switch into Wallet mode and initialize some Wallet data. |
+ SwitchToWallet(); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
+ wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
+ wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); |
+ wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ |
+ // Initially, the default entries should be selected. |
+ ui::MenuModel* cc_billing_model = |
+ controller()->MenuModelForSection(SECTION_CC_BILLING); |
+ ui::MenuModel* shipping_model = |
+ controller()->MenuModelForSection(SECTION_SHIPPING); |
+ // 2 suggestions, "add", and "manage". |
+ ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
+ EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); |
+ // "use billing", 2 suggestions, "add", and "manage". |
+ ASSERT_EQ(5, shipping_model->GetItemCount()); |
+ EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); |
+ |
+ // Simulate switching away from the tab and back. This should issue a request |
+ // for wallet items. |
+ EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
+ controller()->TabActivated(); |
+ |
+ // Simulate a response that includes different default values. |
+ wallet_items = |
+ wallet::GetTestWalletItemsWithDefaultIds("new_default_instrument_id", |
+ "new_default_address_id"); |
+ scoped_ptr<wallet::Address> other_address = wallet::GetTestShippingAddress(); |
+ other_address->set_object_id("other_address_id"); |
+ scoped_ptr<wallet::Address> new_default_address = |
+ wallet::GetTestNonDefaultShippingAddress(); |
+ new_default_address->set_object_id("new_default_address_id"); |
+ |
+ wallet_items->AddInstrument( |
+ wallet::GetTestMaskedInstrumentWithId("other_instrument_id")); |
+ wallet_items->AddInstrument( |
+ wallet::GetTestMaskedInstrumentWithId("new_default_instrument_id")); |
+ wallet_items->AddAddress(new_default_address.Pass()); |
+ wallet_items->AddAddress(other_address.Pass()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ |
+ // The new default entries should be selected. |
+ // 2 suggestions, "add", and "manage". |
+ ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
+ EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); |
+ // "use billing", 2 suggestions, "add", and "manage". |
+ ASSERT_EQ(5, shipping_model->GetItemCount()); |
+ EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); |
+} |
+ |
TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { |
SwitchToWallet(); |