OLD | NEW |
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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
13 #include "components/autofill/core/browser/autofill_manager.h" | 13 #include "components/autofill/core/browser/autofill_manager.h" |
14 #include "components/autofill/core/browser/popup_item_ids.h" | 14 #include "components/autofill/core/browser/popup_item_ids.h" |
| 15 #include "components/autofill/core/browser/suggestion_test_helpers.h" |
15 #include "components/autofill/core/browser/test_autofill_client.h" | 16 #include "components/autofill/core/browser/test_autofill_client.h" |
16 #include "components/autofill/core/browser/test_autofill_driver.h" | 17 #include "components/autofill/core/browser/test_autofill_driver.h" |
17 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 18 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
18 #include "components/autofill/core/common/autofill_switches.h" | 19 #include "components/autofill/core/common/autofill_switches.h" |
19 #include "components/autofill/core/common/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
20 #include "components/autofill/core/common/form_field_data.h" | 21 #include "components/autofill/core/common/form_field_data.h" |
21 #include "components/autofill/core/common/password_form_fill_data.h" | 22 #include "components/autofill/core/common/password_form_fill_data.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
(...skipping 27 matching lines...) Expand all Loading... |
52 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 53 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
53 }; | 54 }; |
54 | 55 |
55 class MockAutofillClient : public autofill::TestAutofillClient { | 56 class MockAutofillClient : public autofill::TestAutofillClient { |
56 public: | 57 public: |
57 MockAutofillClient() {} | 58 MockAutofillClient() {} |
58 | 59 |
59 MOCK_METHOD1(ScanCreditCard, | 60 MOCK_METHOD1(ScanCreditCard, |
60 void(const CreditCardScanCallback& callbacK)); | 61 void(const CreditCardScanCallback& callbacK)); |
61 | 62 |
62 MOCK_METHOD7(ShowAutofillPopup, | 63 MOCK_METHOD4(ShowAutofillPopup, |
63 void(const gfx::RectF& element_bounds, | 64 void(const gfx::RectF& element_bounds, |
64 base::i18n::TextDirection text_direction, | 65 base::i18n::TextDirection text_direction, |
65 const std::vector<base::string16>& values, | 66 const std::vector<Suggestion>& suggestions, |
66 const std::vector<base::string16>& labels, | |
67 const std::vector<base::string16>& icons, | |
68 const std::vector<int>& identifiers, | |
69 base::WeakPtr<AutofillPopupDelegate> delegate)); | 67 base::WeakPtr<AutofillPopupDelegate> delegate)); |
70 | 68 |
71 MOCK_METHOD2(UpdateAutofillPopupDataListValues, | 69 MOCK_METHOD2(UpdateAutofillPopupDataListValues, |
72 void(const std::vector<base::string16>& values, | 70 void(const std::vector<base::string16>& values, |
73 const std::vector<base::string16>& lables)); | 71 const std::vector<base::string16>& lables)); |
74 | 72 |
75 MOCK_METHOD0(HideAutofillPopup, void()); | 73 MOCK_METHOD0(HideAutofillPopup, void()); |
76 | 74 |
77 private: | 75 private: |
78 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 76 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 const FormData form; | 130 const FormData form; |
133 FormFieldData field; | 131 FormFieldData field; |
134 field.is_focusable = true; | 132 field.is_focusable = true; |
135 field.should_autocomplete = true; | 133 field.should_autocomplete = true; |
136 const gfx::RectF element_bounds; | 134 const gfx::RectF element_bounds; |
137 | 135 |
138 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); | 136 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); |
139 } | 137 } |
140 | 138 |
141 void IssueOnSuggestionsReturned() { | 139 void IssueOnSuggestionsReturned() { |
142 std::vector<base::string16> autofill_item; | 140 std::vector<Suggestion> suggestions; |
143 autofill_item.push_back(base::string16()); | 141 suggestions.push_back(Suggestion()); |
144 std::vector<int> autofill_ids; | 142 suggestions[0].frontend_id = kAutofillProfileId; |
145 autofill_ids.push_back(kAutofillProfileId); | 143 external_delegate_->OnSuggestionsReturned(kQueryId, suggestions); |
146 external_delegate_->OnSuggestionsReturned( | |
147 kQueryId, autofill_item, autofill_item, autofill_item, autofill_ids); | |
148 } | 144 } |
149 | 145 |
150 testing::NiceMock<MockAutofillClient> autofill_client_; | 146 testing::NiceMock<MockAutofillClient> autofill_client_; |
151 scoped_ptr<testing::NiceMock<MockAutofillDriver>> autofill_driver_; | 147 scoped_ptr<testing::NiceMock<MockAutofillDriver>> autofill_driver_; |
152 scoped_ptr<MockAutofillManager> autofill_manager_; | 148 scoped_ptr<MockAutofillManager> autofill_manager_; |
153 scoped_ptr<AutofillExternalDelegate> external_delegate_; | 149 scoped_ptr<AutofillExternalDelegate> external_delegate_; |
154 | 150 |
155 base::MessageLoop message_loop_; | 151 base::MessageLoop message_loop_; |
156 }; | 152 }; |
157 | 153 |
158 // Test that our external delegate called the virtual methods at the right time. | 154 // Test that our external delegate called the virtual methods at the right time. |
159 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 155 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
160 IssueOnQuery(kQueryId); | 156 IssueOnQuery(kQueryId); |
161 | 157 |
162 // The enums must be cast to ints to prevent compile errors on linux_rel. | 158 // The enums must be cast to ints to prevent compile errors on linux_rel. |
163 EXPECT_CALL( | 159 EXPECT_CALL( |
164 autofill_client_, | 160 autofill_client_, |
165 ShowAutofillPopup(_, | 161 ShowAutofillPopup(_, |
166 _, | 162 _, |
167 _, | 163 SuggestionVectorIdsAre(testing::ElementsAre( |
168 _, | |
169 _, | |
170 testing::ElementsAre( | |
171 kAutofillProfileId, | 164 kAutofillProfileId, |
172 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), | 165 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
173 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), | 166 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
174 _)); | 167 _)); |
175 | 168 |
176 // This should call ShowAutofillPopup. | 169 // This should call ShowAutofillPopup. |
177 std::vector<base::string16> autofill_item; | 170 std::vector<Suggestion> autofill_item; |
178 autofill_item.push_back(base::string16()); | 171 autofill_item.push_back(Suggestion()); |
179 std::vector<int> autofill_ids; | 172 autofill_item[0].frontend_id = kAutofillProfileId; |
180 autofill_ids.push_back(kAutofillProfileId); | 173 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
181 external_delegate_->OnSuggestionsReturned(kQueryId, | |
182 autofill_item, | |
183 autofill_item, | |
184 autofill_item, | |
185 autofill_ids); | |
186 | 174 |
187 EXPECT_CALL(*autofill_manager_, | 175 EXPECT_CALL(*autofill_manager_, |
188 FillOrPreviewForm( | 176 FillOrPreviewForm( |
189 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); | 177 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); |
190 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 178 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
191 | 179 |
192 // This should trigger a call to hide the popup since we've selected an | 180 // This should trigger a call to hide the popup since we've selected an |
193 // option. | 181 // option. |
194 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); | 182 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, |
| 183 autofill_item[0].frontend_id); |
195 } | 184 } |
196 | 185 |
197 // Test that data list elements for a node will appear in the Autofill popup. | 186 // Test that data list elements for a node will appear in the Autofill popup. |
198 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 187 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
199 IssueOnQuery(kQueryId); | 188 IssueOnQuery(kQueryId); |
200 | 189 |
201 std::vector<base::string16> data_list_items; | 190 std::vector<base::string16> data_list_items; |
202 data_list_items.push_back(base::string16()); | 191 data_list_items.push_back(base::string16()); |
203 | 192 |
204 EXPECT_CALL( | 193 EXPECT_CALL( |
205 autofill_client_, | 194 autofill_client_, |
206 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); | 195 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); |
207 | 196 |
208 external_delegate_->SetCurrentDataListValues(data_list_items, | 197 external_delegate_->SetCurrentDataListValues(data_list_items, |
209 data_list_items); | 198 data_list_items); |
210 | 199 |
211 // The enums must be cast to ints to prevent compile errors on linux_rel. | 200 // The enums must be cast to ints to prevent compile errors on linux_rel. |
212 EXPECT_CALL( | 201 EXPECT_CALL( |
213 autofill_client_, | 202 autofill_client_, |
214 ShowAutofillPopup(_, | 203 ShowAutofillPopup(_, |
215 _, | 204 _, |
216 _, | 205 SuggestionVectorIdsAre(testing::ElementsAre( |
217 _, | |
218 _, | |
219 testing::ElementsAre( | |
220 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), | 206 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
221 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), | 207 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
222 kAutofillProfileId, | 208 kAutofillProfileId, |
223 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), | 209 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
224 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), | 210 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
225 _)); | 211 _)); |
226 | 212 |
227 // This should call ShowAutofillPopup. | 213 // This should call ShowAutofillPopup. |
228 std::vector<base::string16> autofill_item; | 214 std::vector<Suggestion> autofill_item; |
229 autofill_item.push_back(base::string16()); | 215 autofill_item.push_back(Suggestion()); |
230 std::vector<int> autofill_ids; | 216 autofill_item[0].frontend_id = kAutofillProfileId; |
231 autofill_ids.push_back(kAutofillProfileId); | 217 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
232 external_delegate_->OnSuggestionsReturned(kQueryId, | |
233 autofill_item, | |
234 autofill_item, | |
235 autofill_item, | |
236 autofill_ids); | |
237 | 218 |
238 // Try calling OnSuggestionsReturned with no Autofill values and ensure | 219 // Try calling OnSuggestionsReturned with no Autofill values and ensure |
239 // the datalist items are still shown. | 220 // the datalist items are still shown. |
240 // The enum must be cast to an int to prevent compile errors on linux_rel. | 221 // The enum must be cast to an int to prevent compile errors on linux_rel. |
241 EXPECT_CALL( | 222 EXPECT_CALL( |
242 autofill_client_, | 223 autofill_client_, |
243 ShowAutofillPopup( | 224 ShowAutofillPopup( |
244 _, | 225 _, |
245 _, | 226 _, |
246 _, | 227 SuggestionVectorIdsAre(testing::ElementsAre( |
247 _, | 228 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY))), |
248 _, | |
249 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)), | |
250 _)); | 229 _)); |
251 | 230 |
252 autofill_item = std::vector<base::string16>(); | 231 autofill_item.clear(); |
253 autofill_ids = std::vector<int>(); | 232 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
254 external_delegate_->OnSuggestionsReturned(kQueryId, | |
255 autofill_item, | |
256 autofill_item, | |
257 autofill_item, | |
258 autofill_ids); | |
259 } | 233 } |
260 | 234 |
261 // Test that datalist values can get updated while a popup is showing. | 235 // Test that datalist values can get updated while a popup is showing. |
262 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { | 236 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { |
263 IssueOnQuery(kQueryId); | 237 IssueOnQuery(kQueryId); |
264 | 238 |
265 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) | 239 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)) |
266 .Times(0); | 240 .Times(0); |
267 | 241 |
268 // Make sure just setting the data list values doesn't cause the popup to | 242 // Make sure just setting the data list values doesn't cause the popup to |
269 // appear. | 243 // appear. |
270 std::vector<base::string16> data_list_items; | 244 std::vector<base::string16> data_list_items; |
271 data_list_items.push_back(base::string16()); | 245 data_list_items.push_back(base::string16()); |
272 | 246 |
273 EXPECT_CALL( | 247 EXPECT_CALL( |
274 autofill_client_, | 248 autofill_client_, |
275 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); | 249 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); |
276 | 250 |
277 external_delegate_->SetCurrentDataListValues(data_list_items, | 251 external_delegate_->SetCurrentDataListValues(data_list_items, |
278 data_list_items); | 252 data_list_items); |
279 | 253 |
280 // The enums must be cast to ints to prevent compile errors on linux_rel. | 254 // The enums must be cast to ints to prevent compile errors on linux_rel. |
281 EXPECT_CALL( | 255 EXPECT_CALL( |
282 autofill_client_, | 256 autofill_client_, |
283 ShowAutofillPopup(_, | 257 ShowAutofillPopup(_, |
284 _, | 258 _, |
285 _, | 259 SuggestionVectorIdsAre(testing::ElementsAre( |
286 _, | |
287 _, | |
288 testing::ElementsAre( | |
289 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), | 260 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
290 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), | 261 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
291 kAutofillProfileId, | 262 kAutofillProfileId, |
292 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), | 263 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
293 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), | 264 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
294 _)); | 265 _)); |
295 | 266 |
296 // Ensure the popup is displayed. | 267 // Ensure the popup is displayed. |
297 std::vector<base::string16> autofill_item; | 268 std::vector<Suggestion> autofill_item; |
298 autofill_item.push_back(base::string16()); | 269 autofill_item.push_back(Suggestion()); |
299 std::vector<int> autofill_ids; | 270 autofill_item[0].frontend_id = kAutofillProfileId; |
300 autofill_ids.push_back(kAutofillProfileId); | 271 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
301 external_delegate_->OnSuggestionsReturned(kQueryId, | |
302 autofill_item, | |
303 autofill_item, | |
304 autofill_item, | |
305 autofill_ids); | |
306 | 272 |
307 // This would normally get called from ShowAutofillPopup, but it is mocked so | 273 // This would normally get called from ShowAutofillPopup, but it is mocked so |
308 // we need to call OnPopupShown ourselves. | 274 // we need to call OnPopupShown ourselves. |
309 external_delegate_->OnPopupShown(); | 275 external_delegate_->OnPopupShown(); |
310 | 276 |
311 // Update the current data list and ensure the popup is updated. | 277 // Update the current data list and ensure the popup is updated. |
312 data_list_items.push_back(base::string16()); | 278 data_list_items.push_back(base::string16()); |
313 | 279 |
314 // The enums must be cast to ints to prevent compile errors on linux_rel. | 280 // The enums must be cast to ints to prevent compile errors on linux_rel. |
315 EXPECT_CALL( | 281 EXPECT_CALL( |
316 autofill_client_, | 282 autofill_client_, |
317 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); | 283 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); |
318 | 284 |
319 external_delegate_->SetCurrentDataListValues(data_list_items, | 285 external_delegate_->SetCurrentDataListValues(data_list_items, |
320 data_list_items); | 286 data_list_items); |
321 } | 287 } |
322 | 288 |
323 // Test that the Autofill popup is able to display warnings explaining why | 289 // Test that the Autofill popup is able to display warnings explaining why |
324 // Autofill is disabled for a website. | 290 // Autofill is disabled for a website. |
325 // Regression test for http://crbug.com/247880 | 291 // Regression test for http://crbug.com/247880 |
326 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { | 292 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { |
327 IssueOnQuery(kQueryId); | 293 IssueOnQuery(kQueryId); |
328 | 294 |
329 // The enums must be cast to ints to prevent compile errors on linux_rel. | 295 // The enums must be cast to ints to prevent compile errors on linux_rel. |
330 EXPECT_CALL( | 296 EXPECT_CALL( |
331 autofill_client_, | 297 autofill_client_, |
332 ShowAutofillPopup( | 298 ShowAutofillPopup( |
333 _, | 299 _, |
334 _, | 300 _, |
335 _, | 301 SuggestionVectorIdsAre(testing::ElementsAre( |
336 _, | 302 static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE))), |
337 _, | |
338 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)), | |
339 _)); | 303 _)); |
340 | 304 |
341 // This should call ShowAutofillPopup. | 305 // This should call ShowAutofillPopup. |
342 std::vector<base::string16> autofill_item; | 306 std::vector<Suggestion> autofill_item; |
343 autofill_item.push_back(base::string16()); | 307 autofill_item.push_back(Suggestion()); |
344 std::vector<int> autofill_ids; | 308 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; |
345 autofill_ids.push_back(POPUP_ITEM_ID_WARNING_MESSAGE); | 309 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
346 external_delegate_->OnSuggestionsReturned(kQueryId, | |
347 autofill_item, | |
348 autofill_item, | |
349 autofill_item, | |
350 autofill_ids); | |
351 } | 310 } |
352 | 311 |
353 // Test that the Autofill popup doesn't display a warning explaining why | 312 // Test that the Autofill popup doesn't display a warning explaining why |
354 // Autofill is disabled for a website when there are no Autofill suggestions. | 313 // Autofill is disabled for a website when there are no Autofill suggestions. |
355 // Regression test for http://crbug.com/105636 | 314 // Regression test for http://crbug.com/105636 |
356 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { | 315 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { |
357 // This test only makes sense if we're respecting autocomplete="off". | 316 // This test only makes sense if we're respecting autocomplete="off". |
358 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 317 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
359 switches::kRespectAutocompleteOffForAutofill)) | 318 switches::kRespectAutocompleteOffForAutofill)) |
360 return; | 319 return; |
361 | 320 |
362 const FormData form; | 321 const FormData form; |
363 FormFieldData field; | 322 FormFieldData field; |
364 field.is_focusable = true; | 323 field.is_focusable = true; |
365 field.should_autocomplete = false; | 324 field.should_autocomplete = false; |
366 const gfx::RectF element_bounds; | 325 const gfx::RectF element_bounds; |
367 | 326 |
368 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); | 327 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); |
369 | 328 |
370 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) | 329 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)) |
371 .Times(0); | 330 .Times(0); |
372 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1); | 331 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1); |
373 | 332 |
374 // This should not call ShowAutofillPopup. | 333 // This should not call ShowAutofillPopup. |
375 std::vector<base::string16> autofill_item; | 334 std::vector<Suggestion> autofill_item; |
376 autofill_item.push_back(base::string16()); | 335 autofill_item.push_back(Suggestion()); |
377 std::vector<int> autofill_ids; | 336 autofill_item[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
378 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 337 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
379 external_delegate_->OnSuggestionsReturned(kQueryId, | |
380 autofill_item, | |
381 autofill_item, | |
382 autofill_item, | |
383 autofill_ids); | |
384 } | 338 } |
385 | 339 |
386 // Test that the Autofill delegate doesn't try and fill a form with a | 340 // Test that the Autofill delegate doesn't try and fill a form with a |
387 // negative unique id. | 341 // negative unique id. |
388 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 342 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
389 // Ensure it doesn't try to preview the negative id. | 343 // Ensure it doesn't try to preview the negative id. |
390 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 344 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
391 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 345 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
392 external_delegate_->DidSelectSuggestion(base::string16(), -1); | 346 external_delegate_->DidSelectSuggestion(base::string16(), -1); |
393 | 347 |
(...skipping 22 matching lines...) Expand all Loading... |
416 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 370 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
417 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( | 371 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( |
418 ASCIIToUTF16("baz foo"))); | 372 ASCIIToUTF16("baz foo"))); |
419 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), | 373 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), |
420 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 374 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
421 } | 375 } |
422 | 376 |
423 // Test that the popup is hidden once we are done editing the autofill field. | 377 // Test that the popup is hidden once we are done editing the autofill field. |
424 TEST_F(AutofillExternalDelegateUnitTest, | 378 TEST_F(AutofillExternalDelegateUnitTest, |
425 ExternalDelegateHidePopupAfterEditing) { | 379 ExternalDelegateHidePopupAfterEditing) { |
426 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); | 380 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
427 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 381 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
428 | 382 |
429 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 383 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
430 external_delegate_->DidEndTextFieldEditing(); | 384 external_delegate_->DidEndTextFieldEditing(); |
431 } | 385 } |
432 | 386 |
433 // Test that the driver is directed to accept the data list after being notified | 387 // Test that the driver is directed to accept the data list after being notified |
434 // that the user accepted the data list suggestion. | 388 // that the user accepted the data list suggestion. |
435 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { | 389 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { |
436 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 390 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 493 |
540 // Set up a field that shouldn't get autocompleted or display warnings. | 494 // Set up a field that shouldn't get autocompleted or display warnings. |
541 const FormData form; | 495 const FormData form; |
542 FormFieldData field; | 496 FormFieldData field; |
543 field.is_focusable = true; | 497 field.is_focusable = true; |
544 field.should_autocomplete = false; | 498 field.should_autocomplete = false; |
545 const gfx::RectF element_bounds; | 499 const gfx::RectF element_bounds; |
546 | 500 |
547 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 501 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); |
548 | 502 |
549 std::vector<base::string16> autofill_items; | 503 std::vector<Suggestion> autofill_items; |
550 autofill_items.push_back(base::string16()); | 504 autofill_items.push_back(Suggestion()); |
551 std::vector<int> autofill_ids; | 505 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
552 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | |
553 | 506 |
554 // Ensure the popup tries to hide itself, since it is not allowed to show | 507 // Ensure the popup tries to hide itself, since it is not allowed to show |
555 // anything. | 508 // anything. |
556 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 509 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
557 | 510 |
558 external_delegate_->OnSuggestionsReturned(kQueryId, | 511 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); |
559 autofill_items, | |
560 autofill_items, | |
561 autofill_items, | |
562 autofill_ids); | |
563 } | 512 } |
564 | 513 |
565 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { | 514 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { |
566 const FormData form; | 515 const FormData form; |
567 FormFieldData field; | 516 FormFieldData field; |
568 field.is_focusable = true; | 517 field.is_focusable = true; |
569 field.should_autocomplete = false; | 518 field.should_autocomplete = false; |
570 const gfx::RectF element_bounds; | 519 const gfx::RectF element_bounds; |
571 | 520 |
572 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 521 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); |
573 | 522 |
574 std::vector<base::string16> autofill_items; | 523 std::vector<Suggestion> autofill_items; |
575 autofill_items.push_back(base::string16()); | 524 autofill_items.push_back(Suggestion()); |
576 std::vector<int> autofill_ids; | 525 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
577 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | |
578 | 526 |
579 // Ensure the popup tries to show itself, despite autocomplete="off". | 527 // Ensure the popup tries to show itself, despite autocomplete="off". |
580 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); | 528 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
581 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); | 529 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); |
582 | 530 |
583 external_delegate_->OnSuggestionsReturned(kQueryId, | 531 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); |
584 autofill_items, | |
585 autofill_items, | |
586 autofill_items, | |
587 autofill_ids); | |
588 } | 532 } |
589 | 533 |
590 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { | 534 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { |
591 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 535 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
592 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 536 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
593 EXPECT_CALL(*autofill_driver_, | 537 EXPECT_CALL(*autofill_driver_, |
594 RendererShouldFillFieldWithValue(dummy_string)); | 538 RendererShouldFillFieldWithValue(dummy_string)); |
595 external_delegate_->DidAcceptSuggestion(dummy_string, | 539 external_delegate_->DidAcceptSuggestion(dummy_string, |
596 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 540 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
597 } | 541 } |
598 | 542 |
599 } // namespace autofill | 543 } // namespace autofill |
OLD | NEW |