| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 public: | 164 public: |
| 165 MAYBE_PasswordFormConversionUtilsTest() : content::RenderViewTest() {} | 165 MAYBE_PasswordFormConversionUtilsTest() : content::RenderViewTest() {} |
| 166 ~MAYBE_PasswordFormConversionUtilsTest() override {} | 166 ~MAYBE_PasswordFormConversionUtilsTest() override {} |
| 167 | 167 |
| 168 protected: | 168 protected: |
| 169 // Loads the given |html|, retrieves the sole WebFormElement from it, and then | 169 // Loads the given |html|, retrieves the sole WebFormElement from it, and then |
| 170 // calls CreatePasswordForm(), passing it the |predictions| to convert it into | 170 // calls CreatePasswordForm(), passing it the |predictions| to convert it into |
| 171 // a |password_form|. Note that ASSERT() can only be used in void functions, | 171 // a |password_form|. Note that ASSERT() can only be used in void functions, |
| 172 // this is why |password_form| is passed in as a pointer to a scoped_ptr. | 172 // this is why |password_form| is passed in as a pointer to a scoped_ptr. |
| 173 void LoadHTMLAndConvertForm(const std::string& html, | 173 void LoadHTMLAndConvertForm(const std::string& html, |
| 174 scoped_ptr<PasswordForm>* password_form, | 174 std::unique_ptr<PasswordForm>* password_form, |
| 175 FormsPredictionsMap* predictions) { | 175 FormsPredictionsMap* predictions) { |
| 176 WebFormElement form; | 176 WebFormElement form; |
| 177 LoadWebFormFromHTML(html, &form); | 177 LoadWebFormFromHTML(html, &form); |
| 178 | 178 |
| 179 WebVector<WebFormControlElement> control_elements; | 179 WebVector<WebFormControlElement> control_elements; |
| 180 form.getFormControlElements(control_elements); | 180 form.getFormControlElements(control_elements); |
| 181 for (size_t i = 0; i < control_elements.size(); ++i) { | 181 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 182 WebInputElement* input_element = toWebInputElement(&control_elements[i]); | 182 WebInputElement* input_element = toWebInputElement(&control_elements[i]); |
| 183 if (input_element->hasAttribute("set-activated-submit")) | 183 if (input_element->hasAttribute("set-activated-submit")) |
| 184 input_element->setActivatedSubmit(true); | 184 input_element->setActivatedSubmit(true); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { | 238 TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { |
| 239 PasswordFormBuilder builder(kTestFormActionURL); | 239 PasswordFormBuilder builder(kTestFormActionURL); |
| 240 builder.AddTextField("username", "johnsmith", NULL); | 240 builder.AddTextField("username", "johnsmith", NULL); |
| 241 builder.AddSubmitButton("inactive_submit"); | 241 builder.AddSubmitButton("inactive_submit"); |
| 242 builder.AddSubmitButton("active_submit"); | 242 builder.AddSubmitButton("active_submit"); |
| 243 builder.AddSubmitButton("inactive_submit2"); | 243 builder.AddSubmitButton("inactive_submit2"); |
| 244 builder.AddPasswordField("password", "secret", NULL); | 244 builder.AddPasswordField("password", "secret", NULL); |
| 245 std::string html = builder.ProduceHTML(); | 245 std::string html = builder.ProduceHTML(); |
| 246 | 246 |
| 247 scoped_ptr<PasswordForm> password_form; | 247 std::unique_ptr<PasswordForm> password_form; |
| 248 ASSERT_NO_FATAL_FAILURE( | 248 ASSERT_NO_FATAL_FAILURE( |
| 249 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 249 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 250 ASSERT_TRUE(password_form); | 250 ASSERT_TRUE(password_form); |
| 251 | 251 |
| 252 EXPECT_EQ("data:", password_form->signon_realm); | 252 EXPECT_EQ("data:", password_form->signon_realm); |
| 253 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action); | 253 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action); |
| 254 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 254 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 255 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 255 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 256 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 256 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 257 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 257 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 258 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme); | 258 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme); |
| 259 EXPECT_FALSE(password_form->ssl_valid); | 259 EXPECT_FALSE(password_form->ssl_valid); |
| 260 EXPECT_FALSE(password_form->preferred); | 260 EXPECT_FALSE(password_form->preferred); |
| 261 EXPECT_FALSE(password_form->blacklisted_by_user); | 261 EXPECT_FALSE(password_form->blacklisted_by_user); |
| 262 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); | 262 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { | 265 TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { |
| 266 PasswordFormBuilder builder(kTestFormActionURL); | 266 PasswordFormBuilder builder(kTestFormActionURL); |
| 267 builder.AddTextField("username", "johnsmith", NULL); | 267 builder.AddTextField("username", "johnsmith", NULL); |
| 268 builder.AddDisabledUsernameField(); | 268 builder.AddDisabledUsernameField(); |
| 269 builder.AddDisabledPasswordField(); | 269 builder.AddDisabledPasswordField(); |
| 270 builder.AddPasswordField("password", "secret", NULL); | 270 builder.AddPasswordField("password", "secret", NULL); |
| 271 builder.AddSubmitButton("submit"); | 271 builder.AddSubmitButton("submit"); |
| 272 std::string html = builder.ProduceHTML(); | 272 std::string html = builder.ProduceHTML(); |
| 273 | 273 |
| 274 scoped_ptr<PasswordForm> password_form; | 274 std::unique_ptr<PasswordForm> password_form; |
| 275 ASSERT_NO_FATAL_FAILURE( | 275 ASSERT_NO_FATAL_FAILURE( |
| 276 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 276 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 277 ASSERT_TRUE(password_form); | 277 ASSERT_TRUE(password_form); |
| 278 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 278 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 279 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 279 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 280 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 280 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 281 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 281 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { | 284 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 335 |
| 336 PasswordFormBuilder builder(kTestFormActionURL); | 336 PasswordFormBuilder builder(kTestFormActionURL); |
| 337 builder.AddTextField("username1", names[0], cases[i].autocomplete[0]); | 337 builder.AddTextField("username1", names[0], cases[i].autocomplete[0]); |
| 338 builder.AddTextField("username2", names[1], cases[i].autocomplete[1]); | 338 builder.AddTextField("username2", names[1], cases[i].autocomplete[1]); |
| 339 builder.AddPasswordField("password", "secret", NULL); | 339 builder.AddPasswordField("password", "secret", NULL); |
| 340 builder.AddTextField("username3", names[2], cases[i].autocomplete[2]); | 340 builder.AddTextField("username3", names[2], cases[i].autocomplete[2]); |
| 341 builder.AddPasswordField("password2", "othersecret", NULL); | 341 builder.AddPasswordField("password2", "othersecret", NULL); |
| 342 builder.AddSubmitButton("submit"); | 342 builder.AddSubmitButton("submit"); |
| 343 std::string html = builder.ProduceHTML(); | 343 std::string html = builder.ProduceHTML(); |
| 344 | 344 |
| 345 scoped_ptr<PasswordForm> password_form; | 345 std::unique_ptr<PasswordForm> password_form; |
| 346 ASSERT_NO_FATAL_FAILURE( | 346 ASSERT_NO_FATAL_FAILURE( |
| 347 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 347 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 348 ASSERT_TRUE(password_form); | 348 ASSERT_TRUE(password_form); |
| 349 | 349 |
| 350 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), | 350 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
| 351 password_form->username_element); | 351 password_form->username_element); |
| 352 | 352 |
| 353 if (nonempty_username_fields) { | 353 if (nonempty_username_fields) { |
| 354 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), | 354 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), |
| 355 password_form->username_value); | 355 password_form->username_value); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 395 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 396 | 396 |
| 397 PasswordFormBuilder builder(kTestFormActionURL); | 397 PasswordFormBuilder builder(kTestFormActionURL); |
| 398 builder.AddTextField("username1", "William", NULL); | 398 builder.AddTextField("username1", "William", NULL); |
| 399 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 399 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
| 400 builder.AddTextField("username2", "Smith", NULL); | 400 builder.AddTextField("username2", "Smith", NULL); |
| 401 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 401 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
| 402 builder.AddSubmitButton("submit"); | 402 builder.AddSubmitButton("submit"); |
| 403 std::string html = builder.ProduceHTML(); | 403 std::string html = builder.ProduceHTML(); |
| 404 | 404 |
| 405 scoped_ptr<PasswordForm> password_form; | 405 std::unique_ptr<PasswordForm> password_form; |
| 406 ASSERT_NO_FATAL_FAILURE( | 406 ASSERT_NO_FATAL_FAILURE( |
| 407 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 407 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 408 ASSERT_TRUE(password_form); | 408 ASSERT_TRUE(password_form); |
| 409 | 409 |
| 410 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), | 410 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
| 411 password_form->password_element); | 411 password_form->password_element); |
| 412 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), | 412 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), |
| 413 password_form->password_value); | 413 password_form->password_value); |
| 414 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), | 414 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), |
| 415 password_form->new_password_element); | 415 password_form->new_password_element); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 | 457 |
| 458 PasswordFormBuilder builder(kTestFormActionURL); | 458 PasswordFormBuilder builder(kTestFormActionURL); |
| 459 builder.AddTextField("username1", "William", NULL); | 459 builder.AddTextField("username1", "William", NULL); |
| 460 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 460 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
| 461 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 461 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
| 462 builder.AddTextField("username2", "Smith", NULL); | 462 builder.AddTextField("username2", "Smith", NULL); |
| 463 builder.AddPasswordField("password3", cases[i].password_values[2], NULL); | 463 builder.AddPasswordField("password3", cases[i].password_values[2], NULL); |
| 464 builder.AddSubmitButton("submit"); | 464 builder.AddSubmitButton("submit"); |
| 465 std::string html = builder.ProduceHTML(); | 465 std::string html = builder.ProduceHTML(); |
| 466 | 466 |
| 467 scoped_ptr<PasswordForm> password_form; | 467 std::unique_ptr<PasswordForm> password_form; |
| 468 ASSERT_NO_FATAL_FAILURE( | 468 ASSERT_NO_FATAL_FAILURE( |
| 469 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 469 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 470 ASSERT_TRUE(password_form); | 470 ASSERT_TRUE(password_form); |
| 471 | 471 |
| 472 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), | 472 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
| 473 password_form->password_element); | 473 password_form->password_element); |
| 474 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), | 474 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), |
| 475 password_form->password_value); | 475 password_form->password_value); |
| 476 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), | 476 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), |
| 477 password_form->new_password_element); | 477 password_form->new_password_element); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 builder.AddPasswordField("pin1", "123456", NULL); | 598 builder.AddPasswordField("pin1", "123456", NULL); |
| 599 builder.AddPasswordField("pin2", "789101", NULL); | 599 builder.AddPasswordField("pin2", "789101", NULL); |
| 600 builder.AddTextField("username1", "William", NULL); | 600 builder.AddTextField("username1", "William", NULL); |
| 601 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); | 601 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); |
| 602 builder.AddTextField("username2", "Smith", NULL); | 602 builder.AddTextField("username2", "Smith", NULL); |
| 603 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); | 603 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); |
| 604 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); | 604 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); |
| 605 builder.AddSubmitButton("submit"); | 605 builder.AddSubmitButton("submit"); |
| 606 std::string html = builder.ProduceHTML(); | 606 std::string html = builder.ProduceHTML(); |
| 607 | 607 |
| 608 scoped_ptr<PasswordForm> password_form; | 608 std::unique_ptr<PasswordForm> password_form; |
| 609 ASSERT_NO_FATAL_FAILURE( | 609 ASSERT_NO_FATAL_FAILURE( |
| 610 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 610 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 611 ASSERT_TRUE(password_form); | 611 ASSERT_TRUE(password_form); |
| 612 | 612 |
| 613 // In the absence of username autocomplete attributes, the username should | 613 // In the absence of username autocomplete attributes, the username should |
| 614 // be the text input field just before 'current-password' or before | 614 // be the text input field just before 'current-password' or before |
| 615 // 'new-password', if there is no 'current-password'. | 615 // 'new-password', if there is no 'current-password'. |
| 616 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), | 616 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
| 617 password_form->username_element); | 617 password_form->username_element); |
| 618 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), | 618 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 641 PasswordFormBuilder builder(kTestFormActionURL); | 641 PasswordFormBuilder builder(kTestFormActionURL); |
| 642 | 642 |
| 643 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 643 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 644 builder.AddTextField("username", "johnsmith", NULL); | 644 builder.AddTextField("username", "johnsmith", NULL); |
| 645 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); | 645 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); |
| 646 builder.AddPasswordField("password", "secret", NULL); | 646 builder.AddPasswordField("password", "secret", NULL); |
| 647 builder.AddPasswordField("password", "secret", NULL); | 647 builder.AddPasswordField("password", "secret", NULL); |
| 648 builder.AddSubmitButton("submit"); | 648 builder.AddSubmitButton("submit"); |
| 649 std::string html = builder.ProduceHTML(); | 649 std::string html = builder.ProduceHTML(); |
| 650 | 650 |
| 651 scoped_ptr<PasswordForm> password_form; | 651 std::unique_ptr<PasswordForm> password_form; |
| 652 ASSERT_NO_FATAL_FAILURE( | 652 ASSERT_NO_FATAL_FAILURE( |
| 653 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 653 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 654 ASSERT_TRUE(password_form); | 654 ASSERT_TRUE(password_form); |
| 655 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 655 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 656 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 656 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 657 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); | 657 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); |
| 658 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); | 658 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); |
| 659 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); | 659 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); |
| 660 } | 660 } |
| 661 | 661 |
| 662 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { | 662 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { |
| 663 PasswordFormBuilder builder(kTestFormActionURL); | 663 PasswordFormBuilder builder(kTestFormActionURL); |
| 664 | 664 |
| 665 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 665 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 666 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); | 666 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); |
| 667 builder.AddTextField("username", "johnsmith", NULL); | 667 builder.AddTextField("username", "johnsmith", NULL); |
| 668 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); | 668 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); |
| 669 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); | 669 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); |
| 670 builder.AddPasswordField("password", "secret", NULL); | 670 builder.AddPasswordField("password", "secret", NULL); |
| 671 builder.AddPasswordField("password", "secret", NULL); | 671 builder.AddPasswordField("password", "secret", NULL); |
| 672 builder.AddSubmitButton("submit"); | 672 builder.AddSubmitButton("submit"); |
| 673 std::string html = builder.ProduceHTML(); | 673 std::string html = builder.ProduceHTML(); |
| 674 | 674 |
| 675 scoped_ptr<PasswordForm> password_form; | 675 std::unique_ptr<PasswordForm> password_form; |
| 676 ASSERT_NO_FATAL_FAILURE( | 676 ASSERT_NO_FATAL_FAILURE( |
| 677 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 677 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 678 ASSERT_TRUE(password_form); | 678 ASSERT_TRUE(password_form); |
| 679 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 679 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 680 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 680 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 681 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); | 681 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); |
| 682 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); | 682 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); |
| 683 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); | 683 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); |
| 684 } | 684 } |
| 685 | 685 |
| 686 TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { | 686 TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { |
| 687 PasswordFormBuilder builder(kTestFormActionURL); | 687 PasswordFormBuilder builder(kTestFormActionURL); |
| 688 | 688 |
| 689 builder.AddNonDisplayedTextField("username", "William"); | 689 builder.AddNonDisplayedTextField("username", "William"); |
| 690 builder.AddNonDisplayedPasswordField("password", "secret"); | 690 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 691 builder.AddSubmitButton("submit"); | 691 builder.AddSubmitButton("submit"); |
| 692 std::string html = builder.ProduceHTML(); | 692 std::string html = builder.ProduceHTML(); |
| 693 | 693 |
| 694 scoped_ptr<PasswordForm> password_form; | 694 std::unique_ptr<PasswordForm> password_form; |
| 695 ASSERT_NO_FATAL_FAILURE( | 695 ASSERT_NO_FATAL_FAILURE( |
| 696 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 696 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 697 ASSERT_TRUE(password_form); | 697 ASSERT_TRUE(password_form); |
| 698 EXPECT_EQ(base::UTF8ToUTF16("username"), | 698 EXPECT_EQ(base::UTF8ToUTF16("username"), |
| 699 password_form->username_element); | 699 password_form->username_element); |
| 700 EXPECT_EQ(base::UTF8ToUTF16("William"), | 700 EXPECT_EQ(base::UTF8ToUTF16("William"), |
| 701 password_form->username_value); | 701 password_form->username_value); |
| 702 EXPECT_EQ(base::UTF8ToUTF16("password"), | 702 EXPECT_EQ(base::UTF8ToUTF16("password"), |
| 703 password_form->password_element); | 703 password_form->password_element); |
| 704 EXPECT_EQ(base::UTF8ToUTF16("secret"), | 704 EXPECT_EQ(base::UTF8ToUTF16("secret"), |
| 705 password_form->password_value); | 705 password_form->password_value); |
| 706 } | 706 } |
| 707 | 707 |
| 708 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 708 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 709 VisiblePasswordAndInvisibleUsername) { | 709 VisiblePasswordAndInvisibleUsername) { |
| 710 PasswordFormBuilder builder(kTestFormActionURL); | 710 PasswordFormBuilder builder(kTestFormActionURL); |
| 711 | 711 |
| 712 builder.AddNonDisplayedTextField("username", "William"); | 712 builder.AddNonDisplayedTextField("username", "William"); |
| 713 builder.AddPasswordField("password", "secret", NULL); | 713 builder.AddPasswordField("password", "secret", NULL); |
| 714 builder.AddSubmitButton("submit"); | 714 builder.AddSubmitButton("submit"); |
| 715 std::string html = builder.ProduceHTML(); | 715 std::string html = builder.ProduceHTML(); |
| 716 | 716 |
| 717 scoped_ptr<PasswordForm> password_form; | 717 std::unique_ptr<PasswordForm> password_form; |
| 718 ASSERT_NO_FATAL_FAILURE( | 718 ASSERT_NO_FATAL_FAILURE( |
| 719 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 719 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 720 ASSERT_TRUE(password_form); | 720 ASSERT_TRUE(password_form); |
| 721 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 721 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 722 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 722 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 723 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 723 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 724 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 724 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 725 } | 725 } |
| 726 | 726 |
| 727 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 727 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 728 InvisiblePassword_LatestUsernameIsVisible) { | 728 InvisiblePassword_LatestUsernameIsVisible) { |
| 729 PasswordFormBuilder builder(kTestFormActionURL); | 729 PasswordFormBuilder builder(kTestFormActionURL); |
| 730 | 730 |
| 731 builder.AddNonDisplayedTextField("search", "query"); | 731 builder.AddNonDisplayedTextField("search", "query"); |
| 732 builder.AddTextField("username", "William", NULL); | 732 builder.AddTextField("username", "William", NULL); |
| 733 builder.AddNonDisplayedPasswordField("password", "secret"); | 733 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 734 builder.AddSubmitButton("submit"); | 734 builder.AddSubmitButton("submit"); |
| 735 std::string html = builder.ProduceHTML(); | 735 std::string html = builder.ProduceHTML(); |
| 736 | 736 |
| 737 scoped_ptr<PasswordForm> password_form; | 737 std::unique_ptr<PasswordForm> password_form; |
| 738 ASSERT_NO_FATAL_FAILURE( | 738 ASSERT_NO_FATAL_FAILURE( |
| 739 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 739 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 740 ASSERT_TRUE(password_form); | 740 ASSERT_TRUE(password_form); |
| 741 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 741 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 742 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 742 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 743 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 743 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 744 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 744 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 745 } | 745 } |
| 746 | 746 |
| 747 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 747 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 748 InvisiblePassword_LatestUsernameIsInvisible) { | 748 InvisiblePassword_LatestUsernameIsInvisible) { |
| 749 PasswordFormBuilder builder(kTestFormActionURL); | 749 PasswordFormBuilder builder(kTestFormActionURL); |
| 750 | 750 |
| 751 builder.AddTextField("search", "query", NULL); | 751 builder.AddTextField("search", "query", NULL); |
| 752 builder.AddNonDisplayedTextField("username", "William"); | 752 builder.AddNonDisplayedTextField("username", "William"); |
| 753 builder.AddNonDisplayedPasswordField("password", "secret"); | 753 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 754 builder.AddSubmitButton("submit"); | 754 builder.AddSubmitButton("submit"); |
| 755 std::string html = builder.ProduceHTML(); | 755 std::string html = builder.ProduceHTML(); |
| 756 | 756 |
| 757 scoped_ptr<PasswordForm> password_form; | 757 std::unique_ptr<PasswordForm> password_form; |
| 758 ASSERT_NO_FATAL_FAILURE( | 758 ASSERT_NO_FATAL_FAILURE( |
| 759 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 759 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 760 ASSERT_TRUE(password_form); | 760 ASSERT_TRUE(password_form); |
| 761 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 761 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 762 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 762 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 763 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 763 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 764 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 764 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 765 } | 765 } |
| 766 | 766 |
| 767 TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { | 767 TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { |
| 768 PasswordFormBuilder builder("invalid_target"); | 768 PasswordFormBuilder builder("invalid_target"); |
| 769 builder.AddTextField("username", "JohnSmith", NULL); | 769 builder.AddTextField("username", "JohnSmith", NULL); |
| 770 builder.AddSubmitButton("submit"); | 770 builder.AddSubmitButton("submit"); |
| 771 builder.AddPasswordField("password", "secret", NULL); | 771 builder.AddPasswordField("password", "secret", NULL); |
| 772 std::string html = builder.ProduceHTML(); | 772 std::string html = builder.ProduceHTML(); |
| 773 | 773 |
| 774 scoped_ptr<PasswordForm> password_form; | 774 std::unique_ptr<PasswordForm> password_form; |
| 775 ASSERT_NO_FATAL_FAILURE( | 775 ASSERT_NO_FATAL_FAILURE( |
| 776 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 776 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 777 EXPECT_FALSE(password_form); | 777 EXPECT_FALSE(password_form); |
| 778 } | 778 } |
| 779 | 779 |
| 780 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 780 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 781 InvalidFormDueToNoPasswordFields) { | 781 InvalidFormDueToNoPasswordFields) { |
| 782 PasswordFormBuilder builder(kTestFormActionURL); | 782 PasswordFormBuilder builder(kTestFormActionURL); |
| 783 builder.AddTextField("username1", "John", NULL); | 783 builder.AddTextField("username1", "John", NULL); |
| 784 builder.AddTextField("username2", "Smith", NULL); | 784 builder.AddTextField("username2", "Smith", NULL); |
| 785 builder.AddSubmitButton("submit"); | 785 builder.AddSubmitButton("submit"); |
| 786 std::string html = builder.ProduceHTML(); | 786 std::string html = builder.ProduceHTML(); |
| 787 | 787 |
| 788 scoped_ptr<PasswordForm> password_form; | 788 std::unique_ptr<PasswordForm> password_form; |
| 789 ASSERT_NO_FATAL_FAILURE( | 789 ASSERT_NO_FATAL_FAILURE( |
| 790 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 790 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 791 EXPECT_FALSE(password_form); | 791 EXPECT_FALSE(password_form); |
| 792 } | 792 } |
| 793 | 793 |
| 794 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 794 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 795 InvalidFormsDueToConfusingPasswordFields) { | 795 InvalidFormsDueToConfusingPasswordFields) { |
| 796 // Each test case consists of a set of parameters to be plugged into the | 796 // Each test case consists of a set of parameters to be plugged into the |
| 797 // PasswordFormBuilder below. | 797 // PasswordFormBuilder below. |
| 798 const char* cases[][3] = { | 798 const char* cases[][3] = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 809 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 809 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 810 | 810 |
| 811 PasswordFormBuilder builder(kTestFormActionURL); | 811 PasswordFormBuilder builder(kTestFormActionURL); |
| 812 builder.AddTextField("username1", "John", NULL); | 812 builder.AddTextField("username1", "John", NULL); |
| 813 builder.AddPasswordField("password1", cases[i][0], NULL); | 813 builder.AddPasswordField("password1", cases[i][0], NULL); |
| 814 builder.AddPasswordField("password2", cases[i][1], NULL); | 814 builder.AddPasswordField("password2", cases[i][1], NULL); |
| 815 builder.AddPasswordField("password3", cases[i][2], NULL); | 815 builder.AddPasswordField("password3", cases[i][2], NULL); |
| 816 builder.AddSubmitButton("submit"); | 816 builder.AddSubmitButton("submit"); |
| 817 std::string html = builder.ProduceHTML(); | 817 std::string html = builder.ProduceHTML(); |
| 818 | 818 |
| 819 scoped_ptr<PasswordForm> password_form; | 819 std::unique_ptr<PasswordForm> password_form; |
| 820 ASSERT_NO_FATAL_FAILURE( | 820 ASSERT_NO_FATAL_FAILURE( |
| 821 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 821 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 822 EXPECT_FALSE(password_form); | 822 EXPECT_FALSE(password_form); |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 | 825 |
| 826 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 826 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 827 InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { | 827 InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { |
| 828 PasswordFormBuilder builder(kTestFormActionURL); | 828 PasswordFormBuilder builder(kTestFormActionURL); |
| 829 builder.AddTextField("username1", "John", NULL); | 829 builder.AddTextField("username1", "John", NULL); |
| 830 builder.AddPasswordField("password1", "alpha", NULL); | 830 builder.AddPasswordField("password1", "alpha", NULL); |
| 831 builder.AddPasswordField("password2", "alpha", NULL); | 831 builder.AddPasswordField("password2", "alpha", NULL); |
| 832 builder.AddPasswordField("password3", "alpha", NULL); | 832 builder.AddPasswordField("password3", "alpha", NULL); |
| 833 builder.AddPasswordField("password4", "alpha", NULL); | 833 builder.AddPasswordField("password4", "alpha", NULL); |
| 834 builder.AddSubmitButton("submit"); | 834 builder.AddSubmitButton("submit"); |
| 835 std::string html = builder.ProduceHTML(); | 835 std::string html = builder.ProduceHTML(); |
| 836 | 836 |
| 837 scoped_ptr<PasswordForm> password_form; | 837 std::unique_ptr<PasswordForm> password_form; |
| 838 ASSERT_NO_FATAL_FAILURE( | 838 ASSERT_NO_FATAL_FAILURE( |
| 839 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 839 LoadHTMLAndConvertForm(html, &password_form, nullptr)); |
| 840 EXPECT_FALSE(password_form); | 840 EXPECT_FALSE(password_form); |
| 841 } | 841 } |
| 842 | 842 |
| 843 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { | 843 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { |
| 844 PasswordFormBuilder builder(kTestFormActionURL); | 844 PasswordFormBuilder builder(kTestFormActionURL); |
| 845 builder.AddHiddenField(); | 845 builder.AddHiddenField(); |
| 846 builder.AddTextField("username", "", nullptr); | 846 builder.AddTextField("username", "", nullptr); |
| 847 builder.AddPasswordField("password", "", nullptr); | 847 builder.AddPasswordField("password", "", nullptr); |
| 848 builder.AddSubmitButton("submit"); | 848 builder.AddSubmitButton("submit"); |
| 849 std::string login_html = builder.ProduceHTML(); | 849 std::string login_html = builder.ProduceHTML(); |
| 850 | 850 |
| 851 scoped_ptr<PasswordForm> login_form; | 851 std::unique_ptr<PasswordForm> login_form; |
| 852 ASSERT_NO_FATAL_FAILURE( | 852 ASSERT_NO_FATAL_FAILURE( |
| 853 LoadHTMLAndConvertForm(login_html, &login_form, nullptr)); | 853 LoadHTMLAndConvertForm(login_html, &login_form, nullptr)); |
| 854 ASSERT_TRUE(login_form); | 854 ASSERT_TRUE(login_form); |
| 855 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); | 855 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); |
| 856 } | 856 } |
| 857 | 857 |
| 858 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { | 858 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { |
| 859 PasswordFormBuilder builder(kTestFormActionURL); | 859 PasswordFormBuilder builder(kTestFormActionURL); |
| 860 builder.AddTextField("someotherfield", "", nullptr); | 860 builder.AddTextField("someotherfield", "", nullptr); |
| 861 builder.AddTextField("username", "", nullptr); | 861 builder.AddTextField("username", "", nullptr); |
| 862 builder.AddPasswordField("new_password", "", nullptr); | 862 builder.AddPasswordField("new_password", "", nullptr); |
| 863 builder.AddHiddenField(); | 863 builder.AddHiddenField(); |
| 864 builder.AddPasswordField("new_password2", "", nullptr); | 864 builder.AddPasswordField("new_password2", "", nullptr); |
| 865 builder.AddSubmitButton("submit"); | 865 builder.AddSubmitButton("submit"); |
| 866 std::string signup_html = builder.ProduceHTML(); | 866 std::string signup_html = builder.ProduceHTML(); |
| 867 | 867 |
| 868 scoped_ptr<PasswordForm> signup_form; | 868 std::unique_ptr<PasswordForm> signup_form; |
| 869 ASSERT_NO_FATAL_FAILURE( | 869 ASSERT_NO_FATAL_FAILURE( |
| 870 LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr)); | 870 LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr)); |
| 871 ASSERT_TRUE(signup_form); | 871 ASSERT_TRUE(signup_form); |
| 872 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); | 872 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); |
| 873 } | 873 } |
| 874 | 874 |
| 875 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { | 875 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { |
| 876 PasswordFormBuilder builder(kTestFormActionURL); | 876 PasswordFormBuilder builder(kTestFormActionURL); |
| 877 builder.AddTextField("username", "", nullptr); | 877 builder.AddTextField("username", "", nullptr); |
| 878 builder.AddPasswordField("old_password", "", nullptr); | 878 builder.AddPasswordField("old_password", "", nullptr); |
| 879 builder.AddHiddenField(); | 879 builder.AddHiddenField(); |
| 880 builder.AddPasswordField("new_password", "", nullptr); | 880 builder.AddPasswordField("new_password", "", nullptr); |
| 881 builder.AddPasswordField("new_password2", "", nullptr); | 881 builder.AddPasswordField("new_password2", "", nullptr); |
| 882 builder.AddSubmitButton("submit"); | 882 builder.AddSubmitButton("submit"); |
| 883 std::string change_html = builder.ProduceHTML(); | 883 std::string change_html = builder.ProduceHTML(); |
| 884 | 884 |
| 885 scoped_ptr<PasswordForm> change_form; | 885 std::unique_ptr<PasswordForm> change_form; |
| 886 ASSERT_NO_FATAL_FAILURE( | 886 ASSERT_NO_FATAL_FAILURE( |
| 887 LoadHTMLAndConvertForm(change_html, &change_form, nullptr)); | 887 LoadHTMLAndConvertForm(change_html, &change_form, nullptr)); |
| 888 ASSERT_TRUE(change_form); | 888 ASSERT_TRUE(change_form); |
| 889 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); | 889 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); |
| 890 } | 890 } |
| 891 | 891 |
| 892 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 892 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 893 LayoutClassificationLoginPlusSignup_A) { | 893 LayoutClassificationLoginPlusSignup_A) { |
| 894 PasswordFormBuilder builder(kTestFormActionURL); | 894 PasswordFormBuilder builder(kTestFormActionURL); |
| 895 builder.AddTextField("username", "", nullptr); | 895 builder.AddTextField("username", "", nullptr); |
| 896 builder.AddHiddenField(); | 896 builder.AddHiddenField(); |
| 897 builder.AddPasswordField("password", "", nullptr); | 897 builder.AddPasswordField("password", "", nullptr); |
| 898 builder.AddTextField("username2", "", nullptr); | 898 builder.AddTextField("username2", "", nullptr); |
| 899 builder.AddTextField("someotherfield", "", nullptr); | 899 builder.AddTextField("someotherfield", "", nullptr); |
| 900 builder.AddPasswordField("new_password", "", nullptr); | 900 builder.AddPasswordField("new_password", "", nullptr); |
| 901 builder.AddPasswordField("new_password2", "", nullptr); | 901 builder.AddPasswordField("new_password2", "", nullptr); |
| 902 builder.AddHiddenField(); | 902 builder.AddHiddenField(); |
| 903 builder.AddSubmitButton("submit"); | 903 builder.AddSubmitButton("submit"); |
| 904 std::string login_plus_signup_html = builder.ProduceHTML(); | 904 std::string login_plus_signup_html = builder.ProduceHTML(); |
| 905 | 905 |
| 906 scoped_ptr<PasswordForm> login_plus_signup_form; | 906 std::unique_ptr<PasswordForm> login_plus_signup_form; |
| 907 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( | 907 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
| 908 login_plus_signup_html, &login_plus_signup_form, nullptr)); | 908 login_plus_signup_html, &login_plus_signup_form, nullptr)); |
| 909 ASSERT_TRUE(login_plus_signup_form); | 909 ASSERT_TRUE(login_plus_signup_form); |
| 910 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, | 910 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
| 911 login_plus_signup_form->layout); | 911 login_plus_signup_form->layout); |
| 912 } | 912 } |
| 913 | 913 |
| 914 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 914 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 915 LayoutClassificationLoginPlusSignup_B) { | 915 LayoutClassificationLoginPlusSignup_B) { |
| 916 PasswordFormBuilder builder(kTestFormActionURL); | 916 PasswordFormBuilder builder(kTestFormActionURL); |
| 917 builder.AddTextField("username", "", nullptr); | 917 builder.AddTextField("username", "", nullptr); |
| 918 builder.AddHiddenField(); | 918 builder.AddHiddenField(); |
| 919 builder.AddPasswordField("password", "", nullptr); | 919 builder.AddPasswordField("password", "", nullptr); |
| 920 builder.AddTextField("username2", "", nullptr); | 920 builder.AddTextField("username2", "", nullptr); |
| 921 builder.AddTextField("someotherfield", "", nullptr); | 921 builder.AddTextField("someotherfield", "", nullptr); |
| 922 builder.AddPasswordField("new_password", "", nullptr); | 922 builder.AddPasswordField("new_password", "", nullptr); |
| 923 builder.AddTextField("someotherfield2", "", nullptr); | 923 builder.AddTextField("someotherfield2", "", nullptr); |
| 924 builder.AddHiddenField(); | 924 builder.AddHiddenField(); |
| 925 builder.AddSubmitButton("submit"); | 925 builder.AddSubmitButton("submit"); |
| 926 std::string login_plus_signup_html = builder.ProduceHTML(); | 926 std::string login_plus_signup_html = builder.ProduceHTML(); |
| 927 | 927 |
| 928 scoped_ptr<PasswordForm> login_plus_signup_form; | 928 std::unique_ptr<PasswordForm> login_plus_signup_form; |
| 929 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( | 929 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
| 930 login_plus_signup_html, &login_plus_signup_form, nullptr)); | 930 login_plus_signup_html, &login_plus_signup_form, nullptr)); |
| 931 ASSERT_TRUE(login_plus_signup_form); | 931 ASSERT_TRUE(login_plus_signup_form); |
| 932 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, | 932 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
| 933 login_plus_signup_form->layout); | 933 login_plus_signup_form->layout); |
| 934 } | 934 } |
| 935 | 935 |
| 936 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 936 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 937 CreditCardNumberWithTypePasswordForm) { | 937 CreditCardNumberWithTypePasswordForm) { |
| 938 PasswordFormBuilder builder(kTestFormActionURL); | 938 PasswordFormBuilder builder(kTestFormActionURL); |
| 939 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 939 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 940 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", | 940 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", |
| 941 nullptr); | 941 nullptr); |
| 942 builder.AddTextField("cvc", "000", nullptr); | 942 builder.AddTextField("cvc", "000", nullptr); |
| 943 builder.AddSubmitButton("submit"); | 943 builder.AddSubmitButton("submit"); |
| 944 std::string html = builder.ProduceHTML(); | 944 std::string html = builder.ProduceHTML(); |
| 945 | 945 |
| 946 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 946 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 947 predictions_positions[1] = PREDICTION_NOT_PASSWORD; | 947 predictions_positions[1] = PREDICTION_NOT_PASSWORD; |
| 948 | 948 |
| 949 FormsPredictionsMap predictions; | 949 FormsPredictionsMap predictions; |
| 950 SetPredictions(html, &predictions, predictions_positions); | 950 SetPredictions(html, &predictions, predictions_positions); |
| 951 | 951 |
| 952 scoped_ptr<PasswordForm> password_form; | 952 std::unique_ptr<PasswordForm> password_form; |
| 953 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 953 LoadHTMLAndConvertForm(html, &password_form, &predictions); |
| 954 EXPECT_FALSE(password_form); | 954 EXPECT_FALSE(password_form); |
| 955 } | 955 } |
| 956 | 956 |
| 957 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 957 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 958 CreditCardVerificationNumberWithTypePasswordForm) { | 958 CreditCardVerificationNumberWithTypePasswordForm) { |
| 959 PasswordFormBuilder builder(kTestFormActionURL); | 959 PasswordFormBuilder builder(kTestFormActionURL); |
| 960 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 960 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 961 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); | 961 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); |
| 962 builder.AddPasswordField("cvc", "000", nullptr); | 962 builder.AddPasswordField("cvc", "000", nullptr); |
| 963 builder.AddSubmitButton("submit"); | 963 builder.AddSubmitButton("submit"); |
| 964 std::string html = builder.ProduceHTML(); | 964 std::string html = builder.ProduceHTML(); |
| 965 | 965 |
| 966 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 966 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 967 predictions_positions[2] = PREDICTION_NOT_PASSWORD; | 967 predictions_positions[2] = PREDICTION_NOT_PASSWORD; |
| 968 | 968 |
| 969 FormsPredictionsMap predictions; | 969 FormsPredictionsMap predictions; |
| 970 SetPredictions(html, &predictions, predictions_positions); | 970 SetPredictions(html, &predictions, predictions_positions); |
| 971 | 971 |
| 972 scoped_ptr<PasswordForm> password_form; | 972 std::unique_ptr<PasswordForm> password_form; |
| 973 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 973 LoadHTMLAndConvertForm(html, &password_form, &predictions); |
| 974 EXPECT_FALSE(password_form); | 974 EXPECT_FALSE(password_form); |
| 975 } | 975 } |
| 976 | 976 |
| 977 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 977 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 978 CreditCardNumberWithTypePasswordFormWithAutocomplete) { | 978 CreditCardNumberWithTypePasswordFormWithAutocomplete) { |
| 979 PasswordFormBuilder builder(kTestFormActionURL); | 979 PasswordFormBuilder builder(kTestFormActionURL); |
| 980 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 980 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 981 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", | 981 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", |
| 982 "current-password"); | 982 "current-password"); |
| 983 builder.AddTextField("cvc", "000", nullptr); | 983 builder.AddTextField("cvc", "000", nullptr); |
| 984 builder.AddSubmitButton("submit"); | 984 builder.AddSubmitButton("submit"); |
| 985 std::string html = builder.ProduceHTML(); | 985 std::string html = builder.ProduceHTML(); |
| 986 | 986 |
| 987 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 987 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 988 predictions_positions[1] = PREDICTION_NOT_PASSWORD; | 988 predictions_positions[1] = PREDICTION_NOT_PASSWORD; |
| 989 | 989 |
| 990 FormsPredictionsMap predictions; | 990 FormsPredictionsMap predictions; |
| 991 SetPredictions(html, &predictions, predictions_positions); | 991 SetPredictions(html, &predictions, predictions_positions); |
| 992 | 992 |
| 993 scoped_ptr<PasswordForm> password_form; | 993 std::unique_ptr<PasswordForm> password_form; |
| 994 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 994 LoadHTMLAndConvertForm(html, &password_form, &predictions); |
| 995 EXPECT_TRUE(password_form); | 995 EXPECT_TRUE(password_form); |
| 996 } | 996 } |
| 997 | 997 |
| 998 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 998 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 999 CreditCardVerificationNumberWithTypePasswordFormWithAutocomplete) { | 999 CreditCardVerificationNumberWithTypePasswordFormWithAutocomplete) { |
| 1000 PasswordFormBuilder builder(kTestFormActionURL); | 1000 PasswordFormBuilder builder(kTestFormActionURL); |
| 1001 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 1001 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 1002 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); | 1002 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); |
| 1003 builder.AddPasswordField("cvc", "000", "new-password"); | 1003 builder.AddPasswordField("cvc", "000", "new-password"); |
| 1004 builder.AddSubmitButton("submit"); | 1004 builder.AddSubmitButton("submit"); |
| 1005 std::string html = builder.ProduceHTML(); | 1005 std::string html = builder.ProduceHTML(); |
| 1006 | 1006 |
| 1007 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 1007 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 1008 predictions_positions[2] = PREDICTION_NOT_PASSWORD; | 1008 predictions_positions[2] = PREDICTION_NOT_PASSWORD; |
| 1009 | 1009 |
| 1010 FormsPredictionsMap predictions; | 1010 FormsPredictionsMap predictions; |
| 1011 SetPredictions(html, &predictions, predictions_positions); | 1011 SetPredictions(html, &predictions, predictions_positions); |
| 1012 | 1012 |
| 1013 scoped_ptr<PasswordForm> password_form; | 1013 std::unique_ptr<PasswordForm> password_form; |
| 1014 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 1014 LoadHTMLAndConvertForm(html, &password_form, &predictions); |
| 1015 EXPECT_TRUE(password_form); | 1015 EXPECT_TRUE(password_form); |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IsGaiaReauthFormIgnored) { | 1018 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IsGaiaReauthFormIgnored) { |
| 1019 struct TestCase { | 1019 struct TestCase { |
| 1020 const char* origin; | 1020 const char* origin; |
| 1021 struct KeyValue { | 1021 struct KeyValue { |
| 1022 KeyValue() : name(nullptr), value(nullptr) {} | 1022 KeyValue() : name(nullptr), value(nullptr) {} |
| 1023 KeyValue(const char* new_name, const char* new_value) | 1023 KeyValue(const char* new_name, const char* new_value) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 | 1096 |
| 1097 for (TestCase& test_case : cases) { | 1097 for (TestCase& test_case : cases) { |
| 1098 SCOPED_TRACE(testing::Message("origin=") | 1098 SCOPED_TRACE(testing::Message("origin=") |
| 1099 << test_case.origin | 1099 << test_case.origin |
| 1100 << ", hidden_fields[0]=" << test_case.hidden_fields[0].name | 1100 << ", hidden_fields[0]=" << test_case.hidden_fields[0].name |
| 1101 << "/" << test_case.hidden_fields[0].value | 1101 << "/" << test_case.hidden_fields[0].value |
| 1102 << ", hidden_fields[1]=" << test_case.hidden_fields[1].name | 1102 << ", hidden_fields[1]=" << test_case.hidden_fields[1].name |
| 1103 << "/" << test_case.hidden_fields[1].value | 1103 << "/" << test_case.hidden_fields[1].value |
| 1104 << ", expected_form_is_reauth=" | 1104 << ", expected_form_is_reauth=" |
| 1105 << test_case.expected_form_is_reauth); | 1105 << test_case.expected_form_is_reauth); |
| 1106 scoped_ptr<PasswordFormBuilder> builder(new PasswordFormBuilder("")); | 1106 std::unique_ptr<PasswordFormBuilder> builder(new PasswordFormBuilder("")); |
| 1107 builder->AddTextField("username", "", nullptr); | 1107 builder->AddTextField("username", "", nullptr); |
| 1108 builder->AddPasswordField("password", "", nullptr); | 1108 builder->AddPasswordField("password", "", nullptr); |
| 1109 for (TestCase::KeyValue& hidden_field : test_case.hidden_fields) { | 1109 for (TestCase::KeyValue& hidden_field : test_case.hidden_fields) { |
| 1110 if (hidden_field.name) | 1110 if (hidden_field.name) |
| 1111 builder->AddHiddenField(hidden_field.name, hidden_field.value); | 1111 builder->AddHiddenField(hidden_field.name, hidden_field.value); |
| 1112 } | 1112 } |
| 1113 std::string html = builder->ProduceHTML(); | 1113 std::string html = builder->ProduceHTML(); |
| 1114 WebFormElement form; | 1114 WebFormElement form; |
| 1115 LoadWebFormFromHTML(html, &form); | 1115 LoadWebFormFromHTML(html, &form); |
| 1116 std::vector<WebFormControlElement> control_elements; | 1116 std::vector<WebFormControlElement> control_elements; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 if (test_cases[i].new_password_fieldname == kEmpty) { | 1170 if (test_cases[i].new_password_fieldname == kEmpty) { |
| 1171 builder.AddAnonymousInputField("password"); | 1171 builder.AddAnonymousInputField("password"); |
| 1172 } else { | 1172 } else { |
| 1173 builder.AddPasswordField(test_cases[i].new_password_fieldname, "", | 1173 builder.AddPasswordField(test_cases[i].new_password_fieldname, "", |
| 1174 kEmpty); | 1174 kEmpty); |
| 1175 } | 1175 } |
| 1176 std::string html = builder.ProduceHTML(); | 1176 std::string html = builder.ProduceHTML(); |
| 1177 | 1177 |
| 1178 scoped_ptr<PasswordForm> password_form; | 1178 std::unique_ptr<PasswordForm> password_form; |
| 1179 LoadHTMLAndConvertForm(html, &password_form, nullptr); | 1179 LoadHTMLAndConvertForm(html, &password_form, nullptr); |
| 1180 EXPECT_TRUE(password_form); | 1180 EXPECT_TRUE(password_form); |
| 1181 | 1181 |
| 1182 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), | 1182 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), |
| 1183 password_form->username_element); | 1183 password_form->username_element); |
| 1184 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_password_element), | 1184 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_password_element), |
| 1185 password_form->password_element); | 1185 password_form->password_element); |
| 1186 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_new_password_element), | 1186 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_new_password_element), |
| 1187 password_form->new_password_element); | 1187 password_form->new_password_element); |
| 1188 } | 1188 } |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 } // namespace autofill | 1191 } // namespace autofill |
| OLD | NEW |