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 // Tests that no suggestion popup is generated when the username_element_ is |
| 258 // edited. |
| 259 void ExpectNoSuggestionsPopup() { |
| 260 // The first test below ensures that the suggestions have been handled by |
| 261 // the password_autofill_agent, even though autocomplete='off' is set. The |
| 262 // second check ensures that, although handled, no "show suggestions" IPC to |
| 263 // the browser was generated. |
| 264 // |
| 265 // This is interesting in the specific case of an autocomplete='off' form |
| 266 // that also has a remembered username and password |
| 267 // (http://crbug.com/326679). To fix the DCHECK that this case used to hit, |
| 268 // |true| is returned from ShowSuggestions for all forms with valid |
| 269 // usersnames that are autocomplete='off', prentending that a selection box |
| 270 // has been shown to the user. Of course, it hasn't, so a message is never |
| 271 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing |
| 272 // is filled). |
| 273 EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions( |
| 274 username_element_)); |
| 275 |
| 276 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 277 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 278 } |
257 | 279 |
258 void SimulateKeyDownEvent(const WebInputElement& element, | 280 void SimulateKeyDownEvent(const WebInputElement& element, |
259 ui::KeyboardCode key_code) { | 281 ui::KeyboardCode key_code) { |
260 blink::WebKeyboardEvent key_event; | 282 blink::WebKeyboardEvent key_event; |
261 key_event.windowsKeyCode = key_code; | 283 key_event.windowsKeyCode = key_code; |
262 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); | 284 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); |
263 } | 285 } |
264 | 286 |
265 void CheckTextFieldsStateForElements(const WebInputElement& username_element, | 287 void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
266 const std::string& username, | 288 const std::string& username, |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 | 821 |
800 // Verfies that a DOM-activated UI event will not cause an autofill. | 822 // Verfies that a DOM-activated UI event will not cause an autofill. |
801 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 823 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
802 // Trigger the initial autocomplete. | 824 // Trigger the initial autocomplete. |
803 SimulateOnFillPasswordForm(fill_data_); | 825 SimulateOnFillPasswordForm(fill_data_); |
804 | 826 |
805 ExecuteJavaScript(kJavaScriptClick); | 827 ExecuteJavaScript(kJavaScriptClick); |
806 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 828 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
807 } | 829 } |
808 | 830 |
| 831 // Regression test for http://crbug.com/326679 |
| 832 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithUsernameAutofillOff) { |
| 833 // Simulate the browser sending back the login info. |
| 834 SimulateOnFillPasswordForm(fill_data_); |
| 835 |
| 836 // Set the username element to autocomplete='off' |
| 837 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 838 WebString::fromUTF8("off")); |
| 839 |
| 840 // Simulate the user changing the username to some known username. |
| 841 SimulateUsernameChange(kAliceUsername, true); |
| 842 |
| 843 ExpectNoSuggestionsPopup(); |
| 844 } |
| 845 |
| 846 // Regression test for http://crbug.com/326679 |
| 847 TEST_F(PasswordAutofillAgentTest, |
| 848 SelectUnknownUsernameWithUsernameAutofillOff) { |
| 849 // Simulate the browser sending back the login info. |
| 850 SimulateOnFillPasswordForm(fill_data_); |
| 851 |
| 852 // Set the username element to autocomplete='off' |
| 853 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 854 WebString::fromUTF8("off")); |
| 855 |
| 856 // Simulate the user changing the username to some unknown username. |
| 857 SimulateUsernameChange("foo", true); |
| 858 |
| 859 ExpectNoSuggestionsPopup(); |
| 860 } |
| 861 |
| 862 // Regression test for http://crbug.com/326679 |
| 863 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) { |
| 864 // Simulate the browser sending back the login info. |
| 865 SimulateOnFillPasswordForm(fill_data_); |
| 866 |
| 867 // Set the main password element to autocomplete='off' |
| 868 password_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 869 WebString::fromUTF8("off")); |
| 870 |
| 871 // Simulate the user changing the username to some known username. |
| 872 SimulateUsernameChange(kAliceUsername, true); |
| 873 |
| 874 ExpectNoSuggestionsPopup(); |
| 875 } |
| 876 |
| 877 // Regression test for http://crbug.com/326679 |
| 878 TEST_F(PasswordAutofillAgentTest, |
| 879 SelectUnknownUsernameWithPasswordAutofillOff) { |
| 880 // Simulate the browser sending back the login info. |
| 881 SimulateOnFillPasswordForm(fill_data_); |
| 882 |
| 883 // Set the main password element to autocomplete='off' |
| 884 password_element_.setAttribute(WebString::fromUTF8("autocomplete"), |
| 885 WebString::fromUTF8("off")); |
| 886 |
| 887 // Simulate the user changing the username to some unknown username. |
| 888 SimulateUsernameChange("foo", true); |
| 889 |
| 890 ExpectNoSuggestionsPopup(); |
| 891 } |
| 892 |
809 } // namespace autofill | 893 } // namespace autofill |
OLD | NEW |