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

Side by Side Diff: components/autofill/core/browser/form_structure_unittest.cc

Issue 659793005: [Password Generation] Always query password forms via Autofill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More Comments Created 6 years, 1 month 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 "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_metrics.h" 10 #include "components/autofill/core/browser/autofill_metrics.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); 477 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced());
478 478
479 ASSERT_EQ(3U, form_structure->field_count()); 479 ASSERT_EQ(3U, form_structure->field_count());
480 ASSERT_EQ(0U, form_structure->autofill_count()); 480 ASSERT_EQ(0U, form_structure->autofill_count());
481 481
482 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 482 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
483 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 483 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
484 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 484 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
485 } 485 }
486 486
487 // Even with an 'autocomplete' attribute set, ShouldBeCrowdsourced() should
488 // return true if the structure contains a password field, since there are
489 // no local heuristics to depend upon in this case. Fields will still not be
490 // considered autofillable though.
491 TEST(FormStructureTest, PasswordFormShouldBeCrowdsourced) {
492 FormData form;
493
494 // Start with a regular contact form.
495 FormFieldData field;
496 field.form_control_type = "text";
497
498 field.label = ASCIIToUTF16("First Name");
499 field.name = ASCIIToUTF16("firstname");
500 form.fields.push_back(field);
501
502 field.label = ASCIIToUTF16("Last Name");
503 field.name = ASCIIToUTF16("lastname");
504 form.fields.push_back(field);
505
506 field.label = ASCIIToUTF16("Email");
507 field.name = ASCIIToUTF16("email");
508 field.autocomplete_attribute = "username";
509 form.fields.push_back(field);
510
511 field.label = ASCIIToUTF16("Password");
512 field.name = ASCIIToUTF16("Password");
513 field.form_control_type = "password";
514 form.fields.push_back(field);
515
516 FormStructure form_structure(form);
517 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
518 EXPECT_TRUE(form_structure.ShouldBeCrowdsourced());
519 }
520
487 // Verify that we can correctly process sections listed in the |autocomplete| 521 // Verify that we can correctly process sections listed in the |autocomplete|
488 // attribute. 522 // attribute.
489 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { 523 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) {
490 FormData form; 524 FormData form;
491 525
492 FormFieldData field; 526 FormFieldData field;
493 field.form_control_type = "text"; 527 field.form_control_type = "text";
494 528
495 // Some fields will have no section specified. These fall into the default 529 // Some fields will have no section specified. These fall into the default
496 // section. 530 // section.
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 2374
2341 // A freeform input (<input>) allows any value (overriding other <select>s). 2375 // A freeform input (<input>) allows any value (overriding other <select>s).
2342 FormFieldData freeform_field; 2376 FormFieldData freeform_field;
2343 freeform_field.autocomplete_attribute = "billing country"; 2377 freeform_field.autocomplete_attribute = "billing country";
2344 form_data.fields.push_back(freeform_field); 2378 form_data.fields.push_back(freeform_field);
2345 FormStructure form_structure2(form_data); 2379 FormStructure form_structure2(form_data);
2346 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused); 2380 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused);
2347 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size()); 2381 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size());
2348 } 2382 }
2349 2383
2384 TEST(FormStructureTest, ParseQueryResponse) {
2385 FormData form;
2386 FormFieldData field;
2387 field.form_control_type = "text";
2388
2389 field.label = ASCIIToUTF16("fullname");
2390 field.name = ASCIIToUTF16("fullname");
2391 form.fields.push_back(field);
2392
2393 field.label = ASCIIToUTF16("address");
2394 field.name = ASCIIToUTF16("address");
2395 form.fields.push_back(field);
2396
2397 // Checkable fields should be ignored in parsing
2398 FormFieldData checkable_field;
2399 checkable_field.label = ASCIIToUTF16("radio_button");
2400 checkable_field.form_control_type = "radio";
2401 checkable_field.is_checkable = true;
2402 form.fields.push_back(checkable_field);
2403
2404 ScopedVector<FormStructure> forms;
2405 forms.push_back(new FormStructure(form));
2406
2407 field.label = ASCIIToUTF16("email");
2408 field.name = ASCIIToUTF16("email");
2409 form.fields.push_back(field);
2410
2411 field.label = ASCIIToUTF16("password");
2412 field.name = ASCIIToUTF16("password");
2413 field.form_control_type = "password";
2414 form.fields.push_back(field);
2415
2416 forms.push_back(new FormStructure(form));
2417
2418 std::string response =
2419 "<autofillqueryresponse>"
2420 "<field autofilltype=\"7\" />"
2421 "<field autofilltype=\"30\" />"
2422 "<field autofilltype=\"9\" />"
2423 "<field autofilltype=\"0\" />"
2424 "</autofillqueryresponse>";
2425
2426 FormStructure::ParseQueryResponse(response,
2427 forms.get(),
2428 TestAutofillMetrics());
2429
2430 EXPECT_EQ(7, forms[0]->field(0)->server_type());
2431 EXPECT_EQ(30, forms[0]->field(1)->server_type());
2432 EXPECT_EQ(9, forms[1]->field(0)->server_type());
2433 EXPECT_EQ(0, forms[1]->field(1)->server_type());
2434 }
2435
2436 // If user defined types are present, only parse password fields.
2437 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) {
2438 FormData form;
2439 FormFieldData field;
2440
2441 field.label = ASCIIToUTF16("email");
2442 field.name = ASCIIToUTF16("email");
2443 field.form_control_type = "text";
2444 field.autocomplete_attribute = "email";
2445 form.fields.push_back(field);
2446
2447 field.label = ASCIIToUTF16("password");
2448 field.name = ASCIIToUTF16("password");
2449 field.form_control_type = "password";
2450 field.autocomplete_attribute = "new-password";
2451 form.fields.push_back(field);
2452
2453 ScopedVector<FormStructure> forms;
2454 forms.push_back(new FormStructure(form));
2455 forms.front()->DetermineHeuristicTypes(TestAutofillMetrics());
2456
2457 std::string response =
2458 "<autofillqueryresponse>"
2459 "<field autofilltype=\"9\" />"
2460 "<field autofilltype=\"76\" />"
2461 "</autofillqueryresponse>";
2462
2463 FormStructure::ParseQueryResponse(response,
2464 forms.get(),
2465 TestAutofillMetrics());
2466
2467 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type());
2468 EXPECT_EQ(76, forms[0]->field(1)->server_type());
2469 }
2470
2350 } // namespace autofill 2471 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698