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

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

Issue 2750323003: [Password Manager] Replace WebInputElement.setValue with WebInputElement.setAutofillValue (Closed)
Patch Set: Fixed Win tests Created 3 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string.h> 5 #include <string.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 const char kNewPasswordAutocompleteAttributeFormHTML[] = 243 const char kNewPasswordAutocompleteAttributeFormHTML[] =
244 "<FORM name = 'blah' action = 'http://www.random.com/'> " 244 "<FORM name = 'blah' action = 'http://www.random.com/'> "
245 " <INPUT type = 'text' id = 'username'/> " 245 " <INPUT type = 'text' id = 'username'/> "
246 " <INPUT type = 'password' id = 'first_password' " 246 " <INPUT type = 'password' id = 'first_password' "
247 " autocomplete='new-password' size = 5/>" 247 " autocomplete='new-password' size = 5/>"
248 " <INPUT type = 'password' id = 'second_password' size = 5/> " 248 " <INPUT type = 'password' id = 'second_password' size = 5/> "
249 " <INPUT type = 'button' id = 'dummy'/> " 249 " <INPUT type = 'button' id = 'dummy'/> "
250 " <INPUT type = 'submit' value = 'LOGIN' />" 250 " <INPUT type = 'submit' value = 'LOGIN' />"
251 "</FORM>"; 251 "</FORM>";
252 252
253 const char ChangeDetectionScript[] =
254 "<script>"
255 " firstOnChangeCalled = false;"
256 " secondOnChangeCalled = false;"
257 " document.getElementById('first_password').onchange = function() {"
258 " firstOnChangeCalled = true;"
259 " };"
260 " document.getElementById('second_password').onchange = function() {"
261 " secondOnChangeCalled = true;"
262 " };"
263 "</script>";
264
265 const char kPasswordChangeFormHTML[] = 253 const char kPasswordChangeFormHTML[] =
266 "<FORM name = 'ChangeWithUsernameForm' action = 'http://www.bidule.com'> " 254 "<FORM name = 'ChangeWithUsernameForm' action = 'http://www.bidule.com'> "
267 " <INPUT type = 'text' id = 'username'/> " 255 " <INPUT type = 'text' id = 'username'/> "
268 " <INPUT type = 'password' id = 'password'/> " 256 " <INPUT type = 'password' id = 'password'/> "
269 " <INPUT type = 'password' id = 'newpassword'/> " 257 " <INPUT type = 'password' id = 'newpassword'/> "
270 " <INPUT type = 'password' id = 'confirmpassword'/> " 258 " <INPUT type = 'password' id = 'confirmpassword'/> "
271 " <INPUT type = 'button' id = 'dummy'/> " 259 " <INPUT type = 'button' id = 'dummy'/> "
272 " <INPUT type = 'submit' value = 'Login'/> " 260 " <INPUT type = 'submit' value = 'Login'/> "
273 "</FORM>"; 261 "</FORM>";
274 262
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // This doesn't trigger because the form action is invalid. 297 // This doesn't trigger because the form action is invalid.
310 LoadHTMLWithUserGesture(kInvalidActionAccountCreationFormHTML); 298 LoadHTMLWithUserGesture(kInvalidActionAccountCreationFormHTML);
311 SetNotBlacklistedMessage(password_generation_, 299 SetNotBlacklistedMessage(password_generation_,
312 kInvalidActionAccountCreationFormHTML); 300 kInvalidActionAccountCreationFormHTML);
313 SetAccountCreationFormsDetectedMessage(password_generation_, 301 SetAccountCreationFormsDetectedMessage(password_generation_,
314 GetMainFrame()->document(), 0, 1); 302 GetMainFrame()->document(), 0, 1);
315 ExpectGenerationAvailable("first_password", false); 303 ExpectGenerationAvailable("first_password", false);
316 } 304 }
317 305
318 TEST_F(PasswordGenerationAgentTest, FillTest) { 306 TEST_F(PasswordGenerationAgentTest, FillTest) {
307 // Add event listeners for password fields.
308 std::vector<base::string16> variables_to_check;
309 std::string events_registration_script =
310 CreateScriptToRegisterListeners("first_password", &variables_to_check) +
311 CreateScriptToRegisterListeners("second_password", &variables_to_check);
312
319 // Make sure that we are enabled before loading HTML. 313 // Make sure that we are enabled before loading HTML.
320 std::string html = std::string(kAccountCreationFormHTML) + 314 std::string html =
321 ChangeDetectionScript; 315 std::string(kAccountCreationFormHTML) + events_registration_script;
322 LoadHTMLWithUserGesture(html.c_str()); 316 LoadHTMLWithUserGesture(html.c_str());
323 SetNotBlacklistedMessage(password_generation_, html.c_str()); 317 SetNotBlacklistedMessage(password_generation_, html.c_str());
324 SetAccountCreationFormsDetectedMessage(password_generation_, 318 SetAccountCreationFormsDetectedMessage(password_generation_,
325 GetMainFrame()->document(), 0, 1); 319 GetMainFrame()->document(), 0, 1);
326 320
327 WebDocument document = GetMainFrame()->document(); 321 WebDocument document = GetMainFrame()->document();
328 WebElement element = 322 WebElement element =
329 document.getElementById(WebString::fromUTF8("first_password")); 323 document.getElementById(WebString::fromUTF8("first_password"));
330 ASSERT_FALSE(element.isNull()); 324 ASSERT_FALSE(element.isNull());
331 WebInputElement first_password_element = element.to<WebInputElement>(); 325 WebInputElement first_password_element = element.to<WebInputElement>();
332 element = document.getElementById(WebString::fromUTF8("second_password")); 326 element = document.getElementById(WebString::fromUTF8("second_password"));
333 ASSERT_FALSE(element.isNull()); 327 ASSERT_FALSE(element.isNull());
334 WebInputElement second_password_element = element.to<WebInputElement>(); 328 WebInputElement second_password_element = element.to<WebInputElement>();
335 329
336 // Both password fields should be empty. 330 // Both password fields should be empty.
337 EXPECT_TRUE(first_password_element.value().isNull()); 331 EXPECT_TRUE(first_password_element.value().isNull());
338 EXPECT_TRUE(second_password_element.value().isNull()); 332 EXPECT_TRUE(second_password_element.value().isNull());
339 333
340 base::string16 password = base::ASCIIToUTF16("random_password"); 334 base::string16 password = base::ASCIIToUTF16("random_password");
341 password_generation_->GeneratedPasswordAccepted(password); 335 password_generation_->GeneratedPasswordAccepted(password);
342 336
343 // Password fields are filled out and set as being autofilled. 337 // Password fields are filled out and set as being autofilled.
344 EXPECT_EQ(password, first_password_element.value().utf16()); 338 EXPECT_EQ(password, first_password_element.value().utf16());
345 EXPECT_EQ(password, second_password_element.value().utf16()); 339 EXPECT_EQ(password, second_password_element.value().utf16());
346 EXPECT_TRUE(first_password_element.isAutofilled()); 340 EXPECT_TRUE(first_password_element.isAutofilled());
347 EXPECT_TRUE(second_password_element.isAutofilled()); 341 EXPECT_TRUE(second_password_element.isAutofilled());
348 342
349 // Make sure onchange events are called. 343 // Make sure all events are called.
350 int first_onchange_called = -1; 344 for (const base::string16& variable : variables_to_check) {
351 int second_onchange_called = -1; 345 int value;
352 ASSERT_TRUE( 346 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(variable, &value));
353 ExecuteJavaScriptAndReturnIntValue( 347 EXPECT_EQ(1, value) << variable;
354 base::ASCIIToUTF16("firstOnChangeCalled ? 1 : 0"), 348 }
355 &first_onchange_called));
356 EXPECT_EQ(1, first_onchange_called);
357 ASSERT_TRUE(
358 ExecuteJavaScriptAndReturnIntValue(
359 base::ASCIIToUTF16("secondOnChangeCalled ? 1 : 0"),
360 &second_onchange_called));
361 EXPECT_EQ(1, second_onchange_called);
362 349
363 // Focus moved to the next input field. 350 // Focus moved to the next input field.
364 // TODO(zysxqn): Change this back to the address element once Bug 90224 351 // TODO(zysxqn): Change this back to the address element once Bug 90224
365 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. 352 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed.
366 element = document.getElementById(WebString::fromUTF8("first_password")); 353 element = document.getElementById(WebString::fromUTF8("first_password"));
367 ASSERT_FALSE(element.isNull()); 354 ASSERT_FALSE(element.isNull());
368 EXPECT_EQ(element, document.focusedElement()); 355 EXPECT_EQ(element, document.focusedElement());
369 } 356 }
370 357
371 TEST_F(PasswordGenerationAgentTest, EditingTest) { 358 TEST_F(PasswordGenerationAgentTest, EditingTest) {
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 791
805 // Click on another HTML element. 792 // Click on another HTML element.
806 const char* const click_target_name = 793 const char* const click_target_name =
807 clickOnInputField ? kTextFieldId : kSpanId; 794 clickOnInputField ? kTextFieldId : kSpanId;
808 EXPECT_TRUE(SimulateElementClick(click_target_name)); 795 EXPECT_TRUE(SimulateElementClick(click_target_name));
809 EXPECT_FALSE(input.shouldRevealPassword()); 796 EXPECT_FALSE(input.shouldRevealPassword());
810 } 797 }
811 } 798 }
812 799
813 } // namespace autofill 800 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698