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

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 1292693004: [Password Manager] Autofill forms with field name and id attributes missing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Vadym's inputs. Created 5 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2108 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2109 observer.Wait(); 2109 observer.Wait();
2110 // The stored password "pw" was not overriden, so update prompt is not 2110 // The stored password "pw" was not overriden, so update prompt is not
2111 // expected. 2111 // expected.
2112 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 2112 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
2113 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2113 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2114 base::ASCIIToUTF16("pw")); 2114 base::ASCIIToUTF16("pw"));
2115 } 2115 }
2116 #endif 2116 #endif
2117 2117
2118 // Test whether the password form with the username and password fields having
2119 // ambiguity in id attribute gets autofilled correctly.
2120 IN_PROC_BROWSER_TEST_F(
2121 PasswordManagerBrowserTestBase,
2122 AutofillSuggetionsForPasswordFormWithAmbiguousIdAttribute) {
2123 // At first let us save credentials to the PasswordManager.
2124 scoped_refptr<password_manager::PasswordStore> password_store =
2125 PasswordStoreFactory::GetForProfile(browser()->profile(),
2126 ServiceAccessType::IMPLICIT_ACCESS);
2127 autofill::PasswordForm login_form;
2128 login_form.signon_realm = embedded_test_server()->base_url().spec();
2129 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2130 login_form.username_value = base::ASCIIToUTF16("myusername");
2131 login_form.password_value = base::ASCIIToUTF16("mypassword");
2132 password_store->AddLogin(login_form);
2133
2134 // Logins are added asynchronously to the password store. Spin the message
2135 // loop to make sure the |password_store| had a chance to store the
2136 // |login_form|.
2137 base::RunLoop run_loop;
2138 run_loop.RunUntilIdle();
2139
2140 // Now, navigate to the password form having ambiguous Ids for username and
2141 // password fields and verify whether username and password is autofilled.
2142 NavigateToFile("/password/ambiguous_password_form.html");
2143
2144 // Let the user interact with the page, so that DOM gets modification events,
2145 // needed for autofilling fields.
2146 content::SimulateMouseClickAt(
2147 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2148
2149 std::string get_username =
2150 "window.domAutomationController.send("
2151 " document.getElementById('ambiguous_form').elements[0].value);";
2152 std::string actual_username;
2153 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2154 RenderViewHost(), get_username, &actual_username));
2155 EXPECT_EQ("myusername", actual_username);
2156
2157 std::string get_password =
2158 "window.domAutomationController.send("
2159 " document.getElementById('ambiguous_form').elements[1].value);";
2160 std::string actual_password;
2161 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2162 RenderViewHost(), get_password, &actual_password));
2163 EXPECT_EQ("mypassword", actual_password);
2164 }
2165
2166 // Test whether the password form having username and password fields without
2167 // name and id attribute gets autofilled correctly.
2168 IN_PROC_BROWSER_TEST_F(
2169 PasswordManagerBrowserTestBase,
2170 AutofillSuggetionsForPasswordFormWithoutNameOrIdAttribute) {
2171 // At first let us save credentials to the PasswordManager.
2172 scoped_refptr<password_manager::PasswordStore> password_store =
2173 PasswordStoreFactory::GetForProfile(browser()->profile(),
2174 ServiceAccessType::IMPLICIT_ACCESS);
2175 autofill::PasswordForm login_form;
2176 login_form.signon_realm = embedded_test_server()->base_url().spec();
2177 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2178 login_form.username_value = base::ASCIIToUTF16("myusername");
2179 login_form.password_value = base::ASCIIToUTF16("mypassword");
2180 password_store->AddLogin(login_form);
2181
2182 // Logins are added asynchronously to the password store. Spin the message
2183 // loop to make sure the |password_store| had a chance to store the
2184 // |login_form|.
2185 base::RunLoop run_loop;
2186 run_loop.RunUntilIdle();
2187
2188 // Now, navigate to the password form having no Ids for username and password
2189 // fields and verify whether username and password is autofilled.
2190 NavigateToFile("/password/ambiguous_password_form.html");
2191
2192 // Let the user interact with the page, so that DOM gets modification events,
2193 // needed for autofilling fields.
2194 content::SimulateMouseClickAt(
2195 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2196
2197 std::string get_username =
2198 "window.domAutomationController.send("
2199 " document.getElementById('no_username_id_form').elements[0].value);";
2200 std::string actual_username;
2201 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2202 RenderViewHost(), get_username, &actual_username));
2203 EXPECT_EQ("myusername", actual_username);
2204
2205 std::string get_password =
2206 "window.domAutomationController.send("
2207 " document.getElementById('no_username_id_form').elements[1].value);";
2208 std::string actual_password;
2209 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2210 RenderViewHost(), get_password, &actual_password));
2211 EXPECT_EQ("mypassword", actual_password);
2212 }
2213
2118 } // namespace password_manager 2214 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698