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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. | 247 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. |
248 base::MessageLoop::current()->RunUntilIdle(); | 248 base::MessageLoop::current()->RunUntilIdle(); |
249 } | 249 } |
250 | 250 |
251 void SimulateUsernameChange(const std::string& username, | 251 void SimulateUsernameChange(const std::string& username, |
252 bool move_caret_to_end) { | 252 bool move_caret_to_end) { |
253 SimulateUsernameChangeForElement(username, move_caret_to_end, | 253 SimulateUsernameChangeForElement(username, move_caret_to_end, |
254 GetMainFrame(), username_element_); | 254 GetMainFrame(), username_element_); |
255 } | 255 } |
256 | 256 |
257 void SimulateShowSuggestionsWithAutocompleteOff(WebInputElement& element) { | |
Ilya Sherman
2013/12/27 23:17:09
Please document this method.
jww
2013/12/31 00:33:05
Done.
| |
258 // Set the main password element to autocomplete='off' | |
259 element.setAttribute(WebString::fromUTF8("autocomplete"), | |
260 WebString::fromUTF8("off")); | |
261 | |
262 // Simulate the user changing the username to some unknown username. | |
263 SimulateUsernameChange("foobar", true); | |
Ilya Sherman
2013/12/27 23:17:09
IMO, lines 258-263 should be kept in the individua
jww
2013/12/31 00:33:05
Because of the nature of the test setup, it actual
| |
264 | |
265 // This EXPECT_TRUE is interesting because of a quirk in how we handle the | |
266 // corner case of autocomplete='off' fields that also have a remembered | |
267 // password and username. Normally, if a unknown username is enterted, the | |
268 // autofill agent will return "false" from ShowSuggestions, but note that | |
269 // we're expecting "true" here. | |
270 // | |
271 // This is because of the specific case of an autocomplete='off' form that | |
272 // also has a remembered username and password (http://crbug.com/326679). To | |
273 // fix the DCHECK that this case used to hit, we return "true" from | |
274 // ShowSuggestions for all forms that are autocomplete='off', prentending | |
275 // that we've successfully shown a selection box to the user. Of course, we | |
276 // haven't so a message is never sent to the browser on acceptance, and the | |
277 // DCHECK isn't hit (and nothing is filled). | |
278 // | |
279 // However, because we do it for all usernames (known or unknown), we can | |
280 // differentiate this from before the patch, since it used to be that | |
281 // ShowSuggestions would return "false" on unknown usernames. However, we | |
282 // couldn't return "false" in the new case, because that would cause | |
283 // QueryAutofillSuggestions to be called, ultimately leading to the DCHECK | |
284 // being hit again. | |
285 // | |
286 // Thus, the regression test is to make sure that we are returing "true" for | |
287 // all calls to ShowSuggestions on autocomplete='off' forms, even for | |
288 // unknown usernames. | |
289 EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions( | |
290 username_element_)); } | |
257 | 291 |
258 void SimulateKeyDownEvent(const WebInputElement& element, | 292 void SimulateKeyDownEvent(const WebInputElement& element, |
259 ui::KeyboardCode key_code) { | 293 ui::KeyboardCode key_code) { |
260 blink::WebKeyboardEvent key_event; | 294 blink::WebKeyboardEvent key_event; |
261 key_event.windowsKeyCode = key_code; | 295 key_event.windowsKeyCode = key_code; |
262 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); | 296 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); |
263 } | 297 } |
264 | 298 |
265 void CheckTextFieldsStateForElements(const WebInputElement& username_element, | 299 void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
266 const std::string& username, | 300 const std::string& username, |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 | 833 |
800 // Verfies that a DOM-activated UI event will not cause an autofill. | 834 // Verfies that a DOM-activated UI event will not cause an autofill. |
801 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 835 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
802 // Trigger the initial autocomplete. | 836 // Trigger the initial autocomplete. |
803 SimulateOnFillPasswordForm(fill_data_); | 837 SimulateOnFillPasswordForm(fill_data_); |
804 | 838 |
805 ExecuteJavaScript(kJavaScriptClick); | 839 ExecuteJavaScript(kJavaScriptClick); |
806 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 840 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
807 } | 841 } |
808 | 842 |
843 // Regression test for http://crbug.com/326679 | |
844 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithAutofillOff) { | |
845 // Do the test with the password element having autocomplete='off' set | |
846 | |
847 // Simulate the browser sending back the login info. | |
848 SimulateOnFillPasswordForm(fill_data_); | |
849 | |
850 SimulateShowSuggestionsWithAutocompleteOff(password_element_); | |
851 | |
852 // Clear the text fields to start fresh. | |
853 ClearUsernameAndPasswordFields(); | |
Ilya Sherman
2013/12/27 23:17:09
Please make a separate test case (TEST_F invocatio
jww
2013/12/31 00:33:05
Done.
| |
854 | |
855 // Do the test with the username element having autocomplete='off' set | |
856 SimulateOnFillPasswordForm(fill_data_); | |
857 | |
858 SimulateShowSuggestionsWithAutocompleteOff(username_element_); | |
859 } | |
860 | |
809 } // namespace autofill | 861 } // namespace autofill |
OLD | NEW |