OLD | NEW |
---|---|
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 const base::string16& password) { | 124 const base::string16& password) { |
125 auto& passwords_map = password_store->stored_passwords(); | 125 auto& passwords_map = password_store->stored_passwords(); |
126 ASSERT_EQ(1u, passwords_map.size()); | 126 ASSERT_EQ(1u, passwords_map.size()); |
127 auto& passwords_vector = passwords_map.begin()->second; | 127 auto& passwords_vector = passwords_map.begin()->second; |
128 ASSERT_EQ(1u, passwords_vector.size()); | 128 ASSERT_EQ(1u, passwords_vector.size()); |
129 const autofill::PasswordForm& form = passwords_vector[0]; | 129 const autofill::PasswordForm& form = passwords_vector[0]; |
130 EXPECT_EQ(username, form.username_value); | 130 EXPECT_EQ(username, form.username_value); |
131 EXPECT_EQ(password, form.password_value); | 131 EXPECT_EQ(password, form.password_value); |
132 } | 132 } |
133 | 133 |
134 void FillAndSubmitPasswordForm( | |
vabr (Chromium)
2015/08/26 09:36:00
Please remove this function and use the store dire
Pritam Nikam
2015/08/26 13:25:40
Done.
But unfortunately that didn't work for me.
vabr (Chromium)
2015/08/26 13:39:00
I'm afraid I don't understand your sentence "Atop
Pritam Nikam
2015/08/27 11:42:02
Acknowledged.
Able to debug the problem. We had 2
| |
135 Profile* profile, | |
136 content::WebContents* web_contents, | |
137 content::RenderViewHost* render_view_host) { | |
138 password_manager::TestPasswordStore* password_store = | |
139 static_cast<password_manager::TestPasswordStore*>( | |
140 PasswordStoreFactory::GetForProfile( | |
141 profile, ServiceAccessType::IMPLICIT_ACCESS) | |
142 .get()); | |
143 | |
144 EXPECT_TRUE(password_store->IsEmpty()); | |
145 | |
146 // Fill a form and submit through a <input type="submit"> button. | |
147 NavigationObserver observer(web_contents); | |
148 scoped_ptr<PromptObserver> prompt_observer( | |
149 PromptObserver::Create(web_contents)); | |
150 std::string fill_and_submit = | |
151 "document.getElementById('username_field').value = 'myusername';" | |
152 "document.getElementById('password_field').value = 'mypassword';" | |
153 "document.getElementById('input_submit_button').click()"; | |
154 ASSERT_TRUE(content::ExecuteScript(render_view_host, fill_and_submit)); | |
155 observer.Wait(); | |
156 | |
157 prompt_observer->Accept(); | |
158 | |
159 // Spin the message loop to make sure the password store had a chance to save | |
160 // the password. | |
161 base::RunLoop run_loop; | |
162 run_loop.RunUntilIdle(); | |
163 | |
164 EXPECT_FALSE(password_store->IsEmpty()); | |
165 } | |
166 | |
134 } // namespace | 167 } // namespace |
135 | 168 |
136 namespace password_manager { | 169 namespace password_manager { |
137 | 170 |
138 // Actual tests --------------------------------------------------------------- | 171 // Actual tests --------------------------------------------------------------- |
139 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { | 172 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { |
140 NavigateToFile("/password/password_form.html"); | 173 NavigateToFile("/password/password_form.html"); |
141 | 174 |
142 // Fill a form and submit through a <input type="submit"> button. Nothing | 175 // Fill a form and submit through a <input type="submit"> button. Nothing |
143 // special. | 176 // special. |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2119 prompt_observer->AcceptUpdatePrompt(stored_form); | 2152 prompt_observer->AcceptUpdatePrompt(stored_form); |
2120 // Spin the message loop to make sure the password store had a chance to | 2153 // Spin the message loop to make sure the password store had a chance to |
2121 // update the password. | 2154 // update the password. |
2122 base::RunLoop run_loop; | 2155 base::RunLoop run_loop; |
2123 run_loop.RunUntilIdle(); | 2156 run_loop.RunUntilIdle(); |
2124 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), | 2157 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), |
2125 base::ASCIIToUTF16("new_pw")); | 2158 base::ASCIIToUTF16("new_pw")); |
2126 } | 2159 } |
2127 #endif | 2160 #endif |
2128 | 2161 |
2162 // Test whether the password form with the username and password fields having | |
2163 // ambiguity in id attribute gets autofill correctly. | |
vabr (Chromium)
2015/08/26 09:36:00
nit: autofill -> autofilled
Pritam Nikam
2015/08/26 13:25:40
Done.
| |
2164 IN_PROC_BROWSER_TEST_F( | |
2165 PasswordManagerBrowserTestBase, | |
2166 AutofillSuggetionsForPasswordFormWithAmbiguousIdAttribute) { | |
2167 NavigateToFile("/password/password_form.html"); | |
2168 FillAndSubmitPasswordForm(browser()->profile(), WebContents(), | |
2169 RenderViewHost()); | |
2170 | |
2171 // Now, navigate to the password form having ambiguous Ids for username and | |
2172 // password fields and verify whether username and password is autofilled. | |
2173 NavigateToFile("/password/ambiguous_password_form.html"); | |
2174 | |
2175 // Let the user interact with the page, so that DOM gets modification events, | |
2176 // needed for autofilling fields. | |
2177 content::SimulateMouseClickAt( | |
2178 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); | |
2179 | |
2180 std::string get_username = | |
2181 "window.domAutomationController.send(" | |
2182 " document.getElementById('ambiguous_form').elements[0].value);"; | |
2183 | |
2184 std::string actual_username; | |
2185 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
2186 RenderViewHost(), get_username, &actual_username)); | |
2187 ASSERT_EQ("myusername", actual_username); | |
vabr (Chromium)
2015/08/26 09:36:00
EXPECT_EQ seems more appropriate here and on lines
Pritam Nikam
2015/08/26 13:25:40
Done.
| |
2188 std::string get_password = | |
2189 "window.domAutomationController.send(" | |
2190 " document.getElementById('ambiguous_form').elements[1].value);"; | |
2191 std::string actual_password; | |
2192 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
2193 RenderViewHost(), get_password, &actual_password)); | |
2194 ASSERT_EQ("mypassword", actual_password); | |
2195 } | |
2196 | |
2197 // Test whether the password form having username and password fields without | |
2198 // name and id attribute gets autofill correctly. | |
vabr (Chromium)
2015/08/26 09:36:00
nit: autofill -> autofilled
vabr (Chromium)
2015/08/26 09:36:00
nit: Please remove extra space between "attribute"
Pritam Nikam
2015/08/26 13:25:40
Done.
Pritam Nikam
2015/08/26 13:25:40
Done.
| |
2199 IN_PROC_BROWSER_TEST_F( | |
2200 PasswordManagerBrowserTestBase, | |
2201 AutofillSuggetionsForPasswordFormWithoutNameOrIdAttribute) { | |
2202 NavigateToFile("/password/password_form.html"); | |
2203 FillAndSubmitPasswordForm(browser()->profile(), WebContents(), | |
2204 RenderViewHost()); | |
2205 | |
2206 // Now, navigate to the password form having no Ids for username and password | |
2207 // fields and verify whether username and password is autofilled. | |
2208 NavigateToFile("/password/ambiguous_password_form.html"); | |
2209 | |
2210 // Let the user interact with the page, so that DOM gets modification events, | |
2211 // needed for autofilling fields. | |
2212 content::SimulateMouseClickAt( | |
2213 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); | |
2214 | |
2215 std::string get_username = | |
2216 "window.domAutomationController.send(" | |
2217 " document.getElementById('no_username_id_form').elements[0].value);"; | |
2218 | |
2219 std::string actual_username; | |
2220 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
2221 RenderViewHost(), get_username, &actual_username)); | |
2222 ASSERT_EQ("myusername", actual_username); | |
2223 std::string get_password = | |
2224 "window.domAutomationController.send(" | |
2225 " document.getElementById('no_username_id_form').elements[1].value);"; | |
2226 std::string actual_password; | |
2227 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
2228 RenderViewHost(), get_password, &actual_password)); | |
2229 ASSERT_EQ("mypassword", actual_password); | |
2230 } | |
2231 | |
2129 } // namespace password_manager | 2232 } // namespace password_manager |
OLD | NEW |