Commit ee0fd443 authored by ziran.sun's avatar ziran.sun Committed by Commit bot

Do not set autofill property when choose option from datalist.

BUG=404818

Review URL: https://codereview.chromium.org/498653003

Cr-Commit-Position: refs/heads/master@{#292131}
parent d4d317a4
...@@ -294,6 +294,16 @@ class AutofillInteractiveTest : public InProcessBrowserTest { ...@@ -294,6 +294,16 @@ class AutofillInteractiveTest : public InProcessBrowserTest {
EXPECT_EQ(expected_value, value); EXPECT_EQ(expected_value, value);
} }
void GetFieldBackgroundColor(const std::string& field_name,
std::string* color) {
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
GetWebContents(),
"window.domAutomationController.send("
" document.defaultView.getComputedStyle(document.getElementById('" +
field_name + "')).backgroundColor);",
color));
}
void SimulateURLFetch(bool success) { void SimulateURLFetch(bool success) {
net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
ASSERT_TRUE(fetcher); ASSERT_TRUE(fetcher);
...@@ -423,6 +433,20 @@ class AutofillInteractiveTest : public InProcessBrowserTest { ...@@ -423,6 +433,20 @@ class AutofillInteractiveTest : public InProcessBrowserTest {
GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_); GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_);
} }
// Datalist does not support autofill preview. There is no need to start
// message loop for Datalist.
void SendKeyToDataListPopup(ui::KeyboardCode key) {
// Route popup-targeted key presses via the render view host.
content::NativeWebKeyboardEvent event;
event.windowsKeyCode = key;
event.type = blink::WebKeyboardEvent::RawKeyDown;
// Install the key press event sink to ensure that any events that are not
// handled by the installed callbacks do not end up crashing the test.
GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_);
GetRenderViewHost()->ForwardKeyboardEvent(event);
GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_);
}
void TryBasicFormFill() { void TryBasicFormFill() {
FocusFirstNameField(); FocusFirstNameField();
...@@ -634,6 +658,35 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnDeleteValueAfterAutofill) { ...@@ -634,6 +658,35 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnDeleteValueAfterAutofill) {
ExpectFieldValue("firstname", "Milton"); ExpectFieldValue("firstname", "Milton");
} }
// Test that an input field is not rendered with the yellow autofilled
// background color when choosing an option from the datalist suggestion list.
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnSelectOptionFromDatalist) {
// Load the test page.
ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
browser(),
GURL(std::string(kDataURIPrefix) +
"<form action=\"http://www.example.com/\" method=\"POST\">"
" <input list=\"dl\" type=\"search\" id=\"firstname\""
" onfocus=\"domAutomationController.send(true)\"><br>"
" <datalist id=\"dl\">"
" <option value=\"Adam\"></option>"
" <option value=\"Bob\"></option>"
" <option value=\"Carl\"></option>"
" </datalist>"
"</form>")));
std::string orginalcolor;
GetFieldBackgroundColor("firstname", &orginalcolor);
FocusFirstNameField();
SendKeyToPageAndWait(ui::VKEY_DOWN);
SendKeyToDataListPopup(ui::VKEY_DOWN);
SendKeyToDataListPopup(ui::VKEY_RETURN);
ExpectFieldValue("firstname", "Adam");
std::string color;
GetFieldBackgroundColor("firstname", &color);
EXPECT_EQ(color, orginalcolor);
}
// Test that a JavaScript oninput event is fired after auto-filling a form. // Test that a JavaScript oninput event is fired after auto-filling a form.
IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) { IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) {
CreateTestProfile(); CreateTestProfile();
......
...@@ -492,8 +492,10 @@ void AutofillAgent::OnClearPreviewedForm() { ...@@ -492,8 +492,10 @@ void AutofillAgent::OnClearPreviewedForm() {
void AutofillAgent::OnFillFieldWithValue(const base::string16& value) { void AutofillAgent::OnFillFieldWithValue(const base::string16& value) {
WebInputElement* input_element = toWebInputElement(&element_); WebInputElement* input_element = toWebInputElement(&element_);
if (input_element) if (input_element) {
FillFieldWithValue(value, input_element); FillFieldWithValue(value, input_element);
input_element->setAutofilled(true);
}
} }
void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) { void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) {
...@@ -678,7 +680,6 @@ void AutofillAgent::FillFieldWithValue(const base::string16& value, ...@@ -678,7 +680,6 @@ void AutofillAgent::FillFieldWithValue(const base::string16& value,
WebInputElement* node) { WebInputElement* node) {
did_set_node_text_ = true; did_set_node_text_ = true;
node->setEditingValue(value.substr(0, node->maxLength())); node->setEditingValue(value.substr(0, node->maxLength()));
node->setAutofilled(true);
} }
void AutofillAgent::PreviewFieldWithValue(const base::string16& value, void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment