Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // Creates a builder to start composing a new form. The form will have the | 42 // Creates a builder to start composing a new form. The form will have the |
| 43 // specified |action| URL. | 43 // specified |action| URL. |
| 44 explicit PasswordFormBuilder(const char* action) { | 44 explicit PasswordFormBuilder(const char* action) { |
| 45 base::StringAppendF( | 45 base::StringAppendF( |
| 46 &html_, "<FORM name=\"Test\" action=\"%s\" method=\"post\">", action); | 46 &html_, "<FORM name=\"Test\" action=\"%s\" method=\"post\">", action); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Appends a new text-type field at the end of the form, having the specified | 49 // Appends a new text-type field at the end of the form, having the specified |
| 50 // |name_and_id|, |value|, and |autocomplete| attributes. The |autocomplete| | 50 // |name_and_id|, |value|, and |autocomplete| attributes. The |autocomplete| |
| 51 // argument can take two special values, namely: | 51 // argument can take two special values, namely: |
| 52 // 1.) NULL, causing no autocomplete attribute to be added, | 52 // 1.) nullptr, causing no autocomplete attribute to be added, |
| 53 // 2.) "", causing an empty attribute (i.e. autocomplete="") to be added. | 53 // 2.) "", causing an empty attribute (i.e. autocomplete="") to be added. |
| 54 void AddTextField(const char* name_and_id, | 54 void AddTextField(const char* name_and_id, |
| 55 const char* value, | 55 const char* value, |
| 56 const char* autocomplete) { | 56 const char* autocomplete) { |
| 57 std::string autocomplete_attribute(autocomplete ? | 57 std::string autocomplete_attribute(autocomplete ? |
| 58 base::StringPrintf("autocomplete=\"%s\"", autocomplete) : ""); | 58 base::StringPrintf("autocomplete=\"%s\"", autocomplete) : ""); |
| 59 base::StringAppendF( | 59 base::StringAppendF( |
| 60 &html_, | 60 &html_, |
| 61 "<INPUT type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\" %s/>", | 61 "<INPUT type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\" %s/>", |
| 62 name_and_id, name_and_id, value, autocomplete_attribute.c_str()); | 62 name_and_id, name_and_id, value, autocomplete_attribute.c_str()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 #endif // defined(OS_ANDROID) | 161 #endif // defined(OS_ANDROID) |
| 162 | 162 |
| 163 class MAYBE_PasswordFormConversionUtilsTest : public content::RenderViewTest { | 163 class MAYBE_PasswordFormConversionUtilsTest : public content::RenderViewTest { |
| 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|. If |with_user_input| == true it's considered that all |
| 172 // this is why |password_form| is passed in as a pointer to a scoped_ptr. | 172 // values in the form elements came from the user input. Note that ASSERT() |
|
vabr (Chromium)
2016/04/06 22:42:12
Actually, there seems to be no ASSERT in the metho
dvadym
2016/04/07 11:52:18
Thanks, it makes sense, the body of this function
| |
| 173 // can only be used in void functions, this is why |password_form| is passed | |
| 174 // in as a pointer to a unique_ptr. | |
| 173 void LoadHTMLAndConvertForm(const std::string& html, | 175 void LoadHTMLAndConvertForm(const std::string& html, |
| 174 std::unique_ptr<PasswordForm>* password_form, | 176 std::unique_ptr<PasswordForm>* password_form, |
| 175 FormsPredictionsMap* predictions) { | 177 FormsPredictionsMap* predictions, |
| 178 bool with_user_input) { | |
| 176 WebFormElement form; | 179 WebFormElement form; |
| 177 LoadWebFormFromHTML(html, &form); | 180 LoadWebFormFromHTML(html, &form); |
| 178 | 181 |
| 179 WebVector<WebFormControlElement> control_elements; | 182 WebVector<WebFormControlElement> control_elements; |
| 180 form.getFormControlElements(control_elements); | 183 form.getFormControlElements(control_elements); |
| 184 ModifiedValues user_input; | |
| 181 for (size_t i = 0; i < control_elements.size(); ++i) { | 185 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 182 WebInputElement* input_element = toWebInputElement(&control_elements[i]); | 186 WebInputElement* input_element = toWebInputElement(&control_elements[i]); |
| 183 if (input_element->hasAttribute("set-activated-submit")) | 187 if (input_element->hasAttribute("set-activated-submit")) |
| 184 input_element->setActivatedSubmit(true); | 188 input_element->setActivatedSubmit(true); |
| 189 if (with_user_input) | |
| 190 user_input[*input_element] = input_element->value(); | |
| 185 } | 191 } |
| 186 | 192 |
| 187 *password_form = CreatePasswordFormFromWebForm(form, nullptr, predictions); | 193 *password_form = CreatePasswordFormFromWebForm( |
| 194 form, with_user_input ? &user_input : nullptr, predictions); | |
| 188 } | 195 } |
| 189 | 196 |
| 190 // Iterates on the form generated by the |html| and adds the fields and type | 197 // Iterates on the form generated by the |html| and adds the fields and type |
| 191 // predictions corresponding to |predictions_positions| to |predictions|. | 198 // predictions corresponding to |predictions_positions| to |predictions|. |
| 192 void SetPredictions(const std::string& html, | 199 void SetPredictions(const std::string& html, |
| 193 FormsPredictionsMap* predictions, | 200 FormsPredictionsMap* predictions, |
| 194 const std::map<int, PasswordFormFieldPredictionType>& | 201 const std::map<int, PasswordFormFieldPredictionType>& |
| 195 predictions_positions) { | 202 predictions_positions) { |
| 196 WebFormElement form; | 203 WebFormElement form; |
| 197 LoadWebFormFromHTML(html, &form); | 204 LoadWebFormFromHTML(html, &form); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 } | 237 } |
| 231 | 238 |
| 232 private: | 239 private: |
| 233 DISALLOW_COPY_AND_ASSIGN(MAYBE_PasswordFormConversionUtilsTest); | 240 DISALLOW_COPY_AND_ASSIGN(MAYBE_PasswordFormConversionUtilsTest); |
| 234 }; | 241 }; |
| 235 | 242 |
| 236 } // namespace | 243 } // namespace |
| 237 | 244 |
| 238 TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { | 245 TEST_F(MAYBE_PasswordFormConversionUtilsTest, BasicFormAttributes) { |
| 239 PasswordFormBuilder builder(kTestFormActionURL); | 246 PasswordFormBuilder builder(kTestFormActionURL); |
| 240 builder.AddTextField("username", "johnsmith", NULL); | 247 builder.AddTextField("username", "johnsmith", nullptr); |
| 241 builder.AddSubmitButton("inactive_submit"); | 248 builder.AddSubmitButton("inactive_submit"); |
| 242 builder.AddSubmitButton("active_submit"); | 249 builder.AddSubmitButton("active_submit"); |
| 243 builder.AddSubmitButton("inactive_submit2"); | 250 builder.AddSubmitButton("inactive_submit2"); |
| 244 builder.AddPasswordField("password", "secret", NULL); | 251 builder.AddPasswordField("password", "secret", nullptr); |
| 245 std::string html = builder.ProduceHTML(); | 252 std::string html = builder.ProduceHTML(); |
| 246 | 253 |
| 247 std::unique_ptr<PasswordForm> password_form; | 254 std::unique_ptr<PasswordForm> password_form; |
| 248 ASSERT_NO_FATAL_FAILURE( | 255 ASSERT_NO_FATAL_FAILURE( |
| 249 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 256 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 250 ASSERT_TRUE(password_form); | 257 ASSERT_TRUE(password_form); |
| 251 | 258 |
| 252 EXPECT_EQ("data:", password_form->signon_realm); | 259 EXPECT_EQ("data:", password_form->signon_realm); |
| 253 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action); | 260 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action); |
| 254 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 261 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 255 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 262 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 256 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 263 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 257 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 264 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 258 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme); | 265 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme); |
| 259 EXPECT_FALSE(password_form->ssl_valid); | 266 EXPECT_FALSE(password_form->ssl_valid); |
| 260 EXPECT_FALSE(password_form->preferred); | 267 EXPECT_FALSE(password_form->preferred); |
| 261 EXPECT_FALSE(password_form->blacklisted_by_user); | 268 EXPECT_FALSE(password_form->blacklisted_by_user); |
| 262 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); | 269 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); |
| 263 } | 270 } |
| 264 | 271 |
| 265 TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { | 272 TEST_F(MAYBE_PasswordFormConversionUtilsTest, DisabledFieldsAreIgnored) { |
| 266 PasswordFormBuilder builder(kTestFormActionURL); | 273 PasswordFormBuilder builder(kTestFormActionURL); |
| 267 builder.AddTextField("username", "johnsmith", NULL); | 274 builder.AddTextField("username", "johnsmith", nullptr); |
| 268 builder.AddDisabledUsernameField(); | 275 builder.AddDisabledUsernameField(); |
| 269 builder.AddDisabledPasswordField(); | 276 builder.AddDisabledPasswordField(); |
| 270 builder.AddPasswordField("password", "secret", NULL); | 277 builder.AddPasswordField("password", "secret", nullptr); |
| 271 builder.AddSubmitButton("submit"); | 278 builder.AddSubmitButton("submit"); |
| 272 std::string html = builder.ProduceHTML(); | 279 std::string html = builder.ProduceHTML(); |
| 273 | 280 |
| 274 std::unique_ptr<PasswordForm> password_form; | 281 std::unique_ptr<PasswordForm> password_form; |
| 275 ASSERT_NO_FATAL_FAILURE( | 282 ASSERT_NO_FATAL_FAILURE( |
| 276 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 283 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 277 ASSERT_TRUE(password_form); | 284 ASSERT_TRUE(password_form); |
| 278 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 285 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 279 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 286 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 280 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 287 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 281 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 288 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 282 } | 289 } |
| 283 | 290 |
| 284 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { | 291 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IdentifyingUsernameFields) { |
| 285 // Each test case consists of a set of parameters to be plugged into the | 292 // Each test case consists of a set of parameters to be plugged into the |
| 286 // PasswordFormBuilder below, plus the corresponding expectations. | 293 // PasswordFormBuilder below, plus the corresponding expectations. |
| 287 struct TestCase { | 294 struct TestCase { |
| 288 const char* autocomplete[3]; | 295 const char* autocomplete[3]; |
| 289 const char* expected_username_element; | 296 const char* expected_username_element; |
| 290 const char* expected_username_value; | 297 const char* expected_username_value; |
| 291 const char* expected_other_possible_usernames; | 298 const char* expected_other_possible_usernames; |
| 292 } cases[] = { | 299 } cases[] = { |
| 293 // When no elements are marked with autocomplete='username', the text-type | 300 // When no elements are marked with autocomplete='username', the text-type |
| 294 // input field before the first password element should get selected as | 301 // input field before the first password element should get selected as |
| 295 // the username, and the rest should be marked as alternatives. | 302 // the username, and the rest should be marked as alternatives. |
| 296 {{NULL, NULL, NULL}, "username2", "William", "John+Smith"}, | 303 {{nullptr, nullptr, nullptr}, "username2", "William", "John+Smith"}, |
| 297 // When a sole element is marked with autocomplete='username', it should | 304 // When a sole element is marked with autocomplete='username', it should |
| 298 // be treated as the username for sure, with no other_possible_usernames. | 305 // be treated as the username for sure, with no other_possible_usernames. |
| 299 {{"username", NULL, NULL}, "username1", "John", ""}, | 306 {{"username", nullptr, nullptr}, "username1", "John", ""}, |
| 300 {{NULL, "username", NULL}, "username2", "William", ""}, | 307 {{nullptr, "username", nullptr}, "username2", "William", ""}, |
| 301 {{NULL, NULL, "username"}, "username3", "Smith", ""}, | 308 {{nullptr, nullptr, "username"}, "username3", "Smith", ""}, |
| 302 // When >=2 elements have the attribute, the first should be selected as | 309 // When >=2 elements have the attribute, the first should be selected as |
| 303 // the username, and the rest should go to other_possible_usernames. | 310 // the username, and the rest should go to other_possible_usernames. |
| 304 {{"username", "username", NULL}, "username1", "John", "William"}, | 311 {{"username", "username", nullptr}, "username1", "John", "William"}, |
| 305 {{NULL, "username", "username"}, "username2", "William", "Smith"}, | 312 {{nullptr, "username", "username"}, "username2", "William", "Smith"}, |
| 306 {{"username", NULL, "username"}, "username1", "John", "Smith"}, | 313 {{"username", nullptr, "username"}, "username1", "John", "Smith"}, |
| 307 {{"username", "username", "username"}, "username1", "John", | 314 {{"username", "username", "username"}, |
| 315 "username1", | |
| 316 "John", | |
| 308 "William+Smith"}, | 317 "William+Smith"}, |
| 309 // When there is an empty autocomplete attribute (i.e. autocomplete=""), | 318 // When there is an empty autocomplete attribute (i.e. autocomplete=""), |
| 310 // it should have the same effect as having no attribute whatsoever. | 319 // it should have the same effect as having no attribute whatsoever. |
| 311 {{"", "", ""}, "username2", "William", "John+Smith"}, | 320 {{"", "", ""}, "username2", "William", "John+Smith"}, |
| 312 {{"", "", "username"}, "username3", "Smith", ""}, | 321 {{"", "", "username"}, "username3", "Smith", ""}, |
| 313 {{"username", "", "username"}, "username1", "John", "Smith"}, | 322 {{"username", "", "username"}, "username1", "John", "Smith"}, |
| 314 // It should not matter if attribute values are upper or mixed case. | 323 // It should not matter if attribute values are upper or mixed case. |
| 315 {{"USERNAME", NULL, "uSeRNaMe"}, "username1", "John", "Smith"}, | 324 {{"USERNAME", nullptr, "uSeRNaMe"}, "username1", "John", "Smith"}, |
| 316 {{"uSeRNaMe", NULL, "USERNAME"}, "username1", "John", "Smith"}}; | 325 {{"uSeRNaMe", nullptr, "USERNAME"}, "username1", "John", "Smith"}}; |
| 317 | 326 |
| 318 for (size_t i = 0; i < arraysize(cases); ++i) { | 327 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 319 for (size_t nonempty_username_fields = 0; nonempty_username_fields < 2; | 328 for (size_t nonempty_username_fields = 0; nonempty_username_fields < 2; |
| 320 ++nonempty_username_fields) { | 329 ++nonempty_username_fields) { |
| 321 SCOPED_TRACE(testing::Message() | 330 SCOPED_TRACE(testing::Message() |
| 322 << "Iteration " << i << " " | 331 << "Iteration " << i << " " |
| 323 << (nonempty_username_fields ? "nonempty" : "empty")); | 332 << (nonempty_username_fields ? "nonempty" : "empty")); |
| 324 | 333 |
| 325 // Repeat each test once with empty, and once with non-empty usernames. | 334 // Repeat each test once with empty, and once with non-empty usernames. |
| 326 // In the former case, no empty other_possible_usernames should be saved. | 335 // In the former case, no empty other_possible_usernames should be saved. |
| 327 const char* names[3]; | 336 const char* names[3]; |
| 328 if (nonempty_username_fields) { | 337 if (nonempty_username_fields) { |
| 329 names[0] = "John"; | 338 names[0] = "John"; |
| 330 names[1] = "William"; | 339 names[1] = "William"; |
| 331 names[2] = "Smith"; | 340 names[2] = "Smith"; |
| 332 } else { | 341 } else { |
| 333 names[0] = names[1] = names[2] = ""; | 342 names[0] = names[1] = names[2] = ""; |
| 334 } | 343 } |
| 335 | 344 |
| 336 PasswordFormBuilder builder(kTestFormActionURL); | 345 PasswordFormBuilder builder(kTestFormActionURL); |
| 337 builder.AddTextField("username1", names[0], cases[i].autocomplete[0]); | 346 builder.AddTextField("username1", names[0], cases[i].autocomplete[0]); |
| 338 builder.AddTextField("username2", names[1], cases[i].autocomplete[1]); | 347 builder.AddTextField("username2", names[1], cases[i].autocomplete[1]); |
| 339 builder.AddPasswordField("password", "secret", NULL); | 348 builder.AddPasswordField("password", "secret", nullptr); |
| 340 builder.AddTextField("username3", names[2], cases[i].autocomplete[2]); | 349 builder.AddTextField("username3", names[2], cases[i].autocomplete[2]); |
| 341 builder.AddPasswordField("password2", "othersecret", NULL); | 350 builder.AddPasswordField("password2", "othersecret", nullptr); |
| 342 builder.AddSubmitButton("submit"); | 351 builder.AddSubmitButton("submit"); |
| 343 std::string html = builder.ProduceHTML(); | 352 std::string html = builder.ProduceHTML(); |
| 344 | 353 |
| 345 std::unique_ptr<PasswordForm> password_form; | 354 std::unique_ptr<PasswordForm> password_form; |
| 346 ASSERT_NO_FATAL_FAILURE( | 355 ASSERT_NO_FATAL_FAILURE( |
| 347 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 356 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 348 ASSERT_TRUE(password_form); | 357 ASSERT_TRUE(password_form); |
| 349 | 358 |
| 350 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), | 359 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
| 351 password_form->username_element); | 360 password_form->username_element); |
| 352 | 361 |
| 353 if (nonempty_username_fields) { | 362 if (nonempty_username_fields) { |
| 354 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), | 363 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), |
| 355 password_form->username_value); | 364 password_form->username_value); |
| 356 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_other_possible_usernames), | 365 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_other_possible_usernames), |
| 357 base::JoinString(password_form->other_possible_usernames, | 366 base::JoinString(password_form->other_possible_usernames, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 388 // Two different values should be treated as a password change form, one | 397 // Two different values should be treated as a password change form, one |
| 389 // that also asks for the current password, but only once for the new. | 398 // that also asks for the current password, but only once for the new. |
| 390 {{"alpha", ""}, "password1", "alpha", "password2", ""}, | 399 {{"alpha", ""}, "password1", "alpha", "password2", ""}, |
| 391 {{"", "beta"}, "password1", "", "password2", "beta"}, | 400 {{"", "beta"}, "password1", "", "password2", "beta"}, |
| 392 {{"alpha", "beta"}, "password1", "alpha", "password2", "beta"}}; | 401 {{"alpha", "beta"}, "password1", "alpha", "password2", "beta"}}; |
| 393 | 402 |
| 394 for (size_t i = 0; i < arraysize(cases); ++i) { | 403 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 395 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 404 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 396 | 405 |
| 397 PasswordFormBuilder builder(kTestFormActionURL); | 406 PasswordFormBuilder builder(kTestFormActionURL); |
| 398 builder.AddTextField("username1", "William", NULL); | 407 builder.AddTextField("username1", "William", nullptr); |
| 399 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 408 builder.AddPasswordField("password1", cases[i].password_values[0], nullptr); |
| 400 builder.AddTextField("username2", "Smith", NULL); | 409 builder.AddTextField("username2", "Smith", nullptr); |
| 401 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 410 builder.AddPasswordField("password2", cases[i].password_values[1], nullptr); |
| 402 builder.AddSubmitButton("submit"); | 411 builder.AddSubmitButton("submit"); |
| 403 std::string html = builder.ProduceHTML(); | 412 std::string html = builder.ProduceHTML(); |
| 404 | 413 |
| 405 std::unique_ptr<PasswordForm> password_form; | 414 std::unique_ptr<PasswordForm> password_form; |
| 406 ASSERT_NO_FATAL_FAILURE( | 415 ASSERT_NO_FATAL_FAILURE( |
| 407 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 416 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 408 ASSERT_TRUE(password_form); | 417 ASSERT_TRUE(password_form); |
| 409 | 418 |
| 410 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), | 419 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
| 411 password_form->password_element); | 420 password_form->password_element); |
| 412 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), | 421 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), |
| 413 password_form->password_value); | 422 password_form->password_value); |
| 414 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), | 423 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), |
| 415 password_form->new_password_element); | 424 password_form->new_password_element); |
| 416 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), | 425 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), |
| 417 password_form->new_password_value); | 426 password_form->new_password_value); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 // (current + new + new) once they are filled out, so we should classify | 458 // (current + new + new) once they are filled out, so we should classify |
| 450 // them the same for now to keep our abstract interpretation less flaky. | 459 // them the same for now to keep our abstract interpretation less flaky. |
| 451 {{"", "", ""}, "password1", "", "password2", ""}}; | 460 {{"", "", ""}, "password1", "", "password2", ""}}; |
| 452 // Note: In all other cases, we give up and consider the form invalid. | 461 // Note: In all other cases, we give up and consider the form invalid. |
| 453 // This is tested in InvalidFormDueToConfusingPasswordFields. | 462 // This is tested in InvalidFormDueToConfusingPasswordFields. |
| 454 | 463 |
| 455 for (size_t i = 0; i < arraysize(cases); ++i) { | 464 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 456 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 465 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 457 | 466 |
| 458 PasswordFormBuilder builder(kTestFormActionURL); | 467 PasswordFormBuilder builder(kTestFormActionURL); |
| 459 builder.AddTextField("username1", "William", NULL); | 468 builder.AddTextField("username1", "William", nullptr); |
| 460 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 469 builder.AddPasswordField("password1", cases[i].password_values[0], nullptr); |
| 461 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 470 builder.AddPasswordField("password2", cases[i].password_values[1], nullptr); |
| 462 builder.AddTextField("username2", "Smith", NULL); | 471 builder.AddTextField("username2", "Smith", nullptr); |
| 463 builder.AddPasswordField("password3", cases[i].password_values[2], NULL); | 472 builder.AddPasswordField("password3", cases[i].password_values[2], nullptr); |
| 464 builder.AddSubmitButton("submit"); | 473 builder.AddSubmitButton("submit"); |
| 465 std::string html = builder.ProduceHTML(); | 474 std::string html = builder.ProduceHTML(); |
| 466 | 475 |
| 467 std::unique_ptr<PasswordForm> password_form; | 476 std::unique_ptr<PasswordForm> password_form; |
| 468 ASSERT_NO_FATAL_FAILURE( | 477 ASSERT_NO_FATAL_FAILURE( |
| 469 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 478 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 470 ASSERT_TRUE(password_form); | 479 ASSERT_TRUE(password_form); |
| 471 | 480 |
| 472 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), | 481 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), |
| 473 password_form->password_element); | 482 password_form->password_element); |
| 474 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), | 483 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), |
| 475 password_form->password_value); | 484 password_form->password_value); |
| 476 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), | 485 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), |
| 477 password_form->new_password_element); | 486 password_form->new_password_element); |
| 478 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), | 487 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), |
| 479 password_form->new_password_value); | 488 password_form->new_password_value); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 502 } cases[] = { | 511 } cases[] = { |
| 503 // When there are elements marked with autocomplete='current-password', | 512 // When there are elements marked with autocomplete='current-password', |
| 504 // but no elements with 'new-password', we should treat the first of the | 513 // but no elements with 'new-password', we should treat the first of the |
| 505 // former kind as the current password, and ignore all other password | 514 // former kind as the current password, and ignore all other password |
| 506 // fields, assuming they are not intentionally not marked. They might be | 515 // fields, assuming they are not intentionally not marked. They might be |
| 507 // for other purposes, such as PINs, OTPs, and the like. Actual values in | 516 // for other purposes, such as PINs, OTPs, and the like. Actual values in |
| 508 // the password fields should be ignored in all cases below. | 517 // the password fields should be ignored in all cases below. |
| 509 // Username is the element just before the first 'current-password' (even | 518 // Username is the element just before the first 'current-password' (even |
| 510 // if 'new-password' comes earlier). If no 'current-password', then the | 519 // if 'new-password' comes earlier). If no 'current-password', then the |
| 511 // element just before the first 'new-passwords'. | 520 // element just before the first 'new-passwords'. |
| 512 {{"current-password", NULL, NULL}, | 521 {{"current-password", nullptr, nullptr}, |
| 513 "password1", "alpha", "", "", false, "username1", "William"}, | 522 "password1", |
| 514 {{NULL, "current-password", NULL}, | 523 "alpha", |
| 515 "password2", "beta", "", "", false, "username2", "Smith"}, | 524 "", |
| 516 {{NULL, NULL, "current-password"}, | 525 "", |
| 517 "password3", "gamma", "", "", false, "username2", "Smith"}, | 526 false, |
| 518 {{NULL, "current-password", "current-password"}, | 527 "username1", |
| 519 "password2", "beta", "", "", false, "username2", "Smith"}, | 528 "William"}, |
| 520 {{"current-password", NULL, "current-password"}, | 529 {{nullptr, "current-password", nullptr}, |
| 521 "password1", "alpha", "", "", false, "username1", "William"}, | 530 "password2", |
| 522 {{"current-password", "current-password", NULL}, | 531 "beta", |
| 523 "password1", "alpha", "", "", false, "username1", "William"}, | 532 "", |
| 533 "", | |
| 534 false, | |
| 535 "username2", | |
| 536 "Smith"}, | |
| 537 {{nullptr, nullptr, "current-password"}, | |
| 538 "password3", | |
| 539 "gamma", | |
| 540 "", | |
| 541 "", | |
| 542 false, | |
| 543 "username2", | |
| 544 "Smith"}, | |
| 545 {{nullptr, "current-password", "current-password"}, | |
| 546 "password2", | |
| 547 "beta", | |
| 548 "", | |
| 549 "", | |
| 550 false, | |
| 551 "username2", | |
| 552 "Smith"}, | |
| 553 {{"current-password", nullptr, "current-password"}, | |
| 554 "password1", | |
| 555 "alpha", | |
| 556 "", | |
| 557 "", | |
| 558 false, | |
| 559 "username1", | |
| 560 "William"}, | |
| 561 {{"current-password", "current-password", nullptr}, | |
| 562 "password1", | |
| 563 "alpha", | |
| 564 "", | |
| 565 "", | |
| 566 false, | |
| 567 "username1", | |
| 568 "William"}, | |
| 524 {{"current-password", "current-password", "current-password"}, | 569 {{"current-password", "current-password", "current-password"}, |
| 525 "password1", "alpha", "", "", false, "username1", "William"}, | 570 "password1", |
| 571 "alpha", | |
| 572 "", | |
| 573 "", | |
| 574 false, | |
| 575 "username1", | |
| 576 "William"}, | |
| 526 // The same goes vice versa for autocomplete='new-password'. | 577 // The same goes vice versa for autocomplete='new-password'. |
| 527 {{"new-password", NULL, NULL}, | 578 {{"new-password", nullptr, nullptr}, |
| 528 "", "", "password1", "alpha", true, "username1", "William"}, | 579 "", |
| 529 {{NULL, "new-password", NULL}, | 580 "", |
| 530 "", "", "password2", "beta", true, "username2", "Smith"}, | 581 "password1", |
| 531 {{NULL, NULL, "new-password"}, | 582 "alpha", |
| 532 "", "", "password3", "gamma", true, "username2", "Smith"}, | 583 true, |
| 533 {{NULL, "new-password", "new-password"}, | 584 "username1", |
| 534 "", "", "password2", "beta", true, "username2", "Smith"}, | 585 "William"}, |
| 535 {{"new-password", NULL, "new-password"}, | 586 {{nullptr, "new-password", nullptr}, |
| 536 "", "", "password1", "alpha", true, "username1", "William"}, | 587 "", |
| 537 {{"new-password", "new-password", NULL}, | 588 "", |
| 538 "", "", "password1", "alpha", true, "username1", "William"}, | 589 "password2", |
| 590 "beta", | |
| 591 true, | |
| 592 "username2", | |
| 593 "Smith"}, | |
| 594 {{nullptr, nullptr, "new-password"}, | |
| 595 "", | |
| 596 "", | |
| 597 "password3", | |
| 598 "gamma", | |
| 599 true, | |
| 600 "username2", | |
| 601 "Smith"}, | |
| 602 {{nullptr, "new-password", "new-password"}, | |
| 603 "", | |
| 604 "", | |
| 605 "password2", | |
| 606 "beta", | |
| 607 true, | |
| 608 "username2", | |
| 609 "Smith"}, | |
| 610 {{"new-password", nullptr, "new-password"}, | |
| 611 "", | |
| 612 "", | |
| 613 "password1", | |
| 614 "alpha", | |
| 615 true, | |
| 616 "username1", | |
| 617 "William"}, | |
| 618 {{"new-password", "new-password", nullptr}, | |
| 619 "", | |
| 620 "", | |
| 621 "password1", | |
| 622 "alpha", | |
| 623 true, | |
| 624 "username1", | |
| 625 "William"}, | |
| 539 {{"new-password", "new-password", "new-password"}, | 626 {{"new-password", "new-password", "new-password"}, |
| 540 "", "", "password1", "alpha", true, "username1", "William"}, | 627 "", |
| 628 "", | |
| 629 "password1", | |
| 630 "alpha", | |
| 631 true, | |
| 632 "username1", | |
| 633 "William"}, | |
| 541 // When there is one element marked with autocomplete='current-password', | 634 // When there is one element marked with autocomplete='current-password', |
| 542 // and one with 'new-password', just comply. Ignore the unmarked password | 635 // and one with 'new-password', just comply. Ignore the unmarked password |
| 543 // field(s) for the same reason as above. | 636 // field(s) for the same reason as above. |
| 544 {{"current-password", "new-password", NULL}, | 637 {{"current-password", "new-password", nullptr}, |
| 545 "password1", "alpha", "password2", "beta", true, "username1", "William"}, | 638 "password1", |
| 546 {{"current-password", NULL, "new-password"}, | 639 "alpha", |
| 547 "password1", "alpha", "password3", "gamma", true, "username1","William"}, | 640 "password2", |
| 548 {{NULL, "current-password", "new-password"}, | 641 "beta", |
| 549 "password2", "beta", "password3", "gamma", true, "username2", "Smith"}, | 642 true, |
| 550 {{"new-password", "current-password", NULL}, | 643 "username1", |
| 551 "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, | 644 "William"}, |
| 552 {{"new-password", NULL, "current-password"}, | 645 {{"current-password", nullptr, "new-password"}, |
| 553 "password3", "gamma", "password1", "alpha", true, "username2","Smith"}, | 646 "password1", |
| 554 {{NULL, "new-password", "current-password"}, | 647 "alpha", |
| 555 "password3", "gamma", "password2", "beta", true, "username2", "Smith"}, | 648 "password3", |
| 649 "gamma", | |
| 650 true, | |
| 651 "username1", | |
| 652 "William"}, | |
| 653 {{nullptr, "current-password", "new-password"}, | |
| 654 "password2", | |
| 655 "beta", | |
| 656 "password3", | |
| 657 "gamma", | |
| 658 true, | |
| 659 "username2", | |
| 660 "Smith"}, | |
| 661 {{"new-password", "current-password", nullptr}, | |
| 662 "password2", | |
| 663 "beta", | |
| 664 "password1", | |
| 665 "alpha", | |
| 666 true, | |
| 667 "username2", | |
| 668 "Smith"}, | |
| 669 {{"new-password", nullptr, "current-password"}, | |
| 670 "password3", | |
| 671 "gamma", | |
| 672 "password1", | |
| 673 "alpha", | |
| 674 true, | |
| 675 "username2", | |
| 676 "Smith"}, | |
| 677 {{nullptr, "new-password", "current-password"}, | |
| 678 "password3", | |
| 679 "gamma", | |
| 680 "password2", | |
| 681 "beta", | |
| 682 true, | |
| 683 "username2", | |
| 684 "Smith"}, | |
| 556 // In case of duplicated elements of either kind, go with the first one of | 685 // In case of duplicated elements of either kind, go with the first one of |
| 557 // its kind. | 686 // its kind. |
| 558 {{"current-password", "current-password", "new-password"}, | 687 {{"current-password", "current-password", "new-password"}, |
| 559 "password1", "alpha", "password3", "gamma", true, "username1","William"}, | 688 "password1", |
| 689 "alpha", | |
| 690 "password3", | |
| 691 "gamma", | |
| 692 true, | |
| 693 "username1", | |
| 694 "William"}, | |
| 560 {{"current-password", "new-password", "current-password"}, | 695 {{"current-password", "new-password", "current-password"}, |
| 561 "password1", "alpha", "password2", "beta", true, "username1", "William"}, | 696 "password1", |
| 697 "alpha", | |
| 698 "password2", | |
| 699 "beta", | |
| 700 true, | |
| 701 "username1", | |
| 702 "William"}, | |
| 562 {{"new-password", "current-password", "current-password"}, | 703 {{"new-password", "current-password", "current-password"}, |
| 563 "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, | 704 "password2", |
| 705 "beta", | |
| 706 "password1", | |
| 707 "alpha", | |
| 708 true, | |
| 709 "username2", | |
| 710 "Smith"}, | |
| 564 {{"current-password", "new-password", "new-password"}, | 711 {{"current-password", "new-password", "new-password"}, |
| 565 "password1", "alpha", "password2", "beta", true, "username1", "William"}, | 712 "password1", |
| 713 "alpha", | |
| 714 "password2", | |
| 715 "beta", | |
| 716 true, | |
| 717 "username1", | |
| 718 "William"}, | |
| 566 {{"new-password", "current-password", "new-password"}, | 719 {{"new-password", "current-password", "new-password"}, |
| 567 "password2", "beta", "password1", "alpha", true, "username2", "Smith"}, | 720 "password2", |
| 721 "beta", | |
| 722 "password1", | |
| 723 "alpha", | |
| 724 true, | |
| 725 "username2", | |
| 726 "Smith"}, | |
| 568 {{"new-password", "new-password", "current-password"}, | 727 {{"new-password", "new-password", "current-password"}, |
| 569 "password3", "gamma", "password1", "alpha", true, "username2", "Smith"}, | 728 "password3", |
| 729 "gamma", | |
| 730 "password1", | |
| 731 "alpha", | |
| 732 true, | |
| 733 "username2", | |
| 734 "Smith"}, | |
| 570 // When there is an empty autocomplete attribute (i.e. autocomplete=""), | 735 // When there is an empty autocomplete attribute (i.e. autocomplete=""), |
| 571 // it should have the same effect as having no attribute whatsoever. | 736 // it should have the same effect as having no attribute whatsoever. |
| 572 {{"current-password", "", ""}, | 737 {{"current-password", "", ""}, |
| 573 "password1", "alpha", "", "", false, "username1", "William"}, | 738 "password1", |
| 739 "alpha", | |
| 740 "", | |
| 741 "", | |
| 742 false, | |
| 743 "username1", | |
| 744 "William"}, | |
| 574 {{"", "", "new-password"}, | 745 {{"", "", "new-password"}, |
| 575 "", "", "password3", "gamma", true, "username2", "Smith"}, | 746 "", |
| 747 "", | |
| 748 "password3", | |
| 749 "gamma", | |
| 750 true, | |
| 751 "username2", | |
| 752 "Smith"}, | |
| 576 {{"", "new-password", ""}, | 753 {{"", "new-password", ""}, |
| 577 "", "", "password2", "beta", true, "username2", "Smith"}, | 754 "", |
| 755 "", | |
| 756 "password2", | |
| 757 "beta", | |
| 758 true, | |
| 759 "username2", | |
| 760 "Smith"}, | |
| 578 {{"", "current-password", "current-password"}, | 761 {{"", "current-password", "current-password"}, |
| 579 "password2", "beta", "", "", false, "username2", "Smith"}, | 762 "password2", |
| 763 "beta", | |
| 764 "", | |
| 765 "", | |
| 766 false, | |
| 767 "username2", | |
| 768 "Smith"}, | |
| 580 {{"new-password", "", "new-password"}, | 769 {{"new-password", "", "new-password"}, |
| 581 "", "", "password1", "alpha", true, "username1", "William"}, | 770 "", |
| 771 "", | |
| 772 "password1", | |
| 773 "alpha", | |
| 774 true, | |
| 775 "username1", | |
| 776 "William"}, | |
| 582 {{"new-password", "", "current-password"}, | 777 {{"new-password", "", "current-password"}, |
| 583 "password3", "gamma", "password1", "alpha", true, "username2","Smith"}, | 778 "password3", |
| 779 "gamma", | |
| 780 "password1", | |
| 781 "alpha", | |
| 782 true, | |
| 783 "username2", | |
| 784 "Smith"}, | |
| 584 // It should not matter if attribute values are upper or mixed case. | 785 // It should not matter if attribute values are upper or mixed case. |
| 585 {{NULL, "current-password", NULL}, | 786 {{nullptr, "current-password", nullptr}, |
| 586 "password2", "beta", "", "", false, "username2", "Smith"}, | 787 "password2", |
| 587 {{NULL, "CURRENT-PASSWORD", NULL}, | 788 "beta", |
| 588 "password2", "beta", "", "", false, "username2", "Smith"}, | 789 "", |
| 589 {{NULL, "new-password", NULL}, | 790 "", |
| 590 "", "", "password2", "beta", true, "username2", "Smith"}, | 791 false, |
| 591 {{NULL, "nEw-PaSsWoRd", NULL}, | 792 "username2", |
| 592 "", "", "password2", "beta", true, "username2", "Smith"}}; | 793 "Smith"}, |
| 794 {{nullptr, "CURRENT-PASSWORD", nullptr}, | |
| 795 "password2", | |
| 796 "beta", | |
| 797 "", | |
| 798 "", | |
| 799 false, | |
| 800 "username2", | |
| 801 "Smith"}, | |
| 802 {{nullptr, "new-password", nullptr}, | |
| 803 "", | |
| 804 "", | |
| 805 "password2", | |
| 806 "beta", | |
| 807 true, | |
| 808 "username2", | |
| 809 "Smith"}, | |
| 810 {{nullptr, "nEw-PaSsWoRd", nullptr}, | |
| 811 "", | |
| 812 "", | |
| 813 "password2", | |
| 814 "beta", | |
| 815 true, | |
| 816 "username2", | |
| 817 "Smith"}}; | |
| 593 | 818 |
| 594 for (size_t i = 0; i < arraysize(cases); ++i) { | 819 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 595 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 820 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 596 | 821 |
| 597 PasswordFormBuilder builder(kTestFormActionURL); | 822 PasswordFormBuilder builder(kTestFormActionURL); |
| 598 builder.AddPasswordField("pin1", "123456", NULL); | 823 builder.AddPasswordField("pin1", "123456", nullptr); |
| 599 builder.AddPasswordField("pin2", "789101", NULL); | 824 builder.AddPasswordField("pin2", "789101", nullptr); |
| 600 builder.AddTextField("username1", "William", NULL); | 825 builder.AddTextField("username1", "William", nullptr); |
| 601 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); | 826 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); |
| 602 builder.AddTextField("username2", "Smith", NULL); | 827 builder.AddTextField("username2", "Smith", nullptr); |
| 603 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); | 828 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); |
| 604 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); | 829 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); |
| 605 builder.AddSubmitButton("submit"); | 830 builder.AddSubmitButton("submit"); |
| 606 std::string html = builder.ProduceHTML(); | 831 std::string html = builder.ProduceHTML(); |
| 607 | 832 |
| 608 std::unique_ptr<PasswordForm> password_form; | 833 std::unique_ptr<PasswordForm> password_form; |
| 609 ASSERT_NO_FATAL_FAILURE( | 834 ASSERT_NO_FATAL_FAILURE( |
| 610 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 835 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 611 ASSERT_TRUE(password_form); | 836 ASSERT_TRUE(password_form); |
| 612 | 837 |
| 613 // In the absence of username autocomplete attributes, the username should | 838 // In the absence of username autocomplete attributes, the username should |
| 614 // be the text input field just before 'current-password' or before | 839 // be the text input field just before 'current-password' or before |
| 615 // 'new-password', if there is no 'current-password'. | 840 // 'new-password', if there is no 'current-password'. |
| 616 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), | 841 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), |
| 617 password_form->username_element); | 842 password_form->username_element); |
| 618 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), | 843 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), |
| 619 password_form->username_value); | 844 password_form->username_value); |
| 620 if (strcmp(cases[i].expected_username_value, "William") == 0) { | 845 if (strcmp(cases[i].expected_username_value, "William") == 0) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 634 password_form->new_password_value); | 859 password_form->new_password_value); |
| 635 EXPECT_EQ(cases[i].expected_new_password_marked_by_site, | 860 EXPECT_EQ(cases[i].expected_new_password_marked_by_site, |
| 636 password_form->new_password_marked_by_site); | 861 password_form->new_password_marked_by_site); |
| 637 } | 862 } |
| 638 } | 863 } |
| 639 | 864 |
| 640 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedTextFields) { | 865 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedTextFields) { |
| 641 PasswordFormBuilder builder(kTestFormActionURL); | 866 PasswordFormBuilder builder(kTestFormActionURL); |
| 642 | 867 |
| 643 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 868 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 644 builder.AddTextField("username", "johnsmith", NULL); | 869 builder.AddTextField("username", "johnsmith", nullptr); |
| 645 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); | 870 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); |
| 646 builder.AddPasswordField("password", "secret", NULL); | 871 builder.AddPasswordField("password", "secret", nullptr); |
| 647 builder.AddPasswordField("password", "secret", NULL); | 872 builder.AddPasswordField("password", "secret", nullptr); |
| 648 builder.AddSubmitButton("submit"); | 873 builder.AddSubmitButton("submit"); |
| 649 std::string html = builder.ProduceHTML(); | 874 std::string html = builder.ProduceHTML(); |
| 650 | 875 |
| 651 std::unique_ptr<PasswordForm> password_form; | 876 std::unique_ptr<PasswordForm> password_form; |
| 652 ASSERT_NO_FATAL_FAILURE( | 877 ASSERT_NO_FATAL_FAILURE( |
| 653 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 878 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 654 ASSERT_TRUE(password_form); | 879 ASSERT_TRUE(password_form); |
| 655 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 880 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 656 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 881 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 657 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); | 882 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); |
| 658 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); | 883 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); |
| 659 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); | 884 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); |
| 660 } | 885 } |
| 661 | 886 |
| 662 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { | 887 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { |
| 663 PasswordFormBuilder builder(kTestFormActionURL); | 888 PasswordFormBuilder builder(kTestFormActionURL); |
| 664 | 889 |
| 665 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 890 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 666 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); | 891 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); |
| 667 builder.AddTextField("username", "johnsmith", NULL); | 892 builder.AddTextField("username", "johnsmith", nullptr); |
| 668 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); | 893 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); |
| 669 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); | 894 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); |
| 670 builder.AddPasswordField("password", "secret", NULL); | 895 builder.AddPasswordField("password", "secret", nullptr); |
| 671 builder.AddPasswordField("password", "secret", NULL); | 896 builder.AddPasswordField("password", "secret", nullptr); |
| 672 builder.AddSubmitButton("submit"); | 897 builder.AddSubmitButton("submit"); |
| 673 std::string html = builder.ProduceHTML(); | 898 std::string html = builder.ProduceHTML(); |
| 674 | 899 |
| 675 std::unique_ptr<PasswordForm> password_form; | 900 std::unique_ptr<PasswordForm> password_form; |
| 676 ASSERT_NO_FATAL_FAILURE( | 901 ASSERT_NO_FATAL_FAILURE( |
| 677 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 902 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 678 ASSERT_TRUE(password_form); | 903 ASSERT_TRUE(password_form); |
| 679 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 904 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 680 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 905 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 681 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); | 906 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); |
| 682 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); | 907 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); |
| 683 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); | 908 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); |
| 684 } | 909 } |
| 685 | 910 |
| 686 TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { | 911 TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonDisplayedLoginPair) { |
| 687 PasswordFormBuilder builder(kTestFormActionURL); | 912 PasswordFormBuilder builder(kTestFormActionURL); |
| 688 | 913 |
| 689 builder.AddNonDisplayedTextField("username", "William"); | 914 builder.AddNonDisplayedTextField("username", "William"); |
| 690 builder.AddNonDisplayedPasswordField("password", "secret"); | 915 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 691 builder.AddSubmitButton("submit"); | 916 builder.AddSubmitButton("submit"); |
| 692 std::string html = builder.ProduceHTML(); | 917 std::string html = builder.ProduceHTML(); |
| 693 | 918 |
| 694 std::unique_ptr<PasswordForm> password_form; | 919 std::unique_ptr<PasswordForm> password_form; |
| 695 ASSERT_NO_FATAL_FAILURE( | 920 ASSERT_NO_FATAL_FAILURE( |
| 696 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 921 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 697 ASSERT_TRUE(password_form); | 922 ASSERT_TRUE(password_form); |
| 698 EXPECT_EQ(base::UTF8ToUTF16("username"), | 923 EXPECT_EQ(base::UTF8ToUTF16("username"), |
| 699 password_form->username_element); | 924 password_form->username_element); |
| 700 EXPECT_EQ(base::UTF8ToUTF16("William"), | 925 EXPECT_EQ(base::UTF8ToUTF16("William"), |
| 701 password_form->username_value); | 926 password_form->username_value); |
| 702 EXPECT_EQ(base::UTF8ToUTF16("password"), | 927 EXPECT_EQ(base::UTF8ToUTF16("password"), |
| 703 password_form->password_element); | 928 password_form->password_element); |
| 704 EXPECT_EQ(base::UTF8ToUTF16("secret"), | 929 EXPECT_EQ(base::UTF8ToUTF16("secret"), |
| 705 password_form->password_value); | 930 password_form->password_value); |
| 706 } | 931 } |
| 707 | 932 |
| 708 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 933 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 709 VisiblePasswordAndInvisibleUsername) { | 934 VisiblePasswordAndInvisibleUsername) { |
| 710 PasswordFormBuilder builder(kTestFormActionURL); | 935 PasswordFormBuilder builder(kTestFormActionURL); |
| 711 | 936 |
| 712 builder.AddNonDisplayedTextField("username", "William"); | 937 builder.AddNonDisplayedTextField("username", "William"); |
| 713 builder.AddPasswordField("password", "secret", NULL); | 938 builder.AddPasswordField("password", "secret", nullptr); |
| 714 builder.AddSubmitButton("submit"); | 939 builder.AddSubmitButton("submit"); |
| 715 std::string html = builder.ProduceHTML(); | 940 std::string html = builder.ProduceHTML(); |
| 716 | 941 |
| 717 std::unique_ptr<PasswordForm> password_form; | 942 std::unique_ptr<PasswordForm> password_form; |
| 718 ASSERT_NO_FATAL_FAILURE( | 943 ASSERT_NO_FATAL_FAILURE( |
| 719 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 944 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 720 ASSERT_TRUE(password_form); | 945 ASSERT_TRUE(password_form); |
| 721 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 946 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 722 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 947 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 723 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 948 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 724 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 949 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 725 } | 950 } |
| 726 | 951 |
| 727 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 952 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 728 InvisiblePassword_LatestUsernameIsVisible) { | 953 InvisiblePassword_LatestUsernameIsVisible) { |
| 729 PasswordFormBuilder builder(kTestFormActionURL); | 954 PasswordFormBuilder builder(kTestFormActionURL); |
| 730 | 955 |
| 731 builder.AddNonDisplayedTextField("search", "query"); | 956 builder.AddNonDisplayedTextField("search", "query"); |
| 732 builder.AddTextField("username", "William", NULL); | 957 builder.AddTextField("username", "William", nullptr); |
| 733 builder.AddNonDisplayedPasswordField("password", "secret"); | 958 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 734 builder.AddSubmitButton("submit"); | 959 builder.AddSubmitButton("submit"); |
| 735 std::string html = builder.ProduceHTML(); | 960 std::string html = builder.ProduceHTML(); |
| 736 | 961 |
| 737 std::unique_ptr<PasswordForm> password_form; | 962 std::unique_ptr<PasswordForm> password_form; |
| 738 ASSERT_NO_FATAL_FAILURE( | 963 ASSERT_NO_FATAL_FAILURE( |
| 739 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 964 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 740 ASSERT_TRUE(password_form); | 965 ASSERT_TRUE(password_form); |
| 741 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 966 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 742 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 967 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 743 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 968 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 744 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 969 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 745 } | 970 } |
| 746 | 971 |
| 747 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 972 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 748 InvisiblePassword_LatestUsernameIsInvisible) { | 973 InvisiblePassword_LatestUsernameIsInvisible) { |
| 749 PasswordFormBuilder builder(kTestFormActionURL); | 974 PasswordFormBuilder builder(kTestFormActionURL); |
| 750 | 975 |
| 751 builder.AddTextField("search", "query", NULL); | 976 builder.AddTextField("search", "query", nullptr); |
| 752 builder.AddNonDisplayedTextField("username", "William"); | 977 builder.AddNonDisplayedTextField("username", "William"); |
| 753 builder.AddNonDisplayedPasswordField("password", "secret"); | 978 builder.AddNonDisplayedPasswordField("password", "secret"); |
| 754 builder.AddSubmitButton("submit"); | 979 builder.AddSubmitButton("submit"); |
| 755 std::string html = builder.ProduceHTML(); | 980 std::string html = builder.ProduceHTML(); |
| 756 | 981 |
| 757 std::unique_ptr<PasswordForm> password_form; | 982 std::unique_ptr<PasswordForm> password_form; |
| 758 ASSERT_NO_FATAL_FAILURE( | 983 ASSERT_NO_FATAL_FAILURE( |
| 759 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 984 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 760 ASSERT_TRUE(password_form); | 985 ASSERT_TRUE(password_form); |
| 761 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 986 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 762 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); | 987 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 763 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 988 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 764 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 989 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 765 } | 990 } |
| 766 | 991 |
| 767 TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { | 992 TEST_F(MAYBE_PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) { |
| 768 PasswordFormBuilder builder("invalid_target"); | 993 PasswordFormBuilder builder("invalid_target"); |
| 769 builder.AddTextField("username", "JohnSmith", NULL); | 994 builder.AddTextField("username", "JohnSmith", nullptr); |
| 770 builder.AddSubmitButton("submit"); | 995 builder.AddSubmitButton("submit"); |
| 771 builder.AddPasswordField("password", "secret", NULL); | 996 builder.AddPasswordField("password", "secret", nullptr); |
| 772 std::string html = builder.ProduceHTML(); | 997 std::string html = builder.ProduceHTML(); |
| 773 | 998 |
| 774 std::unique_ptr<PasswordForm> password_form; | 999 std::unique_ptr<PasswordForm> password_form; |
| 775 ASSERT_NO_FATAL_FAILURE( | 1000 ASSERT_NO_FATAL_FAILURE( |
| 776 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 1001 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 777 EXPECT_FALSE(password_form); | 1002 EXPECT_FALSE(password_form); |
| 778 } | 1003 } |
| 779 | 1004 |
| 780 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1005 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 781 InvalidFormDueToNoPasswordFields) { | 1006 InvalidFormDueToNoPasswordFields) { |
| 782 PasswordFormBuilder builder(kTestFormActionURL); | 1007 PasswordFormBuilder builder(kTestFormActionURL); |
| 783 builder.AddTextField("username1", "John", NULL); | 1008 builder.AddTextField("username1", "John", nullptr); |
| 784 builder.AddTextField("username2", "Smith", NULL); | 1009 builder.AddTextField("username2", "Smith", nullptr); |
| 785 builder.AddSubmitButton("submit"); | 1010 builder.AddSubmitButton("submit"); |
| 786 std::string html = builder.ProduceHTML(); | 1011 std::string html = builder.ProduceHTML(); |
| 787 | 1012 |
| 788 std::unique_ptr<PasswordForm> password_form; | 1013 std::unique_ptr<PasswordForm> password_form; |
| 789 ASSERT_NO_FATAL_FAILURE( | 1014 ASSERT_NO_FATAL_FAILURE( |
| 790 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 1015 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 791 EXPECT_FALSE(password_form); | 1016 EXPECT_FALSE(password_form); |
| 792 } | 1017 } |
| 793 | 1018 |
| 794 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1019 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 795 InvalidFormsDueToConfusingPasswordFields) { | 1020 InvalidFormsDueToConfusingPasswordFields) { |
| 796 // Each test case consists of a set of parameters to be plugged into the | 1021 // Each test case consists of a set of parameters to be plugged into the |
| 797 // PasswordFormBuilder below. | 1022 // PasswordFormBuilder below. |
| 798 const char* cases[][3] = { | 1023 const char* cases[][3] = { |
| 799 // No autocomplete attributes to guide us, and we see: | 1024 // No autocomplete attributes to guide us, and we see: |
| 800 // * three password values that are all different, | 1025 // * three password values that are all different, |
| 801 // * three password values that are all the same; | 1026 // * three password values that are all the same; |
| 802 // * three password values with the first and last matching. | 1027 // * three password values with the first and last matching. |
| 803 // In any case, we should just give up on this form. | 1028 // In any case, we should just give up on this form. |
| 804 {"alpha", "beta", "gamma"}, | 1029 {"alpha", "beta", "gamma"}, |
| 805 {"alpha", "alpha", "alpha"}, | 1030 {"alpha", "alpha", "alpha"}, |
| 806 {"alpha", "beta", "alpha"}}; | 1031 {"alpha", "beta", "alpha"}}; |
| 807 | 1032 |
| 808 for (size_t i = 0; i < arraysize(cases); ++i) { | 1033 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 809 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 1034 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
| 810 | 1035 |
| 811 PasswordFormBuilder builder(kTestFormActionURL); | 1036 PasswordFormBuilder builder(kTestFormActionURL); |
| 812 builder.AddTextField("username1", "John", NULL); | 1037 builder.AddTextField("username1", "John", nullptr); |
| 813 builder.AddPasswordField("password1", cases[i][0], NULL); | 1038 builder.AddPasswordField("password1", cases[i][0], nullptr); |
| 814 builder.AddPasswordField("password2", cases[i][1], NULL); | 1039 builder.AddPasswordField("password2", cases[i][1], nullptr); |
| 815 builder.AddPasswordField("password3", cases[i][2], NULL); | 1040 builder.AddPasswordField("password3", cases[i][2], nullptr); |
| 816 builder.AddSubmitButton("submit"); | 1041 builder.AddSubmitButton("submit"); |
| 817 std::string html = builder.ProduceHTML(); | 1042 std::string html = builder.ProduceHTML(); |
| 818 | 1043 |
| 819 std::unique_ptr<PasswordForm> password_form; | 1044 std::unique_ptr<PasswordForm> password_form; |
| 820 ASSERT_NO_FATAL_FAILURE( | 1045 ASSERT_NO_FATAL_FAILURE( |
| 821 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 1046 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 822 EXPECT_FALSE(password_form); | 1047 EXPECT_FALSE(password_form); |
| 823 } | 1048 } |
| 824 } | 1049 } |
| 825 | 1050 |
| 826 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1051 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 827 InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { | 1052 InvalidFormDueToTooManyPasswordFieldsWithoutAutocompleteAttributes) { |
| 828 PasswordFormBuilder builder(kTestFormActionURL); | 1053 PasswordFormBuilder builder(kTestFormActionURL); |
| 829 builder.AddTextField("username1", "John", NULL); | 1054 builder.AddTextField("username1", "John", nullptr); |
| 830 builder.AddPasswordField("password1", "alpha", NULL); | 1055 builder.AddPasswordField("password1", "alpha", nullptr); |
| 831 builder.AddPasswordField("password2", "alpha", NULL); | 1056 builder.AddPasswordField("password2", "alpha", nullptr); |
| 832 builder.AddPasswordField("password3", "alpha", NULL); | 1057 builder.AddPasswordField("password3", "alpha", nullptr); |
| 833 builder.AddPasswordField("password4", "alpha", NULL); | 1058 builder.AddPasswordField("password4", "alpha", nullptr); |
| 834 builder.AddSubmitButton("submit"); | 1059 builder.AddSubmitButton("submit"); |
| 835 std::string html = builder.ProduceHTML(); | 1060 std::string html = builder.ProduceHTML(); |
| 836 | 1061 |
| 837 std::unique_ptr<PasswordForm> password_form; | 1062 std::unique_ptr<PasswordForm> password_form; |
| 838 ASSERT_NO_FATAL_FAILURE( | 1063 ASSERT_NO_FATAL_FAILURE( |
| 839 LoadHTMLAndConvertForm(html, &password_form, nullptr)); | 1064 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); |
| 840 EXPECT_FALSE(password_form); | 1065 EXPECT_FALSE(password_form); |
| 841 } | 1066 } |
| 842 | 1067 |
| 843 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { | 1068 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationLogin) { |
| 844 PasswordFormBuilder builder(kTestFormActionURL); | 1069 PasswordFormBuilder builder(kTestFormActionURL); |
| 845 builder.AddHiddenField(); | 1070 builder.AddHiddenField(); |
| 846 builder.AddTextField("username", "", nullptr); | 1071 builder.AddTextField("username", "", nullptr); |
| 847 builder.AddPasswordField("password", "", nullptr); | 1072 builder.AddPasswordField("password", "", nullptr); |
| 848 builder.AddSubmitButton("submit"); | 1073 builder.AddSubmitButton("submit"); |
| 849 std::string login_html = builder.ProduceHTML(); | 1074 std::string login_html = builder.ProduceHTML(); |
| 850 | 1075 |
| 851 std::unique_ptr<PasswordForm> login_form; | 1076 std::unique_ptr<PasswordForm> login_form; |
| 852 ASSERT_NO_FATAL_FAILURE( | 1077 ASSERT_NO_FATAL_FAILURE( |
| 853 LoadHTMLAndConvertForm(login_html, &login_form, nullptr)); | 1078 LoadHTMLAndConvertForm(login_html, &login_form, nullptr, false)); |
| 854 ASSERT_TRUE(login_form); | 1079 ASSERT_TRUE(login_form); |
| 855 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); | 1080 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); |
| 856 } | 1081 } |
| 857 | 1082 |
| 858 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { | 1083 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationSignup) { |
| 859 PasswordFormBuilder builder(kTestFormActionURL); | 1084 PasswordFormBuilder builder(kTestFormActionURL); |
| 860 builder.AddTextField("someotherfield", "", nullptr); | 1085 builder.AddTextField("someotherfield", "", nullptr); |
| 861 builder.AddTextField("username", "", nullptr); | 1086 builder.AddTextField("username", "", nullptr); |
| 862 builder.AddPasswordField("new_password", "", nullptr); | 1087 builder.AddPasswordField("new_password", "", nullptr); |
| 863 builder.AddHiddenField(); | 1088 builder.AddHiddenField(); |
| 864 builder.AddPasswordField("new_password2", "", nullptr); | 1089 builder.AddPasswordField("new_password2", "", nullptr); |
| 865 builder.AddSubmitButton("submit"); | 1090 builder.AddSubmitButton("submit"); |
| 866 std::string signup_html = builder.ProduceHTML(); | 1091 std::string signup_html = builder.ProduceHTML(); |
| 867 | 1092 |
| 868 std::unique_ptr<PasswordForm> signup_form; | 1093 std::unique_ptr<PasswordForm> signup_form; |
| 869 ASSERT_NO_FATAL_FAILURE( | 1094 ASSERT_NO_FATAL_FAILURE( |
| 870 LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr)); | 1095 LoadHTMLAndConvertForm(signup_html, &signup_form, nullptr, false)); |
| 871 ASSERT_TRUE(signup_form); | 1096 ASSERT_TRUE(signup_form); |
| 872 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); | 1097 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); |
| 873 } | 1098 } |
| 874 | 1099 |
| 875 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { | 1100 TEST_F(MAYBE_PasswordFormConversionUtilsTest, LayoutClassificationChange) { |
| 876 PasswordFormBuilder builder(kTestFormActionURL); | 1101 PasswordFormBuilder builder(kTestFormActionURL); |
| 877 builder.AddTextField("username", "", nullptr); | 1102 builder.AddTextField("username", "", nullptr); |
| 878 builder.AddPasswordField("old_password", "", nullptr); | 1103 builder.AddPasswordField("old_password", "", nullptr); |
| 879 builder.AddHiddenField(); | 1104 builder.AddHiddenField(); |
| 880 builder.AddPasswordField("new_password", "", nullptr); | 1105 builder.AddPasswordField("new_password", "", nullptr); |
| 881 builder.AddPasswordField("new_password2", "", nullptr); | 1106 builder.AddPasswordField("new_password2", "", nullptr); |
| 882 builder.AddSubmitButton("submit"); | 1107 builder.AddSubmitButton("submit"); |
| 883 std::string change_html = builder.ProduceHTML(); | 1108 std::string change_html = builder.ProduceHTML(); |
| 884 | 1109 |
| 885 std::unique_ptr<PasswordForm> change_form; | 1110 std::unique_ptr<PasswordForm> change_form; |
| 886 ASSERT_NO_FATAL_FAILURE( | 1111 ASSERT_NO_FATAL_FAILURE( |
| 887 LoadHTMLAndConvertForm(change_html, &change_form, nullptr)); | 1112 LoadHTMLAndConvertForm(change_html, &change_form, nullptr, false)); |
| 888 ASSERT_TRUE(change_form); | 1113 ASSERT_TRUE(change_form); |
| 889 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); | 1114 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); |
| 890 } | 1115 } |
| 891 | 1116 |
| 892 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1117 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 893 LayoutClassificationLoginPlusSignup_A) { | 1118 LayoutClassificationLoginPlusSignup_A) { |
| 894 PasswordFormBuilder builder(kTestFormActionURL); | 1119 PasswordFormBuilder builder(kTestFormActionURL); |
| 895 builder.AddTextField("username", "", nullptr); | 1120 builder.AddTextField("username", "", nullptr); |
| 896 builder.AddHiddenField(); | 1121 builder.AddHiddenField(); |
| 897 builder.AddPasswordField("password", "", nullptr); | 1122 builder.AddPasswordField("password", "", nullptr); |
| 898 builder.AddTextField("username2", "", nullptr); | 1123 builder.AddTextField("username2", "", nullptr); |
| 899 builder.AddTextField("someotherfield", "", nullptr); | 1124 builder.AddTextField("someotherfield", "", nullptr); |
| 900 builder.AddPasswordField("new_password", "", nullptr); | 1125 builder.AddPasswordField("new_password", "", nullptr); |
| 901 builder.AddPasswordField("new_password2", "", nullptr); | 1126 builder.AddPasswordField("new_password2", "", nullptr); |
| 902 builder.AddHiddenField(); | 1127 builder.AddHiddenField(); |
| 903 builder.AddSubmitButton("submit"); | 1128 builder.AddSubmitButton("submit"); |
| 904 std::string login_plus_signup_html = builder.ProduceHTML(); | 1129 std::string login_plus_signup_html = builder.ProduceHTML(); |
| 905 | 1130 |
| 906 std::unique_ptr<PasswordForm> login_plus_signup_form; | 1131 std::unique_ptr<PasswordForm> login_plus_signup_form; |
| 907 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( | 1132 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
| 908 login_plus_signup_html, &login_plus_signup_form, nullptr)); | 1133 login_plus_signup_html, &login_plus_signup_form, nullptr, false)); |
| 909 ASSERT_TRUE(login_plus_signup_form); | 1134 ASSERT_TRUE(login_plus_signup_form); |
| 910 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, | 1135 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
| 911 login_plus_signup_form->layout); | 1136 login_plus_signup_form->layout); |
| 912 } | 1137 } |
| 913 | 1138 |
| 914 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1139 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 915 LayoutClassificationLoginPlusSignup_B) { | 1140 LayoutClassificationLoginPlusSignup_B) { |
| 916 PasswordFormBuilder builder(kTestFormActionURL); | 1141 PasswordFormBuilder builder(kTestFormActionURL); |
| 917 builder.AddTextField("username", "", nullptr); | 1142 builder.AddTextField("username", "", nullptr); |
| 918 builder.AddHiddenField(); | 1143 builder.AddHiddenField(); |
| 919 builder.AddPasswordField("password", "", nullptr); | 1144 builder.AddPasswordField("password", "", nullptr); |
| 920 builder.AddTextField("username2", "", nullptr); | 1145 builder.AddTextField("username2", "", nullptr); |
| 921 builder.AddTextField("someotherfield", "", nullptr); | 1146 builder.AddTextField("someotherfield", "", nullptr); |
| 922 builder.AddPasswordField("new_password", "", nullptr); | 1147 builder.AddPasswordField("new_password", "", nullptr); |
| 923 builder.AddTextField("someotherfield2", "", nullptr); | 1148 builder.AddTextField("someotherfield2", "", nullptr); |
| 924 builder.AddHiddenField(); | 1149 builder.AddHiddenField(); |
| 925 builder.AddSubmitButton("submit"); | 1150 builder.AddSubmitButton("submit"); |
| 926 std::string login_plus_signup_html = builder.ProduceHTML(); | 1151 std::string login_plus_signup_html = builder.ProduceHTML(); |
| 927 | 1152 |
| 928 std::unique_ptr<PasswordForm> login_plus_signup_form; | 1153 std::unique_ptr<PasswordForm> login_plus_signup_form; |
| 929 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( | 1154 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm( |
| 930 login_plus_signup_html, &login_plus_signup_form, nullptr)); | 1155 login_plus_signup_html, &login_plus_signup_form, nullptr, false)); |
| 931 ASSERT_TRUE(login_plus_signup_form); | 1156 ASSERT_TRUE(login_plus_signup_form); |
| 932 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, | 1157 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
| 933 login_plus_signup_form->layout); | 1158 login_plus_signup_form->layout); |
| 934 } | 1159 } |
| 935 | 1160 |
| 936 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1161 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 937 CreditCardNumberWithTypePasswordForm) { | 1162 CreditCardNumberWithTypePasswordForm) { |
| 938 PasswordFormBuilder builder(kTestFormActionURL); | 1163 PasswordFormBuilder builder(kTestFormActionURL); |
| 939 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 1164 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 940 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", | 1165 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", |
| 941 nullptr); | 1166 nullptr); |
| 942 builder.AddTextField("cvc", "000", nullptr); | 1167 builder.AddTextField("cvc", "000", nullptr); |
| 943 builder.AddSubmitButton("submit"); | 1168 builder.AddSubmitButton("submit"); |
| 944 std::string html = builder.ProduceHTML(); | 1169 std::string html = builder.ProduceHTML(); |
| 945 | 1170 |
| 946 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 1171 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 947 predictions_positions[1] = PREDICTION_NOT_PASSWORD; | 1172 predictions_positions[1] = PREDICTION_NOT_PASSWORD; |
| 948 | 1173 |
| 949 FormsPredictionsMap predictions; | 1174 FormsPredictionsMap predictions; |
| 950 SetPredictions(html, &predictions, predictions_positions); | 1175 SetPredictions(html, &predictions, predictions_positions); |
| 951 | 1176 |
| 952 std::unique_ptr<PasswordForm> password_form; | 1177 std::unique_ptr<PasswordForm> password_form; |
| 953 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 1178 LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
| 954 EXPECT_FALSE(password_form); | 1179 EXPECT_FALSE(password_form); |
| 955 } | 1180 } |
| 956 | 1181 |
| 957 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1182 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 958 CreditCardVerificationNumberWithTypePasswordForm) { | 1183 CreditCardVerificationNumberWithTypePasswordForm) { |
| 959 PasswordFormBuilder builder(kTestFormActionURL); | 1184 PasswordFormBuilder builder(kTestFormActionURL); |
| 960 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 1185 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 961 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); | 1186 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); |
| 962 builder.AddPasswordField("cvc", "000", nullptr); | 1187 builder.AddPasswordField("cvc", "000", nullptr); |
| 963 builder.AddSubmitButton("submit"); | 1188 builder.AddSubmitButton("submit"); |
| 964 std::string html = builder.ProduceHTML(); | 1189 std::string html = builder.ProduceHTML(); |
| 965 | 1190 |
| 966 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 1191 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 967 predictions_positions[2] = PREDICTION_NOT_PASSWORD; | 1192 predictions_positions[2] = PREDICTION_NOT_PASSWORD; |
| 968 | 1193 |
| 969 FormsPredictionsMap predictions; | 1194 FormsPredictionsMap predictions; |
| 970 SetPredictions(html, &predictions, predictions_positions); | 1195 SetPredictions(html, &predictions, predictions_positions); |
| 971 | 1196 |
| 972 std::unique_ptr<PasswordForm> password_form; | 1197 std::unique_ptr<PasswordForm> password_form; |
| 973 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 1198 LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
| 974 EXPECT_FALSE(password_form); | 1199 EXPECT_FALSE(password_form); |
| 975 } | 1200 } |
| 976 | 1201 |
| 977 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1202 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 978 CreditCardNumberWithTypePasswordFormWithAutocomplete) { | 1203 CreditCardNumberWithTypePasswordFormWithAutocomplete) { |
| 979 PasswordFormBuilder builder(kTestFormActionURL); | 1204 PasswordFormBuilder builder(kTestFormActionURL); |
| 980 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 1205 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 981 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", | 1206 builder.AddPasswordField("Credit card number", "0000 0000 0000 0000", |
| 982 "current-password"); | 1207 "current-password"); |
| 983 builder.AddTextField("cvc", "000", nullptr); | 1208 builder.AddTextField("cvc", "000", nullptr); |
| 984 builder.AddSubmitButton("submit"); | 1209 builder.AddSubmitButton("submit"); |
| 985 std::string html = builder.ProduceHTML(); | 1210 std::string html = builder.ProduceHTML(); |
| 986 | 1211 |
| 987 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 1212 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 988 predictions_positions[1] = PREDICTION_NOT_PASSWORD; | 1213 predictions_positions[1] = PREDICTION_NOT_PASSWORD; |
| 989 | 1214 |
| 990 FormsPredictionsMap predictions; | 1215 FormsPredictionsMap predictions; |
| 991 SetPredictions(html, &predictions, predictions_positions); | 1216 SetPredictions(html, &predictions, predictions_positions); |
| 992 | 1217 |
| 993 std::unique_ptr<PasswordForm> password_form; | 1218 std::unique_ptr<PasswordForm> password_form; |
| 994 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 1219 LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
| 995 EXPECT_TRUE(password_form); | 1220 EXPECT_TRUE(password_form); |
| 996 } | 1221 } |
| 997 | 1222 |
| 998 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 1223 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 999 CreditCardVerificationNumberWithTypePasswordFormWithAutocomplete) { | 1224 CreditCardVerificationNumberWithTypePasswordFormWithAutocomplete) { |
| 1000 PasswordFormBuilder builder(kTestFormActionURL); | 1225 PasswordFormBuilder builder(kTestFormActionURL); |
| 1001 builder.AddTextField("Credit card owner name", "John Smith", nullptr); | 1226 builder.AddTextField("Credit card owner name", "John Smith", nullptr); |
| 1002 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); | 1227 builder.AddTextField("Credit card number", "0000 0000 0000 0000", nullptr); |
| 1003 builder.AddPasswordField("cvc", "000", "new-password"); | 1228 builder.AddPasswordField("cvc", "000", "new-password"); |
| 1004 builder.AddSubmitButton("submit"); | 1229 builder.AddSubmitButton("submit"); |
| 1005 std::string html = builder.ProduceHTML(); | 1230 std::string html = builder.ProduceHTML(); |
| 1006 | 1231 |
| 1007 std::map<int, PasswordFormFieldPredictionType> predictions_positions; | 1232 std::map<int, PasswordFormFieldPredictionType> predictions_positions; |
| 1008 predictions_positions[2] = PREDICTION_NOT_PASSWORD; | 1233 predictions_positions[2] = PREDICTION_NOT_PASSWORD; |
| 1009 | 1234 |
| 1010 FormsPredictionsMap predictions; | 1235 FormsPredictionsMap predictions; |
| 1011 SetPredictions(html, &predictions, predictions_positions); | 1236 SetPredictions(html, &predictions, predictions_positions); |
| 1012 | 1237 |
| 1013 std::unique_ptr<PasswordForm> password_form; | 1238 std::unique_ptr<PasswordForm> password_form; |
| 1014 LoadHTMLAndConvertForm(html, &password_form, &predictions); | 1239 LoadHTMLAndConvertForm(html, &password_form, &predictions, false); |
| 1015 EXPECT_TRUE(password_form); | 1240 EXPECT_TRUE(password_form); |
| 1016 } | 1241 } |
| 1017 | 1242 |
| 1018 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IsGaiaReauthFormIgnored) { | 1243 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IsGaiaReauthFormIgnored) { |
| 1019 struct TestCase { | 1244 struct TestCase { |
| 1020 const char* origin; | 1245 const char* origin; |
| 1021 struct KeyValue { | 1246 struct KeyValue { |
| 1022 KeyValue() : name(nullptr), value(nullptr) {} | 1247 KeyValue() : name(nullptr), value(nullptr) {} |
| 1023 KeyValue(const char* new_name, const char* new_value) | 1248 KeyValue(const char* new_name, const char* new_value) |
| 1024 : name(new_name), value(new_value) {} | 1249 : name(new_name), value(new_value) {} |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 | 1394 |
| 1170 if (test_cases[i].new_password_fieldname == kEmpty) { | 1395 if (test_cases[i].new_password_fieldname == kEmpty) { |
| 1171 builder.AddAnonymousInputField("password"); | 1396 builder.AddAnonymousInputField("password"); |
| 1172 } else { | 1397 } else { |
| 1173 builder.AddPasswordField(test_cases[i].new_password_fieldname, "", | 1398 builder.AddPasswordField(test_cases[i].new_password_fieldname, "", |
| 1174 kEmpty); | 1399 kEmpty); |
| 1175 } | 1400 } |
| 1176 std::string html = builder.ProduceHTML(); | 1401 std::string html = builder.ProduceHTML(); |
| 1177 | 1402 |
| 1178 std::unique_ptr<PasswordForm> password_form; | 1403 std::unique_ptr<PasswordForm> password_form; |
| 1179 LoadHTMLAndConvertForm(html, &password_form, nullptr); | 1404 LoadHTMLAndConvertForm(html, &password_form, nullptr, false); |
| 1180 EXPECT_TRUE(password_form); | 1405 EXPECT_TRUE(password_form); |
| 1181 | 1406 |
| 1182 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), | 1407 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element), |
| 1183 password_form->username_element); | 1408 password_form->username_element); |
| 1184 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_password_element), | 1409 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_password_element), |
| 1185 password_form->password_element); | 1410 password_form->password_element); |
| 1186 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_new_password_element), | 1411 EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_new_password_element), |
| 1187 password_form->new_password_element); | 1412 password_form->new_password_element); |
| 1188 } | 1413 } |
| 1189 } | 1414 } |
| 1190 | 1415 |
| 1416 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | |
| 1417 ProbablySignUpFormTwoTextOnePassword) { | |
| 1418 PasswordFormBuilder builder(kTestFormActionURL); | |
| 1419 builder.AddTextField("email", "johnsmith@gmail.com", nullptr); | |
| 1420 builder.AddTextField("username", "johnsmith", nullptr); | |
| 1421 builder.AddPasswordField("password", "secret", nullptr); | |
| 1422 std::string html = builder.ProduceHTML(); | |
| 1423 | |
| 1424 std::unique_ptr<PasswordForm> password_form; | |
| 1425 // No user input, not considered as SignUp. | |
| 1426 ASSERT_NO_FATAL_FAILURE( | |
| 1427 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); | |
| 1428 ASSERT_TRUE(password_form); | |
| 1429 EXPECT_FALSE(password_form->does_look_like_signup_form); | |
| 1430 | |
| 1431 // With user input, considered as SignUp. | |
| 1432 ASSERT_NO_FATAL_FAILURE( | |
| 1433 LoadHTMLAndConvertForm(html, &password_form, nullptr, true)); | |
| 1434 ASSERT_TRUE(password_form); | |
| 1435 EXPECT_TRUE(password_form->does_look_like_signup_form); | |
| 1436 } | |
| 1437 | |
| 1438 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | |
| 1439 ProbablySignUpFormOneTextNewAndConfirmPassword) { | |
| 1440 PasswordFormBuilder builder(kTestFormActionURL); | |
| 1441 builder.AddTextField("username", "johnsmith", nullptr); | |
| 1442 builder.AddPasswordField("new_password", "secret", nullptr); | |
| 1443 builder.AddPasswordField("confirm_password", "secret", nullptr); | |
| 1444 std::string html = builder.ProduceHTML(); | |
| 1445 | |
| 1446 std::unique_ptr<PasswordForm> password_form; | |
| 1447 // No user input, not considered as SignUp. | |
| 1448 ASSERT_NO_FATAL_FAILURE( | |
|
vabr (Chromium)
2016/04/06 22:42:12
What would be the fatal failure which could happen
dvadym
2016/04/07 11:52:18
Done.
| |
| 1449 LoadHTMLAndConvertForm(html, &password_form, nullptr, false)); | |
| 1450 ASSERT_TRUE(password_form); | |
| 1451 EXPECT_FALSE(password_form->does_look_like_signup_form); | |
| 1452 | |
| 1453 // With user input, considered as SignUp. | |
| 1454 ASSERT_NO_FATAL_FAILURE( | |
| 1455 LoadHTMLAndConvertForm(html, &password_form, nullptr, true)); | |
| 1456 ASSERT_TRUE(password_form); | |
| 1457 EXPECT_TRUE(password_form->does_look_like_signup_form); | |
| 1458 } | |
| 1459 | |
| 1460 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | |
| 1461 NotProbablySignUpFormOneTextCurrentAndNewPassword) { | |
| 1462 PasswordFormBuilder builder(kTestFormActionURL); | |
| 1463 builder.AddTextField("username", "johnsmith", nullptr); | |
| 1464 builder.AddPasswordField("password", "secret", nullptr); | |
| 1465 builder.AddPasswordField("new_password", "new_secret", nullptr); | |
| 1466 std::string html = builder.ProduceHTML(); | |
| 1467 | |
| 1468 std::unique_ptr<PasswordForm> password_form; | |
| 1469 ASSERT_NO_FATAL_FAILURE( | |
| 1470 LoadHTMLAndConvertForm(html, &password_form, nullptr, true)); | |
| 1471 ASSERT_TRUE(password_form); | |
| 1472 EXPECT_FALSE(password_form->does_look_like_signup_form); | |
| 1473 } | |
| 1474 | |
| 1475 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | |
| 1476 NotProbablySignUpFormForSignInForm) { | |
| 1477 PasswordFormBuilder builder(kTestFormActionURL); | |
| 1478 builder.AddTextField("username", "johnsmith", nullptr); | |
| 1479 builder.AddPasswordField("password", "secret", nullptr); | |
| 1480 std::string html = builder.ProduceHTML(); | |
| 1481 | |
| 1482 std::unique_ptr<PasswordForm> password_form; | |
| 1483 ASSERT_NO_FATAL_FAILURE( | |
| 1484 LoadHTMLAndConvertForm(html, &password_form, nullptr, true)); | |
| 1485 ASSERT_TRUE(password_form); | |
| 1486 EXPECT_FALSE(password_form->does_look_like_signup_form); | |
| 1487 } | |
| 1488 | |
| 1191 } // namespace autofill | 1489 } // namespace autofill |
| OLD | NEW |