Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7383)

Unified Diff: chrome/renderer/autofill/form_autocomplete_browsertest.cc

Issue 1494373003: [Autofill] Send Autofill upload when active form loses focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/content/browser/content_autofill_driver.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | components/autofill/content/browser/content_autofill_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698