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 passwordform; |
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(query_id, form, field, passwordform, |
| 136 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 passwordform; |
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(kQueryId, form, passwordform, field, |
| 334 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 |
| 428 PasswordForm passwordform; |
424 external_delegate_->OnShowPasswordSuggestions(suggestions, | 429 external_delegate_->OnShowPasswordSuggestions(suggestions, |
425 realms, | 430 realms, |
426 field, | 431 field, |
| 432 passwordform, |
427 element_bounds); | 433 element_bounds); |
428 | 434 |
429 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 435 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
430 | 436 |
431 // This should trigger a call to hide the popup since | 437 // This should trigger a call to hide the popup since |
432 // we've selected an option. | 438 // we've selected an option. |
433 external_delegate_->DidAcceptSuggestion( | 439 external_delegate_->DidAcceptSuggestion( |
434 suggestions[0], | 440 suggestions[0], |
435 WebAutofillClient::MenuItemIDPasswordEntry); | 441 WebAutofillClient::MenuItemIDPasswordEntry); |
436 } | 442 } |
(...skipping 20 matching lines...) Expand all Loading... |
457 base::string16(), | 463 base::string16(), |
458 WebAutofillClient::MenuItemIDClearForm); | 464 WebAutofillClient::MenuItemIDClearForm); |
459 } | 465 } |
460 | 466 |
461 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { | 467 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { |
462 // 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. |
463 const FormData form; | 469 const FormData form; |
464 FormFieldData field; | 470 FormFieldData field; |
465 field.is_focusable = true; | 471 field.is_focusable = true; |
466 field.should_autocomplete = false; | 472 field.should_autocomplete = false; |
| 473 PasswordForm passwordform; |
467 const gfx::RectF element_bounds; | 474 const gfx::RectF element_bounds; |
468 | 475 |
469 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); | 476 external_delegate_->OnQuery(kQueryId, form, field, passwordform, |
| 477 element_bounds, false); |
470 | 478 |
471 std::vector<base::string16> autofill_items; | 479 std::vector<base::string16> autofill_items; |
472 autofill_items.push_back(base::string16()); | 480 autofill_items.push_back(base::string16()); |
473 std::vector<int> autofill_ids; | 481 std::vector<int> autofill_ids; |
474 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); | 482 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutocompleteEntry); |
475 | 483 |
476 // Ensure the popup tries to hide itself, since it is not allowed to show | 484 // Ensure the popup tries to hide itself, since it is not allowed to show |
477 // anything. | 485 // anything. |
478 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 486 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
479 | 487 |
480 external_delegate_->OnSuggestionsReturned(kQueryId, | 488 external_delegate_->OnSuggestionsReturned(kQueryId, |
481 autofill_items, | 489 autofill_items, |
482 autofill_items, | 490 autofill_items, |
483 autofill_items, | 491 autofill_items, |
484 autofill_ids); | 492 autofill_ids); |
485 } | 493 } |
486 | 494 |
487 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { | 495 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { |
488 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 496 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
489 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 497 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
490 EXPECT_CALL(*autofill_driver_, | 498 EXPECT_CALL(*autofill_driver_, |
491 RendererShouldSetNodeText(dummy_string)); | 499 RendererShouldSetNodeText(dummy_string)); |
492 external_delegate_->DidAcceptSuggestion( | 500 external_delegate_->DidAcceptSuggestion( |
493 dummy_string, | 501 dummy_string, |
494 WebAutofillClient::MenuItemIDAutocompleteEntry); | 502 WebAutofillClient::MenuItemIDAutocompleteEntry); |
495 } | 503 } |
496 | 504 |
497 } // namespace autofill | 505 } // namespace autofill |
OLD | NEW |