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/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 autofill_driver_.reset(); | 122 autofill_driver_.reset(); |
123 ChromeRenderViewHostTestHarness::TearDown(); | 123 ChromeRenderViewHostTestHarness::TearDown(); |
124 } | 124 } |
125 | 125 |
126 // Issue an OnQuery call with the given |query_id|. | 126 // Issue an OnQuery call with the given |query_id|. |
127 void IssueOnQuery(int query_id) { | 127 void IssueOnQuery(int query_id) { |
128 const FormData form; | 128 const FormData form; |
129 FormFieldData field; | 129 FormFieldData field; |
130 field.is_focusable = true; | 130 field.is_focusable = true; |
131 field.should_autocomplete = true; | 131 field.should_autocomplete = true; |
| 132 PasswordForm password_form; |
132 const gfx::RectF element_bounds; | 133 const gfx::RectF element_bounds; |
133 | 134 |
134 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); | 135 external_delegate_->OnQuery( |
| 136 query_id, form, field, password_form, element_bounds, true); |
135 } | 137 } |
136 | 138 |
137 MockAutofillManagerDelegate manager_delegate_; | 139 MockAutofillManagerDelegate manager_delegate_; |
138 scoped_ptr<MockAutofillDriver> autofill_driver_; | 140 scoped_ptr<MockAutofillDriver> autofill_driver_; |
139 scoped_ptr<MockAutofillManager> autofill_manager_; | 141 scoped_ptr<MockAutofillManager> autofill_manager_; |
140 scoped_ptr<AutofillExternalDelegate> external_delegate_; | 142 scoped_ptr<AutofillExternalDelegate> external_delegate_; |
141 }; | 143 }; |
142 | 144 |
143 // Test that our external delegate called the virtual methods at the right time. | 145 // Test that our external delegate called the virtual methods at the right time. |
144 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 146 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 320 } |
319 | 321 |
320 // Test that the Autofill popup doesn't display a warning explaining why | 322 // Test that the Autofill popup doesn't display a warning explaining why |
321 // Autofill is disabled for a website when there are no Autofill suggestions. | 323 // Autofill is disabled for a website when there are no Autofill suggestions. |
322 // Regression test for http://crbug.com/105636 | 324 // Regression test for http://crbug.com/105636 |
323 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { | 325 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { |
324 const FormData form; | 326 const FormData form; |
325 FormFieldData field; | 327 FormFieldData field; |
326 field.is_focusable = true; | 328 field.is_focusable = true; |
327 field.should_autocomplete = false; | 329 field.should_autocomplete = false; |
| 330 PasswordForm password_form; |
328 const gfx::RectF element_bounds; | 331 const gfx::RectF element_bounds; |
329 | 332 |
330 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); | 333 external_delegate_->OnQuery( |
| 334 kQueryId, form, password_form, field, element_bounds, true); |
331 | 335 |
332 EXPECT_CALL(manager_delegate_, | 336 EXPECT_CALL(manager_delegate_, |
333 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); | 337 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); |
334 EXPECT_CALL(manager_delegate_, HideAutofillPopup()).Times(1); | 338 EXPECT_CALL(manager_delegate_, HideAutofillPopup()).Times(1); |
335 | 339 |
336 // This should not call ShowAutofillPopup. | 340 // This should not call ShowAutofillPopup. |
337 std::vector<base::string16> autofill_item; | 341 std::vector<base::string16> autofill_item; |
338 autofill_item.push_back(base::string16()); | 342 autofill_item.push_back(base::string16()); |
339 std::vector<int> autofill_ids; | 343 std::vector<int> autofill_ids; |
340 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); | 344 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 418 |
415 // The enums must be cast to ints to prevent compile errors on linux_rel. | 419 // The enums must be cast to ints to prevent compile errors on linux_rel. |
416 EXPECT_CALL(manager_delegate_, | 420 EXPECT_CALL(manager_delegate_, |
417 ShowAutofillPopup( | 421 ShowAutofillPopup( |
418 _, _, _, _, _, | 422 _, _, _, _, _, |
419 testing::ElementsAre( | 423 testing::ElementsAre( |
420 static_cast<int>( | 424 static_cast<int>( |
421 WebAutofillClient::MenuItemIDPasswordEntry)), | 425 WebAutofillClient::MenuItemIDPasswordEntry)), |
422 _)); | 426 _)); |
423 | 427 |
424 external_delegate_->OnShowPasswordSuggestions(suggestions, | 428 PasswordForm password_form; |
425 realms, | 429 external_delegate_->OnShowPasswordSuggestions( |
426 field, | 430 suggestions, realms, field, password_form, element_bounds); |
427 element_bounds); | |
428 | 431 |
429 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 432 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
430 | 433 |
431 // This should trigger a call to hide the popup since | 434 // This should trigger a call to hide the popup since |
432 // we've selected an option. | 435 // we've selected an option. |
433 external_delegate_->DidAcceptSuggestion( | 436 external_delegate_->DidAcceptSuggestion( |
434 suggestions[0], | 437 suggestions[0], |
435 WebAutofillClient::MenuItemIDPasswordEntry); | 438 WebAutofillClient::MenuItemIDPasswordEntry); |
436 } | 439 } |
437 | 440 |
(...skipping 19 matching lines...) Expand all Loading... |
457 base::string16(), | 460 base::string16(), |
458 WebAutofillClient::MenuItemIDClearForm); | 461 WebAutofillClient::MenuItemIDClearForm); |
459 } | 462 } |
460 | 463 |
461 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { | 464 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { |
462 // Set up a field that shouldn't get autocompleted or display warnings. | 465 // Set up a field that shouldn't get autocompleted or display warnings. |
463 const FormData form; | 466 const FormData form; |
464 FormFieldData field; | 467 FormFieldData field; |
465 field.is_focusable = true; | 468 field.is_focusable = true; |
466 field.should_autocomplete = false; | 469 field.should_autocomplete = false; |
| 470 PasswordForm password_form; |
467 const gfx::RectF element_bounds; | 471 const gfx::RectF element_bounds; |
468 | 472 |
469 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 473 external_delegate_->OnQuery( |
| 474 kQueryId, form, field, password_form, element_bounds, false); |
470 | 475 |
471 std::vector<base::string16> autofill_items; | 476 std::vector<base::string16> autofill_items; |
472 autofill_items.push_back(base::string16()); | 477 autofill_items.push_back(base::string16()); |
473 std::vector<int> autofill_ids; | 478 std::vector<int> autofill_ids; |
474 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); | 479 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); |
475 | 480 |
476 // 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 |
477 // anything. | 482 // anything. |
478 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 483 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
479 | 484 |
480 external_delegate_->OnSuggestionsReturned(kQueryId, | 485 external_delegate_->OnSuggestionsReturned(kQueryId, |
481 autofill_items, | 486 autofill_items, |
482 autofill_items, | 487 autofill_items, |
483 autofill_items, | 488 autofill_items, |
484 autofill_ids); | 489 autofill_ids); |
485 } | 490 } |
486 | 491 |
487 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { | 492 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { |
488 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 493 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
489 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 494 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
490 EXPECT_CALL(*autofill_driver_, | 495 EXPECT_CALL(*autofill_driver_, |
491 RendererShouldSetNodeText(dummy_string)); | 496 RendererShouldSetNodeText(dummy_string)); |
492 external_delegate_->DidAcceptSuggestion( | 497 external_delegate_->DidAcceptSuggestion( |
493 dummy_string, | 498 dummy_string, |
494 WebAutofillClient::MenuItemIDAutocompleteEntry); | 499 WebAutofillClient::MenuItemIDAutocompleteEntry); |
495 } | 500 } |
496 | 501 |
497 } // namespace autofill | 502 } // namespace autofill |
OLD | NEW |