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

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

Issue 2318533002: [Password Generation] Use signatures for form matching (Closed)
Patch Set: Sent to review Created 4 years, 3 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 "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "components/autofill/core/browser/autofill_test_utils.h" 16 #include "components/autofill/core/browser/autofill_test_utils.h"
17 #include "components/autofill/core/common/autofill_switches.h" 17 #include "components/autofill/core/common/autofill_switches.h"
18 #include "components/autofill/core/common/form_data.h" 18 #include "components/autofill/core/common/form_data.h"
19 #include "components/autofill/core/common/form_field_data.h" 19 #include "components/autofill/core/common/form_field_data.h"
20 #include "components/autofill/core/common/signatures_util.h"
20 #include "components/variations/entropy_provider.h" 21 #include "components/variations/entropy_provider.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 using base::ASCIIToUTF16; 25 using base::ASCIIToUTF16;
25 26
26 namespace autofill { 27 namespace autofill {
27 28
28 namespace content { 29 namespace content {
29 30
(...skipping 13 matching lines...) Expand all
43 } 44 }
44 45
45 return os; 46 return os;
46 } 47 }
47 48
48 } // namespace content 49 } // namespace content
49 50
50 class FormStructureTest : public testing::Test { 51 class FormStructureTest : public testing::Test {
51 public: 52 public:
52 static std::string Hash64Bit(const std::string& str) { 53 static std::string Hash64Bit(const std::string& str) {
53 return base::Uint64ToString(FormStructure::Hash64Bit(str)); 54 return base::Uint64ToString(StrToHash64Bit(str));
54 } 55 }
55 56
56 void SetUp() override { 57 void SetUp() override {
57 // By default this trial is enabled on tests. 58 // By default this trial is enabled on tests.
58 EnableAutofillMetadataFieldTrial(); 59 EnableAutofillMetadataFieldTrial();
59 } 60 }
60 61
61 protected: 62 protected:
62 void DisableAutofillMetadataFieldTrial() { 63 void DisableAutofillMetadataFieldTrial() {
63 field_trial_list_.reset(); 64 field_trial_list_.reset();
(...skipping 3237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 3302
3302 // Checkable fields shouldn't affect the signature. 3303 // Checkable fields shouldn't affect the signature.
3303 field.label = ASCIIToUTF16("Select"); 3304 field.label = ASCIIToUTF16("Select");
3304 field.name = ASCIIToUTF16("Select"); 3305 field.name = ASCIIToUTF16("Select");
3305 field.form_control_type = "checkbox"; 3306 field.form_control_type = "checkbox";
3306 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED; 3307 field.check_status = FormFieldData::CHECKABLE_BUT_UNCHECKED;
3307 form.fields.push_back(field); 3308 form.fields.push_back(field);
3308 3309
3309 form_structure.reset(new FormStructure(form)); 3310 form_structure.reset(new FormStructure(form));
3310 3311
3311 EXPECT_EQ(FormStructureTest::Hash64Bit( 3312 EXPECT_EQ(FormStructureTest::Hash64Bit(std::string("://&&email&first")),
3312 std::string("://&&email&first")), 3313 form_structure->FormSignatureAsStr());
3313 form_structure->FormSignature());
3314 3314
3315 form.origin = GURL(std::string("http://www.facebook.com")); 3315 form.origin = GURL(std::string("http://www.facebook.com"));
3316 form_structure.reset(new FormStructure(form)); 3316 form_structure.reset(new FormStructure(form));
3317 EXPECT_EQ(FormStructureTest::Hash64Bit( 3317 EXPECT_EQ(FormStructureTest::Hash64Bit(
3318 std::string("http://www.facebook.com&&email&first")), 3318 std::string("http://www.facebook.com&&email&first")),
3319 form_structure->FormSignature()); 3319 form_structure->FormSignatureAsStr());
3320 3320
3321 form.action = GURL(std::string("https://login.facebook.com/path")); 3321 form.action = GURL(std::string("https://login.facebook.com/path"));
3322 form_structure.reset(new FormStructure(form)); 3322 form_structure.reset(new FormStructure(form));
3323 EXPECT_EQ(FormStructureTest::Hash64Bit( 3323 EXPECT_EQ(FormStructureTest::Hash64Bit(
3324 std::string("https://login.facebook.com&&email&first")), 3324 std::string("https://login.facebook.com&&email&first")),
3325 form_structure->FormSignature()); 3325 form_structure->FormSignatureAsStr());
3326 3326
3327 form.name = ASCIIToUTF16("login_form"); 3327 form.name = ASCIIToUTF16("login_form");
3328 form_structure.reset(new FormStructure(form)); 3328 form_structure.reset(new FormStructure(form));
3329 EXPECT_EQ(FormStructureTest::Hash64Bit( 3329 EXPECT_EQ(FormStructureTest::Hash64Bit(std::string(
3330 std::string("https://login.facebook.com&login_form&email&first")), 3330 "https://login.facebook.com&login_form&email&first")),
3331 form_structure->FormSignature()); 3331 form_structure->FormSignatureAsStr());
3332 3332
3333 field.check_status = FormFieldData::NOT_CHECKABLE; 3333 field.check_status = FormFieldData::NOT_CHECKABLE;
3334 field.label = ASCIIToUTF16("Random Field label"); 3334 field.label = ASCIIToUTF16("Random Field label");
3335 field.name = ASCIIToUTF16("random1234"); 3335 field.name = ASCIIToUTF16("random1234");
3336 field.form_control_type = "text"; 3336 field.form_control_type = "text";
3337 form.fields.push_back(field); 3337 form.fields.push_back(field);
3338 field.label = ASCIIToUTF16("Random Field label2"); 3338 field.label = ASCIIToUTF16("Random Field label2");
3339 field.name = ASCIIToUTF16("random12345"); 3339 field.name = ASCIIToUTF16("random12345");
3340 form.fields.push_back(field); 3340 form.fields.push_back(field);
3341 field.label = ASCIIToUTF16("Random Field label3"); 3341 field.label = ASCIIToUTF16("Random Field label3");
3342 field.name = ASCIIToUTF16("1random12345678"); 3342 field.name = ASCIIToUTF16("1random12345678");
3343 form.fields.push_back(field); 3343 form.fields.push_back(field);
3344 field.label = ASCIIToUTF16("Random Field label3"); 3344 field.label = ASCIIToUTF16("Random Field label3");
3345 field.name = ASCIIToUTF16("12345random"); 3345 field.name = ASCIIToUTF16("12345random");
3346 form.fields.push_back(field); 3346 form.fields.push_back(field);
3347 form_structure.reset(new FormStructure(form)); 3347 form_structure.reset(new FormStructure(form));
3348 EXPECT_EQ(FormStructureTest::Hash64Bit( 3348 EXPECT_EQ(FormStructureTest::Hash64Bit(
3349 std::string("https://login.facebook.com&login_form&email&first&" 3349 std::string("https://login.facebook.com&login_form&email&first&"
3350 "random1234&random&1random&random")), 3350 "random1234&random&1random&random")),
3351 form_structure->FormSignature()); 3351 form_structure->FormSignatureAsStr());
3352 } 3352 }
3353 3353
3354 TEST_F(FormStructureTest, ToFormData) { 3354 TEST_F(FormStructureTest, ToFormData) {
3355 FormData form; 3355 FormData form;
3356 form.name = ASCIIToUTF16("the-name"); 3356 form.name = ASCIIToUTF16("the-name");
3357 form.origin = GURL("http://cool.com"); 3357 form.origin = GURL("http://cool.com");
3358 form.action = form.origin.Resolve("/login"); 3358 form.action = form.origin.Resolve("/login");
3359 3359
3360 FormFieldData field; 3360 FormFieldData field;
3361 field.label = ASCIIToUTF16("username"); 3361 field.label = ASCIIToUTF16("username");
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 prefix = FormStructure::FindLongestCommonPrefix(strings); 3798 prefix = FormStructure::FindLongestCommonPrefix(strings);
3799 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3799 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3800 3800
3801 // Empty vector. 3801 // Empty vector.
3802 strings.clear(); 3802 strings.clear();
3803 prefix = FormStructure::FindLongestCommonPrefix(strings); 3803 prefix = FormStructure::FindLongestCommonPrefix(strings);
3804 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3804 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3805 } 3805 }
3806 3806
3807 } // namespace autofill 3807 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698