| OLD | NEW |
| 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 Loading... |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 319 // Make sure that we are enabled before loading HTML. | 307 // Make sure that we are enabled before loading HTML. |
| 320 std::string html = std::string(kAccountCreationFormHTML) + | 308 std::string html = std::string(kAccountCreationFormHTML); |
| 321 ChangeDetectionScript; | |
| 322 LoadHTMLWithUserGesture(html.c_str()); | 309 LoadHTMLWithUserGesture(html.c_str()); |
| 323 SetNotBlacklistedMessage(password_generation_, html.c_str()); | 310 SetNotBlacklistedMessage(password_generation_, html.c_str()); |
| 324 SetAccountCreationFormsDetectedMessage(password_generation_, | 311 SetAccountCreationFormsDetectedMessage(password_generation_, |
| 325 GetMainFrame()->document(), 0, 1); | 312 GetMainFrame()->document(), 0, 1); |
| 326 | 313 |
| 327 WebDocument document = GetMainFrame()->document(); | 314 WebDocument document = GetMainFrame()->document(); |
| 328 WebElement element = | 315 WebElement element = |
| 329 document.getElementById(WebString::fromUTF8("first_password")); | 316 document.getElementById(WebString::fromUTF8("first_password")); |
| 330 ASSERT_FALSE(element.isNull()); | 317 ASSERT_FALSE(element.isNull()); |
| 331 WebInputElement first_password_element = element.to<WebInputElement>(); | 318 WebInputElement first_password_element = element.to<WebInputElement>(); |
| 332 element = document.getElementById(WebString::fromUTF8("second_password")); | 319 element = document.getElementById(WebString::fromUTF8("second_password")); |
| 333 ASSERT_FALSE(element.isNull()); | 320 ASSERT_FALSE(element.isNull()); |
| 334 WebInputElement second_password_element = element.to<WebInputElement>(); | 321 WebInputElement second_password_element = element.to<WebInputElement>(); |
| 335 | 322 |
| 336 // Both password fields should be empty. | 323 // Both password fields should be empty. |
| 337 EXPECT_TRUE(first_password_element.value().isNull()); | 324 EXPECT_TRUE(first_password_element.value().isNull()); |
| 338 EXPECT_TRUE(second_password_element.value().isNull()); | 325 EXPECT_TRUE(second_password_element.value().isNull()); |
| 339 | 326 |
| 327 // Add event listeners for password fields. |
| 328 std::vector<std::string> variables_to_check; |
| 329 std::string events_registration_script = |
| 330 CreateScriptToRegisterListeners("first_password", &variables_to_check) + |
| 331 CreateScriptToRegisterListeners("second_password", &variables_to_check); |
| 332 ExecuteJavaScriptForTests(events_registration_script.c_str()); |
| 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 std::string& variable : variables_to_check) { |
| 351 int second_onchange_called = -1; | 345 int value; |
| 352 ASSERT_TRUE( | 346 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(base::UTF8ToUTF16(variable), |
| 353 ExecuteJavaScriptAndReturnIntValue( | 347 &value)); |
| 354 base::ASCIIToUTF16("firstOnChangeCalled ? 1 : 0"), | 348 EXPECT_EQ(1, value) << variable; |
| 355 &first_onchange_called)); | 349 } |
| 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 | 350 |
| 363 // Focus moved to the next input field. | 351 // Focus moved to the next input field. |
| 364 // TODO(zysxqn): Change this back to the address element once Bug 90224 | 352 // 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. | 353 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. |
| 366 element = document.getElementById(WebString::fromUTF8("first_password")); | 354 element = document.getElementById(WebString::fromUTF8("first_password")); |
| 367 ASSERT_FALSE(element.isNull()); | 355 ASSERT_FALSE(element.isNull()); |
| 368 EXPECT_EQ(element, document.focusedElement()); | 356 EXPECT_EQ(element, document.focusedElement()); |
| 369 } | 357 } |
| 370 | 358 |
| 371 TEST_F(PasswordGenerationAgentTest, EditingTest) { | 359 TEST_F(PasswordGenerationAgentTest, EditingTest) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 | 792 |
| 805 // Click on another HTML element. | 793 // Click on another HTML element. |
| 806 const char* const click_target_name = | 794 const char* const click_target_name = |
| 807 clickOnInputField ? kTextFieldId : kSpanId; | 795 clickOnInputField ? kTextFieldId : kSpanId; |
| 808 EXPECT_TRUE(SimulateElementClick(click_target_name)); | 796 EXPECT_TRUE(SimulateElementClick(click_target_name)); |
| 809 EXPECT_FALSE(input.shouldRevealPassword()); | 797 EXPECT_FALSE(input.shouldRevealPassword()); |
| 810 } | 798 } |
| 811 } | 799 } |
| 812 | 800 |
| 813 } // namespace autofill | 801 } // namespace autofill |
| OLD | NEW |