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

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate_unittest.cc

Issue 2473493002: [Autofill] Credit card signin promo: do not require a local suggestion first. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <memory> 5 #include <memory>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 189 EXPECT_CALL(autofill_client_, HideAutofillPopup());
190 190
191 // This should trigger a call to hide the popup since we've selected an 191 // This should trigger a call to hide the popup since we've selected an
192 // option. 192 // option.
193 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, 193 external_delegate_->DidAcceptSuggestion(autofill_item[0].value,
194 autofill_item[0].frontend_id, 194 autofill_item[0].frontend_id,
195 0); 195 0);
196 } 196 }
197 197
198 // Test that our external delegate properly adds the signin promo and its 198 // Test that our external delegate properly adds the signin promo and its
199 // separator in the popup items. 199 // separator in the popup items when there are suggestions.
200 TEST_F(AutofillExternalDelegateUnitTest, TestSigninPromoIsAdded) { 200 TEST_F(AutofillExternalDelegateUnitTest,
201 TestSigninPromoIsAdded_WithSuggestions) {
201 EXPECT_CALL(*autofill_manager_, ShouldShowCreditCardSigninPromo(_, _)) 202 EXPECT_CALL(*autofill_manager_, ShouldShowCreditCardSigninPromo(_, _))
202 .WillOnce(testing::Return(true)); 203 .WillOnce(testing::Return(true));
203 204
204 IssueOnQuery(kQueryId); 205 IssueOnQuery(kQueryId);
205 206
206 // The enums must be cast to ints to prevent compile errors on linux_rel. 207 // The enums must be cast to ints to prevent compile errors on linux_rel.
207 auto element_ids = testing::ElementsAre( 208 auto element_ids = testing::ElementsAre(
208 kAutofillProfileId, 209 kAutofillProfileId,
209 #if !defined(OS_ANDROID) 210 #if !defined(OS_ANDROID)
210 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 211 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
(...skipping 21 matching lines...) Expand all
232 *autofill_manager_, 233 *autofill_manager_,
233 FillOrPreviewForm(AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); 234 FillOrPreviewForm(AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _));
234 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 235 EXPECT_CALL(autofill_client_, HideAutofillPopup());
235 236
236 // This should trigger a call to hide the popup since we've selected an 237 // This should trigger a call to hide the popup since we've selected an
237 // option. 238 // option.
238 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, 239 external_delegate_->DidAcceptSuggestion(autofill_item[0].value,
239 autofill_item[0].frontend_id, 0); 240 autofill_item[0].frontend_id, 0);
240 } 241 }
241 242
243 // Test that our external delegate properly adds the signin promo and no
244 // separator in the dropdown, when there are no suggestions.
245 TEST_F(AutofillExternalDelegateUnitTest,
246 TestSigninPromoIsAdded_WithNoSuggestions) {
247 EXPECT_CALL(*autofill_manager_, ShouldShowCreditCardSigninPromo(_, _))
248 .WillOnce(testing::Return(true));
249
250 IssueOnQuery(kQueryId);
251
252 // The enums must be cast to ints to prevent compile errors on linux_rel.
253 auto element_ids = testing::ElementsAre(
254 static_cast<int>(POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO));
255
256 EXPECT_CALL(autofill_client_,
257 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _));
258
259 base::UserActionTester user_action_tester;
260
261 // This should call ShowAutofillPopup.
262 std::vector<Suggestion> items;
263 external_delegate_->OnSuggestionsReturned(kQueryId, items);
264 EXPECT_EQ(1, user_action_tester.GetActionCount(
265 "Signin_Impression_FromAutofillDropdown"));
266
267 EXPECT_CALL(autofill_client_, StartSigninFlow());
268 EXPECT_CALL(autofill_client_, HideAutofillPopup());
269
270 // This should trigger a call to start the signin flow and hide the popup
271 // since we've selected the sign-in promo option.
272 external_delegate_->DidAcceptSuggestion(
273 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0);
274 }
275
242 // Test that data list elements for a node will appear in the Autofill popup. 276 // Test that data list elements for a node will appear in the Autofill popup.
243 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { 277 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
244 IssueOnQuery(kQueryId); 278 IssueOnQuery(kQueryId);
245 279
246 std::vector<base::string16> data_list_items; 280 std::vector<base::string16> data_list_items;
247 data_list_items.push_back(base::string16()); 281 data_list_items.push_back(base::string16());
248 282
249 EXPECT_CALL( 283 EXPECT_CALL(
250 autofill_client_, 284 autofill_client_,
251 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); 285 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 RendererShouldFillFieldWithValue(dummy_string)); 689 RendererShouldFillFieldWithValue(dummy_string));
656 base::HistogramTester histogram_tester; 690 base::HistogramTester histogram_tester;
657 external_delegate_->DidAcceptSuggestion(dummy_string, 691 external_delegate_->DidAcceptSuggestion(dummy_string,
658 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, 692 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY,
659 0); 693 0);
660 histogram_tester.ExpectUniqueSample( 694 histogram_tester.ExpectUniqueSample(
661 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); 695 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1);
662 } 696 }
663 697
664 } // namespace autofill 698 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698