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

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

Issue 697233002: Remove flag to disable ignore autocomplete='off' for password forms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | components/autofill.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "components/autofill/content/renderer/password_autofill_agent.h" 11 #include "components/autofill/content/renderer/password_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
13 #include "components/autofill/core/common/form_data.h" 13 #include "components/autofill/core/common/form_data.h"
14 #include "components/autofill/core/common/form_field_data.h" 14 #include "components/autofill/core/common/form_field_data.h"
15 #include "components/autofill/core/common/password_autofill_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebVector.h" 17 #include "third_party/WebKit/public/platform/WebVector.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebElement.h" 19 #include "third_party/WebKit/public/web/WebElement.h"
21 #include "third_party/WebKit/public/web/WebFormElement.h" 20 #include "third_party/WebKit/public/web/WebFormElement.h"
22 #include "third_party/WebKit/public/web/WebInputElement.h" 21 #include "third_party/WebKit/public/web/WebInputElement.h"
23 #include "third_party/WebKit/public/web/WebLocalFrame.h" 22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
24 #include "third_party/WebKit/public/web/WebNode.h" 23 #include "third_party/WebKit/public/web/WebNode.h"
25 #include "third_party/WebKit/public/web/WebView.h" 24 #include "third_party/WebKit/public/web/WebView.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 void SimulateUsernameChange(const std::string& username, 317 void SimulateUsernameChange(const std::string& username,
319 bool move_caret_to_end, 318 bool move_caret_to_end,
320 bool is_user_input = false) { 319 bool is_user_input = false) {
321 SimulateInputChangeForElement(username, 320 SimulateInputChangeForElement(username,
322 move_caret_to_end, 321 move_caret_to_end,
323 GetMainFrame(), 322 GetMainFrame(),
324 username_element_, 323 username_element_,
325 is_user_input); 324 is_user_input);
326 } 325 }
327 326
328 // Tests that no suggestion popup is generated when the username_element_ is
329 // edited.
330 void ExpectNoSuggestionsPopup() {
331 // The first test below ensures that the suggestions have been handled by
332 // the password_autofill_agent, even though autocomplete='off' is set. The
333 // second check ensures that, although handled, no "show suggestions" IPC to
334 // the browser was generated.
335 //
336 // This is interesting in the specific case of an autocomplete='off' form
337 // that also has a remembered username and password
338 // (http://crbug.com/326679). To fix the DCHECK that this case used to hit,
339 // |true| is returned from ShowSuggestions for all forms with valid
340 // usersnames that are autocomplete='off', prentending that a selection box
341 // has been shown to the user. Of course, it hasn't, so a message is never
342 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing
343 // is filled).
344 //
345 // These tests only make sense in the context of not ignoring
346 // autocomplete='off', so only test them if the disable autocomplete='off'
347 // flag is not enabled.
348 // TODO(jww): Remove this function and callers once autocomplete='off' is
349 // permanently ignored.
350 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
351 EXPECT_TRUE(
352 password_autofill_agent_->ShowSuggestions(username_element_, false));
353
354 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
355 AutofillHostMsg_ShowPasswordSuggestions::ID));
356 }
357 }
358
359 void SimulateKeyDownEvent(const WebInputElement& element, 327 void SimulateKeyDownEvent(const WebInputElement& element,
360 ui::KeyboardCode key_code) { 328 ui::KeyboardCode key_code) {
361 blink::WebKeyboardEvent key_event; 329 blink::WebKeyboardEvent key_event;
362 key_event.windowsKeyCode = key_code; 330 key_event.windowsKeyCode = key_code;
363 static_cast<blink::WebAutofillClient*>(autofill_agent_) 331 static_cast<blink::WebAutofillClient*>(autofill_agent_)
364 ->textFieldDidReceiveKeyDown(element, key_event); 332 ->textFieldDidReceiveKeyDown(element, key_event);
365 } 333 }
366 334
367 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 335 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
368 const std::string& username, 336 const std::string& username,
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 931
964 // Verfies that a DOM-activated UI event will not cause an autofill. 932 // Verfies that a DOM-activated UI event will not cause an autofill.
965 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { 933 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
966 // Trigger the initial autocomplete. 934 // Trigger the initial autocomplete.
967 SimulateOnFillPasswordForm(fill_data_); 935 SimulateOnFillPasswordForm(fill_data_);
968 936
969 ExecuteJavaScript(kJavaScriptClick); 937 ExecuteJavaScript(kJavaScriptClick);
970 CheckTextFieldsDOMState(kAliceUsername, true, "", true); 938 CheckTextFieldsDOMState(kAliceUsername, true, "", true);
971 } 939 }
972 940
973 // Regression test for http://crbug.com/326679
974 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithUsernameAutofillOff) {
975 // Simulate the browser sending back the login info.
976 SimulateOnFillPasswordForm(fill_data_);
977
978 // Set the username element to autocomplete='off'
979 username_element_.setAttribute(WebString::fromUTF8("autocomplete"),
980 WebString::fromUTF8("off"));
981
982 // Simulate the user changing the username to some known username.
983 SimulateUsernameChange(kAliceUsername, true);
984
985 ExpectNoSuggestionsPopup();
986 }
987
988 // Regression test for http://crbug.com/326679
989 TEST_F(PasswordAutofillAgentTest,
990 SelectUnknownUsernameWithUsernameAutofillOff) {
991 // Simulate the browser sending back the login info.
992 SimulateOnFillPasswordForm(fill_data_);
993
994 // Set the username element to autocomplete='off'
995 username_element_.setAttribute(WebString::fromUTF8("autocomplete"),
996 WebString::fromUTF8("off"));
997
998 // Simulate the user changing the username to some unknown username.
999 SimulateUsernameChange("foo", true);
1000
1001 ExpectNoSuggestionsPopup();
1002 }
1003
1004 // Regression test for http://crbug.com/326679
1005 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) {
1006 // Simulate the browser sending back the login info.
1007 SimulateOnFillPasswordForm(fill_data_);
1008
1009 // Set the main password element to autocomplete='off'
1010 password_element_.setAttribute(WebString::fromUTF8("autocomplete"),
1011 WebString::fromUTF8("off"));
1012
1013 // Simulate the user changing the username to some known username.
1014 SimulateUsernameChange(kAliceUsername, true);
1015
1016 ExpectNoSuggestionsPopup();
1017 }
1018
1019 // Regression test for http://crbug.com/326679
1020 TEST_F(PasswordAutofillAgentTest,
1021 SelectUnknownUsernameWithPasswordAutofillOff) {
1022 // Simulate the browser sending back the login info.
1023 SimulateOnFillPasswordForm(fill_data_);
1024
1025 // Set the main password element to autocomplete='off'
1026 password_element_.setAttribute(WebString::fromUTF8("autocomplete"),
1027 WebString::fromUTF8("off"));
1028
1029 // Simulate the user changing the username to some unknown username.
1030 SimulateUsernameChange("foo", true);
1031
1032 ExpectNoSuggestionsPopup();
1033 }
1034
1035 // Verifies that password autofill triggers onChange events in JavaScript for 941 // Verifies that password autofill triggers onChange events in JavaScript for
1036 // forms that are filled on page load. 942 // forms that are filled on page load.
1037 TEST_F(PasswordAutofillAgentTest, 943 TEST_F(PasswordAutofillAgentTest,
1038 PasswordAutofillTriggersOnChangeEventsOnLoad) { 944 PasswordAutofillTriggersOnChangeEventsOnLoad) {
1039 std::string html = std::string(kFormHTML) + kOnChangeDetectionScript; 945 std::string html = std::string(kFormHTML) + kOnChangeDetectionScript;
1040 LoadHTML(html.c_str()); 946 LoadHTML(html.c_str());
1041 UpdateOriginForHTML(html); 947 UpdateOriginForHTML(html);
1042 UpdateUsernameAndPasswordElements(); 948 UpdateUsernameAndPasswordElements();
1043 949
1044 // Simulate the browser sending back the login info, it triggers the 950 // Simulate the browser sending back the login info, it triggers the
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 password_element_, 1532 password_element_,
1627 /*is_user_input=*/true); 1533 /*is_user_input=*/true);
1628 1534
1629 // Simulate the user typing a stored username. 1535 // Simulate the user typing a stored username.
1630 SimulateUsernameChange(kAliceUsername, true); 1536 SimulateUsernameChange(kAliceUsername, true);
1631 // The autofileld password should replace the typed one. 1537 // The autofileld password should replace the typed one.
1632 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1538 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1633 } 1539 }
1634 1540
1635 } // namespace autofill 1541 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | components/autofill.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698