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 d47e9914d6638003bccc819885733829f779d88b..036816912e5ca06c2721f8aaeaf24de4054a1130 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc |
@@ -52,7 +52,6 @@ class TestAutofillDialogView : public AutofillDialogView { |
OVERRIDE {} |
virtual string16 GetCvc() OVERRIDE { return string16(); } |
virtual bool UseBillingForShipping() OVERRIDE { return false; } |
- virtual bool SaveDetailsInWallet() OVERRIDE { return false; } |
virtual bool SaveDetailsLocally() OVERRIDE { return false; } |
virtual const content::NavigationController* ShowSignIn() OVERRIDE { |
return NULL; |
@@ -143,7 +142,8 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { |
metric_logger_(metric_logger), |
ALLOW_THIS_IN_INITIALIZER_LIST(test_wallet_client_( |
Profile::FromBrowserContext(contents->GetBrowserContext())-> |
- GetRequestContext(), this)) {} |
+ GetRequestContext(), this)), |
+ is_first_run_(true) {} |
virtual ~TestAutofillDialogController() {} |
virtual AutofillDialogView* CreateView() OVERRIDE { |
@@ -166,6 +166,8 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { |
return &test_wallet_client_; |
} |
+ void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } |
+ |
protected: |
virtual PersonalDataManager* GetManager() OVERRIDE { |
return &test_manager_; |
@@ -175,6 +177,10 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { |
return &test_wallet_client_; |
} |
+ virtual bool IsFirstRun() const OVERRIDE { |
+ return is_first_run_; |
+ } |
+ |
private: |
// To specify our own metric logger. |
virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
@@ -184,6 +190,7 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { |
const AutofillMetrics& metric_logger_; |
TestPersonalDataManager test_manager_; |
testing::NiceMock<TestWalletClient> test_wallet_client_; |
+ bool is_first_run_; |
DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
}; |
@@ -255,7 +262,8 @@ class AutofillDialogControllerTest : public testing::Test { |
} |
void SetUpWallet() { |
- controller()->MenuModelForAccountChooser()->ActivatedAt(0); |
+ controller()->MenuModelForAccountChooser()->ActivatedAt( |
+ AccountChooserModel::kWalletItemId); |
controller()->OnUserNameFetchSuccess("user@example.com"); |
} |
@@ -508,10 +516,6 @@ TEST_F(AutofillDialogControllerTest, VerifyCvv) { |
EXPECT_FALSE( |
NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
- const std::vector<DialogNotification>& notifications = |
- NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
- EXPECT_FALSE(notifications.front().interactive()); |
- |
EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); |
EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); |
EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
@@ -568,8 +572,8 @@ TEST_F(AutofillDialogControllerTest, ChangeAccountDuringSubmit) { |
ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
ASSERT_TRUE(account_menu); |
ASSERT_GE(2, account_menu->GetItemCount()); |
- account_menu->ActivatedAt(0); |
- account_menu->ActivatedAt(1); |
+ account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
+ account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
@@ -617,11 +621,103 @@ TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { |
ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
ASSERT_TRUE(account_menu); |
ASSERT_GE(2, account_menu->GetItemCount()); |
- account_menu->ActivatedAt(0); |
- account_menu->ActivatedAt(1); |
+ account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
+ account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
} |
+TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { |
+ SetUpWallet(); |
+ |
+ controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
+ |
+ EXPECT_EQ(1U, NotificationsOfType( |
+ DialogNotification::WALLET_ERROR).size()); |
+ |
+ // No promos or usage confirmations should show if there was a Wallet error. |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
+} |
+ |
+TEST_F(AutofillDialogControllerTest, WalletDetailsExplanation) { |
+ SetUpWallet(); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
+ wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ |
+ // Explanatory messages and usage confirmations are mutually exclusive. |
+ EXPECT_EQ(1U, NotificationsOfType( |
+ DialogNotification::EXPLANATORY_MESSAGE).size()); |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
+ |
+ // Switch to using Autofill, no explanatory message should show. |
+ ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
+ account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::EXPLANATORY_MESSAGE).empty()); |
+ |
+ // Switch to Wallet, pretend this isn't first run. No message should show. |
+ account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
+ controller()->set_is_first_run(false); |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::EXPLANATORY_MESSAGE).empty()); |
+} |
+ |
+TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { |
+ SetUpWallet(); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ |
+ std::vector<DialogNotification> notifications = |
+ NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
+ EXPECT_EQ(1U, notifications.size()); |
+ EXPECT_TRUE(notifications.front().checked()); |
+ EXPECT_TRUE(notifications.front().interactive()); |
+ |
+ // Explanatory messages and usage confirmations are mutually exclusive. |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::EXPLANATORY_MESSAGE).empty()); |
+ |
+ // Using Autofill on second run, show an interactive, unchecked checkbox. |
+ ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); |
+ account_model->ActivatedAt(AccountChooserModel::kAutofillItemId); |
+ controller()->set_is_first_run(false); |
+ |
+ notifications = |
+ NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
+ EXPECT_EQ(1U, notifications.size()); |
+ EXPECT_FALSE(notifications.front().checked()); |
+ EXPECT_TRUE(notifications.front().interactive()); |
+ |
+ // Notifications shouldn't be interactive while submitting. |
+ account_model->ActivatedAt(AccountChooserModel::kWalletItemId); |
+ controller()->OnAccept(); |
+ EXPECT_FALSE(NotificationsOfType( |
+ DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); |
+} |
+ |
Evan Stade
2013/04/10 04:13:09
could you add brief descriptions of what each test
Dan Beam
2013/04/10 04:51:59
Done.
|
+TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { |
+ SetUpWallet(); |
+ controller()->set_is_first_run(false); |
+ |
+ scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
+ wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
+ wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
+ controller()->OnDidGetWalletItems(wallet_items.Pass()); |
+ |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::EXPLANATORY_MESSAGE).empty()); |
+ EXPECT_TRUE(NotificationsOfType( |
+ DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
+} |
+ |
} // namespace autofill |