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

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

Issue 214823011: Autofill/rAc: dispatch "input"/"change" on <input>, <textarea>, and <select> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simpler Created 6 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 unified diff | Download patch | Annotate | Revision Log
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 using base::ASCIIToUTF16; 57 using base::ASCIIToUTF16;
58 58
59 namespace autofill { 59 namespace autofill {
60 60
61 static const char* kDataURIPrefix = "data:text/html;charset=utf-8,"; 61 static const char* kDataURIPrefix = "data:text/html;charset=utf-8,";
62 static const char* kTestFormString = 62 static const char* kTestFormString =
63 "<form action=\"http://www.example.com/\" method=\"POST\">" 63 "<form action=\"http://www.example.com/\" method=\"POST\">"
64 "<label for=\"firstname\">First name:</label>" 64 "<label for=\"firstname\">First name:</label>"
65 " <input type=\"text\" id=\"firstname\"" 65 " <input type=\"text\" id=\"firstname\""
66 " onFocus=\"domAutomationController.send(true)\"><br>" 66 " onfocus=\"domAutomationController.send(true)\"><br>"
67 "<label for=\"lastname\">Last name:</label>" 67 "<label for=\"lastname\">Last name:</label>"
68 " <input type=\"text\" id=\"lastname\"><br>" 68 " <input type=\"text\" id=\"lastname\"><br>"
69 "<label for=\"address1\">Address line 1:</label>" 69 "<label for=\"address1\">Address line 1:</label>"
70 " <input type=\"text\" id=\"address1\"><br>" 70 " <input type=\"text\" id=\"address1\"><br>"
71 "<label for=\"address2\">Address line 2:</label>" 71 "<label for=\"address2\">Address line 2:</label>"
72 " <input type=\"text\" id=\"address2\"><br>" 72 " <input type=\"text\" id=\"address2\"><br>"
73 "<label for=\"city\">City:</label>" 73 "<label for=\"city\">City:</label>"
74 " <input type=\"text\" id=\"city\"><br>" 74 " <input type=\"text\" id=\"city\"><br>"
75 "<label for=\"state\">State:</label>" 75 "<label for=\"state\">State:</label>"
76 " <select id=\"state\">" 76 " <select id=\"state\">"
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 SendKeyToPopupAndWait(ui::VKEY_DOWN); 483 SendKeyToPopupAndWait(ui::VKEY_DOWN);
484 484
485 // Press tab to accept the autofill suggestions. 485 // Press tab to accept the autofill suggestions.
486 SendKeyToPopupAndWait(ui::VKEY_TAB); 486 SendKeyToPopupAndWait(ui::VKEY_TAB);
487 487
488 // The form should be filled. 488 // The form should be filled.
489 ExpectFilledTestForm(); 489 ExpectFilledTestForm();
490 } 490 }
491 491
492 // Test that a JavaScript onchange event is fired after auto-filling a form. 492 // Test that a JavaScript onchange event is fired after auto-filling a form.
493 // Temporarily disabled for crbug.com/353691. 493 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnChangeAfterAutofill) {
Ilya Sherman 2014/03/29 00:07:07 Could you also add a test for oninput?
Dan Beam 2014/03/29 00:51:14 Done.
494 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
495 DISABLED_OnChangeAfterAutofill) {
496 CreateTestProfile(); 494 CreateTestProfile();
497 495
498 const char* kOnChangeScript = 496 const char* kOnChangeScript =
Ilya Sherman 2014/03/29 00:07:07 nit: While you're here... can you update this to b
Dan Beam 2014/03/29 00:51:14 Done.
499 "<script>" 497 "<script>"
500 "focused_fired = false;" 498 "focused_fired = false;"
501 "unfocused_fired = false;" 499 "unfocused_fired = false;"
502 "changed_select_fired = false;" 500 "changed_select_fired = false;"
503 "unchanged_select_fired = false;" 501 "unchanged_select_fired = false;"
504 "document.getElementById('firstname').onchange = function() {" 502 "document.getElementById('firstname').onchange = function() {"
505 " focused_fired = true;" 503 " focused_fired = true;"
506 "};" 504 "};"
507 "document.getElementById('lastname').onchange = function() {" 505 "document.getElementById('lastname').onchange = function() {"
508 " unfocused_fired = true;" 506 " unfocused_fired = true;"
(...skipping 21 matching lines...) Expand all
530 // Press the down arrow to select the suggestion and preview the autofilled 528 // Press the down arrow to select the suggestion and preview the autofilled
531 // form. 529 // form.
532 SendKeyToPopupAndWait(ui::VKEY_DOWN); 530 SendKeyToPopupAndWait(ui::VKEY_DOWN);
533 531
534 // Press Enter to accept the autofill suggestions. 532 // Press Enter to accept the autofill suggestions.
535 SendKeyToPopupAndWait(ui::VKEY_RETURN); 533 SendKeyToPopupAndWait(ui::VKEY_RETURN);
536 534
537 // The form should be filled. 535 // The form should be filled.
538 ExpectFilledTestForm(); 536 ExpectFilledTestForm();
539 537
540 // The change event should have already fired for unfocused fields, both of
541 // <input> and of <select> type. However, it should not yet have fired for the
542 // focused field.
543 bool focused_fired = false; 538 bool focused_fired = false;
544 bool unfocused_fired = false; 539 bool unfocused_fired = false;
545 bool changed_select_fired = false; 540 bool changed_select_fired = false;
546 bool unchanged_select_fired = false; 541 bool unchanged_select_fired = false;
547 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 542 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
548 GetRenderViewHost(), 543 GetRenderViewHost(),
549 "domAutomationController.send(focused_fired);", 544 "domAutomationController.send(focused_fired);",
550 &focused_fired)); 545 &focused_fired));
551 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 546 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
552 GetRenderViewHost(), 547 GetRenderViewHost(),
553 "domAutomationController.send(unfocused_fired);", 548 "domAutomationController.send(unfocused_fired);",
554 &unfocused_fired)); 549 &unfocused_fired));
555 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 550 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
556 GetRenderViewHost(), 551 GetRenderViewHost(),
557 "domAutomationController.send(changed_select_fired);", 552 "domAutomationController.send(changed_select_fired);",
558 &changed_select_fired)); 553 &changed_select_fired));
559 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 554 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
560 GetRenderViewHost(), 555 GetRenderViewHost(),
561 "domAutomationController.send(unchanged_select_fired);", 556 "domAutomationController.send(unchanged_select_fired);",
562 &unchanged_select_fired)); 557 &unchanged_select_fired));
563 EXPECT_FALSE(focused_fired); 558 EXPECT_TRUE(focused_fired);
564 EXPECT_TRUE(unfocused_fired); 559 EXPECT_TRUE(unfocused_fired);
565 EXPECT_TRUE(changed_select_fired); 560 EXPECT_TRUE(changed_select_fired);
566 EXPECT_FALSE(unchanged_select_fired); 561 EXPECT_FALSE(unchanged_select_fired);
567 562
568 // Unfocus the first name field. Its change event should fire. 563 // Unfocus the first name field. Its change event should fire.
569 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 564 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
570 GetRenderViewHost(), 565 GetRenderViewHost(),
571 "document.getElementById('firstname').blur();" 566 "document.getElementById('firstname').blur();"
572 "domAutomationController.send(focused_fired);", &focused_fired)); 567 "domAutomationController.send(focused_fired);", &focused_fired));
573 EXPECT_TRUE(focused_fired); 568 EXPECT_TRUE(focused_fired);
(...skipping 28 matching lines...) Expand all
602 // JavaScript, with only one actually visible at any given time. 597 // JavaScript, with only one actually visible at any given time.
603 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillFormWithRepeatedField) { 598 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillFormWithRepeatedField) {
604 CreateTestProfile(); 599 CreateTestProfile();
605 600
606 // Load the test page. 601 // Load the test page.
607 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 602 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
608 GURL(std::string(kDataURIPrefix) + 603 GURL(std::string(kDataURIPrefix) +
609 "<form action=\"http://www.example.com/\" method=\"POST\">" 604 "<form action=\"http://www.example.com/\" method=\"POST\">"
610 "<label for=\"firstname\">First name:</label>" 605 "<label for=\"firstname\">First name:</label>"
611 " <input type=\"text\" id=\"firstname\"" 606 " <input type=\"text\" id=\"firstname\""
612 " onFocus=\"domAutomationController.send(true)\"><br>" 607 " onfocus=\"domAutomationController.send(true)\"><br>"
613 "<label for=\"lastname\">Last name:</label>" 608 "<label for=\"lastname\">Last name:</label>"
614 " <input type=\"text\" id=\"lastname\"><br>" 609 " <input type=\"text\" id=\"lastname\"><br>"
615 "<label for=\"address1\">Address line 1:</label>" 610 "<label for=\"address1\">Address line 1:</label>"
616 " <input type=\"text\" id=\"address1\"><br>" 611 " <input type=\"text\" id=\"address1\"><br>"
617 "<label for=\"address2\">Address line 2:</label>" 612 "<label for=\"address2\">Address line 2:</label>"
618 " <input type=\"text\" id=\"address2\"><br>" 613 " <input type=\"text\" id=\"address2\"><br>"
619 "<label for=\"city\">City:</label>" 614 "<label for=\"city\">City:</label>"
620 " <input type=\"text\" id=\"city\"><br>" 615 " <input type=\"text\" id=\"city\"><br>"
621 "<label for=\"state\">State:</label>" 616 "<label for=\"state\">State:</label>"
622 " <select id=\"state\">" 617 " <select id=\"state\">"
(...skipping 25 matching lines...) Expand all
648 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, 643 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
649 AutofillFormWithNonAutofillableField) { 644 AutofillFormWithNonAutofillableField) {
650 CreateTestProfile(); 645 CreateTestProfile();
651 646
652 // Load the test page. 647 // Load the test page.
653 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 648 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
654 GURL(std::string(kDataURIPrefix) + 649 GURL(std::string(kDataURIPrefix) +
655 "<form action=\"http://www.example.com/\" method=\"POST\">" 650 "<form action=\"http://www.example.com/\" method=\"POST\">"
656 "<label for=\"firstname\">First name:</label>" 651 "<label for=\"firstname\">First name:</label>"
657 " <input type=\"text\" id=\"firstname\"" 652 " <input type=\"text\" id=\"firstname\""
658 " onFocus=\"domAutomationController.send(true)\"><br>" 653 " onfocus=\"domAutomationController.send(true)\"><br>"
659 "<label for=\"middlename\">Middle name:</label>" 654 "<label for=\"middlename\">Middle name:</label>"
660 " <input type=\"text\" id=\"middlename\" autocomplete=\"off\" /><br>" 655 " <input type=\"text\" id=\"middlename\" autocomplete=\"off\" /><br>"
661 "<label for=\"lastname\">Last name:</label>" 656 "<label for=\"lastname\">Last name:</label>"
662 " <input type=\"text\" id=\"lastname\"><br>" 657 " <input type=\"text\" id=\"lastname\"><br>"
663 "<label for=\"address1\">Address line 1:</label>" 658 "<label for=\"address1\">Address line 1:</label>"
664 " <input type=\"text\" id=\"address1\"><br>" 659 " <input type=\"text\" id=\"address1\"><br>"
665 "<label for=\"address2\">Address line 2:</label>" 660 "<label for=\"address2\">Address line 2:</label>"
666 " <input type=\"text\" id=\"address2\"><br>" 661 " <input type=\"text\" id=\"address2\"><br>"
667 "<label for=\"city\">City:</label>" 662 "<label for=\"city\">City:</label>"
668 " <input type=\"text\" id=\"city\"><br>" 663 " <input type=\"text\" id=\"city\"><br>"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 " var option2 = new Option('United States', 'US');" 723 " var option2 = new Option('United States', 'US');"
729 " select_element.appendChild(option2);" 724 " select_element.appendChild(option2);"
730 " }" 725 " }"
731 "" 726 ""
732 " form.appendChild(select_element);" 727 " form.appendChild(select_element);"
733 " } else {" 728 " } else {"
734 " var input_element = document.createElement('input');" 729 " var input_element = document.createElement('input');"
735 " input_element.setAttribute('id', name);" 730 " input_element.setAttribute('id', name);"
736 " input_element.setAttribute('name', name);" 731 " input_element.setAttribute('name', name);"
737 "" 732 ""
738 " /* Add the onFocus listener to the 'firstname' field. */" 733 " /* Add the onfocus listener to the 'firstname' field. */"
739 " if (name === 'firstname') {" 734 " if (name === 'firstname') {"
740 " input_element.setAttribute(" 735 " input_element.onfocus = function() {"
741 " 'onFocus', 'domAutomationController.send(true)');" 736 " domAutomationController.send(true);"
737 " };"
742 " }" 738 " }"
743 "" 739 ""
744 " form.appendChild(input_element);" 740 " form.appendChild(input_element);"
745 " }" 741 " }"
746 "" 742 ""
747 " form.appendChild(document.createElement('br'));" 743 " form.appendChild(document.createElement('br'));"
748 "};" 744 "};"
749 "" 745 ""
750 "function BuildForm() {" 746 "function BuildForm() {"
751 " var elements = [" 747 " var elements = ["
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 TryBasicFormFill(); 788 TryBasicFormFill();
793 } 789 }
794 790
795 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) { 791 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) {
796 CreateTestProfile(); 792 CreateTestProfile();
797 793
798 GURL url(std::string(kDataURIPrefix) + 794 GURL url(std::string(kDataURIPrefix) +
799 "<form action=\"http://www.example.com/\" method=\"POST\">" 795 "<form action=\"http://www.example.com/\" method=\"POST\">"
800 "<label for=\"fn\">なまえ</label>" 796 "<label for=\"fn\">なまえ</label>"
801 " <input type=\"text\" id=\"fn\"" 797 " <input type=\"text\" id=\"fn\""
802 " onFocus=\"domAutomationController.send(true)\"" 798 " onfocus=\"domAutomationController.send(true)\""
803 "><br>" 799 "><br>"
804 "<label for=\"ln\">みょうじ</label>" 800 "<label for=\"ln\">みょうじ</label>"
805 " <input type=\"text\" id=\"ln\"><br>" 801 " <input type=\"text\" id=\"ln\"><br>"
806 "<label for=\"a1\">Address line 1:</label>" 802 "<label for=\"a1\">Address line 1:</label>"
807 " <input type=\"text\" id=\"a1\"><br>" 803 " <input type=\"text\" id=\"a1\"><br>"
808 "<label for=\"a2\">Address line 2:</label>" 804 "<label for=\"a2\">Address line 2:</label>"
809 " <input type=\"text\" id=\"a2\"><br>" 805 " <input type=\"text\" id=\"a2\"><br>"
810 "<label for=\"ci\">City:</label>" 806 "<label for=\"ci\">City:</label>"
811 " <input type=\"text\" id=\"ci\"><br>" 807 " <input type=\"text\" id=\"ci\"><br>"
812 "<label for=\"st\">State:</label>" 808 "<label for=\"st\">State:</label>"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 ASSERT_TRUE(content::ExecuteScript( 1088 ASSERT_TRUE(content::ExecuteScript(
1093 GetRenderViewHost(), 1089 GetRenderViewHost(),
1094 "document.querySelector('input').autocomplete = 'off';")); 1090 "document.querySelector('input').autocomplete = 'off';"));
1095 1091
1096 // Press the down arrow to select the suggestion and attempt to preview the 1092 // Press the down arrow to select the suggestion and attempt to preview the
1097 // autofilled form. 1093 // autofilled form.
1098 SendKeyToPopupAndWait(ui::VKEY_DOWN); 1094 SendKeyToPopupAndWait(ui::VKEY_DOWN);
1099 } 1095 }
1100 1096
1101 } // namespace autofill 1097 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698