diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 09:52:20 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 09:52:20 +0000 |
commit | 3b3b94d909bef02adc67055096cf1710a7f824de (patch) | |
tree | a5bfd2434100dacfad13cf5bcad236cebf74733c /chrome/browser | |
parent | edec5e1320aca86a56c0a1b780a4be55d4736801 (diff) | |
download | chromium_src-3b3b94d909bef02adc67055096cf1710a7f824de.zip chromium_src-3b3b94d909bef02adc67055096cf1710a7f824de.tar.gz chromium_src-3b3b94d909bef02adc67055096cf1710a7f824de.tar.bz2 |
Dispatch change event for autofilled fields
BUG=42716
TEST=interactive_ui_tests --gtest_filter=AutoFillTest.OnChangeAfterAutoFill
Review URL: http://codereview.chromium.org/6649015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autofill/autofill_browsertest.cc | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index 0a6812a..a29e93b1 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -35,8 +35,7 @@ static const char* kTestFormString = "<form action=\"http://www.example.com/\" method=\"POST\">" "<label for=\"firstname\">First name:</label>" " <input type=\"text\" id=\"firstname\"" - " onFocus=\"domAutomationController.send(true)\"" - " /><br />" + " onFocus=\"domAutomationController.send(true)\" /><br />" "<label for=\"lastname\">Last name:</label>" " <input type=\"text\" id=\"lastname\" /><br />" "<label for=\"address1\">Address line 1:</label>" @@ -263,6 +262,61 @@ IN_PROC_BROWSER_TEST_F(AutoFillTest, AutoFillViaDownArrow) { ExpectFilledTestForm(); } +// Test that a JavaScript onchange event is fired after auto-filling a form. +IN_PROC_BROWSER_TEST_F(AutoFillTest, OnChangeAfterAutoFill) { + CreateTestProfile(); + + const char* kOnChangeScript = + "<script>" + "focused_fired = false;" + "unfocused_fired = false;" + "select_fired = false;" + "document.getElementById('firstname').onchange = function() {" + " focused_fired = true;" + "};" + "document.getElementById('lastname').onchange = function() {" + " unfocused_fired = true;" + "};" + "document.getElementById('state').onchange = function() {" + " select_fired = true;" + "};" + "</script>"; + + // Load the test page. + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); + ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), + GURL(std::string(kDataURIPrefix) + kTestFormString + kOnChangeScript))); + + // Invoke Autofill. + TryBasicFormFill(); + + // The change event should have already fired for unfocused fields, both of + // <input> and of <select> type. However, it should not yet have fired for the + // focused field. + bool focused_fired = false; + bool unfocused_fired = false; + bool select_fired = false; + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + render_view_host(), L"", + L"domAutomationController.send(focused_fired);", &focused_fired)); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + render_view_host(), L"", + L"domAutomationController.send(unfocused_fired);", &unfocused_fired)); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + render_view_host(), L"", + L"domAutomationController.send(select_fired);", &select_fired)); + EXPECT_FALSE(focused_fired); + EXPECT_TRUE(unfocused_fired); + EXPECT_TRUE(select_fired); + + // Unfocus the first name field. Its change event should fire. + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + render_view_host(), L"", + L"document.getElementById('firstname').blur();" + L"domAutomationController.send(focused_fired);", &focused_fired)); + EXPECT_TRUE(focused_fired); +} + // Test that form filling works after reloading the current page. // This test brought to you by http://crbug.com/69204 IN_PROC_BROWSER_TEST_F(AutoFillTest, AutoFillAfterReload) { |