Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2168 | 2168 |
| 2169 SimulateUsernameChange("Bob"); | 2169 SimulateUsernameChange("Bob"); |
| 2170 SimulatePasswordChange("mypassword"); | 2170 SimulatePasswordChange("mypassword"); |
| 2171 | 2171 |
| 2172 password_autofill_agent_->AJAXSucceeded(); | 2172 password_autofill_agent_->AJAXSucceeded(); |
| 2173 | 2173 |
| 2174 base::RunLoop().RunUntilIdle(); | 2174 base::RunLoop().RunUntilIdle(); |
| 2175 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); | 2175 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 2176 } | 2176 } |
| 2177 | 2177 |
| 2178 // Tests that no save promt is shown when an unowned form is changed and AJAX | |
| 2179 // completed but the form is still visible. | |
| 2180 TEST_F(PasswordAutofillAgentTest, | |
| 2181 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndNewElementAppeared) { | |
| 2182 const char kNoFormHTMLWithHiddenField[] = | |
| 2183 "<INPUT type='text' id='username'/>" | |
| 2184 "<INPUT type='password' id='password'/>" | |
| 2185 "<INPUT type='text' id='captcha' style='display:none'/>"; | |
| 2186 LoadHTML(kNoFormHTMLWithHiddenField); | |
| 2187 | |
| 2188 UpdateUsernameAndPasswordElements(); | |
| 2189 WebElement captcha_element = | |
| 2190 GetMainFrame()->document().getElementById(WebString::fromUTF8("captcha")); | |
| 2191 ASSERT_FALSE(captcha_element.isNull()); | |
| 2192 | |
| 2193 SimulateUsernameChange("Bob"); | |
| 2194 SimulatePasswordChange("mypassword"); | |
| 2195 | |
| 2196 // Simulate captcha element show up right before AJAX completed. | |
| 2197 captcha_element.setAttribute("style", "display:inline;"); | |
| 2198 password_autofill_agent_->AJAXSucceeded(); | |
| 2199 | |
| 2200 base::RunLoop().RunUntilIdle(); | |
| 2201 EXPECT_FALSE(fake_driver_.called_inpage_navigation()); | |
| 2202 EXPECT_FALSE(fake_driver_.called_password_form_submitted()); | |
| 2203 } | |
| 2204 | |
| 2205 // Tests that no save promt is shown when a form with empty action URL is | |
| 2206 // changed and AJAX completed but the form is still visible. | |
| 2207 TEST_F(PasswordAutofillAgentTest, | |
| 2208 NoAction_NoPromptForAJAXSubmitWithoutNavigationAndNewElementAppeared) { | |
| 2209 // Form without an action URL. | |
| 2210 const char kHTMLWithHiddenField[] = | |
| 2211 "<FORM name='LoginTestForm'>" | |
| 2212 " <INPUT type='text' id='username'/>" | |
| 2213 " <INPUT type='password' id='password'/>" | |
| 2214 " <INPUT type='text' id='captcha' style='display:none'/>" | |
| 2215 " <INPUT type='submit' value='Login'/>" | |
| 2216 "</FORM>"; | |
| 2217 // Set the valid URL so the form action URL can be generated properly. | |
| 2218 LoadHTMLWithUrlOverride(kHTMLWithHiddenField, "https://www.example.com"); | |
|
dvadym
2017/03/14 17:11:10
Why not LoadHTML?
sense (YandexTeam)
2017/03/15 04:51:24
In this test we explicitly test a form without act
dvadym
2017/03/15 14:27:11
Acknowledged
| |
| 2219 | |
| 2220 UpdateUsernameAndPasswordElements(); | |
| 2221 WebElement captcha_element = | |
| 2222 GetMainFrame()->document().getElementById(WebString::fromUTF8("captcha")); | |
| 2223 ASSERT_FALSE(captcha_element.isNull()); | |
| 2224 | |
| 2225 SimulateUsernameChange("Bob"); | |
| 2226 SimulatePasswordChange("mypassword"); | |
| 2227 | |
| 2228 // Simulate captcha element show up right before AJAX completed. | |
| 2229 captcha_element.setAttribute("style", "display:inline;"); | |
| 2230 password_autofill_agent_->AJAXSucceeded(); | |
| 2231 | |
| 2232 base::RunLoop().RunUntilIdle(); | |
| 2233 EXPECT_FALSE(fake_driver_.called_inpage_navigation()); | |
| 2234 EXPECT_FALSE(fake_driver_.called_password_form_submitted()); | |
| 2235 } | |
| 2236 | |
| 2178 // Tests that credential suggestions are autofilled on a password (and change | 2237 // Tests that credential suggestions are autofilled on a password (and change |
| 2179 // password) forms having either ambiguous or empty name. | 2238 // password) forms having either ambiguous or empty name. |
| 2180 TEST_F(PasswordAutofillAgentTest, | 2239 TEST_F(PasswordAutofillAgentTest, |
| 2181 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | 2240 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { |
| 2182 const char kEmpty[] = ""; | 2241 const char kEmpty[] = ""; |
| 2183 const char kDummyUsernameField[] = "anonymous_username"; | 2242 const char kDummyUsernameField[] = "anonymous_username"; |
| 2184 const char kDummyPasswordField[] = "anonymous_password"; | 2243 const char kDummyPasswordField[] = "anonymous_password"; |
| 2185 const char kFormContainsEmptyNamesHTML[] = | 2244 const char kFormContainsEmptyNamesHTML[] = |
| 2186 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com' >" | 2245 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com' >" |
| 2187 " <INPUT type='text' placeholder='username'/>" | 2246 " <INPUT type='text' placeholder='username'/>" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2531 SimulateElementClick(kUsernameName); | 2590 SimulateElementClick(kUsernameName); |
| 2532 | 2591 |
| 2533 // Simulate a user clicking on the password element. This should produce a | 2592 // Simulate a user clicking on the password element. This should produce a |
| 2534 // dropdown with suggestion of all available usernames. | 2593 // dropdown with suggestion of all available usernames. |
| 2535 static_cast<PageClickListener*>(autofill_agent_) | 2594 static_cast<PageClickListener*>(autofill_agent_) |
| 2536 ->FormControlElementClicked(password_element_, false); | 2595 ->FormControlElementClicked(password_element_, false); |
| 2537 CheckSuggestions("", false); | 2596 CheckSuggestions("", false); |
| 2538 } | 2597 } |
| 2539 | 2598 |
| 2540 } // namespace autofill | 2599 } // namespace autofill |
| OLD | NEW |