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

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

Issue 1026493002: Allow only a user gesture to trigger autofill popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test. Created 5 years, 8 months 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
Index: chrome/renderer/autofill/autofill_renderer_browsertest.cc
diff --git a/chrome/renderer/autofill/autofill_renderer_browsertest.cc b/chrome/renderer/autofill/autofill_renderer_browsertest.cc
index 0ff5d278a96321e89ebb1152f26faae245971380..cc2a9c6c670818ae5f49fe145ca743e577934493 100644
--- a/chrome/renderer/autofill/autofill_renderer_browsertest.cc
+++ b/chrome/renderer/autofill/autofill_renderer_browsertest.cc
@@ -22,6 +22,7 @@
#include "third_party/WebKit/public/web/WebFormElement.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebView.h"
using base::ASCIIToUTF16;
using blink::WebDocument;
@@ -245,6 +246,59 @@ TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) {
EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[8]);
}
+TEST_F(AutofillRendererTest, IgnoreNonUserGestureTextFieldChanges) {
+ LoadHTML("<form method='post'>"
+ " <input type='text' id='full_name'/>"
+ "</form>");
+
+ blink::WebInputElement full_name =
+ GetMainFrame()->document().getElementById("full_name")
+ .to<blink::WebInputElement>();
+ while (!full_name.focused())
+ GetMainFrame()->view()->advanceFocus(false);
+
+ // Not a user gesture, so no IPC message to browser.
+ full_name.setValue("Alice", true);
+ GetMainFrame()->toWebLocalFrame()->autofillClient()->textFieldDidChange(
+ full_name);
+ ProcessInputForAutofill();
+ ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching(
+ AutofillHostMsg_TextFieldDidChange::ID));
+
+ // A user gesture will send a message to the browser.
+ SimulateUserInputChangeForElement(&full_name, "Alice");
+ ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching(
+ AutofillHostMsg_TextFieldDidChange::ID));
+}
+
+TEST_F(AutofillRendererTest, DesktopCompositionDoesNotTriggerAutofill) {
+ LoadHTML("<form method='post'>"
+ " <input type='text' id='full_name'/>"
+ "</form>");
+
+ blink::WebInputElement full_name =
+ GetMainFrame()->document().getElementById("full_name")
+ .to<blink::WebInputElement>();
+ while (!full_name.focused())
+ GetMainFrame()->view()->advanceFocus(false);
+
+ GetWebWidget()->setComposition(base::ASCIIToUTF16("Bob"),
+ std::vector<blink::WebCompositionUnderline>(),
+ 3, 3);
+ ProcessInputForAutofill();
+
+#if defined(OS_ANDROID)
+ // Android will trigger autofill even when IME is composing.
+ ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching(
+ AutofillHostMsg_TextFieldDidChange::ID));
+#else
+ // Desktop will not trigger autofill when IME is composing, because the IME UI
+ // can overlap the autofill UI.
+ ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching(
+ AutofillHostMsg_TextFieldDidChange::ID));
+#endif
+}
+
class RequestAutocompleteRendererTest : public AutofillRendererTest {
public:
RequestAutocompleteRendererTest()

Powered by Google App Engine
This is Rietveld 408576698