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

Side by Side Diff: chrome/browser/autofill/autofill_interactive_uitest.cc

Issue 498653003: Do not set autofill property for datalist options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test file. Created 6 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/renderer/autofill_agent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 const std::string& expected_value) { 287 const std::string& expected_value) {
288 std::string value; 288 std::string value;
289 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 289 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
290 GetWebContents(), 290 GetWebContents(),
291 "window.domAutomationController.send(" 291 "window.domAutomationController.send("
292 " document.getElementById('" + field_name + "').value);", 292 " document.getElementById('" + field_name + "').value);",
293 &value)); 293 &value));
294 EXPECT_EQ(expected_value, value); 294 EXPECT_EQ(expected_value, value);
295 } 295 }
296 296
297 void GetFieldBackgroundColor(const std::string& field_name,
298 std::string& color) {
Ilya Sherman 2014/08/22 23:49:17 nit: Please pass a pointer. We pretty much never
ziran.sun 2014/08/26 13:32:15 Done.
299 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
300 GetWebContents(),
301 "window.domAutomationController.send("
302 " document.defaultView.getComputedStyle(document.getElementById('" +
303 field_name + "')).backgroundColor);",
Ilya Sherman 2014/08/22 23:49:17 nit: The current indentation looks really odd. I'
ziran.sun 2014/08/26 13:32:15 I tried both suggestions, "git cl format" doesn't
Ilya Sherman 2014/08/27 00:37:47 I understand that this is the format that "git cl
304 &color));
305 }
306
297 void SimulateURLFetch(bool success) { 307 void SimulateURLFetch(bool success) {
298 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 308 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
299 ASSERT_TRUE(fetcher); 309 ASSERT_TRUE(fetcher);
300 net::URLRequestStatus status; 310 net::URLRequestStatus status;
301 status.set_status(success ? net::URLRequestStatus::SUCCESS : 311 status.set_status(success ? net::URLRequestStatus::SUCCESS :
302 net::URLRequestStatus::FAILED); 312 net::URLRequestStatus::FAILED);
303 313
304 std::string script = " var google = {};" 314 std::string script = " var google = {};"
305 "google.translate = (function() {" 315 "google.translate = (function() {"
306 " return {" 316 " return {"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 event.type = blink::WebKeyboardEvent::RawKeyDown; 426 event.type = blink::WebKeyboardEvent::RawKeyDown;
417 test_delegate_.Reset(); 427 test_delegate_.Reset();
418 // Install the key press event sink to ensure that any events that are not 428 // Install the key press event sink to ensure that any events that are not
419 // handled by the installed callbacks do not end up crashing the test. 429 // handled by the installed callbacks do not end up crashing the test.
420 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_); 430 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_);
421 GetRenderViewHost()->ForwardKeyboardEvent(event); 431 GetRenderViewHost()->ForwardKeyboardEvent(event);
422 test_delegate_.Wait(); 432 test_delegate_.Wait();
423 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_); 433 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_);
424 } 434 }
425 435
436 // There is no need to start message loop for Datalist.
Ilya Sherman 2014/08/22 23:49:17 Hmm, why not? Doesn't it use the same UI? Even i
ziran.sun 2014/08/26 13:32:15 Existing test cases in this test file assume that
Ilya Sherman 2014/08/27 00:37:47 I see. That makes sense; thanks for the explanati
437 void SendKeyToDataListPopup(ui::KeyboardCode key) {
438 // Route popup-targeted key presses via the render view host.
439 content::NativeWebKeyboardEvent event;
440 event.windowsKeyCode = key;
441 event.type = blink::WebKeyboardEvent::RawKeyDown;
442 // Install the key press event sink to ensure that any events that are not
443 // handled by the installed callbacks do not end up crashing the test.
444 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_);
445 GetRenderViewHost()->ForwardKeyboardEvent(event);
446 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_);
447 }
448
426 void TryBasicFormFill() { 449 void TryBasicFormFill() {
427 FocusFirstNameField(); 450 FocusFirstNameField();
428 451
429 // Start filling the first name field with "M" and wait for the popup to be 452 // Start filling the first name field with "M" and wait for the popup to be
430 // shown. 453 // shown.
431 SendKeyToPageAndWait(ui::VKEY_M); 454 SendKeyToPageAndWait(ui::VKEY_M);
432 455
433 // Press the down arrow to select the suggestion and preview the autofilled 456 // Press the down arrow to select the suggestion and preview the autofilled
434 // form. 457 // form.
435 SendKeyToPopupAndWait(ui::VKEY_DOWN); 458 SendKeyToPopupAndWait(ui::VKEY_DOWN);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 "document.getElementById('firstname').value = '';")); 650 "document.getElementById('firstname').value = '';"));
628 ExpectFieldValue("firstname", ""); 651 ExpectFieldValue("firstname", "");
629 652
630 // Invoke and accept the Autofill popup and verify the field was filled. 653 // Invoke and accept the Autofill popup and verify the field was filled.
631 SendKeyToPageAndWait(ui::VKEY_M); 654 SendKeyToPageAndWait(ui::VKEY_M);
632 SendKeyToPopupAndWait(ui::VKEY_DOWN); 655 SendKeyToPopupAndWait(ui::VKEY_DOWN);
633 SendKeyToPopupAndWait(ui::VKEY_RETURN); 656 SendKeyToPopupAndWait(ui::VKEY_RETURN);
634 ExpectFieldValue("firstname", "Milton"); 657 ExpectFieldValue("firstname", "Milton");
635 } 658 }
636 659
660 // Test that an input field should not be autofilled when choose an option from
661 // its datalist option list.
Ilya Sherman 2014/08/22 23:49:17 nit: Perhaps something like "Test that an input fi
ziran.sun 2014/08/26 13:32:15 Done.
662 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnSelectOptionFromDatalist) {
663 // Load the test page.
664 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
665 browser(),
666 GURL(std::string(kDataURIPrefix) +
667 "<form action=\"http://www.example.com/\" method=\"POST\">"
668 " <input list=\"dl\" type=\"search\" id=\"firstname\""
Ilya Sherman 2014/08/22 23:49:17 nit: Please indent this line, and the ones below,
ziran.sun 2014/08/26 13:32:15 Done.
669 " onfocus=\"domAutomationController.send(true)\"><br>"
670 " <datalist id=\"dl\">"
Ilya Sherman 2014/08/22 23:49:17 nit: Why does the datalist need an id? Would the
ziran.sun 2014/08/26 13:32:15 I think the minimum argument for datalist tag is t
671 " <option value=\"Adam\"></option>"
672 " <option value=\"Bob\"></option>"
673 " <option value=\"Carl\"></option>"
674 " </datalist>"
675 "</form>")));
676 std::string orginalcolor;
677 GetFieldBackgroundColor("firstname", orginalcolor);
678
679 FocusFirstNameField();
680 SendKeyToPageAndWait(ui::VKEY_DOWN);
681 SendKeyToDataListPopup(ui::VKEY_DOWN);
682 SendKeyToDataListPopup(ui::VKEY_RETURN);
683 ExpectFieldValue("firstname", "Adam");
684 std::string color;
685 GetFieldBackgroundColor("firstname", color);
686 EXPECT_EQ(color, orginalcolor);
687 }
688
637 // Test that a JavaScript oninput event is fired after auto-filling a form. 689 // Test that a JavaScript oninput event is fired after auto-filling a form.
638 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) { 690 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) {
639 CreateTestProfile(); 691 CreateTestProfile();
640 692
641 const char kOnInputScript[] = 693 const char kOnInputScript[] =
642 "<script>" 694 "<script>"
643 "focused_fired = false;" 695 "focused_fired = false;"
644 "unfocused_fired = false;" 696 "unfocused_fired = false;"
645 "changed_select_fired = false;" 697 "changed_select_fired = false;"
646 "unchanged_select_fired = false;" 698 "unchanged_select_fired = false;"
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 ASSERT_TRUE(content::ExecuteScript( 1440 ASSERT_TRUE(content::ExecuteScript(
1389 GetRenderViewHost(), 1441 GetRenderViewHost(),
1390 "document.querySelector('input').autocomplete = 'off';")); 1442 "document.querySelector('input').autocomplete = 'off';"));
1391 1443
1392 // Press the down arrow to select the suggestion and attempt to preview the 1444 // Press the down arrow to select the suggestion and attempt to preview the
1393 // autofilled form. 1445 // autofilled form.
1394 SendKeyToPopupAndWait(ui::VKEY_DOWN); 1446 SendKeyToPopupAndWait(ui::VKEY_DOWN);
1395 } 1447 }
1396 1448
1397 } // namespace autofill 1449 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/autofill_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698