summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 03:07:06 +0000
committervabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 03:07:06 +0000
commit43f078ee806c7fc35d4a67da78eee08476d5eb28 (patch)
treee5c78b8ca723575aac944426df711d4eb4128d4a
parent12271633c7a7b43d0dcd9ad210be2dd57e0cf596 (diff)
downloadchromium_src-43f078ee806c7fc35d4a67da78eee08476d5eb28.zip
chromium_src-43f078ee806c7fc35d4a67da78eee08476d5eb28.tar.gz
chromium_src-43f078ee806c7fc35d4a67da78eee08476d5eb28.tar.bz2
Add tests for password manager: forms elements with missing id or name
This complements a crasher fix from https://codereview.chromium.org/83323002/. Adds 2 tests: 1. That the save password prompt triggers on forms where elements have a 'name' but no 'id' attribute. 2. That the save password prompt does not trigger on forms with elements missing both attributes. The interesting part about 2. is that the renderer should not crash. BUG=322242,282487 Review URL: https://codereview.chromium.org/82703003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237230 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/password_manager/password_manager_browsertest.cc37
-rw-r--r--chrome/test/data/password/password_form.html20
2 files changed, 54 insertions, 3 deletions
diff --git a/chrome/browser/password_manager/password_manager_browsertest.cc b/chrome/browser/password_manager/password_manager_browsertest.cc
index eac2762..66f53d8 100644
--- a/chrome/browser/password_manager/password_manager_browsertest.cc
+++ b/chrome/browser/password_manager/password_manager_browsertest.cc
@@ -394,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForSubmitFromIframe) {
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
PromptForInputElementWithoutName) {
- // Check that the prompt is shown for forms where input elements miss the
+ // Check that the prompt is shown for forms where input elements lack the
// "name" attribute but the "id" is present.
NavigateToFile("/password/password_form.html");
@@ -408,6 +408,41 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
EXPECT_TRUE(observer.infobar_shown());
}
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ PromptForInputElementWithoutId) {
+ // Check that the prompt is shown for forms where input elements lack the
+ // "id" attribute but the "name" attribute is present.
+ NavigateToFile("/password/password_form.html");
+
+ NavigationObserver observer(WebContents());
+ std::string fill_and_submit =
+ "document.getElementsByName('username_field_no_id')[0].value = 'temp';"
+ "document.getElementsByName('password_field_no_id')[0].value = 'random';"
+ "document.getElementsByName('input_submit_button_no_id')[0].click()";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ observer.Wait();
+ EXPECT_TRUE(observer.infobar_shown());
+}
+
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ NoPromptForInputElementWithoutIdAndName) {
+ // Check that no prompt is shown for forms where the input fields lack both
+ // the "id" and the "name" attributes.
+ NavigateToFile("/password/password_form.html");
+
+ NavigationObserver observer(WebContents());
+ std::string fill_and_submit =
+ "var form = document.getElementById('testform_elements_no_id_no_name');"
+ "var username = form.children[0];"
+ "username.value = 'temp';"
+ "var password = form.children[1];"
+ "password.value = 'random';"
+ "form.children[2].click()"; // form.children[2] is the submit button.
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ observer.Wait();
+ EXPECT_FALSE(observer.infobar_shown());
+}
+
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) {
NavigateToFile("/password/multi_frames.html");
diff --git a/chrome/test/data/password/password_form.html b/chrome/test/data/password/password_form.html
index eda2b45..daf92c2 100644
--- a/chrome/test/data/password/password_form.html
+++ b/chrome/test/data/password/password_form.html
@@ -11,12 +11,28 @@
Submit!
</button>
-<form method="POST" action="done.html" onsubmit="return true;"
- id="testform_no_name">
+<form method="POST" action="done.html" id="testform_no_name">
<input type="text" id="username_field_no_name">
<input type="password" id="password_field_no_name">
<input type="submit" id="input_submit_button_no_name">
</form>
+<form method="POST" action="done.html" id="testform_elements_no_id">
+ <input type="text" name="username_field_no_id">
+ <input type="password" name="password_field_no_id">
+ <input type="submit" name="input_submit_button_no_id">
+</form>
+
+<!--
+Don't add anything inside this form, and don't change the order of the
+elements. Because the elements have no "id" or "name" attributes, the test
+needs to access them by their offsets in the array of the form children.
+-->
+<form method="POST" action="done.html" id="testform_elements_no_id_no_name">
+ <input type="text">
+ <input type="password">
+ <input type="submit">
+</form>
+
</body>
</html>