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

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

Issue 6896036: Autofill passwords after re-opening tab containing a login page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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
« no previous file with comments | « chrome/renderer/autofill/password_autofill_manager.cc ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/common/autofill_messages.h" 7 #include "chrome/common/autofill_messages.h"
8 #include "chrome/renderer/autofill/autofill_agent.h" 8 #include "chrome/renderer/autofill/autofill_agent.h"
9 #include "chrome/renderer/autofill/password_autofill_manager.h" 9 #include "chrome/renderer/autofill/password_autofill_manager.h"
10 #include "chrome/test/render_view_test.h" 10 #include "chrome/test/render_view_test.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 */ 196 */
197 197
198 // Simulate the browser sending back the login info, it triggers the 198 // Simulate the browser sending back the login info, it triggers the
199 // autocomplete. 199 // autocomplete.
200 SimulateOnFillPasswordForm(fill_data_); 200 SimulateOnFillPasswordForm(fill_data_);
201 201
202 // The username and password should have been autocompleted. 202 // The username and password should have been autocompleted.
203 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 203 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
204 } 204 }
205 205
206 // Tests that having a non-empty username precludes the autocomplete. 206 // Tests that we correctly fill forms having an empty 'action' attribute.
207 TEST_F(PasswordAutofillManagerTest, InitialAutocompleteForEmptyAction) { 207 TEST_F(PasswordAutofillManagerTest, InitialAutocompleteForEmptyAction) {
208 const char kEmptyActionFormHTML[] = 208 const char kEmptyActionFormHTML[] =
209 "<FORM name='LoginTestForm'>" 209 "<FORM name='LoginTestForm'>"
210 " <INPUT type='text' id='username'/>" 210 " <INPUT type='text' id='username'/>"
211 " <INPUT type='password' id='password'/>" 211 " <INPUT type='password' id='password'/>"
212 " <INPUT type='submit' value='Login'/>" 212 " <INPUT type='submit' value='Login'/>"
213 "</FORM>"; 213 "</FORM>";
214 LoadHTML(kEmptyActionFormHTML); 214 LoadHTML(kEmptyActionFormHTML);
215 215
216 // Retrieve the input elements so the test can access them. 216 // Retrieve the input elements so the test can access them.
(...skipping 27 matching lines...) Expand all
244 244
245 // Simulate the browser sending back the login info, it triggers the 245 // Simulate the browser sending back the login info, it triggers the
246 // autocomplete. 246 // autocomplete.
247 SimulateOnFillPasswordForm(fill_data_); 247 SimulateOnFillPasswordForm(fill_data_);
248 248
249 // Only the username should have been autocompleted. 249 // Only the username should have been autocompleted.
250 // TODO(jcivelli): may be we should not event fill the username? 250 // TODO(jcivelli): may be we should not event fill the username?
251 CheckTextFieldsState(kAliceUsername, true, "", false); 251 CheckTextFieldsState(kAliceUsername, true, "", false);
252 } 252 }
253 253
254 // Tests that having a non-empty username precludes the autocomplete. 254 // Tests that having a non-matching username precludes the autocomplete.
255 TEST_F(PasswordAutofillManagerTest, NoInitialAutocompleteForFilledField) { 255 TEST_F(PasswordAutofillManagerTest, NoInitialAutocompleteForFilledField) {
256 username_element_.setValue(WebString::fromUTF8("bogus")); 256 username_element_.setValue(WebString::fromUTF8("bogus"));
257 257
258 // Simulate the browser sending back the login info, it triggers the 258 // Simulate the browser sending back the login info, it triggers the
259 // autocomplete. 259 // autocomplete.
260 SimulateOnFillPasswordForm(fill_data_); 260 SimulateOnFillPasswordForm(fill_data_);
261 261
262 // Neither field should be autocompleted. 262 // Neither field should be autocompleted.
263 CheckTextFieldsState("bogus", false, "", false); 263 CheckTextFieldsState("bogus", false, "", false);
264 } 264 }
265 265
266 // Tests that having a matching username does not preclude the autocomplete.
267 TEST_F(PasswordAutofillManagerTest, InitialAutocompleteForMatchingFilledField) {
268 username_element_.setValue(WebString::fromUTF8(kAliceUsername));
269
270 // Simulate the browser sending back the login info, it triggers the
271 // autocomplete.
272 SimulateOnFillPasswordForm(fill_data_);
273
274 // The username and password should have been autocompleted.
275 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
276 }
277
266 // Tests that editing the password clears the autocompleted password field. 278 // Tests that editing the password clears the autocompleted password field.
267 TEST_F(PasswordAutofillManagerTest, PasswordClearOnEdit) { 279 TEST_F(PasswordAutofillManagerTest, PasswordClearOnEdit) {
268 // Simulate the browser sending back the login info, it triggers the 280 // Simulate the browser sending back the login info, it triggers the
269 // autocomplete. 281 // autocomplete.
270 SimulateOnFillPasswordForm(fill_data_); 282 SimulateOnFillPasswordForm(fill_data_);
271 283
272 // Simulate the user changing the username to some unknown username. 284 // Simulate the user changing the username to some unknown username.
273 SimulateUsernameChange("alicia", true); 285 SimulateUsernameChange("alicia", true);
274 286
275 // The password should have been cleared. 287 // The password should have been cleared.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // To simulate accepting an item in the suggestion drop-down we just mimic 411 // To simulate accepting an item in the suggestion drop-down we just mimic
400 // what the WebView does: it sets the element value then calls 412 // what the WebView does: it sets the element value then calls
401 // didSelectAutoFillSuggestion on the renderer. 413 // didSelectAutoFillSuggestion on the renderer.
402 autofill_agent_->didSelectAutoFillSuggestion(username_element_, 414 autofill_agent_->didSelectAutoFillSuggestion(username_element_,
403 ASCIIToUTF16(kAliceUsername), 415 ASCIIToUTF16(kAliceUsername),
404 WebKit::WebString(), 416 WebKit::WebString(),
405 0); 417 0);
406 // Autocomplete should not have kicked in. 418 // Autocomplete should not have kicked in.
407 CheckTextFieldsState("", false, "", false); 419 CheckTextFieldsState("", false, "", false);
408 } 420 }
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/password_autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698