Index: components/autofill/core/browser/autofill_external_delegate_unittest.cc |
diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
index fab6c933fb760c0198e3496576312a874ea2694b..fb67541dcefee4a0e15ae49b9dab2f167e8b32d9 100644 |
--- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
+++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
@@ -76,6 +76,8 @@ class MockAutofillClient : public TestAutofillClient { |
MOCK_METHOD0(HideAutofillPopup, void()); |
+ MOCK_METHOD0(StartSigninFlow, void()); |
+ |
private: |
DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
}; |
@@ -91,6 +93,9 @@ class MockAutofillManager : public AutofillManager { |
MOCK_METHOD2(ShouldShowScanCreditCard, |
bool(const FormData& form, const FormFieldData& field)); |
+ MOCK_METHOD2(ShouldShowCreditCardSigninPromo, |
+ bool(const FormData& form, const FormFieldData& field)); |
+ |
MOCK_METHOD5(FillOrPreviewForm, |
void(AutofillDriver::RendererFormDataAction action, |
int query_id, |
@@ -188,6 +193,46 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
0); |
} |
+// Test that our external delegate properly adds the signin promo and its |
+// separator in the popup items. |
+TEST_F(AutofillExternalDelegateUnitTest, TestSigninPromoIsAdded) { |
+ EXPECT_CALL(*autofill_manager_, ShouldShowCreditCardSigninPromo(_, _)) |
+ .WillOnce(testing::Return(true)); |
+ |
+ IssueOnQuery(kQueryId); |
+ |
+ // The enums must be cast to ints to prevent compile errors on linux_rel. |
+ auto element_ids = testing::ElementsAre( |
+ kAutofillProfileId, |
+#if !defined(OS_ANDROID) |
+ static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
+#endif |
+ static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS), |
+#if !defined(OS_ANDROID) |
+ static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
+#endif |
+ static_cast<int>(POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO)); |
+ |
+ EXPECT_CALL(autofill_client_, |
+ ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); |
+ |
+ // This should call ShowAutofillPopup. |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = kAutofillProfileId; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
+ |
+ EXPECT_CALL( |
+ *autofill_manager_, |
+ FillOrPreviewForm(AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); |
+ EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
+ |
+ // This should trigger a call to hide the popup since we've selected an |
+ // option. |
+ external_delegate_->DidAcceptSuggestion(autofill_item[0].value, |
+ autofill_item[0].frontend_id, 0); |
+} |
+ |
// Test that data list elements for a node will appear in the Autofill popup. |
TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
IssueOnQuery(kQueryId); |
@@ -564,6 +609,15 @@ MATCHER_P3(CreditCardMatches, |
CreditCard(card_number, expiration_month, expiration_year)); |
} |
+// Test that autofill client will start the signin flow after the user accepted |
+// the suggestion to sign in. |
+TEST_F(AutofillExternalDelegateUnitTest, SigninPromoMenuItem) { |
+ EXPECT_CALL(autofill_client_, StartSigninFlow()); |
+ EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
+ external_delegate_->DidAcceptSuggestion( |
+ base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); |
+} |
+ |
// Test that autofill manager will fill the credit card form after user scans a |
// credit card. |
TEST_F(AutofillExternalDelegateUnitTest, FillCreditCardForm) { |