| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/autofill/core/browser/autofill_manager.h" | 12 #include "components/autofill/core/browser/autofill_manager.h" |
| 13 #include "components/autofill/core/browser/popup_item_ids.h" |
| 13 #include "components/autofill/core/browser/test_autofill_driver.h" | 14 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 14 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 15 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 15 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 16 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
| 16 #include "components/autofill/core/common/form_data.h" | 17 #include "components/autofill/core/common/form_data.h" |
| 17 #include "components/autofill/core/common/form_field_data.h" | 18 #include "components/autofill/core/common/form_field_data.h" |
| 18 #include "components/autofill/core/common/password_form_fill_data.h" | 19 #include "components/autofill/core/common/password_form_fill_data.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/WebKit/public/web/WebAutofillClient.h" | |
| 22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 23 | 23 |
| 24 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
| 25 using blink::WebAutofillClient; | |
| 26 using testing::_; | 25 using testing::_; |
| 27 | 26 |
| 28 namespace autofill { | 27 namespace autofill { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 // A constant value to use as the Autofill query ID. | 31 // A constant value to use as the Autofill query ID. |
| 33 const int kQueryId = 5; | 32 const int kQueryId = 5; |
| 34 | 33 |
| 35 // A constant value to use as an Autofill profile ID. | 34 // A constant value to use as an Autofill profile ID. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 scoped_ptr<AutofillExternalDelegate> external_delegate_; | 133 scoped_ptr<AutofillExternalDelegate> external_delegate_; |
| 135 | 134 |
| 136 base::MessageLoop message_loop_; | 135 base::MessageLoop message_loop_; |
| 137 }; | 136 }; |
| 138 | 137 |
| 139 // Test that our external delegate called the virtual methods at the right time. | 138 // Test that our external delegate called the virtual methods at the right time. |
| 140 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 139 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
| 141 IssueOnQuery(kQueryId); | 140 IssueOnQuery(kQueryId); |
| 142 | 141 |
| 143 // The enums must be cast to ints to prevent compile errors on linux_rel. | 142 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 144 EXPECT_CALL(manager_delegate_, | 143 EXPECT_CALL( |
| 145 ShowAutofillPopup( | 144 manager_delegate_, |
| 146 _, _, _, _, _, | 145 ShowAutofillPopup(_, |
| 147 testing::ElementsAre( | 146 _, |
| 148 kAutofillProfileId, | 147 _, |
| 149 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 148 _, |
| 150 static_cast<int>( | 149 _, |
| 151 WebAutofillClient::MenuItemIDAutofillOptions)), | 150 testing::ElementsAre( |
| 152 _)); | 151 kAutofillProfileId, |
| 152 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 153 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
| 154 _)); |
| 153 | 155 |
| 154 // This should call ShowAutofillPopup. | 156 // This should call ShowAutofillPopup. |
| 155 std::vector<base::string16> autofill_item; | 157 std::vector<base::string16> autofill_item; |
| 156 autofill_item.push_back(base::string16()); | 158 autofill_item.push_back(base::string16()); |
| 157 std::vector<int> autofill_ids; | 159 std::vector<int> autofill_ids; |
| 158 autofill_ids.push_back(kAutofillProfileId); | 160 autofill_ids.push_back(kAutofillProfileId); |
| 159 external_delegate_->OnSuggestionsReturned(kQueryId, | 161 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 160 autofill_item, | 162 autofill_item, |
| 161 autofill_item, | 163 autofill_item, |
| 162 autofill_item, | 164 autofill_item, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 179 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 181 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| 180 IssueOnQuery(kQueryId); | 182 IssueOnQuery(kQueryId); |
| 181 | 183 |
| 182 std::vector<base::string16> data_list_items; | 184 std::vector<base::string16> data_list_items; |
| 183 data_list_items.push_back(base::string16()); | 185 data_list_items.push_back(base::string16()); |
| 184 | 186 |
| 185 external_delegate_->SetCurrentDataListValues(data_list_items, | 187 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 186 data_list_items); | 188 data_list_items); |
| 187 | 189 |
| 188 // The enums must be cast to ints to prevent compile errors on linux_rel. | 190 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 189 EXPECT_CALL(manager_delegate_, | 191 EXPECT_CALL( |
| 190 ShowAutofillPopup( | 192 manager_delegate_, |
| 191 _, _, _, _, _, | 193 ShowAutofillPopup(_, |
| 192 testing::ElementsAre( | 194 _, |
| 193 static_cast<int>( | 195 _, |
| 194 WebAutofillClient::MenuItemIDDataListEntry), | 196 _, |
| 195 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 197 _, |
| 196 kAutofillProfileId, | 198 testing::ElementsAre( |
| 197 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 199 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 198 static_cast<int>( | 200 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 199 WebAutofillClient::MenuItemIDAutofillOptions)), | 201 kAutofillProfileId, |
| 200 _)); | 202 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 203 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
| 204 _)); |
| 201 | 205 |
| 202 // This should call ShowAutofillPopup. | 206 // This should call ShowAutofillPopup. |
| 203 std::vector<base::string16> autofill_item; | 207 std::vector<base::string16> autofill_item; |
| 204 autofill_item.push_back(base::string16()); | 208 autofill_item.push_back(base::string16()); |
| 205 std::vector<int> autofill_ids; | 209 std::vector<int> autofill_ids; |
| 206 autofill_ids.push_back(kAutofillProfileId); | 210 autofill_ids.push_back(kAutofillProfileId); |
| 207 external_delegate_->OnSuggestionsReturned(kQueryId, | 211 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 208 autofill_item, | 212 autofill_item, |
| 209 autofill_item, | 213 autofill_item, |
| 210 autofill_item, | 214 autofill_item, |
| 211 autofill_ids); | 215 autofill_ids); |
| 212 | 216 |
| 213 // Try calling OnSuggestionsReturned with no Autofill values and ensure | 217 // Try calling OnSuggestionsReturned with no Autofill values and ensure |
| 214 // the datalist items are still shown. | 218 // the datalist items are still shown. |
| 215 // The enum must be cast to an int to prevent compile errors on linux_rel. | 219 // The enum must be cast to an int to prevent compile errors on linux_rel. |
| 216 EXPECT_CALL(manager_delegate_, | 220 EXPECT_CALL( |
| 217 ShowAutofillPopup( | 221 manager_delegate_, |
| 218 _, _, _, _, _, | 222 ShowAutofillPopup( |
| 219 testing::ElementsAre( | 223 _, |
| 220 static_cast<int>( | 224 _, |
| 221 WebAutofillClient::MenuItemIDDataListEntry)), | 225 _, |
| 222 _)); | 226 _, |
| 227 _, |
| 228 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)), |
| 229 _)); |
| 223 | 230 |
| 224 autofill_item = std::vector<base::string16>(); | 231 autofill_item = std::vector<base::string16>(); |
| 225 autofill_ids = std::vector<int>(); | 232 autofill_ids = std::vector<int>(); |
| 226 external_delegate_->OnSuggestionsReturned(kQueryId, | 233 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 227 autofill_item, | 234 autofill_item, |
| 228 autofill_item, | 235 autofill_item, |
| 229 autofill_item, | 236 autofill_item, |
| 230 autofill_ids); | 237 autofill_ids); |
| 231 } | 238 } |
| 232 | 239 |
| 233 // Test that datalist values can get updated while a popup is showing. | 240 // Test that datalist values can get updated while a popup is showing. |
| 234 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { | 241 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { |
| 235 IssueOnQuery(kQueryId); | 242 IssueOnQuery(kQueryId); |
| 236 | 243 |
| 237 EXPECT_CALL(manager_delegate_, | 244 EXPECT_CALL(manager_delegate_, |
| 238 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); | 245 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); |
| 239 | 246 |
| 240 // Make sure just setting the data list values doesn't cause the popup to | 247 // Make sure just setting the data list values doesn't cause the popup to |
| 241 // appear. | 248 // appear. |
| 242 std::vector<base::string16> data_list_items; | 249 std::vector<base::string16> data_list_items; |
| 243 data_list_items.push_back(base::string16()); | 250 data_list_items.push_back(base::string16()); |
| 244 | 251 |
| 245 external_delegate_->SetCurrentDataListValues(data_list_items, | 252 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 246 data_list_items); | 253 data_list_items); |
| 247 | 254 |
| 248 // The enums must be cast to ints to prevent compile errors on linux_rel. | 255 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 249 EXPECT_CALL(manager_delegate_, | 256 EXPECT_CALL( |
| 250 ShowAutofillPopup( | 257 manager_delegate_, |
| 251 _, _, _, _, _, | 258 ShowAutofillPopup(_, |
| 252 testing::ElementsAre( | 259 _, |
| 253 static_cast<int>( | 260 _, |
| 254 WebAutofillClient::MenuItemIDDataListEntry), | 261 _, |
| 255 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 262 _, |
| 256 kAutofillProfileId, | 263 testing::ElementsAre( |
| 257 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 264 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 258 static_cast<int>( | 265 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 259 WebAutofillClient::MenuItemIDAutofillOptions)), | 266 kAutofillProfileId, |
| 260 _)); | 267 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 268 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
| 269 _)); |
| 261 | 270 |
| 262 // Ensure the popup is displayed. | 271 // Ensure the popup is displayed. |
| 263 std::vector<base::string16> autofill_item; | 272 std::vector<base::string16> autofill_item; |
| 264 autofill_item.push_back(base::string16()); | 273 autofill_item.push_back(base::string16()); |
| 265 std::vector<int> autofill_ids; | 274 std::vector<int> autofill_ids; |
| 266 autofill_ids.push_back(kAutofillProfileId); | 275 autofill_ids.push_back(kAutofillProfileId); |
| 267 external_delegate_->OnSuggestionsReturned(kQueryId, | 276 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 268 autofill_item, | 277 autofill_item, |
| 269 autofill_item, | 278 autofill_item, |
| 270 autofill_item, | 279 autofill_item, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 data_list_items); | 295 data_list_items); |
| 287 } | 296 } |
| 288 | 297 |
| 289 // Test that the Autofill popup is able to display warnings explaining why | 298 // Test that the Autofill popup is able to display warnings explaining why |
| 290 // Autofill is disabled for a website. | 299 // Autofill is disabled for a website. |
| 291 // Regression test for http://crbug.com/247880 | 300 // Regression test for http://crbug.com/247880 |
| 292 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { | 301 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { |
| 293 IssueOnQuery(kQueryId); | 302 IssueOnQuery(kQueryId); |
| 294 | 303 |
| 295 // The enums must be cast to ints to prevent compile errors on linux_rel. | 304 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 296 EXPECT_CALL(manager_delegate_, | 305 EXPECT_CALL( |
| 297 ShowAutofillPopup( | 306 manager_delegate_, |
| 298 _, _, _, _, _, | 307 ShowAutofillPopup( |
| 299 testing::ElementsAre( | 308 _, |
| 300 static_cast<int>( | 309 _, |
| 301 WebAutofillClient::MenuItemIDWarningMessage)), | 310 _, |
| 302 _)); | 311 _, |
| 312 _, |
| 313 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)), |
| 314 _)); |
| 303 | 315 |
| 304 // This should call ShowAutofillPopup. | 316 // This should call ShowAutofillPopup. |
| 305 std::vector<base::string16> autofill_item; | 317 std::vector<base::string16> autofill_item; |
| 306 autofill_item.push_back(base::string16()); | 318 autofill_item.push_back(base::string16()); |
| 307 std::vector<int> autofill_ids; | 319 std::vector<int> autofill_ids; |
| 308 autofill_ids.push_back(WebAutofillClient::MenuItemIDWarningMessage); | 320 autofill_ids.push_back(POPUP_ITEM_ID_WARNING_MESSAGE); |
| 309 external_delegate_->OnSuggestionsReturned(kQueryId, | 321 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 310 autofill_item, | 322 autofill_item, |
| 311 autofill_item, | 323 autofill_item, |
| 312 autofill_item, | 324 autofill_item, |
| 313 autofill_ids); | 325 autofill_ids); |
| 314 } | 326 } |
| 315 | 327 |
| 316 // Test that the Autofill popup doesn't display a warning explaining why | 328 // Test that the Autofill popup doesn't display a warning explaining why |
| 317 // Autofill is disabled for a website when there are no Autofill suggestions. | 329 // Autofill is disabled for a website when there are no Autofill suggestions. |
| 318 // Regression test for http://crbug.com/105636 | 330 // Regression test for http://crbug.com/105636 |
| 319 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { | 331 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { |
| 320 const FormData form; | 332 const FormData form; |
| 321 FormFieldData field; | 333 FormFieldData field; |
| 322 field.is_focusable = true; | 334 field.is_focusable = true; |
| 323 field.should_autocomplete = false; | 335 field.should_autocomplete = false; |
| 324 const gfx::RectF element_bounds; | 336 const gfx::RectF element_bounds; |
| 325 | 337 |
| 326 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); | 338 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); |
| 327 | 339 |
| 328 EXPECT_CALL(manager_delegate_, | 340 EXPECT_CALL(manager_delegate_, |
| 329 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); | 341 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); |
| 330 EXPECT_CALL(manager_delegate_, HideAutofillPopup()).Times(1); | 342 EXPECT_CALL(manager_delegate_, HideAutofillPopup()).Times(1); |
| 331 | 343 |
| 332 // This should not call ShowAutofillPopup. | 344 // This should not call ShowAutofillPopup. |
| 333 std::vector<base::string16> autofill_item; | 345 std::vector<base::string16> autofill_item; |
| 334 autofill_item.push_back(base::string16()); | 346 autofill_item.push_back(base::string16()); |
| 335 std::vector<int> autofill_ids; | 347 std::vector<int> autofill_ids; |
| 336 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); | 348 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 337 external_delegate_->OnSuggestionsReturned(kQueryId, | 349 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 338 autofill_item, | 350 autofill_item, |
| 339 autofill_item, | 351 autofill_item, |
| 340 autofill_item, | 352 autofill_item, |
| 341 autofill_ids); | 353 autofill_ids); |
| 342 } | 354 } |
| 343 | 355 |
| 344 // Test that the Autofill delegate doesn't try and fill a form with a | 356 // Test that the Autofill delegate doesn't try and fill a form with a |
| 345 // negative unique id. | 357 // negative unique id. |
| 346 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 358 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 361 | 373 |
| 362 // Test that the ClearPreview call is only sent if the form was being previewed | 374 // Test that the ClearPreview call is only sent if the form was being previewed |
| 363 // (i.e. it isn't autofilling a password). | 375 // (i.e. it isn't autofilling a password). |
| 364 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 376 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
| 365 // Called by DidSelectSuggestion, add expectation to remove warning. | 377 // Called by DidSelectSuggestion, add expectation to remove warning. |
| 366 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 378 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 367 | 379 |
| 368 // Ensure selecting a new password entries or Autofill entries will | 380 // Ensure selecting a new password entries or Autofill entries will |
| 369 // cause any previews to get cleared. | 381 // cause any previews to get cleared. |
| 370 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 382 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 371 external_delegate_->DidSelectSuggestion( | 383 external_delegate_->DidSelectSuggestion(POPUP_ITEM_ID_PASSWORD_ENTRY); |
| 372 WebAutofillClient::MenuItemIDPasswordEntry); | |
| 373 | |
| 374 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 384 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 375 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception( | 385 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception( |
| 376 AutofillDriver::FORM_DATA_ACTION_PREVIEW)); | 386 AutofillDriver::FORM_DATA_ACTION_PREVIEW)); |
| 377 external_delegate_->DidSelectSuggestion(1); | 387 external_delegate_->DidSelectSuggestion(1); |
| 378 } | 388 } |
| 379 | 389 |
| 380 // Test that the popup is hidden once we are done editing the autofill field. | 390 // Test that the popup is hidden once we are done editing the autofill field. |
| 381 TEST_F(AutofillExternalDelegateUnitTest, | 391 TEST_F(AutofillExternalDelegateUnitTest, |
| 382 ExternalDelegateHidePopupAfterEditing) { | 392 ExternalDelegateHidePopupAfterEditing) { |
| 383 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); | 393 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 402 field.should_autocomplete = true; | 412 field.should_autocomplete = true; |
| 403 const gfx::RectF element_bounds; | 413 const gfx::RectF element_bounds; |
| 404 | 414 |
| 405 FormFieldData username_field_data; | 415 FormFieldData username_field_data; |
| 406 username_field_data.value = kUsername; | 416 username_field_data.value = kUsername; |
| 407 PasswordFormFillData password_form_fill_data; | 417 PasswordFormFillData password_form_fill_data; |
| 408 password_form_fill_data.basic_data.fields.push_back(username_field_data); | 418 password_form_fill_data.basic_data.fields.push_back(username_field_data); |
| 409 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); | 419 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); |
| 410 | 420 |
| 411 // The enums must be cast to ints to prevent compile errors on linux_rel. | 421 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 412 EXPECT_CALL(manager_delegate_, | 422 EXPECT_CALL( |
| 413 ShowAutofillPopup( | 423 manager_delegate_, |
| 414 _, _, _, _, _, | 424 ShowAutofillPopup( |
| 415 testing::ElementsAre( | 425 _, |
| 416 static_cast<int>( | 426 _, |
| 417 WebAutofillClient::MenuItemIDPasswordEntry)), | 427 _, |
| 418 _)); | 428 _, |
| 429 _, |
| 430 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_PASSWORD_ENTRY)), |
| 431 _)); |
| 419 | 432 |
| 420 external_delegate_->OnShowPasswordSuggestions(suggestions, | 433 external_delegate_->OnShowPasswordSuggestions(suggestions, |
| 421 realms, | 434 realms, |
| 422 field, | 435 field, |
| 423 element_bounds); | 436 element_bounds); |
| 424 | 437 |
| 425 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 438 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 426 | 439 |
| 427 // This should trigger a call to hide the popup since | 440 // This should trigger a call to hide the popup since |
| 428 // we've selected an option. | 441 // we've selected an option. |
| 429 external_delegate_->DidAcceptSuggestion( | 442 external_delegate_->DidAcceptSuggestion(suggestions[0], |
| 430 suggestions[0], | 443 POPUP_ITEM_ID_PASSWORD_ENTRY); |
| 431 WebAutofillClient::MenuItemIDPasswordEntry); | |
| 432 } | 444 } |
| 433 | 445 |
| 434 // Test that the driver is directed to accept the data list after being notified | 446 // Test that the driver is directed to accept the data list after being notified |
| 435 // that the user accepted the data list suggestion. | 447 // that the user accepted the data list suggestion. |
| 436 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { | 448 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { |
| 437 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 449 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 438 base::string16 dummy_string(ASCIIToUTF16("baz qux")); | 450 base::string16 dummy_string(ASCIIToUTF16("baz qux")); |
| 439 EXPECT_CALL(*autofill_driver_, | 451 EXPECT_CALL(*autofill_driver_, |
| 440 RendererShouldAcceptDataListSuggestion(dummy_string)); | 452 RendererShouldAcceptDataListSuggestion(dummy_string)); |
| 441 external_delegate_->DidAcceptSuggestion( | 453 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 442 dummy_string, | 454 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 443 WebAutofillClient::MenuItemIDDataListEntry); | |
| 444 } | 455 } |
| 445 | 456 |
| 446 // Test that the driver is directed to clear the form after being notified that | 457 // Test that the driver is directed to clear the form after being notified that |
| 447 // the user accepted the suggestion to clear the form. | 458 // the user accepted the suggestion to clear the form. |
| 448 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) { | 459 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) { |
| 449 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 460 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 450 EXPECT_CALL(*autofill_driver_, RendererShouldClearFilledForm()); | 461 EXPECT_CALL(*autofill_driver_, RendererShouldClearFilledForm()); |
| 451 | 462 |
| 452 external_delegate_->DidAcceptSuggestion( | 463 external_delegate_->DidAcceptSuggestion(base::string16(), |
| 453 base::string16(), | 464 POPUP_ITEM_ID_CLEAR_FORM); |
| 454 WebAutofillClient::MenuItemIDClearForm); | |
| 455 } | 465 } |
| 456 | 466 |
| 457 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { | 467 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { |
| 458 // 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. |
| 459 const FormData form; | 469 const FormData form; |
| 460 FormFieldData field; | 470 FormFieldData field; |
| 461 field.is_focusable = true; | 471 field.is_focusable = true; |
| 462 field.should_autocomplete = false; | 472 field.should_autocomplete = false; |
| 463 const gfx::RectF element_bounds; | 473 const gfx::RectF element_bounds; |
| 464 | 474 |
| 465 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 475 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); |
| 466 | 476 |
| 467 std::vector<base::string16> autofill_items; | 477 std::vector<base::string16> autofill_items; |
| 468 autofill_items.push_back(base::string16()); | 478 autofill_items.push_back(base::string16()); |
| 469 std::vector<int> autofill_ids; | 479 std::vector<int> autofill_ids; |
| 470 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); | 480 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 471 | 481 |
| 472 // Ensure the popup tries to hide itself, since it is not allowed to show | 482 // Ensure the popup tries to hide itself, since it is not allowed to show |
| 473 // anything. | 483 // anything. |
| 474 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 484 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 475 | 485 |
| 476 external_delegate_->OnSuggestionsReturned(kQueryId, | 486 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 477 autofill_items, | 487 autofill_items, |
| 478 autofill_items, | 488 autofill_items, |
| 479 autofill_items, | 489 autofill_items, |
| 480 autofill_ids); | 490 autofill_ids); |
| 481 } | 491 } |
| 482 | 492 |
| 483 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { | 493 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { |
| 484 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 494 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 485 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 495 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
| 486 EXPECT_CALL(*autofill_driver_, | 496 EXPECT_CALL(*autofill_driver_, |
| 487 RendererShouldSetNodeText(dummy_string)); | 497 RendererShouldSetNodeText(dummy_string)); |
| 488 external_delegate_->DidAcceptSuggestion( | 498 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 489 dummy_string, | 499 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 490 WebAutofillClient::MenuItemIDAutocompleteEntry); | |
| 491 } | 500 } |
| 492 | 501 |
| 493 } // namespace autofill | 502 } // namespace autofill |
| OLD | NEW |