| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 field.label = ASCIIToUTF16("username"); | 87 field.label = ASCIIToUTF16("username"); |
| 88 field.name = ASCIIToUTF16("username"); | 88 field.name = ASCIIToUTF16("username"); |
| 89 field.form_control_type = "text"; | 89 field.form_control_type = "text"; |
| 90 form.fields.push_back(field); | 90 form.fields.push_back(field); |
| 91 | 91 |
| 92 field.label = ASCIIToUTF16("password"); | 92 field.label = ASCIIToUTF16("password"); |
| 93 field.name = ASCIIToUTF16("password"); | 93 field.name = ASCIIToUTF16("password"); |
| 94 field.form_control_type = "password"; | 94 field.form_control_type = "password"; |
| 95 form.fields.push_back(field); | 95 form.fields.push_back(field); |
| 96 | 96 |
| 97 field.label = ASCIIToUTF16("email"); |
| 98 field.name = ASCIIToUTF16("email"); |
| 99 field.form_control_type = "text"; |
| 100 form.fields.push_back(field); |
| 101 |
| 102 field.label = ASCIIToUTF16("city"); |
| 103 field.name = ASCIIToUTF16("city"); |
| 104 field.form_control_type = "text"; |
| 105 form.fields.push_back(field); |
| 106 |
| 97 field.label = ASCIIToUTF16("state"); | 107 field.label = ASCIIToUTF16("state"); |
| 98 field.name = ASCIIToUTF16("state"); | 108 field.name = ASCIIToUTF16("state"); |
| 99 field.form_control_type = "select-one"; | 109 field.form_control_type = "select-one"; |
| 100 form.fields.push_back(field); | 110 form.fields.push_back(field); |
| 101 | 111 |
| 102 field.label = base::string16(); | 112 field.label = base::string16(); |
| 103 field.name = ASCIIToUTF16("Submit"); | 113 field.name = ASCIIToUTF16("Submit"); |
| 104 field.form_control_type = "submit"; | 114 field.form_control_type = "submit"; |
| 105 form.fields.push_back(field); | 115 form.fields.push_back(field); |
| 106 | 116 |
| 107 // Only text and select fields that are heuristically matched are counted. | 117 // Only text and select fields that are heuristically matched are counted. |
| 108 form_structure.reset(new FormStructure(form)); | 118 form_structure.reset(new FormStructure(form)); |
| 109 form_structure->DetermineHeuristicTypes(); | 119 form_structure->DetermineHeuristicTypes(); |
| 110 EXPECT_EQ(1U, form_structure->autofill_count()); | 120 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 111 | 121 |
| 112 // Add a field with should_autocomplete=false. This should not be considered a | 122 // Add a field with should_autocomplete=false. This should not be considered a |
| 113 // fillable field. | 123 // fillable field. |
| 114 field.label = ASCIIToUTF16("address1"); | 124 field.label = ASCIIToUTF16("address1"); |
| 115 field.name = ASCIIToUTF16("address1"); | 125 field.name = ASCIIToUTF16("address1"); |
| 116 field.form_control_type = "text"; | 126 field.form_control_type = "text"; |
| 117 field.should_autocomplete = false; | 127 field.should_autocomplete = false; |
| 118 form.fields.push_back(field); | 128 form.fields.push_back(field); |
| 119 | 129 |
| 120 form_structure.reset(new FormStructure(form)); | 130 form_structure.reset(new FormStructure(form)); |
| 121 form_structure->DetermineHeuristicTypes(); | 131 form_structure->DetermineHeuristicTypes(); |
| 122 EXPECT_EQ(2U, form_structure->autofill_count()); | 132 EXPECT_EQ(4U, form_structure->autofill_count()); |
| 123 | 133 |
| 124 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 134 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 125 switches::kRespectAutocompleteOffForAutofill); | 135 switches::kRespectAutocompleteOffForAutofill); |
| 126 | 136 |
| 127 form_structure.reset(new FormStructure(form)); | 137 form_structure.reset(new FormStructure(form)); |
| 128 form_structure->DetermineHeuristicTypes(); | 138 form_structure->DetermineHeuristicTypes(); |
| 129 EXPECT_EQ(1U, form_structure->autofill_count()); | 139 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 130 } | 140 } |
| 131 | 141 |
| 132 TEST(FormStructureTest, SourceURL) { | 142 TEST(FormStructureTest, SourceURL) { |
| 133 FormData form; | 143 FormData form; |
| 134 form.origin = GURL("http://www.foo.com/"); | 144 form.origin = GURL("http://www.foo.com/"); |
| 135 FormStructure form_structure(form); | 145 FormStructure form_structure(form); |
| 136 | 146 |
| 137 EXPECT_EQ(form.origin, form_structure.source_url()); | 147 EXPECT_EQ(form.origin, form_structure.source_url()); |
| 138 } | 148 } |
| 139 | 149 |
| (...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 field.name = ASCIIToUTF16("1random12345678"); | 2260 field.name = ASCIIToUTF16("1random12345678"); |
| 2251 form.fields.push_back(field); | 2261 form.fields.push_back(field); |
| 2252 field.label = ASCIIToUTF16("Random Field label3"); | 2262 field.label = ASCIIToUTF16("Random Field label3"); |
| 2253 field.name = ASCIIToUTF16("12345random"); | 2263 field.name = ASCIIToUTF16("12345random"); |
| 2254 form.fields.push_back(field); | 2264 form.fields.push_back(field); |
| 2255 form_structure.reset(new FormStructure(form)); | 2265 form_structure.reset(new FormStructure(form)); |
| 2256 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2266 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2257 std::string("https://login.facebook.com&login_form&email&first&" | 2267 std::string("https://login.facebook.com&login_form&email&first&" |
| 2258 "random1234&random&1random&random")), | 2268 "random1234&random&1random&random")), |
| 2259 form_structure->FormSignature()); | 2269 form_structure->FormSignature()); |
| 2260 | |
| 2261 } | 2270 } |
| 2262 | 2271 |
| 2263 TEST(FormStructureTest, ToFormData) { | 2272 TEST(FormStructureTest, ToFormData) { |
| 2264 FormData form; | 2273 FormData form; |
| 2265 form.name = ASCIIToUTF16("the-name"); | 2274 form.name = ASCIIToUTF16("the-name"); |
| 2266 form.origin = GURL("http://cool.com"); | 2275 form.origin = GURL("http://cool.com"); |
| 2267 form.action = form.origin.Resolve("/login"); | 2276 form.action = form.origin.Resolve("/login"); |
| 2268 | 2277 |
| 2269 FormFieldData field; | 2278 FormFieldData field; |
| 2270 field.label = ASCIIToUTF16("username"); | 2279 field.label = ASCIIToUTF16("username"); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2413 std::string response = | 2422 std::string response = |
| 2414 "<autofillqueryresponse>" | 2423 "<autofillqueryresponse>" |
| 2415 "<field autofilltype=\"7\" />" | 2424 "<field autofilltype=\"7\" />" |
| 2416 "<field autofilltype=\"30\" />" | 2425 "<field autofilltype=\"30\" />" |
| 2417 "<field autofilltype=\"9\" />" | 2426 "<field autofilltype=\"9\" />" |
| 2418 "<field autofilltype=\"0\" />" | 2427 "<field autofilltype=\"0\" />" |
| 2419 "</autofillqueryresponse>"; | 2428 "</autofillqueryresponse>"; |
| 2420 | 2429 |
| 2421 FormStructure::ParseQueryResponse(response, forms.get()); | 2430 FormStructure::ParseQueryResponse(response, forms.get()); |
| 2422 | 2431 |
| 2432 ASSERT_GE(forms[0]->field_count(), 2U); |
| 2433 ASSERT_GE(forms[1]->field_count(), 2U); |
| 2423 EXPECT_EQ(7, forms[0]->field(0)->server_type()); | 2434 EXPECT_EQ(7, forms[0]->field(0)->server_type()); |
| 2424 EXPECT_EQ(30, forms[0]->field(1)->server_type()); | 2435 EXPECT_EQ(30, forms[0]->field(1)->server_type()); |
| 2425 EXPECT_EQ(9, forms[1]->field(0)->server_type()); | 2436 EXPECT_EQ(9, forms[1]->field(0)->server_type()); |
| 2426 EXPECT_EQ(0, forms[1]->field(1)->server_type()); | 2437 EXPECT_EQ(0, forms[1]->field(1)->server_type()); |
| 2427 } | 2438 } |
| 2428 | 2439 |
| 2429 // If user defined types are present, only parse password fields. | 2440 // If user defined types are present, only parse password fields. |
| 2430 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { | 2441 TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { |
| 2431 FormData form; | 2442 FormData form; |
| 2432 FormFieldData field; | 2443 FormFieldData field; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2448 forms.front()->DetermineHeuristicTypes(); | 2459 forms.front()->DetermineHeuristicTypes(); |
| 2449 | 2460 |
| 2450 std::string response = | 2461 std::string response = |
| 2451 "<autofillqueryresponse>" | 2462 "<autofillqueryresponse>" |
| 2452 "<field autofilltype=\"9\" />" | 2463 "<field autofilltype=\"9\" />" |
| 2453 "<field autofilltype=\"76\" />" | 2464 "<field autofilltype=\"76\" />" |
| 2454 "</autofillqueryresponse>"; | 2465 "</autofillqueryresponse>"; |
| 2455 | 2466 |
| 2456 FormStructure::ParseQueryResponse(response, forms.get()); | 2467 FormStructure::ParseQueryResponse(response, forms.get()); |
| 2457 | 2468 |
| 2469 ASSERT_GE(forms[0]->field_count(), 2U); |
| 2458 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); | 2470 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); |
| 2459 EXPECT_EQ(76, forms[0]->field(1)->server_type()); | 2471 EXPECT_EQ(76, forms[0]->field(1)->server_type()); |
| 2460 } | 2472 } |
| 2461 | 2473 |
| 2462 } // namespace autofill | 2474 } // namespace autofill |
| OLD | NEW |