| Index: chrome/renderer/autofill/form_autocomplete_browsertest.cc
|
| diff --git a/chrome/renderer/autofill/form_autocomplete_browsertest.cc b/chrome/renderer/autofill/form_autocomplete_browsertest.cc
|
| index 3ce69aae6435532ec16476851d673765d9243d45..ac7e499578b904b97e93c36b6b47122a07e6b829 100644
|
| --- a/chrome/renderer/autofill/form_autocomplete_browsertest.cc
|
| +++ b/chrome/renderer/autofill/form_autocomplete_browsertest.cc
|
| @@ -387,6 +387,68 @@ TEST_F(FormAutocompleteTest, AjaxSucceeded_FilledFormStillVisible) {
|
| VerifyNoSubmitMessagesReceived(render_thread_.get());
|
| }
|
|
|
| +// Test that a FocusNoLongerOnForm message is sent if focus goes from an
|
| +// interacted form to an element outside the form.
|
| +TEST_F(FormAutocompleteTest,
|
| + InteractedFormNoLongerFocused_FocusNoLongerOnForm) {
|
| + // Load a form.
|
| + LoadHTML(
|
| + "<html><input type='text' id='different'/>"
|
| + "<form id='myForm' action='http://example.com/blade.php'>"
|
| + "<input name='fname' id='fname' value='Bob'/>"
|
| + "<input name='lname' value='Deckard'/><input type=submit></form></html>");
|
| +
|
| + // Simulate user input so that the form is "remembered".
|
| + WebDocument document = GetMainFrame()->document();
|
| + WebElement element = document.getElementById(WebString::fromUTF8("fname"));
|
| + ASSERT_FALSE(element.isNull());
|
| + WebInputElement fname_element = element.to<WebInputElement>();
|
| + SimulateUserInputChangeForElement(&fname_element, std::string("Rick"));
|
| +
|
| + // Change focus to a different node outside the form.
|
| + WebElement different =
|
| + document.getElementById(WebString::fromUTF8("different"));
|
| + SetFocused(different);
|
| +
|
| + ProcessPendingMessages();
|
| +
|
| + EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| + AutofillHostMsg_FocusNoLongerOnForm::ID) != nullptr);
|
| +}
|
| +
|
| +// Test that a FocusNoLongerOnForm message is sent if focus goes from one
|
| +// interacted form to another.
|
| +TEST_F(FormAutocompleteTest, InteractingInDifferentForms_FocusNoLongerOnForm) {
|
| + // Load a form.
|
| + LoadHTML(
|
| + "<html><form id='myForm' action='http://example.com/blade.php'>"
|
| + "<input name='fname' id='fname' value='Bob'/>"
|
| + "<input name='lname' value='Deckard'/><input type=submit></form>"
|
| + "<form id='myForm2' action='http://example.com/runner.php'>"
|
| + "<input name='fname' id='fname2' value='Bob'/>"
|
| + "<input name='lname' value='Deckard'/><input type=submit></form></html>");
|
| +
|
| + // Simulate user input in the first form so that the form is "remembered".
|
| + WebDocument document = GetMainFrame()->document();
|
| + WebElement element = document.getElementById(WebString::fromUTF8("fname"));
|
| + ASSERT_FALSE(element.isNull());
|
| + WebInputElement fname_element = element.to<WebInputElement>();
|
| + SimulateUserInputChangeForElement(&fname_element, std::string("Rick"));
|
| +
|
| + // Simulate user input in the second form so that a "no longer focused"
|
| + // message is sent for the first form.
|
| + document = GetMainFrame()->document();
|
| + element = document.getElementById(WebString::fromUTF8("fname2"));
|
| + ASSERT_FALSE(element.isNull());
|
| + fname_element = element.to<WebInputElement>();
|
| + SimulateUserInputChangeForElement(&fname_element, std::string("John"));
|
| +
|
| + ProcessPendingMessages();
|
| +
|
| + EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
|
| + AutofillHostMsg_FocusNoLongerOnForm::ID) != nullptr);
|
| +}
|
| +
|
| // Tests that submitting a form that has autocomplete="off" generates
|
| // WillSubmitForm and FormSubmitted messages.
|
| TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
|
|
|