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

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

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 2 Created 6 years 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 17 matching lines...) Expand all
28 namespace autofill { 28 namespace autofill {
29 29
30 namespace { 30 namespace {
31 31
32 // A constant value to use as the Autofill query ID. 32 // A constant value to use as the Autofill query ID.
33 const int kQueryId = 5; 33 const int kQueryId = 5;
34 34
35 // A constant value to use as an Autofill profile ID. 35 // A constant value to use as an Autofill profile ID.
36 const int kAutofillProfileId = 1; 36 const int kAutofillProfileId = 1;
37 37
38 // Gmock matcher that allows checking the frontend IDs of a sequence of
39 // suggestions. This wraps a GMock container matcher, converts the suggestion
40 // frontend IDs to a vector of ints, and then runs the container matcher
41 // against the result to test an argument. See SuggestionVectorIdsAre() below.
42 class SuggestionVectorIdsAreMatcher
43 : public testing::MatcherInterface<const std::vector<Suggestion>&> {
44 public:
45 typedef std::vector<int> Container;
46 typedef testing::Matcher<Container> ContainerMatcher;
47
48 explicit SuggestionVectorIdsAreMatcher(const ContainerMatcher& seq_matcher)
49 : container_matcher_(seq_matcher) {
50 }
51
52 virtual bool MatchAndExplain(const std::vector<Suggestion>& suggestions,
53 testing::MatchResultListener* listener) const {
54 Container frontend_ids;
55 for (const auto& suggestion : suggestions)
56 frontend_ids.push_back(suggestion.frontend_id);
57 return container_matcher_.MatchAndExplain(frontend_ids, listener);
58 }
59
60 virtual void DescribeTo(::std::ostream* os) const {
61 container_matcher_.DescribeTo(os);
62 }
63
64 virtual void DescribeNegationTo(::std::ostream* os) const {
65 container_matcher_.DescribeNegationTo(os);
66 }
67
68 private:
69 ContainerMatcher container_matcher_;
70 };
71
72 // Use this matcher to compare a sequence vector's IDs to a list. In an
73 // EXPECT_CALL statement, use the following for an vector<Suggestion> argument
74 // to compare the IDs against a constant list:
75 // SuggestionVectorIdsAre(testing::ElementsAre(1, 2, 3, 4))
76 template<class EltsAreMatcher>
77 inline testing::Matcher<const std::vector<Suggestion>&>
78 SuggestionVectorIdsAre(const EltsAreMatcher& elts_are_matcher) {
79 return MakeMatcher(
80 new SuggestionVectorIdsAreMatcher(elts_are_matcher));
81 }
82
38 class MockAutofillDriver : public TestAutofillDriver { 83 class MockAutofillDriver : public TestAutofillDriver {
39 public: 84 public:
40 MockAutofillDriver() {} 85 MockAutofillDriver() {}
41 // Mock methods to enable testability. 86 // Mock methods to enable testability.
42 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, 87 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion,
43 void(const base::string16&)); 88 void(const base::string16&));
44 MOCK_METHOD0(RendererShouldClearFilledForm, void()); 89 MOCK_METHOD0(RendererShouldClearFilledForm, void());
45 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); 90 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
46 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&)); 91 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&));
47 MOCK_METHOD1(RendererShouldPreviewFieldWithValue, 92 MOCK_METHOD1(RendererShouldPreviewFieldWithValue,
48 void(const base::string16&)); 93 void(const base::string16&));
49 94
50 private: 95 private:
51 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 96 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
52 }; 97 };
53 98
54 class MockAutofillClient : public autofill::TestAutofillClient { 99 class MockAutofillClient : public autofill::TestAutofillClient {
55 public: 100 public:
56 MockAutofillClient() {} 101 MockAutofillClient() {}
57 102
58 MOCK_METHOD1(ScanCreditCard, 103 MOCK_METHOD1(ScanCreditCard,
59 void(const CreditCardScanCallback& callbacK)); 104 void(const CreditCardScanCallback& callbacK));
60 105
61 MOCK_METHOD7(ShowAutofillPopup, 106 MOCK_METHOD4(ShowAutofillPopup,
62 void(const gfx::RectF& element_bounds, 107 void(const gfx::RectF& element_bounds,
63 base::i18n::TextDirection text_direction, 108 base::i18n::TextDirection text_direction,
64 const std::vector<base::string16>& values, 109 const std::vector<Suggestion>& suggestions,
65 const std::vector<base::string16>& labels,
66 const std::vector<base::string16>& icons,
67 const std::vector<int>& identifiers,
68 base::WeakPtr<AutofillPopupDelegate> delegate)); 110 base::WeakPtr<AutofillPopupDelegate> delegate));
69 111
70 MOCK_METHOD2(UpdateAutofillPopupDataListValues, 112 MOCK_METHOD2(UpdateAutofillPopupDataListValues,
71 void(const std::vector<base::string16>& values, 113 void(const std::vector<base::string16>& values,
72 const std::vector<base::string16>& lables)); 114 const std::vector<base::string16>& lables));
73 115
74 MOCK_METHOD0(HideAutofillPopup, void()); 116 MOCK_METHOD0(HideAutofillPopup, void());
75 117
76 private: 118 private:
77 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); 119 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 186
145 // Test that our external delegate called the virtual methods at the right time. 187 // Test that our external delegate called the virtual methods at the right time.
146 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 188 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
147 IssueOnQuery(kQueryId); 189 IssueOnQuery(kQueryId);
148 190
149 // The enums must be cast to ints to prevent compile errors on linux_rel. 191 // The enums must be cast to ints to prevent compile errors on linux_rel.
150 EXPECT_CALL( 192 EXPECT_CALL(
151 autofill_client_, 193 autofill_client_,
152 ShowAutofillPopup(_, 194 ShowAutofillPopup(_,
153 _, 195 _,
154 _, 196 SuggestionVectorIdsAre(testing::ElementsAre(
155 _,
156 _,
157 testing::ElementsAre(
158 kAutofillProfileId, 197 kAutofillProfileId,
159 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 198 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
160 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), 199 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))),
161 _)); 200 _));
162 201
163 // This should call ShowAutofillPopup. 202 // This should call ShowAutofillPopup.
164 std::vector<base::string16> autofill_item; 203 std::vector<Suggestion> autofill_item;
165 autofill_item.push_back(base::string16()); 204 autofill_item.push_back(Suggestion());
166 std::vector<int> autofill_ids; 205 autofill_item[0].frontend_id = kAutofillProfileId;
167 autofill_ids.push_back(kAutofillProfileId); 206 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
168 external_delegate_->OnSuggestionsReturned(kQueryId,
169 autofill_item,
170 autofill_item,
171 autofill_item,
172 autofill_ids);
173 207
174 EXPECT_CALL(*autofill_manager_, 208 EXPECT_CALL(*autofill_manager_,
175 FillOrPreviewForm( 209 FillOrPreviewForm(
176 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); 210 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _));
177 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 211 EXPECT_CALL(autofill_client_, HideAutofillPopup());
178 212
179 // This should trigger a call to hide the popup since we've selected an 213 // This should trigger a call to hide the popup since we've selected an
180 // option. 214 // option.
181 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); 215 external_delegate_->DidAcceptSuggestion(autofill_item[0].value,
216 autofill_item[0].frontend_id);
182 } 217 }
183 218
184 // Test that data list elements for a node will appear in the Autofill popup. 219 // Test that data list elements for a node will appear in the Autofill popup.
185 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { 220 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
186 IssueOnQuery(kQueryId); 221 IssueOnQuery(kQueryId);
187 222
188 std::vector<base::string16> data_list_items; 223 std::vector<base::string16> data_list_items;
189 data_list_items.push_back(base::string16()); 224 data_list_items.push_back(base::string16());
190 225
191 EXPECT_CALL( 226 EXPECT_CALL(
192 autofill_client_, 227 autofill_client_,
193 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); 228 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
194 229
195 external_delegate_->SetCurrentDataListValues(data_list_items, 230 external_delegate_->SetCurrentDataListValues(data_list_items,
196 data_list_items); 231 data_list_items);
197 232
198 // The enums must be cast to ints to prevent compile errors on linux_rel. 233 // The enums must be cast to ints to prevent compile errors on linux_rel.
199 EXPECT_CALL( 234 EXPECT_CALL(
200 autofill_client_, 235 autofill_client_,
201 ShowAutofillPopup(_, 236 ShowAutofillPopup(_,
202 _, 237 _,
203 _, 238 SuggestionVectorIdsAre(testing::ElementsAre(
204 _,
205 _,
206 testing::ElementsAre(
207 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), 239 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
208 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 240 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
209 kAutofillProfileId, 241 kAutofillProfileId,
210 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 242 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
211 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), 243 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))),
212 _)); 244 _));
213 245
214 // This should call ShowAutofillPopup. 246 // This should call ShowAutofillPopup.
215 std::vector<base::string16> autofill_item; 247 std::vector<Suggestion> autofill_item;
216 autofill_item.push_back(base::string16()); 248 autofill_item.push_back(Suggestion());
217 std::vector<int> autofill_ids; 249 autofill_item[0].frontend_id = kAutofillProfileId;
218 autofill_ids.push_back(kAutofillProfileId); 250 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
219 external_delegate_->OnSuggestionsReturned(kQueryId,
220 autofill_item,
221 autofill_item,
222 autofill_item,
223 autofill_ids);
224 251
225 // Try calling OnSuggestionsReturned with no Autofill values and ensure 252 // Try calling OnSuggestionsReturned with no Autofill values and ensure
226 // the datalist items are still shown. 253 // the datalist items are still shown.
227 // The enum must be cast to an int to prevent compile errors on linux_rel. 254 // The enum must be cast to an int to prevent compile errors on linux_rel.
228 EXPECT_CALL( 255 EXPECT_CALL(
229 autofill_client_, 256 autofill_client_,
230 ShowAutofillPopup( 257 ShowAutofillPopup(
231 _, 258 _,
232 _, 259 _,
233 _, 260 SuggestionVectorIdsAre(testing::ElementsAre(
234 _, 261 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY))),
235 _,
236 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)),
237 _)); 262 _));
238 263
239 autofill_item = std::vector<base::string16>(); 264 autofill_item.clear();
240 autofill_ids = std::vector<int>(); 265 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
241 external_delegate_->OnSuggestionsReturned(kQueryId,
242 autofill_item,
243 autofill_item,
244 autofill_item,
245 autofill_ids);
246 } 266 }
247 267
248 // Test that datalist values can get updated while a popup is showing. 268 // Test that datalist values can get updated while a popup is showing.
249 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { 269 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) {
250 IssueOnQuery(kQueryId); 270 IssueOnQuery(kQueryId);
251 271
252 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) 272 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _))
253 .Times(0); 273 .Times(0);
254 274
255 // Make sure just setting the data list values doesn't cause the popup to 275 // Make sure just setting the data list values doesn't cause the popup to
256 // appear. 276 // appear.
257 std::vector<base::string16> data_list_items; 277 std::vector<base::string16> data_list_items;
258 data_list_items.push_back(base::string16()); 278 data_list_items.push_back(base::string16());
259 279
260 EXPECT_CALL( 280 EXPECT_CALL(
261 autofill_client_, 281 autofill_client_,
262 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); 282 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
263 283
264 external_delegate_->SetCurrentDataListValues(data_list_items, 284 external_delegate_->SetCurrentDataListValues(data_list_items,
265 data_list_items); 285 data_list_items);
266 286
267 // The enums must be cast to ints to prevent compile errors on linux_rel. 287 // The enums must be cast to ints to prevent compile errors on linux_rel.
268 EXPECT_CALL( 288 EXPECT_CALL(
269 autofill_client_, 289 autofill_client_,
270 ShowAutofillPopup(_, 290 ShowAutofillPopup(_,
271 _, 291 _,
272 _, 292 SuggestionVectorIdsAre(testing::ElementsAre(
273 _,
274 _,
275 testing::ElementsAre(
276 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), 293 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
277 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 294 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
278 kAutofillProfileId, 295 kAutofillProfileId,
279 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 296 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
280 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), 297 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))),
281 _)); 298 _));
282 299
283 // Ensure the popup is displayed. 300 // Ensure the popup is displayed.
284 std::vector<base::string16> autofill_item; 301 std::vector<Suggestion> autofill_item;
285 autofill_item.push_back(base::string16()); 302 autofill_item.push_back(Suggestion());
286 std::vector<int> autofill_ids; 303 autofill_item[0].frontend_id = kAutofillProfileId;
287 autofill_ids.push_back(kAutofillProfileId); 304 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
288 external_delegate_->OnSuggestionsReturned(kQueryId,
289 autofill_item,
290 autofill_item,
291 autofill_item,
292 autofill_ids);
293 305
294 // This would normally get called from ShowAutofillPopup, but it is mocked so 306 // This would normally get called from ShowAutofillPopup, but it is mocked so
295 // we need to call OnPopupShown ourselves. 307 // we need to call OnPopupShown ourselves.
296 external_delegate_->OnPopupShown(); 308 external_delegate_->OnPopupShown();
297 309
298 // Update the current data list and ensure the popup is updated. 310 // Update the current data list and ensure the popup is updated.
299 data_list_items.push_back(base::string16()); 311 data_list_items.push_back(base::string16());
300 312
301 // The enums must be cast to ints to prevent compile errors on linux_rel. 313 // The enums must be cast to ints to prevent compile errors on linux_rel.
302 EXPECT_CALL( 314 EXPECT_CALL(
303 autofill_client_, 315 autofill_client_,
304 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); 316 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
305 317
306 external_delegate_->SetCurrentDataListValues(data_list_items, 318 external_delegate_->SetCurrentDataListValues(data_list_items,
307 data_list_items); 319 data_list_items);
308 } 320 }
309 321
310 // Test that the Autofill popup is able to display warnings explaining why 322 // Test that the Autofill popup is able to display warnings explaining why
311 // Autofill is disabled for a website. 323 // Autofill is disabled for a website.
312 // Regression test for http://crbug.com/247880 324 // Regression test for http://crbug.com/247880
313 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { 325 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) {
314 IssueOnQuery(kQueryId); 326 IssueOnQuery(kQueryId);
315 327
316 // The enums must be cast to ints to prevent compile errors on linux_rel. 328 // The enums must be cast to ints to prevent compile errors on linux_rel.
317 EXPECT_CALL( 329 EXPECT_CALL(
318 autofill_client_, 330 autofill_client_,
319 ShowAutofillPopup( 331 ShowAutofillPopup(
320 _, 332 _,
321 _, 333 _,
322 _, 334 SuggestionVectorIdsAre(testing::ElementsAre(
323 _, 335 static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE))),
324 _,
325 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)),
326 _)); 336 _));
327 337
328 // This should call ShowAutofillPopup. 338 // This should call ShowAutofillPopup.
329 std::vector<base::string16> autofill_item; 339 std::vector<Suggestion> autofill_item;
330 autofill_item.push_back(base::string16()); 340 autofill_item.push_back(Suggestion());
331 std::vector<int> autofill_ids; 341 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE;
332 autofill_ids.push_back(POPUP_ITEM_ID_WARNING_MESSAGE); 342 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
333 external_delegate_->OnSuggestionsReturned(kQueryId,
334 autofill_item,
335 autofill_item,
336 autofill_item,
337 autofill_ids);
338 } 343 }
339 344
340 // Test that the Autofill popup doesn't display a warning explaining why 345 // Test that the Autofill popup doesn't display a warning explaining why
341 // Autofill is disabled for a website when there are no Autofill suggestions. 346 // Autofill is disabled for a website when there are no Autofill suggestions.
342 // Regression test for http://crbug.com/105636 347 // Regression test for http://crbug.com/105636
343 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { 348 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) {
344 // This test only makes sense if we're respecting autocomplete="off". 349 // This test only makes sense if we're respecting autocomplete="off".
345 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 350 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
346 switches::kRespectAutocompleteOffForAutofill)) 351 switches::kRespectAutocompleteOffForAutofill))
347 return; 352 return;
348 353
349 const FormData form; 354 const FormData form;
350 FormFieldData field; 355 FormFieldData field;
351 field.is_focusable = true; 356 field.is_focusable = true;
352 field.should_autocomplete = false; 357 field.should_autocomplete = false;
353 const gfx::RectF element_bounds; 358 const gfx::RectF element_bounds;
354 359
355 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); 360 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true);
356 361
357 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) 362 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _))
358 .Times(0); 363 .Times(0);
359 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1); 364 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1);
360 365
361 // This should not call ShowAutofillPopup. 366 // This should not call ShowAutofillPopup.
362 std::vector<base::string16> autofill_item; 367 std::vector<Suggestion> autofill_item;
363 autofill_item.push_back(base::string16()); 368 autofill_item.push_back(Suggestion());
364 std::vector<int> autofill_ids; 369 autofill_item[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
365 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 370 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
366 external_delegate_->OnSuggestionsReturned(kQueryId,
367 autofill_item,
368 autofill_item,
369 autofill_item,
370 autofill_ids);
371 } 371 }
372 372
373 // Test that the Autofill delegate doesn't try and fill a form with a 373 // Test that the Autofill delegate doesn't try and fill a form with a
374 // negative unique id. 374 // negative unique id.
375 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 375 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
376 // Ensure it doesn't try to preview the negative id. 376 // Ensure it doesn't try to preview the negative id.
377 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); 377 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0);
378 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 378 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
379 external_delegate_->DidSelectSuggestion(base::string16(), -1); 379 external_delegate_->DidSelectSuggestion(base::string16(), -1);
380 380
(...skipping 22 matching lines...) Expand all
403 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 403 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
404 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( 404 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue(
405 ASCIIToUTF16("baz foo"))); 405 ASCIIToUTF16("baz foo")));
406 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 406 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
407 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 407 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
408 } 408 }
409 409
410 // Test that the popup is hidden once we are done editing the autofill field. 410 // Test that the popup is hidden once we are done editing the autofill field.
411 TEST_F(AutofillExternalDelegateUnitTest, 411 TEST_F(AutofillExternalDelegateUnitTest,
412 ExternalDelegateHidePopupAfterEditing) { 412 ExternalDelegateHidePopupAfterEditing) {
413 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); 413 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _));
414 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 414 autofill::GenerateTestAutofillPopup(external_delegate_.get());
415 415
416 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 416 EXPECT_CALL(autofill_client_, HideAutofillPopup());
417 external_delegate_->DidEndTextFieldEditing(); 417 external_delegate_->DidEndTextFieldEditing();
418 } 418 }
419 419
420 // Test that the driver is directed to accept the data list after being notified 420 // Test that the driver is directed to accept the data list after being notified
421 // that the user accepted the data list suggestion. 421 // that the user accepted the data list suggestion.
422 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { 422 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) {
423 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 423 EXPECT_CALL(autofill_client_, HideAutofillPopup());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 467
468 // Set up a field that shouldn't get autocompleted or display warnings. 468 // Set up a field that shouldn't get autocompleted or display warnings.
469 const FormData form; 469 const FormData form;
470 FormFieldData field; 470 FormFieldData field;
471 field.is_focusable = true; 471 field.is_focusable = true;
472 field.should_autocomplete = false; 472 field.should_autocomplete = false;
473 const gfx::RectF element_bounds; 473 const gfx::RectF element_bounds;
474 474
475 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); 475 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false);
476 476
477 std::vector<base::string16> autofill_items; 477 std::vector<Suggestion> autofill_items;
478 autofill_items.push_back(base::string16()); 478 autofill_items.push_back(Suggestion());
479 std::vector<int> autofill_ids; 479 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
480 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
481 480
482 // Ensure the popup tries to hide itself, since it is not allowed to show 481 // Ensure the popup tries to hide itself, since it is not allowed to show
483 // anything. 482 // anything.
484 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 483 EXPECT_CALL(autofill_client_, HideAutofillPopup());
485 484
486 external_delegate_->OnSuggestionsReturned(kQueryId, 485 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items);
487 autofill_items,
488 autofill_items,
489 autofill_items,
490 autofill_ids);
491 } 486 }
492 487
493 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { 488 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) {
494 const FormData form; 489 const FormData form;
495 FormFieldData field; 490 FormFieldData field;
496 field.is_focusable = true; 491 field.is_focusable = true;
497 field.should_autocomplete = false; 492 field.should_autocomplete = false;
498 const gfx::RectF element_bounds; 493 const gfx::RectF element_bounds;
499 494
500 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); 495 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false);
501 496
502 std::vector<base::string16> autofill_items; 497 std::vector<Suggestion> autofill_items;
503 autofill_items.push_back(base::string16()); 498 autofill_items.push_back(Suggestion());
504 std::vector<int> autofill_ids; 499 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
505 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
506 500
507 // Ensure the popup tries to show itself, despite autocomplete="off". 501 // Ensure the popup tries to show itself, despite autocomplete="off".
508 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); 502 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _));
509 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); 503 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0);
510 504
511 external_delegate_->OnSuggestionsReturned(kQueryId, 505 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items);
512 autofill_items,
513 autofill_items,
514 autofill_items,
515 autofill_ids);
516 } 506 }
517 507
518 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { 508 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) {
519 EXPECT_CALL(autofill_client_, HideAutofillPopup()); 509 EXPECT_CALL(autofill_client_, HideAutofillPopup());
520 base::string16 dummy_string(ASCIIToUTF16("baz foo")); 510 base::string16 dummy_string(ASCIIToUTF16("baz foo"));
521 EXPECT_CALL(*autofill_driver_, 511 EXPECT_CALL(*autofill_driver_,
522 RendererShouldFillFieldWithValue(dummy_string)); 512 RendererShouldFillFieldWithValue(dummy_string));
523 external_delegate_->DidAcceptSuggestion(dummy_string, 513 external_delegate_->DidAcceptSuggestion(dummy_string,
524 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 514 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
525 } 515 }
526 516
527 } // namespace autofill 517 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698