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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698