| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/common/autofill_switches.h" | 12 #include "components/autofill/core/common/autofill_switches.h" |
| 12 #include "components/autofill/core/common/form_data.h" | 13 #include "components/autofill/core/common/form_data.h" |
| 13 #include "components/autofill/core/common/form_field_data.h" | 14 #include "components/autofill/core/common/form_field_data.h" |
| 14 #include "components/rappor/test_rappor_service.h" | 15 #include "components/rappor/test_rappor_service.h" |
| 16 #include "components/variations/entropy_provider.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 | 19 |
| 18 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
| 19 using rappor::TestRapporService; | 21 using rappor::TestRapporService; |
| 20 | 22 |
| 21 namespace autofill { | 23 namespace autofill { |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 iter != form.fields.end(); ++iter) { | 37 iter != form.fields.end(); ++iter) { |
| 36 os << *iter | 38 os << *iter |
| 37 << " "; | 39 << " "; |
| 38 } | 40 } |
| 39 | 41 |
| 40 return os; | 42 return os; |
| 41 } | 43 } |
| 42 | 44 |
| 43 } // namespace content | 45 } // namespace content |
| 44 | 46 |
| 45 class FormStructureTest { | 47 class FormStructureTest : public testing::Test { |
| 46 public: | 48 public: |
| 47 static std::string Hash64Bit(const std::string& str) { | 49 static std::string Hash64Bit(const std::string& str) { |
| 48 return FormStructure::Hash64Bit(str); | 50 return FormStructure::Hash64Bit(str); |
| 49 } | 51 } |
| 52 |
| 53 void SetUp() override { |
| 54 // By default this trial is enabled on tests. |
| 55 EnableAutofillMetadataFieldTrial(); |
| 56 } |
| 57 |
| 58 protected: |
| 59 void DisableAutofillMetadataFieldTrial() { |
| 60 field_trial_list_.reset(NULL); |
| 61 } |
| 62 |
| 63 private: |
| 64 void EnableAutofillMetadataFieldTrial() { |
| 65 // Clear the existing |field_trial_list_| to avoid firing a DCHECK. |
| 66 field_trial_list_.reset(NULL); |
| 67 field_trial_list_.reset( |
| 68 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); |
| 69 field_trial_ = base::FieldTrialList::CreateFieldTrial( |
| 70 "AutofillFieldMetadata", "Enabled"); |
| 71 field_trial_->group(); |
| 72 } |
| 73 |
| 74 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 75 scoped_refptr<base::FieldTrial> field_trial_; |
| 50 }; | 76 }; |
| 51 | 77 |
| 52 TEST(FormStructureTest, FieldCount) { | 78 TEST_F(FormStructureTest, FieldCount) { |
| 53 scoped_ptr<FormStructure> form_structure; | 79 scoped_ptr<FormStructure> form_structure; |
| 54 FormData form; | 80 FormData form; |
| 55 | 81 |
| 56 FormFieldData field; | 82 FormFieldData field; |
| 57 field.label = ASCIIToUTF16("username"); | 83 field.label = ASCIIToUTF16("username"); |
| 58 field.name = ASCIIToUTF16("username"); | 84 field.name = ASCIIToUTF16("username"); |
| 59 field.form_control_type = "text"; | 85 field.form_control_type = "text"; |
| 60 form.fields.push_back(field); | 86 form.fields.push_back(field); |
| 61 | 87 |
| 62 field.label = ASCIIToUTF16("password"); | 88 field.label = ASCIIToUTF16("password"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 field.form_control_type = "text"; | 100 field.form_control_type = "text"; |
| 75 field.should_autocomplete = false; | 101 field.should_autocomplete = false; |
| 76 form.fields.push_back(field); | 102 form.fields.push_back(field); |
| 77 | 103 |
| 78 // The render process sends all fields to browser including fields with | 104 // The render process sends all fields to browser including fields with |
| 79 // autocomplete=off | 105 // autocomplete=off |
| 80 form_structure.reset(new FormStructure(form)); | 106 form_structure.reset(new FormStructure(form)); |
| 81 EXPECT_EQ(4U, form_structure->field_count()); | 107 EXPECT_EQ(4U, form_structure->field_count()); |
| 82 } | 108 } |
| 83 | 109 |
| 84 TEST(FormStructureTest, AutofillCount) { | 110 TEST_F(FormStructureTest, AutofillCount) { |
| 85 scoped_ptr<FormStructure> form_structure; | 111 scoped_ptr<FormStructure> form_structure; |
| 86 FormData form; | 112 FormData form; |
| 87 | 113 |
| 88 FormFieldData field; | 114 FormFieldData field; |
| 89 field.label = ASCIIToUTF16("username"); | 115 field.label = ASCIIToUTF16("username"); |
| 90 field.name = ASCIIToUTF16("username"); | 116 field.name = ASCIIToUTF16("username"); |
| 91 field.form_control_type = "text"; | 117 field.form_control_type = "text"; |
| 92 form.fields.push_back(field); | 118 form.fields.push_back(field); |
| 93 | 119 |
| 94 field.label = ASCIIToUTF16("password"); | 120 field.label = ASCIIToUTF16("password"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 field.name = ASCIIToUTF16("address1"); | 153 field.name = ASCIIToUTF16("address1"); |
| 128 field.form_control_type = "text"; | 154 field.form_control_type = "text"; |
| 129 field.should_autocomplete = false; | 155 field.should_autocomplete = false; |
| 130 form.fields.push_back(field); | 156 form.fields.push_back(field); |
| 131 | 157 |
| 132 form_structure.reset(new FormStructure(form)); | 158 form_structure.reset(new FormStructure(form)); |
| 133 form_structure->DetermineHeuristicTypes(); | 159 form_structure->DetermineHeuristicTypes(); |
| 134 EXPECT_EQ(4U, form_structure->autofill_count()); | 160 EXPECT_EQ(4U, form_structure->autofill_count()); |
| 135 } | 161 } |
| 136 | 162 |
| 137 TEST(FormStructureTest, SourceURL) { | 163 TEST_F(FormStructureTest, SourceURL) { |
| 138 FormData form; | 164 FormData form; |
| 139 form.origin = GURL("http://www.foo.com/"); | 165 form.origin = GURL("http://www.foo.com/"); |
| 140 FormStructure form_structure(form); | 166 FormStructure form_structure(form); |
| 141 | 167 |
| 142 EXPECT_EQ(form.origin, form_structure.source_url()); | 168 EXPECT_EQ(form.origin, form_structure.source_url()); |
| 143 } | 169 } |
| 144 | 170 |
| 145 TEST(FormStructureTest, IsAutofillable) { | 171 TEST_F(FormStructureTest, IsAutofillable) { |
| 146 scoped_ptr<FormStructure> form_structure; | 172 scoped_ptr<FormStructure> form_structure; |
| 147 FormData form; | 173 FormData form; |
| 148 | 174 |
| 149 // We need at least three text fields to be auto-fillable. | 175 // We need at least three text fields to be auto-fillable. |
| 150 FormFieldData field; | 176 FormFieldData field; |
| 151 | 177 |
| 152 field.label = ASCIIToUTF16("username"); | 178 field.label = ASCIIToUTF16("username"); |
| 153 field.name = ASCIIToUTF16("username"); | 179 field.name = ASCIIToUTF16("username"); |
| 154 field.form_control_type = "text"; | 180 field.form_control_type = "text"; |
| 155 form.fields.push_back(field); | 181 form.fields.push_back(field); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 form_structure->DetermineHeuristicTypes(); | 225 form_structure->DetermineHeuristicTypes(); |
| 200 EXPECT_FALSE(form_structure->IsAutofillable()); | 226 EXPECT_FALSE(form_structure->IsAutofillable()); |
| 201 | 227 |
| 202 // But search can be in the URL. | 228 // But search can be in the URL. |
| 203 form.action = GURL("http://search.com/?q=hello"); | 229 form.action = GURL("http://search.com/?q=hello"); |
| 204 form_structure.reset(new FormStructure(form)); | 230 form_structure.reset(new FormStructure(form)); |
| 205 form_structure->DetermineHeuristicTypes(); | 231 form_structure->DetermineHeuristicTypes(); |
| 206 EXPECT_TRUE(form_structure->IsAutofillable()); | 232 EXPECT_TRUE(form_structure->IsAutofillable()); |
| 207 } | 233 } |
| 208 | 234 |
| 209 TEST(FormStructureTest, ShouldBeParsed) { | 235 TEST_F(FormStructureTest, ShouldBeParsed) { |
| 210 scoped_ptr<FormStructure> form_structure; | 236 scoped_ptr<FormStructure> form_structure; |
| 211 FormData form; | 237 FormData form; |
| 212 | 238 |
| 213 // We need at least three text fields to be parseable. | 239 // We need at least three text fields to be parseable. |
| 214 FormFieldData field; | 240 FormFieldData field; |
| 215 field.label = ASCIIToUTF16("username"); | 241 field.label = ASCIIToUTF16("username"); |
| 216 field.name = ASCIIToUTF16("username"); | 242 field.name = ASCIIToUTF16("username"); |
| 217 field.form_control_type = "text"; | 243 field.form_control_type = "text"; |
| 218 form.fields.push_back(field); | 244 form.fields.push_back(field); |
| 219 | 245 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 306 |
| 281 form_structure.reset(new FormStructure(form)); | 307 form_structure.reset(new FormStructure(form)); |
| 282 EXPECT_TRUE(form_structure->ShouldBeParsed()); | 308 EXPECT_TRUE(form_structure->ShouldBeParsed()); |
| 283 | 309 |
| 284 form.fields[0].form_control_type = "select-one"; | 310 form.fields[0].form_control_type = "select-one"; |
| 285 // Now, no text fields. | 311 // Now, no text fields. |
| 286 form_structure.reset(new FormStructure(form)); | 312 form_structure.reset(new FormStructure(form)); |
| 287 EXPECT_FALSE(form_structure->ShouldBeParsed()); | 313 EXPECT_FALSE(form_structure->ShouldBeParsed()); |
| 288 } | 314 } |
| 289 | 315 |
| 290 TEST(FormStructureTest, HeuristicsContactInfo) { | 316 TEST_F(FormStructureTest, HeuristicsContactInfo) { |
| 291 scoped_ptr<FormStructure> form_structure; | 317 scoped_ptr<FormStructure> form_structure; |
| 292 FormData form; | 318 FormData form; |
| 293 | 319 |
| 294 FormFieldData field; | 320 FormFieldData field; |
| 295 field.form_control_type = "text"; | 321 field.form_control_type = "text"; |
| 296 | 322 |
| 297 field.label = ASCIIToUTF16("First Name"); | 323 field.label = ASCIIToUTF16("First Name"); |
| 298 field.name = ASCIIToUTF16("firstname"); | 324 field.name = ASCIIToUTF16("firstname"); |
| 299 form.fields.push_back(field); | 325 form.fields.push_back(field); |
| 300 | 326 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); | 374 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); |
| 349 // City. | 375 // City. |
| 350 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); | 376 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); |
| 351 // Zip. | 377 // Zip. |
| 352 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); | 378 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); |
| 353 // Submit. | 379 // Submit. |
| 354 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); | 380 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); |
| 355 } | 381 } |
| 356 | 382 |
| 357 // Verify that we can correctly process the |autocomplete| attribute. | 383 // Verify that we can correctly process the |autocomplete| attribute. |
| 358 TEST(FormStructureTest, HeuristicsAutocompleteAttribute) { | 384 TEST_F(FormStructureTest, HeuristicsAutocompleteAttribute) { |
| 359 scoped_ptr<FormStructure> form_structure; | 385 scoped_ptr<FormStructure> form_structure; |
| 360 FormData form; | 386 FormData form; |
| 361 | 387 |
| 362 FormFieldData field; | 388 FormFieldData field; |
| 363 field.form_control_type = "text"; | 389 field.form_control_type = "text"; |
| 364 | 390 |
| 365 field.label = base::string16(); | 391 field.label = base::string16(); |
| 366 field.name = ASCIIToUTF16("field1"); | 392 field.name = ASCIIToUTF16("field1"); |
| 367 field.autocomplete_attribute = "given-name"; | 393 field.autocomplete_attribute = "given-name"; |
| 368 form.fields.push_back(field); | 394 form.fields.push_back(field); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 388 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); | 414 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); |
| 389 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); | 415 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); |
| 390 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); | 416 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); |
| 391 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 417 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 392 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 418 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 393 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 419 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| 394 } | 420 } |
| 395 | 421 |
| 396 // Verify that we can correctly process the 'autocomplete' attribute for phone | 422 // Verify that we can correctly process the 'autocomplete' attribute for phone |
| 397 // number types (especially phone prefixes and suffixes). | 423 // number types (especially phone prefixes and suffixes). |
| 398 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { | 424 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { |
| 399 scoped_ptr<FormStructure> form_structure; | 425 scoped_ptr<FormStructure> form_structure; |
| 400 FormData form; | 426 FormData form; |
| 401 | 427 |
| 402 FormFieldData field; | 428 FormFieldData field; |
| 403 field.form_control_type = "text"; | 429 field.form_control_type = "text"; |
| 404 | 430 |
| 405 field.label = base::string16(); | 431 field.label = base::string16(); |
| 406 field.name = ASCIIToUTF16("field1"); | 432 field.name = ASCIIToUTF16("field1"); |
| 407 field.autocomplete_attribute = "tel-local"; | 433 field.autocomplete_attribute = "tel-local"; |
| 408 form.fields.push_back(field); | 434 form.fields.push_back(field); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 430 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); | 456 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); |
| 431 EXPECT_EQ(AutofillField::PHONE_PREFIX, | 457 EXPECT_EQ(AutofillField::PHONE_PREFIX, |
| 432 form_structure->field(1)->phone_part()); | 458 form_structure->field(1)->phone_part()); |
| 433 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type()); | 459 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type()); |
| 434 EXPECT_EQ(AutofillField::PHONE_SUFFIX, | 460 EXPECT_EQ(AutofillField::PHONE_SUFFIX, |
| 435 form_structure->field(2)->phone_part()); | 461 form_structure->field(2)->phone_part()); |
| 436 } | 462 } |
| 437 | 463 |
| 438 // If at least one field includes type hints in the 'autocomplete' attribute, we | 464 // If at least one field includes type hints in the 'autocomplete' attribute, we |
| 439 // should not try to apply any other heuristics. | 465 // should not try to apply any other heuristics. |
| 440 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { | 466 TEST_F(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { |
| 441 scoped_ptr<FormStructure> form_structure; | 467 scoped_ptr<FormStructure> form_structure; |
| 442 FormData form; | 468 FormData form; |
| 443 | 469 |
| 444 // Start with a regular contact form. | 470 // Start with a regular contact form. |
| 445 FormFieldData field; | 471 FormFieldData field; |
| 446 field.form_control_type = "text"; | 472 field.form_control_type = "text"; |
| 447 | 473 |
| 448 field.label = ASCIIToUTF16("First Name"); | 474 field.label = ASCIIToUTF16("First Name"); |
| 449 field.name = ASCIIToUTF16("firstname"); | 475 field.name = ASCIIToUTF16("firstname"); |
| 450 form.fields.push_back(field); | 476 form.fields.push_back(field); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 481 | 507 |
| 482 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 508 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 483 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 509 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 484 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 510 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| 485 } | 511 } |
| 486 | 512 |
| 487 // Even with an 'autocomplete' attribute set, ShouldBeCrowdsourced() should | 513 // Even with an 'autocomplete' attribute set, ShouldBeCrowdsourced() should |
| 488 // return true if the structure contains a password field, since there are | 514 // 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 | 515 // no local heuristics to depend upon in this case. Fields will still not be |
| 490 // considered autofillable though. | 516 // considered autofillable though. |
| 491 TEST(FormStructureTest, PasswordFormShouldBeCrowdsourced) { | 517 TEST_F(FormStructureTest, PasswordFormShouldBeCrowdsourced) { |
| 492 FormData form; | 518 FormData form; |
| 493 | 519 |
| 494 // Start with a regular contact form. | 520 // Start with a regular contact form. |
| 495 FormFieldData field; | 521 FormFieldData field; |
| 496 field.form_control_type = "text"; | 522 field.form_control_type = "text"; |
| 497 | 523 |
| 498 field.label = ASCIIToUTF16("First Name"); | 524 field.label = ASCIIToUTF16("First Name"); |
| 499 field.name = ASCIIToUTF16("firstname"); | 525 field.name = ASCIIToUTF16("firstname"); |
| 500 form.fields.push_back(field); | 526 form.fields.push_back(field); |
| 501 | 527 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 513 field.form_control_type = "password"; | 539 field.form_control_type = "password"; |
| 514 form.fields.push_back(field); | 540 form.fields.push_back(field); |
| 515 | 541 |
| 516 FormStructure form_structure(form); | 542 FormStructure form_structure(form); |
| 517 form_structure.DetermineHeuristicTypes(); | 543 form_structure.DetermineHeuristicTypes(); |
| 518 EXPECT_TRUE(form_structure.ShouldBeCrowdsourced()); | 544 EXPECT_TRUE(form_structure.ShouldBeCrowdsourced()); |
| 519 } | 545 } |
| 520 | 546 |
| 521 // Verify that we can correctly process sections listed in the |autocomplete| | 547 // Verify that we can correctly process sections listed in the |autocomplete| |
| 522 // attribute. | 548 // attribute. |
| 523 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { | 549 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { |
| 524 FormData form; | 550 FormData form; |
| 525 | 551 |
| 526 FormFieldData field; | 552 FormFieldData field; |
| 527 field.form_control_type = "text"; | 553 field.form_control_type = "text"; |
| 528 | 554 |
| 529 // Some fields will have no section specified. These fall into the default | 555 // Some fields will have no section specified. These fall into the default |
| 530 // section. | 556 // section. |
| 531 field.autocomplete_attribute = "email"; | 557 field.autocomplete_attribute = "email"; |
| 532 form.fields.push_back(field); | 558 form.fields.push_back(field); |
| 533 | 559 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // sections. | 602 // sections. |
| 577 std::set<std::string> section_names; | 603 std::set<std::string> section_names; |
| 578 for (size_t i = 0; i < 9; ++i) { | 604 for (size_t i = 0; i < 9; ++i) { |
| 579 section_names.insert(form_structure.field(i)->section()); | 605 section_names.insert(form_structure.field(i)->section()); |
| 580 } | 606 } |
| 581 EXPECT_EQ(9U, section_names.size()); | 607 EXPECT_EQ(9U, section_names.size()); |
| 582 } | 608 } |
| 583 | 609 |
| 584 // Verify that we can correctly process a degenerate section listed in the | 610 // Verify that we can correctly process a degenerate section listed in the |
| 585 // |autocomplete| attribute. | 611 // |autocomplete| attribute. |
| 586 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsDegenerate) { | 612 TEST_F(FormStructureTest, |
| 613 HeuristicsAutocompleteAttributeWithSectionsDegenerate) { |
| 587 FormData form; | 614 FormData form; |
| 588 | 615 |
| 589 FormFieldData field; | 616 FormFieldData field; |
| 590 field.form_control_type = "text"; | 617 field.form_control_type = "text"; |
| 591 | 618 |
| 592 // Some fields will have no section specified. These fall into the default | 619 // Some fields will have no section specified. These fall into the default |
| 593 // section. | 620 // section. |
| 594 field.autocomplete_attribute = "email"; | 621 field.autocomplete_attribute = "email"; |
| 595 form.fields.push_back(field); | 622 form.fields.push_back(field); |
| 596 | 623 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 619 // section. | 646 // section. |
| 620 std::set<std::string> section_names; | 647 std::set<std::string> section_names; |
| 621 for (size_t i = 0; i < 6; ++i) { | 648 for (size_t i = 0; i < 6; ++i) { |
| 622 section_names.insert(form_structure.field(i)->section()); | 649 section_names.insert(form_structure.field(i)->section()); |
| 623 } | 650 } |
| 624 EXPECT_EQ(1U, section_names.size()); | 651 EXPECT_EQ(1U, section_names.size()); |
| 625 } | 652 } |
| 626 | 653 |
| 627 // Verify that we can correctly process repeated sections listed in the | 654 // Verify that we can correctly process repeated sections listed in the |
| 628 // |autocomplete| attribute. | 655 // |autocomplete| attribute. |
| 629 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { | 656 TEST_F(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
| 630 FormData form; | 657 FormData form; |
| 631 | 658 |
| 632 FormFieldData field; | 659 FormFieldData field; |
| 633 field.form_control_type = "text"; | 660 field.form_control_type = "text"; |
| 634 | 661 |
| 635 field.autocomplete_attribute = "section-foo email"; | 662 field.autocomplete_attribute = "section-foo email"; |
| 636 form.fields.push_back(field); | 663 form.fields.push_back(field); |
| 637 field.autocomplete_attribute = "section-foo address-line1"; | 664 field.autocomplete_attribute = "section-foo address-line1"; |
| 638 form.fields.push_back(field); | 665 form.fields.push_back(field); |
| 639 | 666 |
| 640 FormStructure form_structure(form); | 667 FormStructure form_structure(form); |
| 641 form_structure.DetermineHeuristicTypes(); | 668 form_structure.DetermineHeuristicTypes(); |
| 642 | 669 |
| 643 // Expect the correct number of fields. | 670 // Expect the correct number of fields. |
| 644 ASSERT_EQ(2U, form_structure.field_count()); | 671 ASSERT_EQ(2U, form_structure.field_count()); |
| 645 EXPECT_EQ(2U, form_structure.autofill_count()); | 672 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 646 | 673 |
| 647 // All of the fields in this form should be parsed as belonging to the same | 674 // All of the fields in this form should be parsed as belonging to the same |
| 648 // section. | 675 // section. |
| 649 std::set<std::string> section_names; | 676 std::set<std::string> section_names; |
| 650 for (size_t i = 0; i < 2; ++i) { | 677 for (size_t i = 0; i < 2; ++i) { |
| 651 section_names.insert(form_structure.field(i)->section()); | 678 section_names.insert(form_structure.field(i)->section()); |
| 652 } | 679 } |
| 653 EXPECT_EQ(1U, section_names.size()); | 680 EXPECT_EQ(1U, section_names.size()); |
| 654 } | 681 } |
| 655 | 682 |
| 656 // Verify that we do not override the author-specified sections from a form with | 683 // Verify that we do not override the author-specified sections from a form with |
| 657 // local heuristics. | 684 // local heuristics. |
| 658 TEST(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { | 685 TEST_F(FormStructureTest, HeuristicsDontOverrideAutocompleteAttributeSections) { |
| 659 FormData form; | 686 FormData form; |
| 660 | 687 |
| 661 FormFieldData field; | 688 FormFieldData field; |
| 662 field.form_control_type = "text"; | 689 field.form_control_type = "text"; |
| 663 | 690 |
| 664 field.name = ASCIIToUTF16("one"); | 691 field.name = ASCIIToUTF16("one"); |
| 665 field.autocomplete_attribute = "address-line1"; | 692 field.autocomplete_attribute = "address-line1"; |
| 666 form.fields.push_back(field); | 693 form.fields.push_back(field); |
| 667 field.name = base::string16(); | 694 field.name = base::string16(); |
| 668 field.autocomplete_attribute = "section-foo email"; | 695 field.autocomplete_attribute = "section-foo email"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 683 | 710 |
| 684 // Normally, the two separate address fields would cause us to detect two | 711 // Normally, the two separate address fields would cause us to detect two |
| 685 // separate sections; but because there is an author-specified section in this | 712 // separate sections; but because there is an author-specified section in this |
| 686 // form, we do not apply these usual heuristics. | 713 // form, we do not apply these usual heuristics. |
| 687 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); | 714 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); |
| 688 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name); | 715 EXPECT_EQ(ASCIIToUTF16("two"), form_structure.field(3)->name); |
| 689 EXPECT_EQ(form_structure.field(0)->section(), | 716 EXPECT_EQ(form_structure.field(0)->section(), |
| 690 form_structure.field(3)->section()); | 717 form_structure.field(3)->section()); |
| 691 } | 718 } |
| 692 | 719 |
| 693 TEST(FormStructureTest, HeuristicsSample8) { | 720 TEST_F(FormStructureTest, HeuristicsSample8) { |
| 694 scoped_ptr<FormStructure> form_structure; | 721 scoped_ptr<FormStructure> form_structure; |
| 695 FormData form; | 722 FormData form; |
| 696 | 723 |
| 697 FormFieldData field; | 724 FormFieldData field; |
| 698 field.form_control_type = "text"; | 725 field.form_control_type = "text"; |
| 699 | 726 |
| 700 field.label = ASCIIToUTF16("Your First Name:"); | 727 field.label = ASCIIToUTF16("Your First Name:"); |
| 701 field.name = ASCIIToUTF16("bill.first"); | 728 field.name = ASCIIToUTF16("bill.first"); |
| 702 form.fields.push_back(field); | 729 form.fields.push_back(field); |
| 703 | 730 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); | 787 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); |
| 761 // Country. | 788 // Country. |
| 762 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); | 789 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); |
| 763 // Phone. | 790 // Phone. |
| 764 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 791 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| 765 form_structure->field(8)->heuristic_type()); | 792 form_structure->field(8)->heuristic_type()); |
| 766 // Submit. | 793 // Submit. |
| 767 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); | 794 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type()); |
| 768 } | 795 } |
| 769 | 796 |
| 770 TEST(FormStructureTest, HeuristicsSample6) { | 797 TEST_F(FormStructureTest, HeuristicsSample6) { |
| 771 scoped_ptr<FormStructure> form_structure; | 798 scoped_ptr<FormStructure> form_structure; |
| 772 FormData form; | 799 FormData form; |
| 773 | 800 |
| 774 FormFieldData field; | 801 FormFieldData field; |
| 775 field.form_control_type = "text"; | 802 field.form_control_type = "text"; |
| 776 | 803 |
| 777 field.label = ASCIIToUTF16("E-mail address"); | 804 field.label = ASCIIToUTF16("E-mail address"); |
| 778 field.name = ASCIIToUTF16("email"); | 805 field.name = ASCIIToUTF16("email"); |
| 779 form.fields.push_back(field); | 806 form.fields.push_back(field); |
| 780 | 807 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); | 849 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type()); |
| 823 // Zip. | 850 // Zip. |
| 824 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); | 851 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(5)->heuristic_type()); |
| 825 // Submit. | 852 // Submit. |
| 826 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); | 853 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); |
| 827 } | 854 } |
| 828 | 855 |
| 829 // Tests a sequence of FormFields where only labels are supplied to heuristics | 856 // Tests a sequence of FormFields where only labels are supplied to heuristics |
| 830 // for matching. This works because FormFieldData labels are matched in the | 857 // for matching. This works because FormFieldData labels are matched in the |
| 831 // case that input element ids (or |name| fields) are missing. | 858 // case that input element ids (or |name| fields) are missing. |
| 832 TEST(FormStructureTest, HeuristicsLabelsOnly) { | 859 TEST_F(FormStructureTest, HeuristicsLabelsOnly) { |
| 833 scoped_ptr<FormStructure> form_structure; | 860 scoped_ptr<FormStructure> form_structure; |
| 834 FormData form; | 861 FormData form; |
| 835 | 862 |
| 836 FormFieldData field; | 863 FormFieldData field; |
| 837 field.form_control_type = "text"; | 864 field.form_control_type = "text"; |
| 838 | 865 |
| 839 field.label = ASCIIToUTF16("First Name"); | 866 field.label = ASCIIToUTF16("First Name"); |
| 840 field.name = base::string16(); | 867 field.name = base::string16(); |
| 841 form.fields.push_back(field); | 868 form.fields.push_back(field); |
| 842 | 869 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 // Address. | 914 // Address. |
| 888 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); | 915 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(4)->heuristic_type()); |
| 889 // Address Line 2. | 916 // Address Line 2. |
| 890 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type()); | 917 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(5)->heuristic_type()); |
| 891 // Zip. | 918 // Zip. |
| 892 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); | 919 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type()); |
| 893 // Submit. | 920 // Submit. |
| 894 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); | 921 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type()); |
| 895 } | 922 } |
| 896 | 923 |
| 897 TEST(FormStructureTest, HeuristicsCreditCardInfo) { | 924 TEST_F(FormStructureTest, HeuristicsCreditCardInfo) { |
| 898 scoped_ptr<FormStructure> form_structure; | 925 scoped_ptr<FormStructure> form_structure; |
| 899 FormData form; | 926 FormData form; |
| 900 | 927 |
| 901 FormFieldData field; | 928 FormFieldData field; |
| 902 field.form_control_type = "text"; | 929 field.form_control_type = "text"; |
| 903 | 930 |
| 904 field.label = ASCIIToUTF16("Name on Card"); | 931 field.label = ASCIIToUTF16("Name on Card"); |
| 905 field.name = ASCIIToUTF16("name_on_card"); | 932 field.name = ASCIIToUTF16("name_on_card"); |
| 906 form.fields.push_back(field); | 933 form.fields.push_back(field); |
| 907 | 934 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 // Credit card expiration year. | 968 // Credit card expiration year. |
| 942 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 969 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 943 form_structure->field(3)->heuristic_type()); | 970 form_structure->field(3)->heuristic_type()); |
| 944 // CVV. | 971 // CVV. |
| 945 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | 972 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, |
| 946 form_structure->field(4)->heuristic_type()); | 973 form_structure->field(4)->heuristic_type()); |
| 947 // Submit. | 974 // Submit. |
| 948 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); | 975 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(5)->heuristic_type()); |
| 949 } | 976 } |
| 950 | 977 |
| 951 TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { | 978 TEST_F(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) { |
| 952 scoped_ptr<FormStructure> form_structure; | 979 scoped_ptr<FormStructure> form_structure; |
| 953 FormData form; | 980 FormData form; |
| 954 | 981 |
| 955 FormFieldData field; | 982 FormFieldData field; |
| 956 field.form_control_type = "text"; | 983 field.form_control_type = "text"; |
| 957 | 984 |
| 958 field.label = ASCIIToUTF16("Name on Card"); | 985 field.label = ASCIIToUTF16("Name on Card"); |
| 959 field.name = ASCIIToUTF16("name_on_card"); | 986 field.name = ASCIIToUTF16("name_on_card"); |
| 960 form.fields.push_back(field); | 987 form.fields.push_back(field); |
| 961 | 988 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 // Credit card expiration year. | 1030 // Credit card expiration year. |
| 1004 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1031 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1005 form_structure->field(4)->heuristic_type()); | 1032 form_structure->field(4)->heuristic_type()); |
| 1006 // CVV. | 1033 // CVV. |
| 1007 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | 1034 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, |
| 1008 form_structure->field(5)->heuristic_type()); | 1035 form_structure->field(5)->heuristic_type()); |
| 1009 // Submit. | 1036 // Submit. |
| 1010 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); | 1037 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type()); |
| 1011 } | 1038 } |
| 1012 | 1039 |
| 1013 TEST(FormStructureTest, ThreeAddressLines) { | 1040 TEST_F(FormStructureTest, ThreeAddressLines) { |
| 1014 scoped_ptr<FormStructure> form_structure; | 1041 scoped_ptr<FormStructure> form_structure; |
| 1015 FormData form; | 1042 FormData form; |
| 1016 | 1043 |
| 1017 FormFieldData field; | 1044 FormFieldData field; |
| 1018 field.form_control_type = "text"; | 1045 field.form_control_type = "text"; |
| 1019 | 1046 |
| 1020 field.label = ASCIIToUTF16("Address Line1"); | 1047 field.label = ASCIIToUTF16("Address Line1"); |
| 1021 field.name = ASCIIToUTF16("Address"); | 1048 field.name = ASCIIToUTF16("Address"); |
| 1022 form.fields.push_back(field); | 1049 form.fields.push_back(field); |
| 1023 | 1050 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1043 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1070 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1044 // Address Line 2. | 1071 // Address Line 2. |
| 1045 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1072 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1046 // Address Line 3. | 1073 // Address Line 3. |
| 1047 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); | 1074 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); |
| 1048 // City. | 1075 // City. |
| 1049 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); | 1076 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); |
| 1050 } | 1077 } |
| 1051 | 1078 |
| 1052 // Numbered address lines after line two are ignored. | 1079 // Numbered address lines after line two are ignored. |
| 1053 TEST(FormStructureTest, SurplusAddressLinesIgnored) { | 1080 TEST_F(FormStructureTest, SurplusAddressLinesIgnored) { |
| 1054 scoped_ptr<FormStructure> form_structure; | 1081 scoped_ptr<FormStructure> form_structure; |
| 1055 FormData form; | 1082 FormData form; |
| 1056 | 1083 |
| 1057 FormFieldData field; | 1084 FormFieldData field; |
| 1058 field.form_control_type = "text"; | 1085 field.form_control_type = "text"; |
| 1059 | 1086 |
| 1060 field.label = ASCIIToUTF16("Address Line1"); | 1087 field.label = ASCIIToUTF16("Address Line1"); |
| 1061 field.name = ASCIIToUTF16("shipping.address.addressLine1"); | 1088 field.name = ASCIIToUTF16("shipping.address.addressLine1"); |
| 1062 form.fields.push_back(field); | 1089 form.fields.push_back(field); |
| 1063 | 1090 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1086 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); | 1113 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); |
| 1087 // Address Line 4 (ignored). | 1114 // Address Line 4 (ignored). |
| 1088 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); | 1115 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); |
| 1089 } | 1116 } |
| 1090 | 1117 |
| 1091 // This example comes from expedia.com where they used to use a "Suite" label | 1118 // This example comes from expedia.com where they used to use a "Suite" label |
| 1092 // to indicate a suite or apartment number (the form has changed since this | 1119 // to indicate a suite or apartment number (the form has changed since this |
| 1093 // test was written). We interpret this as address line 2. And the following | 1120 // test was written). We interpret this as address line 2. And the following |
| 1094 // "Street address second line" we interpret as address line 3. | 1121 // "Street address second line" we interpret as address line 3. |
| 1095 // See http://crbug.com/48197 for details. | 1122 // See http://crbug.com/48197 for details. |
| 1096 TEST(FormStructureTest, ThreeAddressLinesExpedia) { | 1123 TEST_F(FormStructureTest, ThreeAddressLinesExpedia) { |
| 1097 scoped_ptr<FormStructure> form_structure; | 1124 scoped_ptr<FormStructure> form_structure; |
| 1098 FormData form; | 1125 FormData form; |
| 1099 | 1126 |
| 1100 FormFieldData field; | 1127 FormFieldData field; |
| 1101 field.form_control_type = "text"; | 1128 field.form_control_type = "text"; |
| 1102 | 1129 |
| 1103 field.label = ASCIIToUTF16("Street:"); | 1130 field.label = ASCIIToUTF16("Street:"); |
| 1104 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"); | 1131 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads1"); |
| 1105 form.fields.push_back(field); | 1132 form.fields.push_back(field); |
| 1106 | 1133 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1128 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1155 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1129 // Address Line 3. | 1156 // Address Line 3. |
| 1130 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); | 1157 EXPECT_EQ(ADDRESS_HOME_LINE3, form_structure->field(2)->heuristic_type()); |
| 1131 // City. | 1158 // City. |
| 1132 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); | 1159 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(3)->heuristic_type()); |
| 1133 } | 1160 } |
| 1134 | 1161 |
| 1135 // This example comes from ebay.com where the word "suite" appears in the label | 1162 // This example comes from ebay.com where the word "suite" appears in the label |
| 1136 // and the name "address2" clearly indicates that this is the address line 2. | 1163 // and the name "address2" clearly indicates that this is the address line 2. |
| 1137 // See http://crbug.com/48197 for details. | 1164 // See http://crbug.com/48197 for details. |
| 1138 TEST(FormStructureTest, TwoAddressLinesEbay) { | 1165 TEST_F(FormStructureTest, TwoAddressLinesEbay) { |
| 1139 scoped_ptr<FormStructure> form_structure; | 1166 scoped_ptr<FormStructure> form_structure; |
| 1140 FormData form; | 1167 FormData form; |
| 1141 | 1168 |
| 1142 FormFieldData field; | 1169 FormFieldData field; |
| 1143 field.form_control_type = "text"; | 1170 field.form_control_type = "text"; |
| 1144 | 1171 |
| 1145 field.label = ASCIIToUTF16("Address Line1"); | 1172 field.label = ASCIIToUTF16("Address Line1"); |
| 1146 field.name = ASCIIToUTF16("address1"); | 1173 field.name = ASCIIToUTF16("address1"); |
| 1147 form.fields.push_back(field); | 1174 form.fields.push_back(field); |
| 1148 | 1175 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1161 ASSERT_EQ(3U, form_structure->autofill_count()); | 1188 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1162 | 1189 |
| 1163 // Address Line 1. | 1190 // Address Line 1. |
| 1164 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1191 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1165 // Address Line 2. | 1192 // Address Line 2. |
| 1166 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1193 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1167 // City. | 1194 // City. |
| 1168 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); | 1195 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(2)->heuristic_type()); |
| 1169 } | 1196 } |
| 1170 | 1197 |
| 1171 TEST(FormStructureTest, HeuristicsStateWithProvince) { | 1198 TEST_F(FormStructureTest, HeuristicsStateWithProvince) { |
| 1172 scoped_ptr<FormStructure> form_structure; | 1199 scoped_ptr<FormStructure> form_structure; |
| 1173 FormData form; | 1200 FormData form; |
| 1174 | 1201 |
| 1175 FormFieldData field; | 1202 FormFieldData field; |
| 1176 field.form_control_type = "text"; | 1203 field.form_control_type = "text"; |
| 1177 | 1204 |
| 1178 field.label = ASCIIToUTF16("Address Line1"); | 1205 field.label = ASCIIToUTF16("Address Line1"); |
| 1179 field.name = ASCIIToUTF16("Address"); | 1206 field.name = ASCIIToUTF16("Address"); |
| 1180 form.fields.push_back(field); | 1207 form.fields.push_back(field); |
| 1181 | 1208 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1195 | 1222 |
| 1196 // Address Line 1. | 1223 // Address Line 1. |
| 1197 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1224 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1198 // Address Line 2. | 1225 // Address Line 2. |
| 1199 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1226 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1200 // State. | 1227 // State. |
| 1201 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); | 1228 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(2)->heuristic_type()); |
| 1202 } | 1229 } |
| 1203 | 1230 |
| 1204 // This example comes from lego.com's checkout page. | 1231 // This example comes from lego.com's checkout page. |
| 1205 TEST(FormStructureTest, HeuristicsWithBilling) { | 1232 TEST_F(FormStructureTest, HeuristicsWithBilling) { |
| 1206 scoped_ptr<FormStructure> form_structure; | 1233 scoped_ptr<FormStructure> form_structure; |
| 1207 FormData form; | 1234 FormData form; |
| 1208 | 1235 |
| 1209 FormFieldData field; | 1236 FormFieldData field; |
| 1210 field.form_control_type = "text"; | 1237 field.form_control_type = "text"; |
| 1211 | 1238 |
| 1212 field.label = ASCIIToUTF16("First Name*:"); | 1239 field.label = ASCIIToUTF16("First Name*:"); |
| 1213 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox"); | 1240 field.name = ASCIIToUTF16("editBillingAddress$firstNameBox"); |
| 1214 form.fields.push_back(field); | 1241 form.fields.push_back(field); |
| 1215 | 1242 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(4)->heuristic_type()); | 1293 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(4)->heuristic_type()); |
| 1267 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); | 1294 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(5)->heuristic_type()); |
| 1268 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type()); | 1295 EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(6)->heuristic_type()); |
| 1269 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); | 1296 EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type()); |
| 1270 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type()); | 1297 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(8)->heuristic_type()); |
| 1271 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 1298 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| 1272 form_structure->field(9)->heuristic_type()); | 1299 form_structure->field(9)->heuristic_type()); |
| 1273 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); | 1300 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(10)->heuristic_type()); |
| 1274 } | 1301 } |
| 1275 | 1302 |
| 1276 TEST(FormStructureTest, ThreePartPhoneNumber) { | 1303 TEST_F(FormStructureTest, ThreePartPhoneNumber) { |
| 1277 scoped_ptr<FormStructure> form_structure; | 1304 scoped_ptr<FormStructure> form_structure; |
| 1278 FormData form; | 1305 FormData form; |
| 1279 | 1306 |
| 1280 FormFieldData field; | 1307 FormFieldData field; |
| 1281 field.form_control_type = "text"; | 1308 field.form_control_type = "text"; |
| 1282 | 1309 |
| 1283 field.label = ASCIIToUTF16("Phone:"); | 1310 field.label = ASCIIToUTF16("Phone:"); |
| 1284 field.name = ASCIIToUTF16("dayphone1"); | 1311 field.name = ASCIIToUTF16("dayphone1"); |
| 1285 field.max_length = 0; | 1312 field.max_length = 0; |
| 1286 form.fields.push_back(field); | 1313 form.fields.push_back(field); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1313 // Phone number suffix. | 1340 // Phone number suffix. |
| 1314 EXPECT_EQ(PHONE_HOME_NUMBER, | 1341 EXPECT_EQ(PHONE_HOME_NUMBER, |
| 1315 form_structure->field(1)->heuristic_type()); | 1342 form_structure->field(1)->heuristic_type()); |
| 1316 // Phone number suffix. | 1343 // Phone number suffix. |
| 1317 EXPECT_EQ(PHONE_HOME_NUMBER, | 1344 EXPECT_EQ(PHONE_HOME_NUMBER, |
| 1318 form_structure->field(2)->heuristic_type()); | 1345 form_structure->field(2)->heuristic_type()); |
| 1319 // Unknown. | 1346 // Unknown. |
| 1320 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); | 1347 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type()); |
| 1321 } | 1348 } |
| 1322 | 1349 |
| 1323 TEST(FormStructureTest, HeuristicsInfernoCC) { | 1350 TEST_F(FormStructureTest, HeuristicsInfernoCC) { |
| 1324 scoped_ptr<FormStructure> form_structure; | 1351 scoped_ptr<FormStructure> form_structure; |
| 1325 FormData form; | 1352 FormData form; |
| 1326 | 1353 |
| 1327 FormFieldData field; | 1354 FormFieldData field; |
| 1328 field.form_control_type = "text"; | 1355 field.form_control_type = "text"; |
| 1329 | 1356 |
| 1330 field.label = ASCIIToUTF16("Name on Card"); | 1357 field.label = ASCIIToUTF16("Name on Card"); |
| 1331 field.name = ASCIIToUTF16("name_on_card"); | 1358 field.name = ASCIIToUTF16("name_on_card"); |
| 1332 form.fields.push_back(field); | 1359 form.fields.push_back(field); |
| 1333 | 1360 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1361 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); | 1388 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(1)->heuristic_type()); |
| 1362 // Card Number. | 1389 // Card Number. |
| 1363 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); | 1390 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type()); |
| 1364 // Expiration Date. | 1391 // Expiration Date. |
| 1365 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | 1392 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); |
| 1366 // Expiration Year. | 1393 // Expiration Year. |
| 1367 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1394 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1368 form_structure->field(4)->heuristic_type()); | 1395 form_structure->field(4)->heuristic_type()); |
| 1369 } | 1396 } |
| 1370 | 1397 |
| 1371 TEST(FormStructureTest, CVCCodeClash) { | 1398 TEST_F(FormStructureTest, CVCCodeClash) { |
| 1372 scoped_ptr<FormStructure> form_structure; | 1399 scoped_ptr<FormStructure> form_structure; |
| 1373 FormData form; | 1400 FormData form; |
| 1374 | 1401 |
| 1375 FormFieldData field; | 1402 FormFieldData field; |
| 1376 field.form_control_type = "text"; | 1403 field.form_control_type = "text"; |
| 1377 | 1404 |
| 1378 field.label = ASCIIToUTF16("Card number"); | 1405 field.label = ASCIIToUTF16("Card number"); |
| 1379 field.name = ASCIIToUTF16("ccnumber"); | 1406 field.name = ASCIIToUTF16("ccnumber"); |
| 1380 form.fields.push_back(field); | 1407 form.fields.push_back(field); |
| 1381 | 1408 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 // Expiration Date. | 1443 // Expiration Date. |
| 1417 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); | 1444 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type()); |
| 1418 // Expiration Year. | 1445 // Expiration Year. |
| 1419 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1446 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1420 form_structure->field(4)->heuristic_type()); | 1447 form_structure->field(4)->heuristic_type()); |
| 1421 // CVC code. | 1448 // CVC code. |
| 1422 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, | 1449 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, |
| 1423 form_structure->field(5)->heuristic_type()); | 1450 form_structure->field(5)->heuristic_type()); |
| 1424 } | 1451 } |
| 1425 | 1452 |
| 1426 TEST(FormStructureTest, EncodeQueryRequest) { | 1453 TEST_F(FormStructureTest, EncodeQueryRequest) { |
| 1427 FormData form; | 1454 FormData form; |
| 1428 | 1455 |
| 1429 FormFieldData field; | 1456 FormFieldData field; |
| 1430 field.form_control_type = "text"; | 1457 field.form_control_type = "text"; |
| 1431 | 1458 |
| 1432 field.label = ASCIIToUTF16("Name on Card"); | 1459 field.label = ASCIIToUTF16("Name on Card"); |
| 1433 field.name = ASCIIToUTF16("name_on_card"); | 1460 field.name = ASCIIToUTF16("name_on_card"); |
| 1434 form.fields.push_back(field); | 1461 form.fields.push_back(field); |
| 1435 | 1462 |
| 1436 field.label = ASCIIToUTF16("Address"); | 1463 field.label = ASCIIToUTF16("Address"); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 // Check that we fail if there are only bad form(s). | 1571 // Check that we fail if there are only bad form(s). |
| 1545 ScopedVector<FormStructure> bad_forms; | 1572 ScopedVector<FormStructure> bad_forms; |
| 1546 bad_forms.push_back(new FormStructure(malformed_form)); | 1573 bad_forms.push_back(new FormStructure(malformed_form)); |
| 1547 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1574 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
| 1548 &encoded_signatures, | 1575 &encoded_signatures, |
| 1549 &encoded_xml)); | 1576 &encoded_xml)); |
| 1550 EXPECT_EQ(0U, encoded_signatures.size()); | 1577 EXPECT_EQ(0U, encoded_signatures.size()); |
| 1551 EXPECT_EQ("", encoded_xml); | 1578 EXPECT_EQ("", encoded_xml); |
| 1552 } | 1579 } |
| 1553 | 1580 |
| 1554 TEST(FormStructureTest, EncodeUploadRequest) { | 1581 TEST_F(FormStructureTest, EncodeUploadRequest) { |
| 1555 scoped_ptr<FormStructure> form_structure; | 1582 scoped_ptr<FormStructure> form_structure; |
| 1556 std::vector<ServerFieldTypeSet> possible_field_types; | 1583 std::vector<ServerFieldTypeSet> possible_field_types; |
| 1557 FormData form; | 1584 FormData form; |
| 1558 form_structure.reset(new FormStructure(form)); | 1585 form_structure.reset(new FormStructure(form)); |
| 1559 form_structure->DetermineHeuristicTypes(); | 1586 form_structure->DetermineHeuristicTypes(); |
| 1560 | 1587 |
| 1561 FormFieldData field; | 1588 FormFieldData field; |
| 1562 field.form_control_type = "text"; | 1589 field.form_control_type = "text"; |
| 1563 | 1590 |
| 1564 field.label = ASCIIToUTF16("First Name"); | 1591 field.label = ASCIIToUTF16("First Name"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1748 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
| 1722 } | 1749 } |
| 1723 form_structure.reset(new FormStructure(form)); | 1750 form_structure.reset(new FormStructure(form)); |
| 1724 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1751 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1725 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1752 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1726 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1753 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1727 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, | 1754 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 1728 &encoded_xml)); | 1755 &encoded_xml)); |
| 1729 } | 1756 } |
| 1730 | 1757 |
| 1731 TEST(FormStructureTest, EncodeUploadRequestWithAutocomplete) { | 1758 TEST_F(FormStructureTest, EncodeUploadRequestWithAutocomplete) { |
| 1732 scoped_ptr<FormStructure> form_structure; | 1759 scoped_ptr<FormStructure> form_structure; |
| 1733 std::vector<ServerFieldTypeSet> possible_field_types; | 1760 std::vector<ServerFieldTypeSet> possible_field_types; |
| 1734 FormData form; | 1761 FormData form; |
| 1735 form_structure.reset(new FormStructure(form)); | 1762 form_structure.reset(new FormStructure(form)); |
| 1736 form_structure->DetermineHeuristicTypes(); | 1763 form_structure->DetermineHeuristicTypes(); |
| 1737 | 1764 |
| 1738 FormFieldData field; | 1765 FormFieldData field; |
| 1739 field.form_control_type = "text"; | 1766 field.form_control_type = "text"; |
| 1740 | 1767 |
| 1741 field.label = ASCIIToUTF16("First Name"); | 1768 field.label = ASCIIToUTF16("First Name"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 " datapresent=\"1440\">" | 1807 " datapresent=\"1440\">" |
| 1781 "<field signature=\"3763331450\" name=\"firstname\" type=\"text\"" | 1808 "<field signature=\"3763331450\" name=\"firstname\" type=\"text\"" |
| 1782 " autocomplete=\"given-name\" autofilltype=\"3\"/>" | 1809 " autocomplete=\"given-name\" autofilltype=\"3\"/>" |
| 1783 "<field signature=\"3494530716\" name=\"lastname\" type=\"text\"" | 1810 "<field signature=\"3494530716\" name=\"lastname\" type=\"text\"" |
| 1784 " autocomplete=\"family-name\" autofilltype=\"5\"/>" | 1811 " autocomplete=\"family-name\" autofilltype=\"5\"/>" |
| 1785 "<field signature=\"1029417091\" name=\"email\" type=\"email\"" | 1812 "<field signature=\"1029417091\" name=\"email\" type=\"email\"" |
| 1786 " autocomplete=\"email\" autofilltype=\"9\"/></autofillupload>", | 1813 " autocomplete=\"email\" autofilltype=\"9\"/></autofillupload>", |
| 1787 encoded_xml); | 1814 encoded_xml); |
| 1788 } | 1815 } |
| 1789 | 1816 |
| 1790 TEST(FormStructureTest, EncodeUploadRequestPartialMetadata) { | 1817 TEST_F(FormStructureTest, EncodeUploadRequestPartialMetadata) { |
| 1791 scoped_ptr<FormStructure> form_structure; | 1818 scoped_ptr<FormStructure> form_structure; |
| 1792 std::vector<ServerFieldTypeSet> possible_field_types; | 1819 std::vector<ServerFieldTypeSet> possible_field_types; |
| 1793 FormData form; | 1820 FormData form; |
| 1794 form_structure.reset(new FormStructure(form)); | 1821 form_structure.reset(new FormStructure(form)); |
| 1795 form_structure->DetermineHeuristicTypes(); | 1822 form_structure->DetermineHeuristicTypes(); |
| 1796 | 1823 |
| 1797 FormFieldData field; | 1824 FormFieldData field; |
| 1798 field.form_control_type = "text"; | 1825 field.form_control_type = "text"; |
| 1799 | 1826 |
| 1800 // Some fields don't have "name" or "autocomplete" attributes, and some have | 1827 // Some fields don't have "name" or "autocomplete" attributes, and some have |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 " formsignature=\"13043654279838250996\" autofillused=\"true\"" | 1864 " formsignature=\"13043654279838250996\" autofillused=\"true\"" |
| 1838 " datapresent=\"1440\">" | 1865 " datapresent=\"1440\">" |
| 1839 "<field signature=\"1318412689\" type=\"text\" autofilltype=\"3\"/>" | 1866 "<field signature=\"1318412689\" type=\"text\" autofilltype=\"3\"/>" |
| 1840 "<field signature=\"3494530716\" name=\"lastname\" type=\"text\"" | 1867 "<field signature=\"3494530716\" name=\"lastname\" type=\"text\"" |
| 1841 " autocomplete=\"family-name\" autofilltype=\"5\"/>" | 1868 " autocomplete=\"family-name\" autofilltype=\"5\"/>" |
| 1842 "<field signature=\"1545468175\" name=\"lastname\" type=\"email\"" | 1869 "<field signature=\"1545468175\" name=\"lastname\" type=\"email\"" |
| 1843 " autocomplete=\"email\" autofilltype=\"9\"/></autofillupload>", | 1870 " autocomplete=\"email\" autofilltype=\"9\"/></autofillupload>", |
| 1844 encoded_xml); | 1871 encoded_xml); |
| 1845 } | 1872 } |
| 1846 | 1873 |
| 1847 TEST(FormStructureTest, EncodeFieldAssignments) { | 1874 // Sending field metadata to the server is disabled. |
| 1875 TEST_F(FormStructureTest, EncodeUploadRequest_DisabledMetadataTrial) { |
| 1876 DisableAutofillMetadataFieldTrial(); |
| 1877 |
| 1848 scoped_ptr<FormStructure> form_structure; | 1878 scoped_ptr<FormStructure> form_structure; |
| 1849 std::vector<ServerFieldTypeSet> possible_field_types; | 1879 std::vector<ServerFieldTypeSet> possible_field_types; |
| 1850 FormData form; | 1880 FormData form; |
| 1881 form_structure.reset(new FormStructure(form)); |
| 1882 form_structure->DetermineHeuristicTypes(); |
| 1883 |
| 1884 FormFieldData field; |
| 1885 field.form_control_type = "text"; |
| 1886 |
| 1887 field.label = ASCIIToUTF16("First Name"); |
| 1888 field.name = ASCIIToUTF16("firstname"); |
| 1889 field.autocomplete_attribute = "given-name"; |
| 1890 form.fields.push_back(field); |
| 1891 possible_field_types.push_back(ServerFieldTypeSet()); |
| 1892 possible_field_types.back().insert(NAME_FIRST); |
| 1893 |
| 1894 field.label = ASCIIToUTF16("Last Name"); |
| 1895 field.name = ASCIIToUTF16("lastname"); |
| 1896 field.autocomplete_attribute = "family-name"; |
| 1897 form.fields.push_back(field); |
| 1898 possible_field_types.push_back(ServerFieldTypeSet()); |
| 1899 possible_field_types.back().insert(NAME_LAST); |
| 1900 |
| 1901 field.label = ASCIIToUTF16("Email"); |
| 1902 field.name = ASCIIToUTF16("email"); |
| 1903 field.form_control_type = "email"; |
| 1904 field.autocomplete_attribute = "email"; |
| 1905 form.fields.push_back(field); |
| 1906 possible_field_types.push_back(ServerFieldTypeSet()); |
| 1907 possible_field_types.back().insert(EMAIL_ADDRESS); |
| 1908 |
| 1909 form_structure.reset(new FormStructure(form)); |
| 1910 |
| 1911 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1912 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1913 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1914 |
| 1915 ServerFieldTypeSet available_field_types; |
| 1916 available_field_types.insert(NAME_FIRST); |
| 1917 available_field_types.insert(NAME_LAST); |
| 1918 available_field_types.insert(EMAIL_ADDRESS); |
| 1919 |
| 1920 std::string encoded_xml; |
| 1921 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, true, |
| 1922 &encoded_xml)); |
| 1923 EXPECT_EQ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 1924 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" |
| 1925 " formsignature=\"14746822798145140279\" autofillused=\"true\"" |
| 1926 " datapresent=\"1440\">" |
| 1927 "<field signature=\"3763331450\"/>" |
| 1928 "<field signature=\"3494530716\"/>" |
| 1929 "<field signature=\"1029417091\"/></autofillupload>", |
| 1930 encoded_xml); |
| 1931 } |
| 1932 |
| 1933 TEST_F(FormStructureTest, EncodeFieldAssignments) { |
| 1934 scoped_ptr<FormStructure> form_structure; |
| 1935 std::vector<ServerFieldTypeSet> possible_field_types; |
| 1936 FormData form; |
| 1851 form_structure.reset(new FormStructure(form)); | 1937 form_structure.reset(new FormStructure(form)); |
| 1852 form_structure->DetermineHeuristicTypes(); | 1938 form_structure->DetermineHeuristicTypes(); |
| 1853 | 1939 |
| 1854 FormFieldData field; | 1940 FormFieldData field; |
| 1855 field.form_control_type = "text"; | 1941 field.form_control_type = "text"; |
| 1856 | 1942 |
| 1857 field.label = ASCIIToUTF16("First Name"); | 1943 field.label = ASCIIToUTF16("First Name"); |
| 1858 field.name = ASCIIToUTF16("firstname"); | 1944 field.name = ASCIIToUTF16("firstname"); |
| 1859 form.fields.push_back(field); | 1945 form.fields.push_back(field); |
| 1860 possible_field_types.push_back(ServerFieldTypeSet()); | 1946 possible_field_types.push_back(ServerFieldTypeSet()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 "<fields fieldid=\"509334676\" fieldtype=\"30\" name=\"address\"/>" | 2050 "<fields fieldid=\"509334676\" fieldtype=\"30\" name=\"address\"/>" |
| 1965 "<fields fieldid=\"509334676\" fieldtype=\"31\" name=\"address\"/>" | 2051 "<fields fieldid=\"509334676\" fieldtype=\"31\" name=\"address\"/>" |
| 1966 "<fields fieldid=\"509334676\" fieldtype=\"37\" name=\"address\"/>" | 2052 "<fields fieldid=\"509334676\" fieldtype=\"37\" name=\"address\"/>" |
| 1967 "<fields fieldid=\"509334676\" fieldtype=\"38\" name=\"address\"/>" | 2053 "<fields fieldid=\"509334676\" fieldtype=\"38\" name=\"address\"/>" |
| 1968 "</fieldassignments>", | 2054 "</fieldassignments>", |
| 1969 encoded_xml); | 2055 encoded_xml); |
| 1970 } | 2056 } |
| 1971 | 2057 |
| 1972 // Check that we compute the "datapresent" string correctly for the given | 2058 // Check that we compute the "datapresent" string correctly for the given |
| 1973 // |available_types|. | 2059 // |available_types|. |
| 1974 TEST(FormStructureTest, CheckDataPresence) { | 2060 TEST_F(FormStructureTest, CheckDataPresence) { |
| 1975 FormData form; | 2061 FormData form; |
| 1976 | 2062 |
| 1977 FormFieldData field; | 2063 FormFieldData field; |
| 1978 field.form_control_type = "text"; | 2064 field.form_control_type = "text"; |
| 1979 | 2065 |
| 1980 field.label = ASCIIToUTF16("First Name"); | 2066 field.label = ASCIIToUTF16("First Name"); |
| 1981 field.name = ASCIIToUTF16("first"); | 2067 field.name = ASCIIToUTF16("first"); |
| 1982 form.fields.push_back(field); | 2068 form.fields.push_back(field); |
| 1983 | 2069 |
| 1984 field.label = ASCIIToUTF16("Last Name"); | 2070 field.label = ASCIIToUTF16("Last Name"); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 " datapresent=\"1f7e000378001fc8\">" | 2287 " datapresent=\"1f7e000378001fc8\">" |
| 2202 "<field signature=\"1089846351\" name=\"first\" type=\"text\"" | 2288 "<field signature=\"1089846351\" name=\"first\" type=\"text\"" |
| 2203 " autofilltype=\"1\"/>" | 2289 " autofilltype=\"1\"/>" |
| 2204 "<field signature=\"2404144663\" name=\"last\" type=\"text\"" | 2290 "<field signature=\"2404144663\" name=\"last\" type=\"text\"" |
| 2205 " autofilltype=\"1\"/>" | 2291 " autofilltype=\"1\"/>" |
| 2206 "<field signature=\"420638584\" name=\"email\" type=\"text\"" | 2292 "<field signature=\"420638584\" name=\"email\" type=\"text\"" |
| 2207 " autofilltype=\"1\"/></autofillupload>", | 2293 " autofilltype=\"1\"/></autofillupload>", |
| 2208 encoded_xml); | 2294 encoded_xml); |
| 2209 } | 2295 } |
| 2210 | 2296 |
| 2211 TEST(FormStructureTest, CheckMultipleTypes) { | 2297 TEST_F(FormStructureTest, CheckMultipleTypes) { |
| 2212 // Throughout this test, datapresent should be | 2298 // Throughout this test, datapresent should be |
| 2213 // 0x1440000360000008 == | 2299 // 0x1440000360000008 == |
| 2214 // 0b0001010001000000000000000000001101100000000000000000000000001000 | 2300 // 0b0001010001000000000000000000001101100000000000000000000000001000 |
| 2215 // The set bits are: | 2301 // The set bits are: |
| 2216 // 3 == NAME_FIRST | 2302 // 3 == NAME_FIRST |
| 2217 // 5 == NAME_LAST | 2303 // 5 == NAME_LAST |
| 2218 // 9 == EMAIL_ADDRESS | 2304 // 9 == EMAIL_ADDRESS |
| 2219 // 30 == ADDRESS_HOME_LINE1 | 2305 // 30 == ADDRESS_HOME_LINE1 |
| 2220 // 31 == ADDRESS_HOME_LINE2 | 2306 // 31 == ADDRESS_HOME_LINE2 |
| 2221 // 33 == ADDRESS_HOME_CITY | 2307 // 33 == ADDRESS_HOME_CITY |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2345 " autofilltype=\"3\"/>" | 2431 " autofilltype=\"3\"/>" |
| 2346 "<field signature=\"2404144663\" name=\"last\" type=\"text\"" | 2432 "<field signature=\"2404144663\" name=\"last\" type=\"text\"" |
| 2347 " autofilltype=\"5\"/>" | 2433 " autofilltype=\"5\"/>" |
| 2348 "<field signature=\"509334676\" name=\"address\" type=\"text\"" | 2434 "<field signature=\"509334676\" name=\"address\" type=\"text\"" |
| 2349 " autofilltype=\"30\"/>" | 2435 " autofilltype=\"30\"/>" |
| 2350 "<field signature=\"509334676\" name=\"address\" type=\"text\"" | 2436 "<field signature=\"509334676\" name=\"address\" type=\"text\"" |
| 2351 " autofilltype=\"60\"/></autofillupload>", | 2437 " autofilltype=\"60\"/></autofillupload>", |
| 2352 encoded_xml); | 2438 encoded_xml); |
| 2353 } | 2439 } |
| 2354 | 2440 |
| 2355 TEST(FormStructureTest, CheckFormSignature) { | 2441 TEST_F(FormStructureTest, CheckFormSignature) { |
| 2356 // Check that form signature is created correctly. | 2442 // Check that form signature is created correctly. |
| 2357 scoped_ptr<FormStructure> form_structure; | 2443 scoped_ptr<FormStructure> form_structure; |
| 2358 FormData form; | 2444 FormData form; |
| 2359 | 2445 |
| 2360 FormFieldData field; | 2446 FormFieldData field; |
| 2361 field.form_control_type = "text"; | 2447 field.form_control_type = "text"; |
| 2362 | 2448 |
| 2363 field.label = ASCIIToUTF16("email"); | 2449 field.label = ASCIIToUTF16("email"); |
| 2364 field.name = ASCIIToUTF16("email"); | 2450 field.name = ASCIIToUTF16("email"); |
| 2365 form.fields.push_back(field); | 2451 form.fields.push_back(field); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2413 field.label = ASCIIToUTF16("Random Field label3"); | 2499 field.label = ASCIIToUTF16("Random Field label3"); |
| 2414 field.name = ASCIIToUTF16("12345random"); | 2500 field.name = ASCIIToUTF16("12345random"); |
| 2415 form.fields.push_back(field); | 2501 form.fields.push_back(field); |
| 2416 form_structure.reset(new FormStructure(form)); | 2502 form_structure.reset(new FormStructure(form)); |
| 2417 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2503 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2418 std::string("https://login.facebook.com&login_form&email&first&" | 2504 std::string("https://login.facebook.com&login_form&email&first&" |
| 2419 "random1234&random&1random&random")), | 2505 "random1234&random&1random&random")), |
| 2420 form_structure->FormSignature()); | 2506 form_structure->FormSignature()); |
| 2421 } | 2507 } |
| 2422 | 2508 |
| 2423 TEST(FormStructureTest, ToFormData) { | 2509 TEST_F(FormStructureTest, ToFormData) { |
| 2424 FormData form; | 2510 FormData form; |
| 2425 form.name = ASCIIToUTF16("the-name"); | 2511 form.name = ASCIIToUTF16("the-name"); |
| 2426 form.origin = GURL("http://cool.com"); | 2512 form.origin = GURL("http://cool.com"); |
| 2427 form.action = form.origin.Resolve("/login"); | 2513 form.action = form.origin.Resolve("/login"); |
| 2428 | 2514 |
| 2429 FormFieldData field; | 2515 FormFieldData field; |
| 2430 field.label = ASCIIToUTF16("username"); | 2516 field.label = ASCIIToUTF16("username"); |
| 2431 field.name = ASCIIToUTF16("username"); | 2517 field.name = ASCIIToUTF16("username"); |
| 2432 field.form_control_type = "text"; | 2518 field.form_control_type = "text"; |
| 2433 form.fields.push_back(field); | 2519 form.fields.push_back(field); |
| 2434 | 2520 |
| 2435 field.label = ASCIIToUTF16("password"); | 2521 field.label = ASCIIToUTF16("password"); |
| 2436 field.name = ASCIIToUTF16("password"); | 2522 field.name = ASCIIToUTF16("password"); |
| 2437 field.form_control_type = "password"; | 2523 field.form_control_type = "password"; |
| 2438 form.fields.push_back(field); | 2524 form.fields.push_back(field); |
| 2439 | 2525 |
| 2440 field.label = base::string16(); | 2526 field.label = base::string16(); |
| 2441 field.name = ASCIIToUTF16("Submit"); | 2527 field.name = ASCIIToUTF16("Submit"); |
| 2442 field.form_control_type = "submit"; | 2528 field.form_control_type = "submit"; |
| 2443 form.fields.push_back(field); | 2529 form.fields.push_back(field); |
| 2444 | 2530 |
| 2445 EXPECT_TRUE(form.SameFormAs(FormStructure(form).ToFormData())); | 2531 EXPECT_TRUE(form.SameFormAs(FormStructure(form).ToFormData())); |
| 2446 | 2532 |
| 2447 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2533 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
| 2448 // false. This forces a future author that changes this to update this test. | 2534 // false. This forces a future author that changes this to update this test. |
| 2449 form.user_submitted = true; | 2535 form.user_submitted = true; |
| 2450 EXPECT_FALSE(form.SameFormAs(FormStructure(form).ToFormData())); | 2536 EXPECT_FALSE(form.SameFormAs(FormStructure(form).ToFormData())); |
| 2451 } | 2537 } |
| 2452 | 2538 |
| 2453 TEST(FormStructureTest, SkipFieldTest) { | 2539 TEST_F(FormStructureTest, SkipFieldTest) { |
| 2454 FormData form; | 2540 FormData form; |
| 2455 form.name = ASCIIToUTF16("the-name"); | 2541 form.name = ASCIIToUTF16("the-name"); |
| 2456 form.origin = GURL("http://cool.com"); | 2542 form.origin = GURL("http://cool.com"); |
| 2457 form.action = form.origin.Resolve("/login"); | 2543 form.action = form.origin.Resolve("/login"); |
| 2458 | 2544 |
| 2459 FormFieldData field; | 2545 FormFieldData field; |
| 2460 field.label = ASCIIToUTF16("username"); | 2546 field.label = ASCIIToUTF16("username"); |
| 2461 field.name = ASCIIToUTF16("username"); | 2547 field.name = ASCIIToUTF16("username"); |
| 2462 field.form_control_type = "text"; | 2548 field.form_control_type = "text"; |
| 2463 form.fields.push_back(field); | 2549 form.fields.push_back(field); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2488 "</autofillquery>"; | 2574 "</autofillquery>"; |
| 2489 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 2575 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 2490 &encoded_signatures, | 2576 &encoded_signatures, |
| 2491 &encoded_xml)); | 2577 &encoded_xml)); |
| 2492 ASSERT_EQ(1U, encoded_signatures.size()); | 2578 ASSERT_EQ(1U, encoded_signatures.size()); |
| 2493 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2579 EXPECT_EQ(kSignature, encoded_signatures[0]); |
| 2494 EXPECT_EQ(kResponse, encoded_xml); | 2580 EXPECT_EQ(kResponse, encoded_xml); |
| 2495 } | 2581 } |
| 2496 | 2582 |
| 2497 // One name is missing from one field. | 2583 // One name is missing from one field. |
| 2498 TEST(FormStructureTest, EncodeQueryRequest_MissingNames) { | 2584 TEST_F(FormStructureTest, EncodeQueryRequest_MissingNames) { |
| 2499 FormData form; | 2585 FormData form; |
| 2500 // No name set for the form. | 2586 // No name set for the form. |
| 2501 form.origin = GURL("http://cool.com"); | 2587 form.origin = GURL("http://cool.com"); |
| 2502 form.action = form.origin.Resolve("/login"); | 2588 form.action = form.origin.Resolve("/login"); |
| 2503 | 2589 |
| 2504 FormFieldData field; | 2590 FormFieldData field; |
| 2505 field.label = ASCIIToUTF16("username"); | 2591 field.label = ASCIIToUTF16("username"); |
| 2506 field.name = ASCIIToUTF16("username"); | 2592 field.name = ASCIIToUTF16("username"); |
| 2507 field.form_control_type = "text"; | 2593 field.form_control_type = "text"; |
| 2508 form.fields.push_back(field); | 2594 form.fields.push_back(field); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2526 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" | 2612 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" |
| 2527 "<field signature=\"1318412689\" type=\"text\"/></form></autofillquery>"; | 2613 "<field signature=\"1318412689\" type=\"text\"/></form></autofillquery>"; |
| 2528 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 2614 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 2529 &encoded_signatures, | 2615 &encoded_signatures, |
| 2530 &encoded_xml)); | 2616 &encoded_xml)); |
| 2531 ASSERT_EQ(1U, encoded_signatures.size()); | 2617 ASSERT_EQ(1U, encoded_signatures.size()); |
| 2532 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2618 EXPECT_EQ(kSignature, encoded_signatures[0]); |
| 2533 EXPECT_EQ(kResponse, encoded_xml); | 2619 EXPECT_EQ(kResponse, encoded_xml); |
| 2534 } | 2620 } |
| 2535 | 2621 |
| 2536 TEST(FormStructureTest, PossibleValues) { | 2622 // Sending field metadata to the server is disabled. |
| 2623 TEST_F(FormStructureTest, EncodeQueryRequest_DisabledMetadataTrial) { |
| 2624 DisableAutofillMetadataFieldTrial(); |
| 2625 |
| 2626 FormData form; |
| 2627 // No name set for the form. |
| 2628 form.origin = GURL("http://cool.com"); |
| 2629 form.action = form.origin.Resolve("/login"); |
| 2630 |
| 2631 FormFieldData field; |
| 2632 field.label = ASCIIToUTF16("username"); |
| 2633 field.name = ASCIIToUTF16("username"); |
| 2634 field.form_control_type = "text"; |
| 2635 form.fields.push_back(field); |
| 2636 |
| 2637 field.label = base::string16(); |
| 2638 field.name = ASCIIToUTF16("country"); |
| 2639 field.form_control_type = "text"; |
| 2640 field.is_checkable = false; |
| 2641 form.fields.push_back(field); |
| 2642 |
| 2643 ScopedVector<FormStructure> forms; |
| 2644 forms.push_back(new FormStructure(form)); |
| 2645 std::vector<std::string> encoded_signatures; |
| 2646 std::string encoded_xml; |
| 2647 |
| 2648 const char kSignature[] = "7635954436925888745"; |
| 2649 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 2650 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
| 2651 "<form signature=\"7635954436925888745\">" |
| 2652 "<field signature=\"239111655\"/>" |
| 2653 "<field signature=\"3654076265\"/>" |
| 2654 "</form></autofillquery>"; |
| 2655 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 2656 &encoded_signatures, |
| 2657 &encoded_xml)); |
| 2658 ASSERT_EQ(1U, encoded_signatures.size()); |
| 2659 EXPECT_EQ(kSignature, encoded_signatures[0]); |
| 2660 EXPECT_EQ(kResponse, encoded_xml); |
| 2661 } |
| 2662 |
| 2663 TEST_F(FormStructureTest, PossibleValues) { |
| 2537 FormData form_data; | 2664 FormData form_data; |
| 2538 FormFieldData field; | 2665 FormFieldData field; |
| 2539 field.autocomplete_attribute = "billing country"; | 2666 field.autocomplete_attribute = "billing country"; |
| 2540 field.option_contents.push_back(ASCIIToUTF16("Down Under")); | 2667 field.option_contents.push_back(ASCIIToUTF16("Down Under")); |
| 2541 field.option_values.push_back(ASCIIToUTF16("AU")); | 2668 field.option_values.push_back(ASCIIToUTF16("AU")); |
| 2542 field.option_contents.push_back(ASCIIToUTF16("Fr")); | 2669 field.option_contents.push_back(ASCIIToUTF16("Fr")); |
| 2543 field.option_values.push_back(ASCIIToUTF16("")); | 2670 field.option_values.push_back(ASCIIToUTF16("")); |
| 2544 field.option_contents.push_back(ASCIIToUTF16("Germany")); | 2671 field.option_contents.push_back(ASCIIToUTF16("Germany")); |
| 2545 field.option_values.push_back(ASCIIToUTF16("GRMNY")); | 2672 field.option_values.push_back(ASCIIToUTF16("GRMNY")); |
| 2546 form_data.fields.push_back(field); | 2673 form_data.fields.push_back(field); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2566 | 2693 |
| 2567 // A freeform input (<input>) allows any value (overriding other <select>s). | 2694 // A freeform input (<input>) allows any value (overriding other <select>s). |
| 2568 FormFieldData freeform_field; | 2695 FormFieldData freeform_field; |
| 2569 freeform_field.autocomplete_attribute = "billing country"; | 2696 freeform_field.autocomplete_attribute = "billing country"; |
| 2570 form_data.fields.push_back(freeform_field); | 2697 form_data.fields.push_back(freeform_field); |
| 2571 FormStructure form_structure2(form_data); | 2698 FormStructure form_structure2(form_data); |
| 2572 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused); | 2699 form_structure2.ParseFieldTypesFromAutocompleteAttributes(&unused, &unused); |
| 2573 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size()); | 2700 EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size()); |
| 2574 } | 2701 } |
| 2575 | 2702 |
| 2576 TEST(FormStructureTest, ParseQueryResponse) { | 2703 TEST_F(FormStructureTest, ParseQueryResponse) { |
| 2577 TestRapporService rappor_service; | 2704 TestRapporService rappor_service; |
| 2578 FormData form; | 2705 FormData form; |
| 2579 form.origin = GURL("http://foo.com"); | 2706 form.origin = GURL("http://foo.com"); |
| 2580 FormFieldData field; | 2707 FormFieldData field; |
| 2581 field.form_control_type = "text"; | 2708 field.form_control_type = "text"; |
| 2582 | 2709 |
| 2583 field.label = ASCIIToUTF16("fullname"); | 2710 field.label = ASCIIToUTF16("fullname"); |
| 2584 field.name = ASCIIToUTF16("fullname"); | 2711 field.name = ASCIIToUTF16("fullname"); |
| 2585 form.fields.push_back(field); | 2712 form.fields.push_back(field); |
| 2586 | 2713 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2625 EXPECT_EQ(30, forms[0]->field(1)->server_type()); | 2752 EXPECT_EQ(30, forms[0]->field(1)->server_type()); |
| 2626 EXPECT_EQ(9, forms[1]->field(0)->server_type()); | 2753 EXPECT_EQ(9, forms[1]->field(0)->server_type()); |
| 2627 EXPECT_EQ(0, forms[1]->field(1)->server_type()); | 2754 EXPECT_EQ(0, forms[1]->field(1)->server_type()); |
| 2628 | 2755 |
| 2629 // No RAPPOR metrics are logged in the case there is server data available for | 2756 // No RAPPOR metrics are logged in the case there is server data available for |
| 2630 // all forms. | 2757 // all forms. |
| 2631 EXPECT_EQ(0, rappor_service.GetReportsCount()); | 2758 EXPECT_EQ(0, rappor_service.GetReportsCount()); |
| 2632 } | 2759 } |
| 2633 | 2760 |
| 2634 // If user defined types are present, only parse password fields. | 2761 // If user defined types are present, only parse password fields. |
| 2635 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { | 2762 TEST_F(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { |
| 2636 TestRapporService rappor_service; | 2763 TestRapporService rappor_service; |
| 2637 FormData form; | 2764 FormData form; |
| 2638 form.origin = GURL("http://foo.com"); | 2765 form.origin = GURL("http://foo.com"); |
| 2639 FormFieldData field; | 2766 FormFieldData field; |
| 2640 | 2767 |
| 2641 field.label = ASCIIToUTF16("email"); | 2768 field.label = ASCIIToUTF16("email"); |
| 2642 field.name = ASCIIToUTF16("email"); | 2769 field.name = ASCIIToUTF16("email"); |
| 2643 field.form_control_type = "text"; | 2770 field.form_control_type = "text"; |
| 2644 field.autocomplete_attribute = "email"; | 2771 field.autocomplete_attribute = "email"; |
| 2645 form.fields.push_back(field); | 2772 form.fields.push_back(field); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2662 | 2789 |
| 2663 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); | 2790 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); |
| 2664 | 2791 |
| 2665 ASSERT_GE(forms[0]->field_count(), 2U); | 2792 ASSERT_GE(forms[0]->field_count(), 2U); |
| 2666 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); | 2793 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); |
| 2667 EXPECT_EQ(76, forms[0]->field(1)->server_type()); | 2794 EXPECT_EQ(76, forms[0]->field(1)->server_type()); |
| 2668 } | 2795 } |
| 2669 | 2796 |
| 2670 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR | 2797 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR |
| 2671 // logging. | 2798 // logging. |
| 2672 TEST(FormStructureTest, ParseQueryResponse_RapporLogging_OneFormNoServerData) { | 2799 TEST_F(FormStructureTest, |
| 2800 ParseQueryResponse_RapporLogging_OneFormNoServerData) { |
| 2673 TestRapporService rappor_service; | 2801 TestRapporService rappor_service; |
| 2674 FormData form; | 2802 FormData form; |
| 2675 form.origin = GURL("http://foo.com"); | 2803 form.origin = GURL("http://foo.com"); |
| 2676 FormFieldData field; | 2804 FormFieldData field; |
| 2677 field.form_control_type = "text"; | 2805 field.form_control_type = "text"; |
| 2678 | 2806 |
| 2679 field.label = ASCIIToUTF16("fullname"); | 2807 field.label = ASCIIToUTF16("fullname"); |
| 2680 field.name = ASCIIToUTF16("fullname"); | 2808 field.name = ASCIIToUTF16("fullname"); |
| 2681 form.fields.push_back(field); | 2809 form.fields.push_back(field); |
| 2682 | 2810 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2712 std::string sample; | 2840 std::string sample; |
| 2713 rappor::RapporType type; | 2841 rappor::RapporType type; |
| 2714 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 2842 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
| 2715 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 2843 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
| 2716 EXPECT_EQ("foo.com", sample); | 2844 EXPECT_EQ("foo.com", sample); |
| 2717 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 2845 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 2718 } | 2846 } |
| 2719 | 2847 |
| 2720 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR | 2848 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR |
| 2721 // logging. | 2849 // logging. |
| 2722 TEST(FormStructureTest, ParseQueryResponse_RapporLogging_AllFormsNoServerData) { | 2850 TEST_F(FormStructureTest, |
| 2851 ParseQueryResponse_RapporLogging_AllFormsNoServerData) { |
| 2723 TestRapporService rappor_service; | 2852 TestRapporService rappor_service; |
| 2724 FormData form; | 2853 FormData form; |
| 2725 form.origin = GURL("http://foo.com"); | 2854 form.origin = GURL("http://foo.com"); |
| 2726 FormFieldData field; | 2855 FormFieldData field; |
| 2727 field.form_control_type = "text"; | 2856 field.form_control_type = "text"; |
| 2728 | 2857 |
| 2729 field.label = ASCIIToUTF16("fullname"); | 2858 field.label = ASCIIToUTF16("fullname"); |
| 2730 field.name = ASCIIToUTF16("fullname"); | 2859 field.name = ASCIIToUTF16("fullname"); |
| 2731 form.fields.push_back(field); | 2860 form.fields.push_back(field); |
| 2732 | 2861 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2764 std::string sample; | 2893 std::string sample; |
| 2765 rappor::RapporType type; | 2894 rappor::RapporType type; |
| 2766 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 2895 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
| 2767 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); | 2896 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type)); |
| 2768 EXPECT_EQ("foo.com", sample); | 2897 EXPECT_EQ("foo.com", sample); |
| 2769 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 2898 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 2770 } | 2899 } |
| 2771 | 2900 |
| 2772 // If the server returns NO_SERVER_DATA for only some of the fields, expect no | 2901 // If the server returns NO_SERVER_DATA for only some of the fields, expect no |
| 2773 // RAPPOR logging. | 2902 // RAPPOR logging. |
| 2774 TEST(FormStructureTest, ParseQueryResponse_RapporLogging_PartialNoServerData) { | 2903 TEST_F(FormStructureTest, |
| 2904 ParseQueryResponse_RapporLogging_PartialNoServerData) { |
| 2775 TestRapporService rappor_service; | 2905 TestRapporService rappor_service; |
| 2776 FormData form; | 2906 FormData form; |
| 2777 form.origin = GURL("http://foo.com"); | 2907 form.origin = GURL("http://foo.com"); |
| 2778 FormFieldData field; | 2908 FormFieldData field; |
| 2779 field.form_control_type = "text"; | 2909 field.form_control_type = "text"; |
| 2780 | 2910 |
| 2781 field.label = ASCIIToUTF16("fullname"); | 2911 field.label = ASCIIToUTF16("fullname"); |
| 2782 field.name = ASCIIToUTF16("fullname"); | 2912 field.name = ASCIIToUTF16("fullname"); |
| 2783 form.fields.push_back(field); | 2913 form.fields.push_back(field); |
| 2784 | 2914 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2809 "</autofillqueryresponse>"; | 2939 "</autofillqueryresponse>"; |
| 2810 | 2940 |
| 2811 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); | 2941 FormStructure::ParseQueryResponse(response, forms.get(), &rappor_service); |
| 2812 | 2942 |
| 2813 // No RAPPOR metrics are logged in the case there is at least some server data | 2943 // No RAPPOR metrics are logged in the case there is at least some server data |
| 2814 // available for all forms. | 2944 // available for all forms. |
| 2815 EXPECT_EQ(0, rappor_service.GetReportsCount()); | 2945 EXPECT_EQ(0, rappor_service.GetReportsCount()); |
| 2816 } | 2946 } |
| 2817 | 2947 |
| 2818 } // namespace autofill | 2948 } // namespace autofill |
| OLD | NEW |