Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 120343003: Autofill popup should not be presented when autocomplete='off', even if (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added browser test Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 bool SimulateShowSuggestions() {
258 return autofill_agent_->password_autofill_agent_->ShowSuggestions(
259 username_element_);
260 }
257 261
258 void SimulateKeyDownEvent(const WebInputElement& element, 262 void SimulateKeyDownEvent(const WebInputElement& element,
259 ui::KeyboardCode key_code) { 263 ui::KeyboardCode key_code) {
260 blink::WebKeyboardEvent key_event; 264 blink::WebKeyboardEvent key_event;
261 key_event.windowsKeyCode = key_code; 265 key_event.windowsKeyCode = key_code;
262 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); 266 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event);
263 } 267 }
264 268
265 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 269 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
266 const std::string& username, 270 const std::string& username,
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 803
800 // Verfies that a DOM-activated UI event will not cause an autofill. 804 // Verfies that a DOM-activated UI event will not cause an autofill.
801 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { 805 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
802 // Trigger the initial autocomplete. 806 // Trigger the initial autocomplete.
803 SimulateOnFillPasswordForm(fill_data_); 807 SimulateOnFillPasswordForm(fill_data_);
804 808
805 ExecuteJavaScript(kJavaScriptClick); 809 ExecuteJavaScript(kJavaScriptClick);
806 CheckTextFieldsDOMState(kAliceUsername, true, "", true); 810 CheckTextFieldsDOMState(kAliceUsername, true, "", true);
807 } 811 }
808 812
813 // Regression test for http://crbug.com/326679
814 TEST_F(PasswordAutofillAgentTest, SelectUsernameOnAutofillOff) {
Ilya Sherman 2013/12/27 21:43:22 nit: "On" -> "When" or "With" or something like th
jww 2013/12/27 23:04:39 Done.
815 // Set the main password element to autocomplete='off'
816 password_element_.setAttribute(WebString::fromUTF8("autocomplete"),
817 WebString::fromUTF8("off"));
Ilya Sherman 2013/12/27 21:43:22 It looks like the code refuses to show suggestions
jww 2013/12/27 23:04:39 Done.
818
819 // Simulate the browser sending back the login info, it triggers the
820 // autocomplete.
821 SimulateOnFillPasswordForm(fill_data_);
822
823 // Simulate the user changing the username to some unknown username.
824 SimulateUsernameChange("foobar", true);
825
826 // This EXPECT_TRUE is interesting because of a quirk in how we handle the
827 // corner case of autocomplete='off' fields that also have a remembered
828 // password and username. Normally, if a unknown username is enterted, the
829 // autofill agent will return "false" from ShowSuggestions, but note that
830 // we're expecting "true" here.
831 //
832 // This is because of the specific case of an autocomplete='off' form that
833 // also has a remembered username and password (http://crbug.com/326679). To
834 // fix the DCHECK that this case used to hit, we return "true" from
835 // ShowSuggestions for all forms that are autocomplete='off', prentending that
836 // we've successfully shown a selection box to the user. Of course, we haven't
837 // so a message is never sent to the browser on acceptance, and the DCHECK
838 // isn't hit (and nothing is filled).
839 //
840 // However, because we do it for all usernames (known or unknown), we can
841 // differentiate this from before the patch, since it used to be that
842 // ShowSuggestions would return "false" on unknown usernames. However, we
843 // couldn't return "false" in the new case, because that would cause
844 // QueryAutofillSuggestions to be called, ultimately leading to the DCHECK
845 // being hit again.
846 //
847 // Thus, the regression test is to make sure that we are returing "true" for
848 // all calls to ShowSuggestions on autocomplete='off' forms, even for unknown
849 // usernames.
850 EXPECT_TRUE(SimulateShowSuggestions());
Ilya Sherman 2013/12/27 21:43:22 Please also test that no AutofillHostMsg_ShowPassw
jww 2013/12/27 23:04:39 That's a great idea. I didn't attempt it because I
Ilya Sherman 2013/12/27 23:17:09 I think something like this ought to work: https:/
jww 2013/12/31 00:33:05 Done.
851 }
852
809 } // namespace autofill 853 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698