| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
| 8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
| 10 #include "components/autofill/core/common/form_data.h" | 10 #include "components/autofill/core/common/form_data.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Form still visible. | 380 // Form still visible. |
| 381 | 381 |
| 382 // Simulate an Ajax request completing. | 382 // Simulate an Ajax request completing. |
| 383 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded(); | 383 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded(); |
| 384 ProcessPendingMessages(); | 384 ProcessPendingMessages(); |
| 385 | 385 |
| 386 // No submission messages sent. | 386 // No submission messages sent. |
| 387 VerifyNoSubmitMessagesReceived(render_thread_.get()); | 387 VerifyNoSubmitMessagesReceived(render_thread_.get()); |
| 388 } | 388 } |
| 389 | 389 |
| 390 // Test that a FocusNoLongerOnForm message is sent if focus goes from an |
| 391 // interacted form to an element outside the form. |
| 392 TEST_F(FormAutocompleteTest, |
| 393 InteractedFormNoLongerFocused_FocusNoLongerOnForm) { |
| 394 // Load a form. |
| 395 LoadHTML( |
| 396 "<html><input type='text' id='different'/>" |
| 397 "<form id='myForm' action='http://example.com/blade.php'>" |
| 398 "<input name='fname' id='fname' value='Bob'/>" |
| 399 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 400 |
| 401 // Simulate user input so that the form is "remembered". |
| 402 WebDocument document = GetMainFrame()->document(); |
| 403 WebElement element = document.getElementById(WebString::fromUTF8("fname")); |
| 404 ASSERT_FALSE(element.isNull()); |
| 405 WebInputElement fname_element = element.to<WebInputElement>(); |
| 406 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 407 |
| 408 // Change focus to a different node outside the form. |
| 409 WebElement different = |
| 410 document.getElementById(WebString::fromUTF8("different")); |
| 411 SetFocused(different); |
| 412 |
| 413 ProcessPendingMessages(); |
| 414 |
| 415 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 416 AutofillHostMsg_FocusNoLongerOnForm::ID) != nullptr); |
| 417 } |
| 418 |
| 419 // Test that a FocusNoLongerOnForm message is sent if focus goes from one |
| 420 // interacted form to another. |
| 421 TEST_F(FormAutocompleteTest, InteractingInDifferentForms_FocusNoLongerOnForm) { |
| 422 // Load a form. |
| 423 LoadHTML( |
| 424 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 425 "<input name='fname' id='fname' value='Bob'/>" |
| 426 "<input name='lname' value='Deckard'/><input type=submit></form>" |
| 427 "<form id='myForm2' action='http://example.com/runner.php'>" |
| 428 "<input name='fname' id='fname2' value='Bob'/>" |
| 429 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 430 |
| 431 // Simulate user input in the first form so that the form is "remembered". |
| 432 WebDocument document = GetMainFrame()->document(); |
| 433 WebElement element = document.getElementById(WebString::fromUTF8("fname")); |
| 434 ASSERT_FALSE(element.isNull()); |
| 435 WebInputElement fname_element = element.to<WebInputElement>(); |
| 436 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 437 |
| 438 // Simulate user input in the second form so that a "no longer focused" |
| 439 // message is sent for the first form. |
| 440 document = GetMainFrame()->document(); |
| 441 element = document.getElementById(WebString::fromUTF8("fname2")); |
| 442 ASSERT_FALSE(element.isNull()); |
| 443 fname_element = element.to<WebInputElement>(); |
| 444 SimulateUserInputChangeForElement(&fname_element, std::string("John")); |
| 445 |
| 446 ProcessPendingMessages(); |
| 447 |
| 448 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 449 AutofillHostMsg_FocusNoLongerOnForm::ID) != nullptr); |
| 450 } |
| 451 |
| 390 // Tests that submitting a form that has autocomplete="off" generates | 452 // Tests that submitting a form that has autocomplete="off" generates |
| 391 // WillSubmitForm and FormSubmitted messages. | 453 // WillSubmitForm and FormSubmitted messages. |
| 392 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { | 454 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |
| 393 // Load a form. | 455 // Load a form. |
| 394 LoadHTML("<html><form id='myForm' autocomplete='off'>" | 456 LoadHTML("<html><form id='myForm' autocomplete='off'>" |
| 395 "<input name='fname' value='Rick'/>" | 457 "<input name='fname' value='Rick'/>" |
| 396 "<input name='lname' value='Deckard'/>" | 458 "<input name='lname' value='Deckard'/>" |
| 397 "</form></html>"); | 459 "</form></html>"); |
| 398 | 460 |
| 399 // Submit the form. | 461 // Submit the form. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 504 |
| 443 // Submit the form. | 505 // Submit the form. |
| 444 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 506 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 445 ProcessPendingMessages(); | 507 ProcessPendingMessages(); |
| 446 | 508 |
| 447 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", | 509 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", |
| 448 true /* expect_submitted_message */); | 510 true /* expect_submitted_message */); |
| 449 } | 511 } |
| 450 | 512 |
| 451 } // namespace autofill | 513 } // namespace autofill |
| OLD | NEW |