| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Issue an OnQuery call with the given |query_id|. | 129 // Issue an OnQuery call with the given |query_id|. |
| 130 void IssueOnQuery(int query_id) { | 130 void IssueOnQuery(int query_id) { |
| 131 const FormData form; | 131 const FormData form; |
| 132 FormFieldData field; | 132 FormFieldData field; |
| 133 field.is_focusable = true; | 133 field.is_focusable = true; |
| 134 field.should_autocomplete = true; | 134 field.should_autocomplete = true; |
| 135 const gfx::RectF element_bounds; | 135 const gfx::RectF element_bounds; |
| 136 | 136 |
| 137 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); | 137 external_delegate_->OnQuery(query_id, form, field, element_bounds); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void IssueOnSuggestionsReturned() { | 140 void IssueOnSuggestionsReturned() { |
| 141 std::vector<Suggestion> suggestions; | 141 std::vector<Suggestion> suggestions; |
| 142 suggestions.push_back(Suggestion()); | 142 suggestions.push_back(Suggestion()); |
| 143 suggestions[0].frontend_id = kAutofillProfileId; | 143 suggestions[0].frontend_id = kAutofillProfileId; |
| 144 external_delegate_->OnSuggestionsReturned(kQueryId, suggestions); | 144 external_delegate_->OnSuggestionsReturned(kQueryId, suggestions); |
| 145 } | 145 } |
| 146 | 146 |
| 147 testing::NiceMock<MockAutofillClient> autofill_client_; | 147 testing::NiceMock<MockAutofillClient> autofill_client_; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE))), | 303 static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE))), |
| 304 _)); | 304 _)); |
| 305 | 305 |
| 306 // This should call ShowAutofillPopup. | 306 // This should call ShowAutofillPopup. |
| 307 std::vector<Suggestion> autofill_item; | 307 std::vector<Suggestion> autofill_item; |
| 308 autofill_item.push_back(Suggestion()); | 308 autofill_item.push_back(Suggestion()); |
| 309 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; | 309 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; |
| 310 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); | 310 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Test that the Autofill popup doesn't display a warning explaining why | |
| 314 // Autofill is disabled for a website when there are no Autofill suggestions. | |
| 315 // Regression test for http://crbug.com/105636 | |
| 316 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { | |
| 317 // This test only makes sense if we're respecting autocomplete="off". | |
| 318 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 319 switches::kRespectAutocompleteOffForAutofill)) | |
| 320 return; | |
| 321 | |
| 322 const FormData form; | |
| 323 FormFieldData field; | |
| 324 field.is_focusable = true; | |
| 325 field.should_autocomplete = false; | |
| 326 const gfx::RectF element_bounds; | |
| 327 | |
| 328 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); | |
| 329 | |
| 330 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)) | |
| 331 .Times(0); | |
| 332 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1); | |
| 333 | |
| 334 // This should not call ShowAutofillPopup. | |
| 335 std::vector<Suggestion> autofill_item; | |
| 336 autofill_item.push_back(Suggestion()); | |
| 337 autofill_item[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; | |
| 338 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); | |
| 339 } | |
| 340 | |
| 341 // Test that the Autofill delegate doesn't try and fill a form with a | 313 // Test that the Autofill delegate doesn't try and fill a form with a |
| 342 // negative unique id. | 314 // negative unique id. |
| 343 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 315 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 344 // Ensure it doesn't try to preview the negative id. | 316 // Ensure it doesn't try to preview the negative id. |
| 345 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 317 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
| 346 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 318 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 347 external_delegate_->DidSelectSuggestion(base::string16(), -1); | 319 external_delegate_->DidSelectSuggestion(base::string16(), -1); |
| 348 | 320 |
| 349 // Ensure it doesn't try to fill the form in with the negative id. | 321 // Ensure it doesn't try to fill the form in with the negative id. |
| 350 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 322 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 int expiration_month = 1; | 453 int expiration_month = 1; |
| 482 int expiration_year = 3000; | 454 int expiration_year = 3000; |
| 483 EXPECT_CALL( | 455 EXPECT_CALL( |
| 484 *autofill_manager_, | 456 *autofill_manager_, |
| 485 FillCreditCardForm( | 457 FillCreditCardForm( |
| 486 _, _, _, CreditCard(card_number, expiration_month, expiration_year))); | 458 _, _, _, CreditCard(card_number, expiration_month, expiration_year))); |
| 487 external_delegate_->OnCreditCardScanned(card_number, expiration_month, | 459 external_delegate_->OnCreditCardScanned(card_number, expiration_month, |
| 488 expiration_year); | 460 expiration_year); |
| 489 } | 461 } |
| 490 | 462 |
| 491 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { | |
| 492 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 493 switches::kRespectAutocompleteOffForAutofill); | |
| 494 | |
| 495 // Set up a field that shouldn't get autocompleted or display warnings. | |
| 496 const FormData form; | |
| 497 FormFieldData field; | |
| 498 field.is_focusable = true; | |
| 499 field.should_autocomplete = false; | |
| 500 const gfx::RectF element_bounds; | |
| 501 | |
| 502 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | |
| 503 | |
| 504 std::vector<Suggestion> autofill_items; | |
| 505 autofill_items.push_back(Suggestion()); | |
| 506 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; | |
| 507 | |
| 508 // Ensure the popup tries to hide itself, since it is not allowed to show | |
| 509 // anything. | |
| 510 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | |
| 511 | |
| 512 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); | |
| 513 } | |
| 514 | |
| 515 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { | 463 TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { |
| 516 const FormData form; | 464 const FormData form; |
| 517 FormFieldData field; | 465 FormFieldData field; |
| 518 field.is_focusable = true; | 466 field.is_focusable = true; |
| 519 field.should_autocomplete = false; | 467 field.should_autocomplete = false; |
| 520 const gfx::RectF element_bounds; | 468 const gfx::RectF element_bounds; |
| 521 | 469 |
| 522 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 470 external_delegate_->OnQuery(kQueryId, form, field, element_bounds); |
| 523 | 471 |
| 524 std::vector<Suggestion> autofill_items; | 472 std::vector<Suggestion> autofill_items; |
| 525 autofill_items.push_back(Suggestion()); | 473 autofill_items.push_back(Suggestion()); |
| 526 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; | 474 autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
| 527 | 475 |
| 528 // Ensure the popup tries to show itself, despite autocomplete="off". | 476 // Ensure the popup tries to show itself, despite autocomplete="off". |
| 529 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); | 477 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
| 530 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); | 478 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); |
| 531 | 479 |
| 532 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); | 480 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); |
| 533 } | 481 } |
| 534 | 482 |
| 535 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { | 483 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { |
| 536 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 484 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 537 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 485 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
| 538 EXPECT_CALL(*autofill_driver_, | 486 EXPECT_CALL(*autofill_driver_, |
| 539 RendererShouldFillFieldWithValue(dummy_string)); | 487 RendererShouldFillFieldWithValue(dummy_string)); |
| 540 external_delegate_->DidAcceptSuggestion(dummy_string, | 488 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 541 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 489 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 542 } | 490 } |
| 543 | 491 |
| 544 } // namespace autofill | 492 } // namespace autofill |
| OLD | NEW |