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

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

Issue 83023017: Basic autofill into password value on user gesture only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits from gcasto Created 7 years 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/renderer/autofill_agent.h" 8 #include "components/autofill/content/renderer/autofill_agent.h"
9 #include "components/autofill/content/renderer/form_autofill_util.h" 9 #include "components/autofill/content/renderer/form_autofill_util.h"
10 #include "components/autofill/content/renderer/password_autofill_agent.h" 10 #include "components/autofill/content/renderer/password_autofill_agent.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 " <script type='text/javascript'>" 125 " <script type='text/javascript'>"
126 " function addParagraph() {" 126 " function addParagraph() {"
127 " var p = document.createElement('p');" 127 " var p = document.createElement('p');"
128 " document.body.appendChild(p);" 128 " document.body.appendChild(p);"
129 " }" 129 " }"
130 " window.onload = addParagraph;" 130 " window.onload = addParagraph;"
131 " </script>" 131 " </script>"
132 " </body>" 132 " </body>"
133 "</html>"; 133 "</html>";
134 134
135 const char kJavaScriptClick[] =
136 "var event = new MouseEvent('click', {"
137 " 'view': window,"
138 " 'bubbles': true,"
139 " 'cancelable': true"
140 "});"
141 "var form = document.getElementById('myform1');"
142 "form.dispatchEvent(event);"
143 "console.log('clicked!');";
144
135 } // namespace 145 } // namespace
136 146
137 namespace autofill { 147 namespace autofill {
138 148
139 class PasswordAutofillAgentTest : public ChromeRenderViewTest { 149 class PasswordAutofillAgentTest : public ChromeRenderViewTest {
140 public: 150 public:
141 PasswordAutofillAgentTest() { 151 PasswordAutofillAgentTest() {
142 } 152 }
143 153
144 // Simulates the fill password form message being sent to the renderer. 154 // Simulates the fill password form message being sent to the renderer.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 blink::WebKeyboardEvent key_event; 258 blink::WebKeyboardEvent key_event;
249 key_event.windowsKeyCode = key_code; 259 key_event.windowsKeyCode = key_code;
250 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); 260 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event);
251 } 261 }
252 262
253 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 263 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
254 const std::string& username, 264 const std::string& username,
255 bool username_autofilled, 265 bool username_autofilled,
256 const WebInputElement& password_element, 266 const WebInputElement& password_element,
257 const std::string& password, 267 const std::string& password,
258 bool password_autofilled) { 268 bool password_autofilled,
269 bool checkSuggestedValue = true) {
259 EXPECT_EQ(username, 270 EXPECT_EQ(username,
260 static_cast<std::string>(username_element.value().utf8())); 271 static_cast<std::string>(username_element.value().utf8()));
261 EXPECT_EQ(username_autofilled, username_element.isAutofilled()); 272 EXPECT_EQ(username_autofilled, username_element.isAutofilled());
262 EXPECT_EQ(password, 273 EXPECT_EQ(password,
263 static_cast<std::string>(password_element.value().utf8())); 274 static_cast<std::string>(
275 checkSuggestedValue ? password_element.suggestedValue().utf8()
276 : password_element.value().utf8()));
264 EXPECT_EQ(password_autofilled, password_element.isAutofilled()); 277 EXPECT_EQ(password_autofilled, password_element.isAutofilled());
265 } 278 }
266 279
280 // Checks the DOM-accessible value of the username element and the
281 // *suggested* value of the password element.
267 void CheckTextFieldsState(const std::string& username, 282 void CheckTextFieldsState(const std::string& username,
268 bool username_autofilled, 283 bool username_autofilled,
269 const std::string& password, 284 const std::string& password,
270 bool password_autofilled) { 285 bool password_autofilled) {
271 CheckTextFieldsStateForElements(username_element_, username, 286 CheckTextFieldsStateForElements(username_element_, username,
272 username_autofilled, password_element_, 287 username_autofilled, password_element_,
273 password, password_autofilled); 288 password, password_autofilled);
274 } 289 }
275 290
291 // Checks the DOM-accessible value of the username element and the
292 // DOM-accessible value of the password element.
293 void CheckTextFieldsDOMState(const std::string& username,
294 bool username_autofilled,
295 const std::string& password,
296 bool password_autofilled) {
297 CheckTextFieldsStateForElements(username_element_,
298 username,
299 username_autofilled,
300 password_element_,
301 password,
302 password_autofilled,
303 false);
304 }
305
276 void CheckUsernameSelection(int start, int end) { 306 void CheckUsernameSelection(int start, int end) {
277 EXPECT_EQ(start, username_element_.selectionStart()); 307 EXPECT_EQ(start, username_element_.selectionStart());
278 EXPECT_EQ(end, username_element_.selectionEnd()); 308 EXPECT_EQ(end, username_element_.selectionEnd());
279 } 309 }
280 310
281 string16 username1_; 311 string16 username1_;
282 string16 username2_; 312 string16 username2_;
283 string16 username3_; 313 string16 username3_;
284 string16 password1_; 314 string16 password1_;
285 string16 password2_; 315 string16 password2_;
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 801
772 // Simulate the user typing in the username in the iframe, which should cause 802 // Simulate the user typing in the username in the iframe, which should cause
773 // an autofill. 803 // an autofill.
774 SimulateUsernameChangeForElement(kAliceUsername, true, 804 SimulateUsernameChangeForElement(kAliceUsername, true,
775 iframe, username_input); 805 iframe, username_input);
776 806
777 CheckTextFieldsStateForElements(username_input, kAliceUsername, true, 807 CheckTextFieldsStateForElements(username_input, kAliceUsername, true,
778 password_input, kAlicePassword, true); 808 password_input, kAlicePassword, true);
779 } 809 }
780 810
811 // Tests that a password will only be filled as a suggested and will not be
812 // accessible by the DOM until a user gesture has occurred.
813 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) {
814 // Trigger the initial autocomplete.
815 SimulateOnFillPasswordForm(fill_data_);
816
817 // The username and password should have been autocompleted.
818 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
819
820 // However, it should only have completed with the suggested value, as tested
821 // above, and it should not have completed into the DOM accessible value for
822 // the password field.
823 CheckTextFieldsDOMState(kAliceUsername, true, "", true);
824
825 // Simulate a user click so that the password field's real value is filled.
826 SimulateElementClick(kUsernameName);
827 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
828 }
829
830 // Verfies that a DOM-activated UI event will not cause an autofill.
831 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
832 // Trigger the initial autocomplete.
833 SimulateOnFillPasswordForm(fill_data_);
834
835 ExecuteJavaScript(kJavaScriptClick);
836 CheckTextFieldsDOMState(kAliceUsername, true, "", true);
837 }
838
781 } // namespace autofill 839 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698