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

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 2109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2120 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2121 observer.Wait(); 2121 observer.Wait();
2122 // The stored password "pw" was not overriden, so update prompt is not 2122 // The stored password "pw" was not overriden, so update prompt is not
2123 // expected. 2123 // expected.
2124 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 2124 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
2125 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2125 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2126 base::ASCIIToUTF16("pw")); 2126 base::ASCIIToUTF16("pw"));
2127 } 2127 }
2128 #endif 2128 #endif
2129 2129
2130 // Test whether the password form with the username and password fields having
2131 // ambiguity in id attribute gets autofilled correctly.
2132 IN_PROC_BROWSER_TEST_F(
2133 PasswordManagerBrowserTestBase,
2134 AutofillSuggetionsForPasswordFormWithAmbiguousIdAttribute) {
2135 // At first let us save credentials to the PasswordManager.
2136 scoped_refptr<password_manager::PasswordStore> password_store =
2137 PasswordStoreFactory::GetForProfile(browser()->profile(),
2138 ServiceAccessType::IMPLICIT_ACCESS);
2139 autofill::PasswordForm login_form;
2140 login_form.signon_realm = embedded_test_server()->base_url().spec();
2141 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2142 login_form.username_value = base::ASCIIToUTF16("myusername");
2143 login_form.password_value = base::ASCIIToUTF16("mypassword");
2144 password_store->AddLogin(login_form);
2145
2146 // Logins are added asynchronously to the password store. Spin the message
2147 // loop to make sure the |password_store| had a chance to store the
2148 // |login_form|.
2149 base::RunLoop run_loop;
2150 run_loop.RunUntilIdle();
2151
2152 // Now, navigate to the password form having ambiguous Ids for username and
2153 // password fields and verify whether username and password is autofilled.
2154 NavigateToFile("/password/ambiguous_password_form.html");
2155
2156 // Let the user interact with the page, so that DOM gets modification events,
2157 // needed for autofilling fields.
2158 content::SimulateMouseClickAt(
2159 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2160
2161 std::string get_username =
2162 "window.domAutomationController.send("
2163 " document.getElementById('ambiguous_form').elements[0].value);";
2164 std::string actual_username;
2165 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2166 RenderViewHost(), get_username, &actual_username));
2167 EXPECT_EQ("myusername", actual_username);
2168
2169 std::string get_password =
2170 "window.domAutomationController.send("
2171 " document.getElementById('ambiguous_form').elements[1].value);";
2172 std::string actual_password;
2173 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2174 RenderViewHost(), get_password, &actual_password));
2175 EXPECT_EQ("mypassword", actual_password);
2176 }
2177
2178 // Test whether the password form having username and password fields without
2179 // name and id attribute gets autofilled correctly.
2180 IN_PROC_BROWSER_TEST_F(
2181 PasswordManagerBrowserTestBase,
2182 AutofillSuggetionsForPasswordFormWithoutNameOrIdAttribute) {
2183 // At first let us save credentials to the PasswordManager.
2184 scoped_refptr<password_manager::PasswordStore> password_store =
2185 PasswordStoreFactory::GetForProfile(browser()->profile(),
2186 ServiceAccessType::IMPLICIT_ACCESS);
2187 autofill::PasswordForm login_form;
2188 login_form.signon_realm = embedded_test_server()->base_url().spec();
2189 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2190 login_form.username_value = base::ASCIIToUTF16("myusername");
2191 login_form.password_value = base::ASCIIToUTF16("mypassword");
2192 password_store->AddLogin(login_form);
2193
2194 // Logins are added asynchronously to the password store. Spin the message
2195 // loop to make sure the |password_store| had a chance to store the
2196 // |login_form|.
2197 base::RunLoop run_loop;
2198 run_loop.RunUntilIdle();
2199
2200 // Now, navigate to the password form having no Ids for username and password
2201 // fields and verify whether username and password is autofilled.
2202 NavigateToFile("/password/ambiguous_password_form.html");
2203
2204 // Let the user interact with the page, so that DOM gets modification events,
2205 // needed for autofilling fields.
2206 content::SimulateMouseClickAt(
2207 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2208
2209 std::string get_username =
2210 "window.domAutomationController.send("
2211 " document.getElementById('no_username_id_form').elements[0].value);";
2212 std::string actual_username;
2213 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2214 RenderViewHost(), get_username, &actual_username));
2215 EXPECT_EQ("myusername", actual_username);
2216
2217 std::string get_password =
2218 "window.domAutomationController.send("
2219 " document.getElementById('no_username_id_form').elements[1].value);";
2220 std::string actual_password;
2221 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2222 RenderViewHost(), get_password, &actual_password));
2223 EXPECT_EQ("mypassword", actual_password);
2224 }
2225
2130 } // namespace password_manager 2226 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698