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

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: Test 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 scoped_ptr<FormStructure> form_structure;
Ilya Sherman 2014/10/24 22:42:31 nit: Why use a scoped_ptr here, rather than stack-
Garrett Casto 2014/10/24 23:19:52 The evils of copy and paste. It is rather common i
493 FormData form;
494
495 // Start with a regular contact form.
496 FormFieldData field;
497 field.form_control_type = "text";
498
499 field.label = ASCIIToUTF16("First Name");
500 field.name = ASCIIToUTF16("firstname");
501 form.fields.push_back(field);
502
503 field.label = ASCIIToUTF16("Last Name");
504 field.name = ASCIIToUTF16("lastname");
505 form.fields.push_back(field);
506
507 field.label = ASCIIToUTF16("Email");
508 field.name = ASCIIToUTF16("email");
509 field.autocomplete_attribute = "username";
510 form.fields.push_back(field);
511
512 field.label = ASCIIToUTF16("Password");
513 field.name = ASCIIToUTF16("Password");
514 field.form_control_type = "password";
515 form.fields.push_back(field);
516
517 form_structure.reset(new FormStructure(form));
518 form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
519 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced());
520 }
521
487 // Verify that we can correctly process sections listed in the |autocomplete| 522 // Verify that we can correctly process sections listed in the |autocomplete|
488 // attribute. 523 // attribute.
489 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { 524 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) {
490 FormData form; 525 FormData form;
491 526
492 FormFieldData field; 527 FormFieldData field;
493 field.form_control_type = "text"; 528 field.form_control_type = "text";
494 529
495 // Some fields will have no section specified. These fall into the default 530 // Some fields will have no section specified. These fall into the default
496 // section. 531 // section.
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 2375
2341 // A freeform input (<input>) allows any value (overriding other <select>s). 2376 // A freeform input (<input>) allows any value (overriding other <select>s).
2342 FormFieldData freeform_field; 2377 FormFieldData freeform_field;
2343 freeform_field.autocomplete_attribute = "billing country"; 2378 freeform_field.autocomplete_attribute = "billing country";
2344 form_data.fields.push_back(freeform_field); 2379 form_data.fields.push_back(freeform_field);
2345 FormStructure form_structure2(form_data); 2380 FormStructure form_structure2(form_data);
2346 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused); 2381 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused);
2347 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size()); 2382 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size());
2348 } 2383 }
2349 2384
2385 TEST(FormStructureTest, ParseQueryResponse) {
2386 FormData form;
2387 FormFieldData field;
2388 field.form_control_type = "text";
2389
2390 field.label = ASCIIToUTF16("fullname");
2391 field.name = ASCIIToUTF16("fullname");
2392 form.fields.push_back(field);
2393
2394 field.label = ASCIIToUTF16("address");
2395 field.name = ASCIIToUTF16("address");
2396 form.fields.push_back(field);
2397
2398 // Checkable fields should be ignored in parsing
2399 FormFieldData checkable_field;
2400 checkable_field.label = ASCIIToUTF16("radio_button");
2401 checkable_field.form_control_type = "radio";
2402 checkable_field.is_checkable = true;
2403 form.fields.push_back(checkable_field);
2404
2405 std::vector<FormStructure*> forms;
2406 forms.push_back(new FormStructure(form));
2407
2408 field.label = ASCIIToUTF16("email");
2409 field.name = ASCIIToUTF16("email");
2410 form.fields.push_back(field);
2411
2412 field.label = ASCIIToUTF16("password");
2413 field.name = ASCIIToUTF16("password");
2414 field.form_control_type = "password";
2415 form.fields.push_back(field);
2416
2417 forms.push_back(new FormStructure(form));
2418
2419 std::string response =
2420 "<autofillqueryresponse>"
2421 "<field autofilltype=\"7\" />"
2422 "<field autofilltype=\"30\" />"
2423 "<field autofilltype=\"9\" />"
2424 "<field autofilltype=\"0\" />"
2425 "</autofillqueryresponse>";
2426
2427 FormStructure::ParseQueryResponse(response, forms, TestAutofillMetrics());
2428
2429 EXPECT_EQ(7, forms[0]->field(0)->server_type());
2430 EXPECT_EQ(30, forms[0]->field(1)->server_type());
2431 EXPECT_EQ(9, forms[1]->field(0)->server_type());
2432 EXPECT_EQ(0, forms[1]->field(1)->server_type());
2433
2434 STLDeleteContainerPointers(forms.begin(), forms.end());
Ilya Sherman 2014/10/24 22:42:31 Oof. Can we use a ScopedVector to control memory
Garrett Casto 2014/10/24 23:19:52 Done.
2435 }
2436
2437 // If user defined types are present, only parse password fields.
2438 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) {
2439 FormData form;
2440 FormFieldData field;
2441
2442 field.label = ASCIIToUTF16("email");
2443 field.name = ASCIIToUTF16("email");
2444 field.form_control_type = "text";
2445 field.autocomplete_attribute = "email";
2446 form.fields.push_back(field);
2447
2448 field.label = ASCIIToUTF16("password");
2449 field.name = ASCIIToUTF16("password");
2450 field.form_control_type = "password";
2451 field.autocomplete_attribute = "new-password";
2452 form.fields.push_back(field);
2453
2454 std::vector<FormStructure*> forms;
2455 forms.push_back(new FormStructure(form));
2456 forms.front()->DetermineHeuristicTypes(TestAutofillMetrics());
2457
2458 std::string response =
2459 "<autofillqueryresponse>"
2460 "<field autofilltype=\"9\" />"
2461 "<field autofilltype=\"76\" />"
2462 "</autofillqueryresponse>";
2463
2464 FormStructure::ParseQueryResponse(response, forms, TestAutofillMetrics());
2465
2466 EXPECT_EQ(0, forms[0]->field(0)->server_type());
Ilya Sherman 2014/10/24 22:42:31 nit: I think UNKNOWN_TYPE rather than "0" would be
Garrett Casto 2014/10/24 23:19:52 It's actually NO_SERVER_DATA, but I see your point
2467 EXPECT_EQ(76, forms[0]->field(1)->server_type());
2468
2469 STLDeleteContainerPointers(forms.begin(), forms.end());
2470 }
2471
2350 } // namespace autofill 2472 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698