Chromium Code Reviews| 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..deb42e13d47b439474ded5d008246542f2991acd 100644 |
| --- a/chrome/renderer/autofill/form_autocomplete_browsertest.cc |
| +++ b/chrome/renderer/autofill/form_autocomplete_browsertest.cc |
| @@ -387,6 +387,72 @@ 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(); |
| + |
| + const IPC::Message* focus_no_longer_on_form_message = |
| + render_thread_->sink().GetFirstMessageMatching( |
| + AutofillHostMsg_FocusNoLongerOnForm::ID); |
| + EXPECT_TRUE(focus_no_longer_on_form_message != NULL); |
|
vabr (Chromium)
2015/12/07 09:47:33
nit: NULL -> nullptr, or drop the "!= NULL" comple
Mathieu
2015/12/07 14:23:07
Done.
|
| +} |
| + |
| +// 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(); |
| + |
| + const IPC::Message* focus_no_longer_on_form_message = |
| + render_thread_->sink().GetFirstMessageMatching( |
| + AutofillHostMsg_FocusNoLongerOnForm::ID); |
| + EXPECT_TRUE(focus_no_longer_on_form_message != NULL); |
|
vabr (Chromium)
2015/12/07 09:47:33
Consider my comment for line 418 here as well.
Mathieu
2015/12/07 14:23:07
Done.
|
| +} |
| + |
| // Tests that submitting a form that has autocomplete="off" generates |
| // WillSubmitForm and FormSubmitted messages. |
| TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |