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 "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 // This EXPECT_TRUE is interesting because of a quirk in how we handle the | |
| 261 // corner case of autocomplete='off' fields that also have a remembered | |
| 262 // password and username. Normally, if a unknown username is enterted, the | |
|
Ilya Sherman
2014/01/07 00:56:23
nit: "a unknown" -> "an unknown"
jww
2014/01/07 20:00:25
Done.
| |
| 263 // autofill agent will return "false" from ShowSuggestions, but note that | |
| 264 // we're expecting "true" here. | |
|
Ilya Sherman
2014/01/07 00:56:23
This sentence doesn't make sense anymore, since th
jww
2014/01/07 20:00:25
Done.
| |
| 265 // | |
| 266 // This is because of the specific case of an autocomplete='off' form that | |
| 267 // also has a remembered username and password (http://crbug.com/326679). To | |
| 268 // fix the DCHECK that this case used to hit, we return "true" from | |
| 269 // ShowSuggestions for all forms that are autocomplete='off', prentending | |
| 270 // that we've successfully shown a selection box to the user. Of course, we | |
| 271 // haven't so a message is never sent to the browser on acceptance, and the | |
| 272 // DCHECK isn't hit (and nothing is filled). | |
| 273 // | |
| 274 // However, because we do it for all usernames (known or unknown), we can | |
| 275 // differentiate this from before the patch, since it used to be that | |
| 276 // ShowSuggestions would return "false" on unknown usernames. However, we | |
| 277 // couldn't return "false" in the new case, because that would cause | |
| 278 // QueryAutofillSuggestions to be called, ultimately leading to the DCHECK | |
| 279 // being hit again. | |
| 280 // | |
| 281 // Thus, the regression test is to make sure that we are returing "true" for | |
| 282 // all calls to ShowSuggestions on autocomplete='off' forms, even for | |
| 283 // unknown usernames. | |
| 284 EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions( | |
| 285 username_element_)); | |
| 286 | |
| 287 // And as a final sanity check, we also make sure that no "show suggestions" | |
|
Ilya Sherman
2014/01/07 00:56:23
nit: s/"we"//
jww
2014/01/07 20:00:25
Done.
| |
| 288 // IPC to the browser was generated. | |
| 289 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | |
| 290 AutofillHostMsg_ShowPasswordSuggestions::ID) == NULL); | |
|
Ilya Sherman
2014/01/07 00:56:23
nit: I'd write this as either
EXPECT_FALSE(render
jww
2014/01/07 20:00:25
Done.
| |
| 291 } | |
| 257 | 292 |
| 258 void SimulateKeyDownEvent(const WebInputElement& element, | 293 void SimulateKeyDownEvent(const WebInputElement& element, |
| 259 ui::KeyboardCode key_code) { | 294 ui::KeyboardCode key_code) { |
| 260 blink::WebKeyboardEvent key_event; | 295 blink::WebKeyboardEvent key_event; |
| 261 key_event.windowsKeyCode = key_code; | 296 key_event.windowsKeyCode = key_code; |
| 262 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); | 297 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); |
| 263 } | 298 } |
| 264 | 299 |
| 265 void CheckTextFieldsStateForElements(const WebInputElement& username_element, | 300 void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
| 266 const std::string& username, | 301 const std::string& username, |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 | 834 |
| 800 // Verfies that a DOM-activated UI event will not cause an autofill. | 835 // Verfies that a DOM-activated UI event will not cause an autofill. |
| 801 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 836 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
| 802 // Trigger the initial autocomplete. | 837 // Trigger the initial autocomplete. |
| 803 SimulateOnFillPasswordForm(fill_data_); | 838 SimulateOnFillPasswordForm(fill_data_); |
| 804 | 839 |
| 805 ExecuteJavaScript(kJavaScriptClick); | 840 ExecuteJavaScript(kJavaScriptClick); |
| 806 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 841 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
| 807 } | 842 } |
| 808 | 843 |
| 844 // The following two tests are regression tests for http://crbug.com/326679 | |
|
Ilya Sherman
2014/01/07 00:56:23
nit: Please have one comment per test, in case tes
jww
2014/01/07 20:00:25
Done.
| |
| 845 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithUsernameAutofillOff) { | |
| 846 // Simulate the browser sending back the login info. | |
| 847 SimulateOnFillPasswordForm(fill_data_); | |
| 848 | |
| 849 // Set the main password element to autocomplete='off' | |
|
Ilya Sherman
2014/01/07 00:56:23
nit: Please update this comment.
jww
2014/01/07 20:00:25
Done.
| |
| 850 username_element_.setAttribute(WebString::fromUTF8("autocomplete"), | |
| 851 WebString::fromUTF8("off")); | |
| 852 | |
| 853 // Simulate the user changing the username to some known username. | |
| 854 SimulateUsernameChange(kAliceUsername, true); | |
| 855 | |
| 856 ExpectNoSuggestionsPopup(); | |
| 857 } | |
| 858 | |
| 859 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) { | |
| 860 // Simulate the browser sending back the login info. | |
| 861 SimulateOnFillPasswordForm(fill_data_); | |
| 862 | |
| 863 // Set the main password element to autocomplete='off' | |
| 864 password_element_.setAttribute(WebString::fromUTF8("autocomplete"), | |
| 865 WebString::fromUTF8("off")); | |
| 866 | |
| 867 // Simulate the user changing the username to some known username. | |
| 868 SimulateUsernameChange(kAliceUsername, true); | |
| 869 | |
| 870 ExpectNoSuggestionsPopup(); | |
| 871 } | |
| 872 | |
| 809 } // namespace autofill | 873 } // namespace autofill |
| OLD | NEW |