Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: components/autofill/core/browser/autofill_external_delegate_unittest.cc

Issue 2124343002: [Autofill] Implement Credit Card Signin Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.cc ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698