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