| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autofill_metrics.h" | 10 #include "chrome/browser/autofill/autofill_metrics.h" |
| 12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/form_data.h" | 12 #include "chrome/common/form_data.h" |
| 14 #include "chrome/common/form_field_data.h" | 13 #include "chrome/common/form_field_data.h" |
| 15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 field.label = ASCIIToUTF16("password"); | 75 field.label = ASCIIToUTF16("password"); |
| 77 field.name = ASCIIToUTF16("password"); | 76 field.name = ASCIIToUTF16("password"); |
| 78 field.form_control_type = "password"; | 77 field.form_control_type = "password"; |
| 79 form.fields.push_back(field); | 78 form.fields.push_back(field); |
| 80 | 79 |
| 81 field.label = string16(); | 80 field.label = string16(); |
| 82 field.name = ASCIIToUTF16("Submit"); | 81 field.name = ASCIIToUTF16("Submit"); |
| 83 field.form_control_type = "submit"; | 82 field.form_control_type = "submit"; |
| 84 form.fields.push_back(field); | 83 form.fields.push_back(field); |
| 85 | 84 |
| 86 FormStructure form_structure(form); | 85 FormStructure form_structure(form, std::string()); |
| 87 | 86 |
| 88 // All fields are counted. | 87 // All fields are counted. |
| 89 EXPECT_EQ(3U, form_structure.field_count()); | 88 EXPECT_EQ(3U, form_structure.field_count()); |
| 90 } | 89 } |
| 91 | 90 |
| 92 TEST(FormStructureTest, AutofillCount) { | 91 TEST(FormStructureTest, AutofillCount) { |
| 93 FormData form; | 92 FormData form; |
| 94 form.method = ASCIIToUTF16("post"); | 93 form.method = ASCIIToUTF16("post"); |
| 95 | 94 |
| 96 FormFieldData field; | 95 FormFieldData field; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 field.label = ASCIIToUTF16("state"); | 106 field.label = ASCIIToUTF16("state"); |
| 108 field.name = ASCIIToUTF16("state"); | 107 field.name = ASCIIToUTF16("state"); |
| 109 field.form_control_type = "select-one"; | 108 field.form_control_type = "select-one"; |
| 110 form.fields.push_back(field); | 109 form.fields.push_back(field); |
| 111 | 110 |
| 112 field.label = string16(); | 111 field.label = string16(); |
| 113 field.name = ASCIIToUTF16("Submit"); | 112 field.name = ASCIIToUTF16("Submit"); |
| 114 field.form_control_type = "submit"; | 113 field.form_control_type = "submit"; |
| 115 form.fields.push_back(field); | 114 form.fields.push_back(field); |
| 116 | 115 |
| 117 FormStructure form_structure(form); | 116 FormStructure form_structure(form, std::string()); |
| 118 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 117 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 119 | 118 |
| 120 // Only text and select fields that are heuristically matched are counted. | 119 // Only text and select fields that are heuristically matched are counted. |
| 121 EXPECT_EQ(1U, form_structure.autofill_count()); | 120 EXPECT_EQ(1U, form_structure.autofill_count()); |
| 122 } | 121 } |
| 123 | 122 |
| 124 TEST(FormStructureTest, SourceURL) { | 123 TEST(FormStructureTest, SourceURL) { |
| 125 FormData form; | 124 FormData form; |
| 126 form.origin = GURL("http://www.foo.com/"); | 125 form.origin = GURL("http://www.foo.com/"); |
| 127 form.method = ASCIIToUTF16("post"); | 126 form.method = ASCIIToUTF16("post"); |
| 128 FormStructure form_structure(form); | 127 FormStructure form_structure(form, std::string()); |
| 129 | 128 |
| 130 EXPECT_EQ(form.origin, form_structure.source_url()); | 129 EXPECT_EQ(form.origin, form_structure.source_url()); |
| 131 } | 130 } |
| 132 | 131 |
| 133 TEST(FormStructureTest, IsAutofillable) { | 132 TEST(FormStructureTest, IsAutofillable) { |
| 134 scoped_ptr<FormStructure> form_structure; | 133 scoped_ptr<FormStructure> form_structure; |
| 135 FormData form; | 134 FormData form; |
| 136 | 135 |
| 137 // We need at least three text fields to be auto-fillable. | 136 // We need at least three text fields to be auto-fillable. |
| 138 form.method = ASCIIToUTF16("post"); | 137 form.method = ASCIIToUTF16("post"); |
| 139 | 138 |
| 140 FormFieldData field; | 139 FormFieldData field; |
| 141 field.label = ASCIIToUTF16("username"); | 140 field.label = ASCIIToUTF16("username"); |
| 142 field.name = ASCIIToUTF16("username"); | 141 field.name = ASCIIToUTF16("username"); |
| 143 field.form_control_type = "text"; | 142 field.form_control_type = "text"; |
| 144 form.fields.push_back(field); | 143 form.fields.push_back(field); |
| 145 | 144 |
| 146 field.label = ASCIIToUTF16("password"); | 145 field.label = ASCIIToUTF16("password"); |
| 147 field.name = ASCIIToUTF16("password"); | 146 field.name = ASCIIToUTF16("password"); |
| 148 field.form_control_type = "password"; | 147 field.form_control_type = "password"; |
| 149 form.fields.push_back(field); | 148 form.fields.push_back(field); |
| 150 | 149 |
| 151 field.label = string16(); | 150 field.label = string16(); |
| 152 field.name = ASCIIToUTF16("Submit"); | 151 field.name = ASCIIToUTF16("Submit"); |
| 153 field.form_control_type = "submit"; | 152 field.form_control_type = "submit"; |
| 154 form.fields.push_back(field); | 153 form.fields.push_back(field); |
| 155 | 154 |
| 156 form_structure.reset(new FormStructure(form)); | 155 form_structure.reset(new FormStructure(form, std::string())); |
| 157 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 156 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 158 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 157 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 159 | 158 |
| 160 // We now have three text fields, but only two auto-fillable fields. | 159 // We now have three text fields, but only two auto-fillable fields. |
| 161 field.label = ASCIIToUTF16("First Name"); | 160 field.label = ASCIIToUTF16("First Name"); |
| 162 field.name = ASCIIToUTF16("firstname"); | 161 field.name = ASCIIToUTF16("firstname"); |
| 163 field.form_control_type = "text"; | 162 field.form_control_type = "text"; |
| 164 form.fields.push_back(field); | 163 form.fields.push_back(field); |
| 165 | 164 |
| 166 field.label = ASCIIToUTF16("Last Name"); | 165 field.label = ASCIIToUTF16("Last Name"); |
| 167 field.name = ASCIIToUTF16("lastname"); | 166 field.name = ASCIIToUTF16("lastname"); |
| 168 field.form_control_type = "text"; | 167 field.form_control_type = "text"; |
| 169 form.fields.push_back(field); | 168 form.fields.push_back(field); |
| 170 | 169 |
| 171 form_structure.reset(new FormStructure(form)); | 170 form_structure.reset(new FormStructure(form, std::string())); |
| 172 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 171 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 173 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 172 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 174 | 173 |
| 175 // We now have three auto-fillable fields. | 174 // We now have three auto-fillable fields. |
| 176 field.label = ASCIIToUTF16("Email"); | 175 field.label = ASCIIToUTF16("Email"); |
| 177 field.name = ASCIIToUTF16("email"); | 176 field.name = ASCIIToUTF16("email"); |
| 178 field.form_control_type = "email"; | 177 field.form_control_type = "email"; |
| 179 form.fields.push_back(field); | 178 form.fields.push_back(field); |
| 180 | 179 |
| 181 form_structure.reset(new FormStructure(form)); | 180 form_structure.reset(new FormStructure(form, std::string())); |
| 182 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 181 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 183 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 182 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 184 | 183 |
| 185 // The method must be 'post', though we can intentionally ignore this | 184 // The method must be 'post', though we can intentionally ignore this |
| 186 // criterion for the sake of providing a helpful warning message to the user. | 185 // criterion for the sake of providing a helpful warning message to the user. |
| 187 form.method = ASCIIToUTF16("get"); | 186 form.method = ASCIIToUTF16("get"); |
| 188 form_structure.reset(new FormStructure(form)); | 187 form_structure.reset(new FormStructure(form, std::string())); |
| 189 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 188 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 190 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 189 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 191 EXPECT_TRUE(form_structure->IsAutofillable(false)); | 190 EXPECT_TRUE(form_structure->IsAutofillable(false)); |
| 192 | 191 |
| 193 // The target cannot include http(s)://*/search... | 192 // The target cannot include http(s)://*/search... |
| 194 form.method = ASCIIToUTF16("post"); | 193 form.method = ASCIIToUTF16("post"); |
| 195 form.action = GURL("http://google.com/search?q=hello"); | 194 form.action = GURL("http://google.com/search?q=hello"); |
| 196 form_structure.reset(new FormStructure(form)); | 195 form_structure.reset(new FormStructure(form, std::string())); |
| 197 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 196 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 198 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 197 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 199 | 198 |
| 200 // But search can be in the URL. | 199 // But search can be in the URL. |
| 201 form.action = GURL("http://search.com/?q=hello"); | 200 form.action = GURL("http://search.com/?q=hello"); |
| 202 form_structure.reset(new FormStructure(form)); | 201 form_structure.reset(new FormStructure(form, std::string())); |
| 203 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 202 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 204 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 203 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 205 } | 204 } |
| 206 | 205 |
| 207 TEST(FormStructureTest, ShouldBeParsed) { | 206 TEST(FormStructureTest, ShouldBeParsed) { |
| 208 scoped_ptr<FormStructure> form_structure; | 207 scoped_ptr<FormStructure> form_structure; |
| 209 FormData form; | 208 FormData form; |
| 210 | 209 |
| 211 // We need at least three text fields to be parseable. | 210 // We need at least three text fields to be parseable. |
| 212 form.method = ASCIIToUTF16("post"); | 211 form.method = ASCIIToUTF16("post"); |
| 213 | 212 |
| 214 FormFieldData field; | 213 FormFieldData field; |
| 215 field.label = ASCIIToUTF16("username"); | 214 field.label = ASCIIToUTF16("username"); |
| 216 field.name = ASCIIToUTF16("username"); | 215 field.name = ASCIIToUTF16("username"); |
| 217 field.form_control_type = "text"; | 216 field.form_control_type = "text"; |
| 218 form.fields.push_back(field); | 217 form.fields.push_back(field); |
| 219 | 218 |
| 220 FormFieldData checkable_field; | 219 FormFieldData checkable_field; |
| 221 checkable_field.is_checkable = true; | 220 checkable_field.is_checkable = true; |
| 222 checkable_field.name = ASCIIToUTF16("radiobtn"); | 221 checkable_field.name = ASCIIToUTF16("radiobtn"); |
| 223 checkable_field.form_control_type = "radio"; | 222 checkable_field.form_control_type = "radio"; |
| 224 form.fields.push_back(checkable_field); | 223 form.fields.push_back(checkable_field); |
| 225 | 224 |
| 226 checkable_field.name = ASCIIToUTF16("checkbox"); | 225 checkable_field.name = ASCIIToUTF16("checkbox"); |
| 227 checkable_field.form_control_type = "checkbox"; | 226 checkable_field.form_control_type = "checkbox"; |
| 228 form.fields.push_back(checkable_field); | 227 form.fields.push_back(checkable_field); |
| 229 | 228 |
| 230 form_structure.reset(new FormStructure(form)); | 229 form_structure.reset(new FormStructure(form, std::string())); |
| 231 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 230 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 232 | 231 |
| 233 // We now have three text fields, though only two are auto-fillable. | 232 // We now have three text fields, though only two are auto-fillable. |
| 234 field.label = ASCIIToUTF16("First Name"); | 233 field.label = ASCIIToUTF16("First Name"); |
| 235 field.name = ASCIIToUTF16("firstname"); | 234 field.name = ASCIIToUTF16("firstname"); |
| 236 field.form_control_type = "text"; | 235 field.form_control_type = "text"; |
| 237 form.fields.push_back(field); | 236 form.fields.push_back(field); |
| 238 | 237 |
| 239 field.label = ASCIIToUTF16("Last Name"); | 238 field.label = ASCIIToUTF16("Last Name"); |
| 240 field.name = ASCIIToUTF16("lastname"); | 239 field.name = ASCIIToUTF16("lastname"); |
| 241 field.form_control_type = "text"; | 240 field.form_control_type = "text"; |
| 242 form.fields.push_back(field); | 241 form.fields.push_back(field); |
| 243 | 242 |
| 244 form_structure.reset(new FormStructure(form)); | 243 form_structure.reset(new FormStructure(form, std::string())); |
| 245 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 244 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 246 | 245 |
| 247 // The method must be 'post', though we can intentionally ignore this | 246 // The method must be 'post', though we can intentionally ignore this |
| 248 // criterion for the sake of providing a helpful warning message to the user. | 247 // criterion for the sake of providing a helpful warning message to the user. |
| 249 form.method = ASCIIToUTF16("get"); | 248 form.method = ASCIIToUTF16("get"); |
| 250 form_structure.reset(new FormStructure(form)); | 249 form_structure.reset(new FormStructure(form, std::string())); |
| 251 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 250 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 252 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); | 251 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); |
| 253 | 252 |
| 254 // The target cannot include http(s)://*/search... | 253 // The target cannot include http(s)://*/search... |
| 255 form.method = ASCIIToUTF16("post"); | 254 form.method = ASCIIToUTF16("post"); |
| 256 form.action = GURL("http://google.com/search?q=hello"); | 255 form.action = GURL("http://google.com/search?q=hello"); |
| 257 form_structure.reset(new FormStructure(form)); | 256 form_structure.reset(new FormStructure(form, std::string())); |
| 258 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 257 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 259 | 258 |
| 260 // But search can be in the URL. | 259 // But search can be in the URL. |
| 261 form.action = GURL("http://search.com/?q=hello"); | 260 form.action = GURL("http://search.com/?q=hello"); |
| 262 form_structure.reset(new FormStructure(form)); | 261 form_structure.reset(new FormStructure(form, std::string())); |
| 263 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 262 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 264 | 263 |
| 265 // The form need only have three fields, but at least one must be a text | 264 // The form need only have three fields, but at least one must be a text |
| 266 // field. | 265 // field. |
| 267 form.fields.clear(); | 266 form.fields.clear(); |
| 268 | 267 |
| 269 field.label = ASCIIToUTF16("Email"); | 268 field.label = ASCIIToUTF16("Email"); |
| 270 field.name = ASCIIToUTF16("email"); | 269 field.name = ASCIIToUTF16("email"); |
| 271 field.form_control_type = "email"; | 270 field.form_control_type = "email"; |
| 272 form.fields.push_back(field); | 271 form.fields.push_back(field); |
| 273 | 272 |
| 274 field.label = ASCIIToUTF16("State"); | 273 field.label = ASCIIToUTF16("State"); |
| 275 field.name = ASCIIToUTF16("state"); | 274 field.name = ASCIIToUTF16("state"); |
| 276 field.form_control_type = "select-one"; | 275 field.form_control_type = "select-one"; |
| 277 form.fields.push_back(field); | 276 form.fields.push_back(field); |
| 278 | 277 |
| 279 field.label = ASCIIToUTF16("Country"); | 278 field.label = ASCIIToUTF16("Country"); |
| 280 field.name = ASCIIToUTF16("country"); | 279 field.name = ASCIIToUTF16("country"); |
| 281 field.form_control_type = "select-one"; | 280 field.form_control_type = "select-one"; |
| 282 form.fields.push_back(field); | 281 form.fields.push_back(field); |
| 283 | 282 |
| 284 form_structure.reset(new FormStructure(form)); | 283 form_structure.reset(new FormStructure(form, std::string())); |
| 285 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 284 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
| 286 | 285 |
| 287 form.fields[0].form_control_type = "select-one"; | 286 form.fields[0].form_control_type = "select-one"; |
| 288 form_structure.reset(new FormStructure(form)); | 287 form_structure.reset(new FormStructure(form, std::string())); |
| 289 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 288 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
| 290 } | 289 } |
| 291 | 290 |
| 292 TEST(FormStructureTest, HeuristicsContactInfo) { | 291 TEST(FormStructureTest, HeuristicsContactInfo) { |
| 293 scoped_ptr<FormStructure> form_structure; | 292 scoped_ptr<FormStructure> form_structure; |
| 294 FormData form; | 293 FormData form; |
| 295 form.method = ASCIIToUTF16("post"); | 294 form.method = ASCIIToUTF16("post"); |
| 296 | 295 |
| 297 FormFieldData field; | 296 FormFieldData field; |
| 298 field.form_control_type = "text"; | 297 field.form_control_type = "text"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 323 | 322 |
| 324 field.label = ASCIIToUTF16("Zip code"); | 323 field.label = ASCIIToUTF16("Zip code"); |
| 325 field.name = ASCIIToUTF16("zipcode"); | 324 field.name = ASCIIToUTF16("zipcode"); |
| 326 form.fields.push_back(field); | 325 form.fields.push_back(field); |
| 327 | 326 |
| 328 field.label = string16(); | 327 field.label = string16(); |
| 329 field.name = ASCIIToUTF16("Submit"); | 328 field.name = ASCIIToUTF16("Submit"); |
| 330 field.form_control_type = "submit"; | 329 field.form_control_type = "submit"; |
| 331 form.fields.push_back(field); | 330 form.fields.push_back(field); |
| 332 | 331 |
| 333 form_structure.reset(new FormStructure(form)); | 332 form_structure.reset(new FormStructure(form, std::string())); |
| 334 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 333 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 335 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 334 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 336 | 335 |
| 337 // Expect the correct number of fields. | 336 // Expect the correct number of fields. |
| 338 ASSERT_EQ(8U, form_structure->field_count()); | 337 ASSERT_EQ(8U, form_structure->field_count()); |
| 339 ASSERT_EQ(7U, form_structure->autofill_count()); | 338 ASSERT_EQ(7U, form_structure->autofill_count()); |
| 340 | 339 |
| 341 // First name. | 340 // First name. |
| 342 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 341 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 343 // Last name. | 342 // Last name. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 374 field.label = string16(); | 373 field.label = string16(); |
| 375 field.name = ASCIIToUTF16("field2"); | 374 field.name = ASCIIToUTF16("field2"); |
| 376 field.autocomplete_attribute = "family-name"; | 375 field.autocomplete_attribute = "family-name"; |
| 377 form.fields.push_back(field); | 376 form.fields.push_back(field); |
| 378 | 377 |
| 379 field.label = string16(); | 378 field.label = string16(); |
| 380 field.name = ASCIIToUTF16("field3"); | 379 field.name = ASCIIToUTF16("field3"); |
| 381 field.autocomplete_attribute = "email"; | 380 field.autocomplete_attribute = "email"; |
| 382 form.fields.push_back(field); | 381 form.fields.push_back(field); |
| 383 | 382 |
| 384 form_structure.reset(new FormStructure(form)); | 383 form_structure.reset(new FormStructure(form, std::string())); |
| 385 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 384 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 386 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 385 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 387 | 386 |
| 388 // Expect the correct number of fields. | 387 // Expect the correct number of fields. |
| 389 ASSERT_EQ(3U, form_structure->field_count()); | 388 ASSERT_EQ(3U, form_structure->field_count()); |
| 390 ASSERT_EQ(3U, form_structure->autofill_count()); | 389 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 391 | 390 |
| 392 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 391 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 393 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 392 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 394 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 393 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 412 field.label = string16(); | 411 field.label = string16(); |
| 413 field.name = ASCIIToUTF16("field2"); | 412 field.name = ASCIIToUTF16("field2"); |
| 414 field.autocomplete_attribute = "tel-local-prefix"; | 413 field.autocomplete_attribute = "tel-local-prefix"; |
| 415 form.fields.push_back(field); | 414 form.fields.push_back(field); |
| 416 | 415 |
| 417 field.label = string16(); | 416 field.label = string16(); |
| 418 field.name = ASCIIToUTF16("field3"); | 417 field.name = ASCIIToUTF16("field3"); |
| 419 field.autocomplete_attribute = "tel-local-suffix"; | 418 field.autocomplete_attribute = "tel-local-suffix"; |
| 420 form.fields.push_back(field); | 419 form.fields.push_back(field); |
| 421 | 420 |
| 422 form_structure.reset(new FormStructure(form)); | 421 form_structure.reset(new FormStructure(form, std::string())); |
| 423 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 422 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 424 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 423 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 425 | 424 |
| 426 // Expect the correct number of fields. | 425 // Expect the correct number of fields. |
| 427 ASSERT_EQ(3U, form_structure->field_count()); | 426 ASSERT_EQ(3U, form_structure->field_count()); |
| 428 EXPECT_EQ(3U, form_structure->autofill_count()); | 427 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 429 | 428 |
| 430 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); | 429 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); |
| 431 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); | 430 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); |
| 432 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); | 431 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 453 form.fields.push_back(field); | 452 form.fields.push_back(field); |
| 454 | 453 |
| 455 field.label = ASCIIToUTF16("Last Name"); | 454 field.label = ASCIIToUTF16("Last Name"); |
| 456 field.name = ASCIIToUTF16("lastname"); | 455 field.name = ASCIIToUTF16("lastname"); |
| 457 form.fields.push_back(field); | 456 form.fields.push_back(field); |
| 458 | 457 |
| 459 field.label = ASCIIToUTF16("Email"); | 458 field.label = ASCIIToUTF16("Email"); |
| 460 field.name = ASCIIToUTF16("email"); | 459 field.name = ASCIIToUTF16("email"); |
| 461 form.fields.push_back(field); | 460 form.fields.push_back(field); |
| 462 | 461 |
| 463 form_structure.reset(new FormStructure(form)); | 462 form_structure.reset(new FormStructure(form, std::string())); |
| 464 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 463 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 465 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 464 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 466 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); | 465 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); |
| 467 | 466 |
| 468 ASSERT_EQ(3U, form_structure->field_count()); | 467 ASSERT_EQ(3U, form_structure->field_count()); |
| 469 ASSERT_EQ(3U, form_structure->autofill_count()); | 468 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 470 | 469 |
| 471 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 470 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 472 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 471 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 473 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 472 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
| 474 | 473 |
| 475 // Now update the first form field to include an 'autocomplete' attribute. | 474 // Now update the first form field to include an 'autocomplete' attribute. |
| 476 form.fields.front().autocomplete_attribute = "x-other"; | 475 form.fields.front().autocomplete_attribute = "x-other"; |
| 477 form_structure.reset(new FormStructure(form)); | 476 form_structure.reset(new FormStructure(form, std::string())); |
| 478 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 477 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 479 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 478 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
| 480 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); | 479 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); |
| 481 | 480 |
| 482 ASSERT_EQ(3U, form_structure->field_count()); | 481 ASSERT_EQ(3U, form_structure->field_count()); |
| 483 ASSERT_EQ(0U, form_structure->autofill_count()); | 482 ASSERT_EQ(0U, form_structure->autofill_count()); |
| 484 | 483 |
| 485 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 484 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 486 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 485 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 487 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 486 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 // different sections. This is only an interesting test due to how we | 526 // different sections. This is only an interesting test due to how we |
| 528 // implement implicit section names from attributes like "shipping email"; see | 527 // implement implicit section names from attributes like "shipping email"; see |
| 529 // the implementation for more details. | 528 // the implementation for more details. |
| 530 field.autocomplete_attribute = "section--shipping email"; | 529 field.autocomplete_attribute = "section--shipping email"; |
| 531 form.fields.push_back(field); | 530 form.fields.push_back(field); |
| 532 | 531 |
| 533 // Credit card fields are implicitly in a separate section from other fields. | 532 // Credit card fields are implicitly in a separate section from other fields. |
| 534 field.autocomplete_attribute = "section-foo cc-number"; | 533 field.autocomplete_attribute = "section-foo cc-number"; |
| 535 form.fields.push_back(field); | 534 form.fields.push_back(field); |
| 536 | 535 |
| 537 FormStructure form_structure(form); | 536 FormStructure form_structure(form, std::string()); |
| 538 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 537 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 539 EXPECT_TRUE(form_structure.IsAutofillable(true)); | 538 EXPECT_TRUE(form_structure.IsAutofillable(true)); |
| 540 | 539 |
| 541 // Expect the correct number of fields. | 540 // Expect the correct number of fields. |
| 542 ASSERT_EQ(9U, form_structure.field_count()); | 541 ASSERT_EQ(9U, form_structure.field_count()); |
| 543 EXPECT_EQ(9U, form_structure.autofill_count()); | 542 EXPECT_EQ(9U, form_structure.autofill_count()); |
| 544 | 543 |
| 545 // All of the fields in this form should be parsed as belonging to different | 544 // All of the fields in this form should be parsed as belonging to different |
| 546 // sections. | 545 // sections. |
| 547 std::set<std::string> section_names; | 546 std::set<std::string> section_names; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 572 // Invalid tokens should prevent us from setting a section name. | 571 // Invalid tokens should prevent us from setting a section name. |
| 573 field.autocomplete_attribute = "garbage section-foo email"; | 572 field.autocomplete_attribute = "garbage section-foo email"; |
| 574 form.fields.push_back(field); | 573 form.fields.push_back(field); |
| 575 field.autocomplete_attribute = "garbage section-bar email"; | 574 field.autocomplete_attribute = "garbage section-bar email"; |
| 576 form.fields.push_back(field); | 575 form.fields.push_back(field); |
| 577 field.autocomplete_attribute = "garbage shipping email"; | 576 field.autocomplete_attribute = "garbage shipping email"; |
| 578 form.fields.push_back(field); | 577 form.fields.push_back(field); |
| 579 field.autocomplete_attribute = "garbage billing email"; | 578 field.autocomplete_attribute = "garbage billing email"; |
| 580 form.fields.push_back(field); | 579 form.fields.push_back(field); |
| 581 | 580 |
| 582 FormStructure form_structure(form); | 581 FormStructure form_structure(form, std::string()); |
| 583 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 582 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 584 | 583 |
| 585 // Expect the correct number of fields. | 584 // Expect the correct number of fields. |
| 586 ASSERT_EQ(6U, form_structure.field_count()); | 585 ASSERT_EQ(6U, form_structure.field_count()); |
| 587 EXPECT_EQ(2U, form_structure.autofill_count()); | 586 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 588 | 587 |
| 589 // All of the fields in this form should be parsed as belonging to the same | 588 // All of the fields in this form should be parsed as belonging to the same |
| 590 // section. | 589 // section. |
| 591 std::set<std::string> section_names; | 590 std::set<std::string> section_names; |
| 592 for (size_t i = 0; i < 6; ++i) { | 591 for (size_t i = 0; i < 6; ++i) { |
| 593 section_names.insert(form_structure.field(i)->section()); | 592 section_names.insert(form_structure.field(i)->section()); |
| 594 } | 593 } |
| 595 EXPECT_EQ(1U, section_names.size()); | 594 EXPECT_EQ(1U, section_names.size()); |
| 596 } | 595 } |
| 597 | 596 |
| 598 // Verify that we can correctly process repeated sections listed in the | 597 // Verify that we can correctly process repeated sections listed in the |
| 599 // |autocomplete| attribute. | 598 // |autocomplete| attribute. |
| 600 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { | 599 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
| 601 FormData form; | 600 FormData form; |
| 602 form.method = ASCIIToUTF16("post"); | 601 form.method = ASCIIToUTF16("post"); |
| 603 | 602 |
| 604 FormFieldData field; | 603 FormFieldData field; |
| 605 field.form_control_type = "text"; | 604 field.form_control_type = "text"; |
| 606 | 605 |
| 607 field.autocomplete_attribute = "section-foo email"; | 606 field.autocomplete_attribute = "section-foo email"; |
| 608 form.fields.push_back(field); | 607 form.fields.push_back(field); |
| 609 field.autocomplete_attribute = "section-foo street-address"; | 608 field.autocomplete_attribute = "section-foo street-address"; |
| 610 form.fields.push_back(field); | 609 form.fields.push_back(field); |
| 611 | 610 |
| 612 FormStructure form_structure(form); | 611 FormStructure form_structure(form, std::string()); |
| 613 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 612 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 614 | 613 |
| 615 // Expect the correct number of fields. | 614 // Expect the correct number of fields. |
| 616 ASSERT_EQ(2U, form_structure.field_count()); | 615 ASSERT_EQ(2U, form_structure.field_count()); |
| 617 EXPECT_EQ(2U, form_structure.autofill_count()); | 616 EXPECT_EQ(2U, form_structure.autofill_count()); |
| 618 | 617 |
| 619 // All of the fields in this form should be parsed as belonging to the same | 618 // All of the fields in this form should be parsed as belonging to the same |
| 620 // section. | 619 // section. |
| 621 std::set<std::string> section_names; | 620 std::set<std::string> section_names; |
| 622 for (size_t i = 0; i < 2; ++i) { | 621 for (size_t i = 0; i < 2; ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 640 field.name = string16(); | 639 field.name = string16(); |
| 641 field.autocomplete_attribute = "section-foo email"; | 640 field.autocomplete_attribute = "section-foo email"; |
| 642 form.fields.push_back(field); | 641 form.fields.push_back(field); |
| 643 field.name = string16(); | 642 field.name = string16(); |
| 644 field.autocomplete_attribute = "name"; | 643 field.autocomplete_attribute = "name"; |
| 645 form.fields.push_back(field); | 644 form.fields.push_back(field); |
| 646 field.name = ASCIIToUTF16("two"); | 645 field.name = ASCIIToUTF16("two"); |
| 647 field.autocomplete_attribute = "street-address"; | 646 field.autocomplete_attribute = "street-address"; |
| 648 form.fields.push_back(field); | 647 form.fields.push_back(field); |
| 649 | 648 |
| 650 FormStructure form_structure(form); | 649 FormStructure form_structure(form, std::string()); |
| 651 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 650 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 652 | 651 |
| 653 // Expect the correct number of fields. | 652 // Expect the correct number of fields. |
| 654 ASSERT_EQ(4U, form_structure.field_count()); | 653 ASSERT_EQ(4U, form_structure.field_count()); |
| 655 EXPECT_EQ(4U, form_structure.autofill_count()); | 654 EXPECT_EQ(4U, form_structure.autofill_count()); |
| 656 | 655 |
| 657 // Normally, the two separate address fields would cause us to detect two | 656 // Normally, the two separate address fields would cause us to detect two |
| 658 // separate sections; but because there is an author-specified section in this | 657 // separate sections; but because there is an author-specified section in this |
| 659 // form, we do not apply these usual heuristics. | 658 // form, we do not apply these usual heuristics. |
| 660 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); | 659 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 704 |
| 706 field.label = ASCIIToUTF16("Phone Number:"); | 705 field.label = ASCIIToUTF16("Phone Number:"); |
| 707 field.name = ASCIIToUTF16("BillTo.Phone"); | 706 field.name = ASCIIToUTF16("BillTo.Phone"); |
| 708 form.fields.push_back(field); | 707 form.fields.push_back(field); |
| 709 | 708 |
| 710 field.label = string16(); | 709 field.label = string16(); |
| 711 field.name = ASCIIToUTF16("Submit"); | 710 field.name = ASCIIToUTF16("Submit"); |
| 712 field.form_control_type = "submit"; | 711 field.form_control_type = "submit"; |
| 713 form.fields.push_back(field); | 712 form.fields.push_back(field); |
| 714 | 713 |
| 715 form_structure.reset(new FormStructure(form)); | 714 form_structure.reset(new FormStructure(form, std::string())); |
| 716 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 715 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 717 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 716 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 718 ASSERT_EQ(10U, form_structure->field_count()); | 717 ASSERT_EQ(10U, form_structure->field_count()); |
| 719 ASSERT_EQ(9U, form_structure->autofill_count()); | 718 ASSERT_EQ(9U, form_structure->autofill_count()); |
| 720 | 719 |
| 721 // First name. | 720 // First name. |
| 722 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 721 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 723 // Last name. | 722 // Last name. |
| 724 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 723 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 725 // Address. | 724 // Address. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 field.label = ASCIIToUTF16("Zip Code"); | 772 field.label = ASCIIToUTF16("Zip Code"); |
| 774 field.name = ASCIIToUTF16("Home.PostalCode"); | 773 field.name = ASCIIToUTF16("Home.PostalCode"); |
| 775 form.fields.push_back(field); | 774 form.fields.push_back(field); |
| 776 | 775 |
| 777 field.label = string16(); | 776 field.label = string16(); |
| 778 field.name = ASCIIToUTF16("Submit"); | 777 field.name = ASCIIToUTF16("Submit"); |
| 779 field.value = ASCIIToUTF16("continue"); | 778 field.value = ASCIIToUTF16("continue"); |
| 780 field.form_control_type = "submit"; | 779 field.form_control_type = "submit"; |
| 781 form.fields.push_back(field); | 780 form.fields.push_back(field); |
| 782 | 781 |
| 783 form_structure.reset(new FormStructure(form)); | 782 form_structure.reset(new FormStructure(form, std::string())); |
| 784 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 783 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 785 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 784 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 786 ASSERT_EQ(7U, form_structure->field_count()); | 785 ASSERT_EQ(7U, form_structure->field_count()); |
| 787 ASSERT_EQ(6U, form_structure->autofill_count()); | 786 ASSERT_EQ(6U, form_structure->autofill_count()); |
| 788 | 787 |
| 789 // Email. | 788 // Email. |
| 790 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); | 789 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); |
| 791 // Full name. | 790 // Full name. |
| 792 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); | 791 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); |
| 793 // Company | 792 // Company |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 838 |
| 840 field.label = ASCIIToUTF16("Zip code"); | 839 field.label = ASCIIToUTF16("Zip code"); |
| 841 field.name = string16(); | 840 field.name = string16(); |
| 842 form.fields.push_back(field); | 841 form.fields.push_back(field); |
| 843 | 842 |
| 844 field.label = string16(); | 843 field.label = string16(); |
| 845 field.name = ASCIIToUTF16("Submit"); | 844 field.name = ASCIIToUTF16("Submit"); |
| 846 field.form_control_type = "submit"; | 845 field.form_control_type = "submit"; |
| 847 form.fields.push_back(field); | 846 form.fields.push_back(field); |
| 848 | 847 |
| 849 form_structure.reset(new FormStructure(form)); | 848 form_structure.reset(new FormStructure(form, std::string())); |
| 850 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 849 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 851 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 850 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 852 ASSERT_EQ(8U, form_structure->field_count()); | 851 ASSERT_EQ(8U, form_structure->field_count()); |
| 853 ASSERT_EQ(7U, form_structure->autofill_count()); | 852 ASSERT_EQ(7U, form_structure->autofill_count()); |
| 854 | 853 |
| 855 // First name. | 854 // First name. |
| 856 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 855 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 857 // Last name. | 856 // Last name. |
| 858 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 857 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 859 // Email. | 858 // Email. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 | 896 |
| 898 field.label = ASCIIToUTF16("Verification"); | 897 field.label = ASCIIToUTF16("Verification"); |
| 899 field.name = ASCIIToUTF16("verification"); | 898 field.name = ASCIIToUTF16("verification"); |
| 900 form.fields.push_back(field); | 899 form.fields.push_back(field); |
| 901 | 900 |
| 902 field.label = string16(); | 901 field.label = string16(); |
| 903 field.name = ASCIIToUTF16("Submit"); | 902 field.name = ASCIIToUTF16("Submit"); |
| 904 field.form_control_type = "submit"; | 903 field.form_control_type = "submit"; |
| 905 form.fields.push_back(field); | 904 form.fields.push_back(field); |
| 906 | 905 |
| 907 form_structure.reset(new FormStructure(form)); | 906 form_structure.reset(new FormStructure(form, std::string())); |
| 908 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 907 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 909 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 908 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 910 ASSERT_EQ(6U, form_structure->field_count()); | 909 ASSERT_EQ(6U, form_structure->field_count()); |
| 911 ASSERT_EQ(5U, form_structure->autofill_count()); | 910 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 912 | 911 |
| 913 // Credit card name. | 912 // Credit card name. |
| 914 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 913 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 915 // Credit card number. | 914 // Credit card number. |
| 916 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); | 915 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); |
| 917 // Credit card expiration month. | 916 // Credit card expiration month. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 | 957 |
| 959 field.label = ASCIIToUTF16("Verification"); | 958 field.label = ASCIIToUTF16("Verification"); |
| 960 field.name = ASCIIToUTF16("verification"); | 959 field.name = ASCIIToUTF16("verification"); |
| 961 form.fields.push_back(field); | 960 form.fields.push_back(field); |
| 962 | 961 |
| 963 field.label = string16(); | 962 field.label = string16(); |
| 964 field.name = ASCIIToUTF16("Submit"); | 963 field.name = ASCIIToUTF16("Submit"); |
| 965 field.form_control_type = "submit"; | 964 field.form_control_type = "submit"; |
| 966 form.fields.push_back(field); | 965 form.fields.push_back(field); |
| 967 | 966 |
| 968 form_structure.reset(new FormStructure(form)); | 967 form_structure.reset(new FormStructure(form, std::string())); |
| 969 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 968 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 970 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 969 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 971 ASSERT_EQ(7U, form_structure->field_count()); | 970 ASSERT_EQ(7U, form_structure->field_count()); |
| 972 ASSERT_EQ(5U, form_structure->autofill_count()); | 971 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 973 | 972 |
| 974 // Credit card name. | 973 // Credit card name. |
| 975 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 974 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 976 // Credit card type. This is an unknown type but related to the credit card. | 975 // Credit card type. This is an unknown type but related to the credit card. |
| 977 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 976 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 978 // Credit card number. | 977 // Credit card number. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1006 form.fields.push_back(field); | 1005 form.fields.push_back(field); |
| 1007 | 1006 |
| 1008 field.label = ASCIIToUTF16("Address Line3"); | 1007 field.label = ASCIIToUTF16("Address Line3"); |
| 1009 field.name = ASCIIToUTF16("Address"); | 1008 field.name = ASCIIToUTF16("Address"); |
| 1010 form.fields.push_back(field); | 1009 form.fields.push_back(field); |
| 1011 | 1010 |
| 1012 field.label = ASCIIToUTF16("City"); | 1011 field.label = ASCIIToUTF16("City"); |
| 1013 field.name = ASCIIToUTF16("city"); | 1012 field.name = ASCIIToUTF16("city"); |
| 1014 form.fields.push_back(field); | 1013 form.fields.push_back(field); |
| 1015 | 1014 |
| 1016 form_structure.reset(new FormStructure(form)); | 1015 form_structure.reset(new FormStructure(form, std::string())); |
| 1017 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1016 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1018 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1017 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1019 ASSERT_EQ(4U, form_structure->field_count()); | 1018 ASSERT_EQ(4U, form_structure->field_count()); |
| 1020 ASSERT_EQ(3U, form_structure->autofill_count()); | 1019 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1021 | 1020 |
| 1022 // Address Line 1. | 1021 // Address Line 1. |
| 1023 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1022 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1024 // Address Line 2. | 1023 // Address Line 2. |
| 1025 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1024 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1026 // Address Line 3. | 1025 // Address Line 3. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1048 form.fields.push_back(field); | 1047 form.fields.push_back(field); |
| 1049 | 1048 |
| 1050 field.label = ASCIIToUTF16("Address Line1"); | 1049 field.label = ASCIIToUTF16("Address Line1"); |
| 1051 field.name = ASCIIToUTF16("billing.address.addressLine1"); | 1050 field.name = ASCIIToUTF16("billing.address.addressLine1"); |
| 1052 form.fields.push_back(field); | 1051 form.fields.push_back(field); |
| 1053 | 1052 |
| 1054 field.label = ASCIIToUTF16("Address Line2"); | 1053 field.label = ASCIIToUTF16("Address Line2"); |
| 1055 field.name = ASCIIToUTF16("billing.address.addressLine2"); | 1054 field.name = ASCIIToUTF16("billing.address.addressLine2"); |
| 1056 form.fields.push_back(field); | 1055 form.fields.push_back(field); |
| 1057 | 1056 |
| 1058 form_structure.reset(new FormStructure(form)); | 1057 form_structure.reset(new FormStructure(form, std::string())); |
| 1059 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1058 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1060 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1059 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1061 ASSERT_EQ(4U, form_structure->field_count()); | 1060 ASSERT_EQ(4U, form_structure->field_count()); |
| 1062 ASSERT_EQ(4U, form_structure->autofill_count()); | 1061 ASSERT_EQ(4U, form_structure->autofill_count()); |
| 1063 | 1062 |
| 1064 // Address Line 1. | 1063 // Address Line 1. |
| 1065 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1064 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1066 // Address Line 2. | 1065 // Address Line 2. |
| 1067 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1066 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1068 // Address Line 1. | 1067 // Address Line 1. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1094 form.fields.push_back(field); | 1093 form.fields.push_back(field); |
| 1095 | 1094 |
| 1096 field.label = ASCIIToUTF16("Street address second line"); | 1095 field.label = ASCIIToUTF16("Street address second line"); |
| 1097 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); | 1096 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); |
| 1098 form.fields.push_back(field); | 1097 form.fields.push_back(field); |
| 1099 | 1098 |
| 1100 field.label = ASCIIToUTF16("City:"); | 1099 field.label = ASCIIToUTF16("City:"); |
| 1101 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); | 1100 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); |
| 1102 form.fields.push_back(field); | 1101 form.fields.push_back(field); |
| 1103 | 1102 |
| 1104 form_structure.reset(new FormStructure(form)); | 1103 form_structure.reset(new FormStructure(form, std::string())); |
| 1105 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1104 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1106 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1105 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1107 ASSERT_EQ(4U, form_structure->field_count()); | 1106 ASSERT_EQ(4U, form_structure->field_count()); |
| 1108 EXPECT_EQ(3U, form_structure->autofill_count()); | 1107 EXPECT_EQ(3U, form_structure->autofill_count()); |
| 1109 | 1108 |
| 1110 // Address Line 1. | 1109 // Address Line 1. |
| 1111 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1110 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1112 // Suite / Apt. | 1111 // Suite / Apt. |
| 1113 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1112 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1114 // Address Line 3. | 1113 // Address Line 3. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1133 form.fields.push_back(field); | 1132 form.fields.push_back(field); |
| 1134 | 1133 |
| 1135 field.label = ASCIIToUTF16("Floor number, suite number, etc"); | 1134 field.label = ASCIIToUTF16("Floor number, suite number, etc"); |
| 1136 field.name = ASCIIToUTF16("address2"); | 1135 field.name = ASCIIToUTF16("address2"); |
| 1137 form.fields.push_back(field); | 1136 form.fields.push_back(field); |
| 1138 | 1137 |
| 1139 field.label = ASCIIToUTF16("City:"); | 1138 field.label = ASCIIToUTF16("City:"); |
| 1140 field.name = ASCIIToUTF16("city"); | 1139 field.name = ASCIIToUTF16("city"); |
| 1141 form.fields.push_back(field); | 1140 form.fields.push_back(field); |
| 1142 | 1141 |
| 1143 form_structure.reset(new FormStructure(form)); | 1142 form_structure.reset(new FormStructure(form, std::string())); |
| 1144 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1143 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1145 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1144 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1146 ASSERT_EQ(3U, form_structure->field_count()); | 1145 ASSERT_EQ(3U, form_structure->field_count()); |
| 1147 ASSERT_EQ(3U, form_structure->autofill_count()); | 1146 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1148 | 1147 |
| 1149 // Address Line 1. | 1148 // Address Line 1. |
| 1150 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1149 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1151 // Address Line 2. | 1150 // Address Line 2. |
| 1152 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1151 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1153 // City. | 1152 // City. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1167 form.fields.push_back(field); | 1166 form.fields.push_back(field); |
| 1168 | 1167 |
| 1169 field.label = ASCIIToUTF16("Address Line2"); | 1168 field.label = ASCIIToUTF16("Address Line2"); |
| 1170 field.name = ASCIIToUTF16("Address"); | 1169 field.name = ASCIIToUTF16("Address"); |
| 1171 form.fields.push_back(field); | 1170 form.fields.push_back(field); |
| 1172 | 1171 |
| 1173 field.label = ASCIIToUTF16("State/Province/Region"); | 1172 field.label = ASCIIToUTF16("State/Province/Region"); |
| 1174 field.name = ASCIIToUTF16("State"); | 1173 field.name = ASCIIToUTF16("State"); |
| 1175 form.fields.push_back(field); | 1174 form.fields.push_back(field); |
| 1176 | 1175 |
| 1177 form_structure.reset(new FormStructure(form)); | 1176 form_structure.reset(new FormStructure(form, std::string())); |
| 1178 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1177 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1179 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1178 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1180 ASSERT_EQ(3U, form_structure->field_count()); | 1179 ASSERT_EQ(3U, form_structure->field_count()); |
| 1181 ASSERT_EQ(3U, form_structure->autofill_count()); | 1180 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1182 | 1181 |
| 1183 // Address Line 1. | 1182 // Address Line 1. |
| 1184 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1183 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
| 1185 // Address Line 2. | 1184 // Address Line 2. |
| 1186 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1185 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
| 1187 // State. | 1186 // State. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 form.fields.push_back(field); | 1233 form.fields.push_back(field); |
| 1235 | 1234 |
| 1236 field.label = ASCIIToUTF16("Phone*:"); | 1235 field.label = ASCIIToUTF16("Phone*:"); |
| 1237 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); | 1236 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); |
| 1238 form.fields.push_back(field); | 1237 form.fields.push_back(field); |
| 1239 | 1238 |
| 1240 field.label = ASCIIToUTF16("Email Address*:"); | 1239 field.label = ASCIIToUTF16("Email Address*:"); |
| 1241 field.name = ASCIIToUTF16("email$emailBox"); | 1240 field.name = ASCIIToUTF16("email$emailBox"); |
| 1242 form.fields.push_back(field); | 1241 form.fields.push_back(field); |
| 1243 | 1242 |
| 1244 form_structure.reset(new FormStructure(form)); | 1243 form_structure.reset(new FormStructure(form, std::string())); |
| 1245 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1244 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1246 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1245 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1247 ASSERT_EQ(11U, form_structure->field_count()); | 1246 ASSERT_EQ(11U, form_structure->field_count()); |
| 1248 ASSERT_EQ(11U, form_structure->autofill_count()); | 1247 ASSERT_EQ(11U, form_structure->autofill_count()); |
| 1249 | 1248 |
| 1250 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 1249 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
| 1251 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 1250 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
| 1252 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); | 1251 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); |
| 1253 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); | 1252 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); |
| 1254 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); | 1253 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1285 field.max_length = 4; // Size of suffix is 4. If unlimited size is | 1284 field.max_length = 4; // Size of suffix is 4. If unlimited size is |
| 1286 // passed, phone will be parsed as | 1285 // passed, phone will be parsed as |
| 1287 // <country code> - <area code> - <phone>. | 1286 // <country code> - <area code> - <phone>. |
| 1288 form.fields.push_back(field); | 1287 form.fields.push_back(field); |
| 1289 | 1288 |
| 1290 field.label = ASCIIToUTF16("ext.:"); | 1289 field.label = ASCIIToUTF16("ext.:"); |
| 1291 field.name = ASCIIToUTF16("dayphone4"); | 1290 field.name = ASCIIToUTF16("dayphone4"); |
| 1292 field.max_length = 0; | 1291 field.max_length = 0; |
| 1293 form.fields.push_back(field); | 1292 form.fields.push_back(field); |
| 1294 | 1293 |
| 1295 form_structure.reset(new FormStructure(form)); | 1294 form_structure.reset(new FormStructure(form, std::string())); |
| 1296 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1295 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1297 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1296 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1298 ASSERT_EQ(4U, form_structure->field_count()); | 1297 ASSERT_EQ(4U, form_structure->field_count()); |
| 1299 ASSERT_EQ(3U, form_structure->autofill_count()); | 1298 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 1300 | 1299 |
| 1301 // Area code. | 1300 // Area code. |
| 1302 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); | 1301 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); |
| 1303 // Phone number suffix. | 1302 // Phone number suffix. |
| 1304 EXPECT_EQ(PHONE_HOME_NUMBER, | 1303 EXPECT_EQ(PHONE_HOME_NUMBER, |
| 1305 form_structure->field(1)->heuristic_type()); | 1304 form_structure->field(1)->heuristic_type()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1331 form.fields.push_back(field); | 1330 form.fields.push_back(field); |
| 1332 | 1331 |
| 1333 field.label = ASCIIToUTF16("Expiration Date"); | 1332 field.label = ASCIIToUTF16("Expiration Date"); |
| 1334 field.name = ASCIIToUTF16("expiration_month"); | 1333 field.name = ASCIIToUTF16("expiration_month"); |
| 1335 form.fields.push_back(field); | 1334 form.fields.push_back(field); |
| 1336 | 1335 |
| 1337 field.label = ASCIIToUTF16("Expiration Year"); | 1336 field.label = ASCIIToUTF16("Expiration Year"); |
| 1338 field.name = ASCIIToUTF16("expiration_year"); | 1337 field.name = ASCIIToUTF16("expiration_year"); |
| 1339 form.fields.push_back(field); | 1338 form.fields.push_back(field); |
| 1340 | 1339 |
| 1341 form_structure.reset(new FormStructure(form)); | 1340 form_structure.reset(new FormStructure(form, std::string())); |
| 1342 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1341 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1343 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1342 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1344 | 1343 |
| 1345 // Expect the correct number of fields. | 1344 // Expect the correct number of fields. |
| 1346 ASSERT_EQ(5U, form_structure->field_count()); | 1345 ASSERT_EQ(5U, form_structure->field_count()); |
| 1347 EXPECT_EQ(5U, form_structure->autofill_count()); | 1346 EXPECT_EQ(5U, form_structure->autofill_count()); |
| 1348 | 1347 |
| 1349 // Name on Card. | 1348 // Name on Card. |
| 1350 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1349 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
| 1351 // Address. | 1350 // Address. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 form.fields.push_back(field); | 1383 form.fields.push_back(field); |
| 1385 | 1384 |
| 1386 field.label = string16(); | 1385 field.label = string16(); |
| 1387 field.name = ASCIIToUTF16("ccexpiresyear"); | 1386 field.name = ASCIIToUTF16("ccexpiresyear"); |
| 1388 form.fields.push_back(field); | 1387 form.fields.push_back(field); |
| 1389 | 1388 |
| 1390 field.label = ASCIIToUTF16("cvc number"); | 1389 field.label = ASCIIToUTF16("cvc number"); |
| 1391 field.name = ASCIIToUTF16("csc"); | 1390 field.name = ASCIIToUTF16("csc"); |
| 1392 form.fields.push_back(field); | 1391 form.fields.push_back(field); |
| 1393 | 1392 |
| 1394 form_structure.reset(new FormStructure(form)); | 1393 form_structure.reset(new FormStructure(form, std::string())); |
| 1395 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1394 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1396 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1395 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
| 1397 | 1396 |
| 1398 // Expect the correct number of fields. | 1397 // Expect the correct number of fields. |
| 1399 ASSERT_EQ(6U, form_structure->field_count()); | 1398 ASSERT_EQ(6U, form_structure->field_count()); |
| 1400 ASSERT_EQ(5U, form_structure->autofill_count()); | 1399 ASSERT_EQ(5U, form_structure->autofill_count()); |
| 1401 | 1400 |
| 1402 // Card Number. | 1401 // Card Number. |
| 1403 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); | 1402 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); |
| 1404 // First name, taken as name on card. | 1403 // First name, taken as name on card. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 form.fields.push_back(field); | 1442 form.fields.push_back(field); |
| 1444 | 1443 |
| 1445 // Add checkable field. | 1444 // Add checkable field. |
| 1446 FormFieldData checkable_field; | 1445 FormFieldData checkable_field; |
| 1447 checkable_field.is_checkable = true; | 1446 checkable_field.is_checkable = true; |
| 1448 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1447 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1449 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1448 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1450 form.fields.push_back(checkable_field); | 1449 form.fields.push_back(checkable_field); |
| 1451 | 1450 |
| 1452 ScopedVector<FormStructure> forms; | 1451 ScopedVector<FormStructure> forms; |
| 1453 forms.push_back(new FormStructure(form)); | 1452 forms.push_back(new FormStructure(form, std::string())); |
| 1454 std::vector<std::string> encoded_signatures; | 1453 std::vector<std::string> encoded_signatures; |
| 1455 std::string encoded_xml; | 1454 std::string encoded_xml; |
| 1456 const char * const kSignature1 = "11337937696949187602"; | 1455 const char * const kSignature1 = "11337937696949187602"; |
| 1457 const char * const kResponse1 = | 1456 const char * const kResponse1 = |
| 1458 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1457 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
| 1459 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1458 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
| 1460 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" | 1459 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" |
| 1461 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1460 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
| 1462 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" | 1461 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" |
| 1463 "</autofillquery>"; | 1462 "</autofillquery>"; |
| 1464 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1463 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1465 &encoded_signatures, | 1464 &encoded_signatures, |
| 1466 &encoded_xml)); | 1465 &encoded_xml)); |
| 1467 ASSERT_EQ(1U, encoded_signatures.size()); | 1466 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1468 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1467 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1469 EXPECT_EQ(kResponse1, encoded_xml); | 1468 EXPECT_EQ(kResponse1, encoded_xml); |
| 1470 | 1469 |
| 1471 // Add the same form, only one will be encoded, so EncodeQueryRequest() should | 1470 // Add the same form, only one will be encoded, so EncodeQueryRequest() should |
| 1472 // return the same data. | 1471 // return the same data. |
| 1473 forms.push_back(new FormStructure(form)); | 1472 forms.push_back(new FormStructure(form, std::string())); |
| 1474 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1473 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1475 &encoded_signatures, | 1474 &encoded_signatures, |
| 1476 &encoded_xml)); | 1475 &encoded_xml)); |
| 1477 ASSERT_EQ(1U, encoded_signatures.size()); | 1476 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1478 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1477 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1479 EXPECT_EQ(kResponse1, encoded_xml); | 1478 EXPECT_EQ(kResponse1, encoded_xml); |
| 1480 // Add 5 address fields - this should be still a valid form. | 1479 // Add 5 address fields - this should be still a valid form. |
| 1481 for (size_t i = 0; i < 5; ++i) { | 1480 for (size_t i = 0; i < 5; ++i) { |
| 1482 field.label = ASCIIToUTF16("Address"); | 1481 field.label = ASCIIToUTF16("Address"); |
| 1483 field.name = ASCIIToUTF16("address"); | 1482 field.name = ASCIIToUTF16("address"); |
| 1484 form.fields.push_back(field); | 1483 form.fields.push_back(field); |
| 1485 } | 1484 } |
| 1486 | 1485 |
| 1487 forms.push_back(new FormStructure(form)); | 1486 forms.push_back(new FormStructure(form, std::string())); |
| 1488 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1487 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1489 &encoded_signatures, | 1488 &encoded_signatures, |
| 1490 &encoded_xml)); | 1489 &encoded_xml)); |
| 1491 ASSERT_EQ(2U, encoded_signatures.size()); | 1490 ASSERT_EQ(2U, encoded_signatures.size()); |
| 1492 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1491 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1493 const char * const kSignature2 = "8308881815906226214"; | 1492 const char * const kSignature2 = "8308881815906226214"; |
| 1494 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1493 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
| 1495 const char * const kResponse2 = | 1494 const char * const kResponse2 = |
| 1496 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1495 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
| 1497 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1496 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1508 | 1507 |
| 1509 FormData malformed_form(form); | 1508 FormData malformed_form(form); |
| 1510 // Add 50 address fields - the form is not valid anymore, but previous ones | 1509 // Add 50 address fields - the form is not valid anymore, but previous ones |
| 1511 // are. The result should be the same as in previous test. | 1510 // are. The result should be the same as in previous test. |
| 1512 for (size_t i = 0; i < 50; ++i) { | 1511 for (size_t i = 0; i < 50; ++i) { |
| 1513 field.label = ASCIIToUTF16("Address"); | 1512 field.label = ASCIIToUTF16("Address"); |
| 1514 field.name = ASCIIToUTF16("address"); | 1513 field.name = ASCIIToUTF16("address"); |
| 1515 malformed_form.fields.push_back(field); | 1514 malformed_form.fields.push_back(field); |
| 1516 } | 1515 } |
| 1517 | 1516 |
| 1518 forms.push_back(new FormStructure(malformed_form)); | 1517 forms.push_back(new FormStructure(malformed_form, std::string())); |
| 1519 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1518 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
| 1520 &encoded_signatures, | 1519 &encoded_signatures, |
| 1521 &encoded_xml)); | 1520 &encoded_xml)); |
| 1522 ASSERT_EQ(2U, encoded_signatures.size()); | 1521 ASSERT_EQ(2U, encoded_signatures.size()); |
| 1523 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1522 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
| 1524 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1523 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
| 1525 EXPECT_EQ(kResponse2, encoded_xml); | 1524 EXPECT_EQ(kResponse2, encoded_xml); |
| 1526 | 1525 |
| 1527 // Check that we fail if there are only bad form(s). | 1526 // Check that we fail if there are only bad form(s). |
| 1528 ScopedVector<FormStructure> bad_forms; | 1527 ScopedVector<FormStructure> bad_forms; |
| 1529 bad_forms.push_back(new FormStructure(malformed_form)); | 1528 bad_forms.push_back(new FormStructure(malformed_form, std::string())); |
| 1530 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1529 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
| 1531 &encoded_signatures, | 1530 &encoded_signatures, |
| 1532 &encoded_xml)); | 1531 &encoded_xml)); |
| 1533 EXPECT_EQ(0U, encoded_signatures.size()); | 1532 EXPECT_EQ(0U, encoded_signatures.size()); |
| 1534 EXPECT_EQ("", encoded_xml); | 1533 EXPECT_EQ("", encoded_xml); |
| 1535 | 1534 |
| 1536 // Check the behaviour with kEnableExperimentalFormFilling switch on. | 1535 // Check the behaviour with kEnableExperimentalFormFilling switch on. |
| 1537 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1538 switches::kEnableExperimentalFormFilling); | |
| 1539 // Add the previous form but with flag set. | 1536 // Add the previous form but with flag set. |
| 1540 ScopedVector<FormStructure> checkable_forms; | 1537 ScopedVector<FormStructure> checkable_forms; |
| 1541 checkable_forms.push_back(new FormStructure(form)); | 1538 checkable_forms.push_back( |
| 1539 new FormStructure(form, "https://www.abc.com/checkout")); |
| 1542 | 1540 |
| 1543 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | 1541 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), |
| 1544 &encoded_signatures, | 1542 &encoded_signatures, |
| 1545 &encoded_xml)); | 1543 &encoded_xml)); |
| 1546 const char * const kSignature3 = "7747357776717901584"; | 1544 const char * const kSignature3 = "7747357776717901584"; |
| 1547 const char * const kResponse3 = | 1545 const char * const kResponse3 = |
| 1548 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | 1546 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " |
| 1549 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" | 1547 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" |
| 1550 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" | 1548 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" |
| 1551 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | 1549 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" |
| 1552 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | 1550 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " |
| 1553 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | 1551 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " |
| 1554 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1552 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
| 1555 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | 1553 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" |
| 1556 "</autofillquery>"; | 1554 "</autofillquery>"; |
| 1557 ASSERT_EQ(1U, encoded_signatures.size()); | 1555 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1558 EXPECT_EQ(kSignature3, encoded_signatures[0]); | 1556 EXPECT_EQ(kSignature3, encoded_signatures[0]); |
| 1559 EXPECT_EQ(kResponse3, encoded_xml); | 1557 EXPECT_EQ(kResponse3, encoded_xml); |
| 1560 } | 1558 } |
| 1561 | 1559 |
| 1562 TEST(FormStructureTest, EncodeUploadRequest) { | 1560 TEST(FormStructureTest, EncodeUploadRequest) { |
| 1563 scoped_ptr<FormStructure> form_structure; | 1561 scoped_ptr<FormStructure> form_structure; |
| 1564 std::vector<FieldTypeSet> possible_field_types; | 1562 std::vector<FieldTypeSet> possible_field_types; |
| 1565 FormData form; | 1563 FormData form; |
| 1566 form.method = ASCIIToUTF16("post"); | 1564 form.method = ASCIIToUTF16("post"); |
| 1567 form_structure.reset(new FormStructure(form)); | 1565 form_structure.reset(new FormStructure(form, std::string())); |
| 1568 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1566 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
| 1569 | 1567 |
| 1570 FormFieldData field; | 1568 FormFieldData field; |
| 1571 field.form_control_type = "text"; | 1569 field.form_control_type = "text"; |
| 1572 | 1570 |
| 1573 field.label = ASCIIToUTF16("First Name"); | 1571 field.label = ASCIIToUTF16("First Name"); |
| 1574 field.name = ASCIIToUTF16("firstname"); | 1572 field.name = ASCIIToUTF16("firstname"); |
| 1575 form.fields.push_back(field); | 1573 form.fields.push_back(field); |
| 1576 possible_field_types.push_back(FieldTypeSet()); | 1574 possible_field_types.push_back(FieldTypeSet()); |
| 1577 possible_field_types.back().insert(NAME_FIRST); | 1575 possible_field_types.back().insert(NAME_FIRST); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1605 | 1603 |
| 1606 // Add checkable field. | 1604 // Add checkable field. |
| 1607 FormFieldData checkable_field; | 1605 FormFieldData checkable_field; |
| 1608 checkable_field.is_checkable = true; | 1606 checkable_field.is_checkable = true; |
| 1609 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1607 checkable_field.label = ASCIIToUTF16("Checkable1"); |
| 1610 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1608 checkable_field.name = ASCIIToUTF16("Checkable1"); |
| 1611 form.fields.push_back(checkable_field); | 1609 form.fields.push_back(checkable_field); |
| 1612 possible_field_types.push_back(FieldTypeSet()); | 1610 possible_field_types.push_back(FieldTypeSet()); |
| 1613 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 1611 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
| 1614 | 1612 |
| 1615 form_structure.reset(new FormStructure(form)); | 1613 form_structure.reset(new FormStructure(form, std::string())); |
| 1616 | 1614 |
| 1617 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1615 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1618 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1616 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1619 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1617 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1620 | 1618 |
| 1621 FieldTypeSet available_field_types; | 1619 FieldTypeSet available_field_types; |
| 1622 available_field_types.insert(NAME_FIRST); | 1620 available_field_types.insert(NAME_FIRST); |
| 1623 available_field_types.insert(NAME_LAST); | 1621 available_field_types.insert(NAME_LAST); |
| 1624 available_field_types.insert(ADDRESS_HOME_LINE1); | 1622 available_field_types.insert(ADDRESS_HOME_LINE1); |
| 1625 available_field_types.insert(ADDRESS_HOME_LINE2); | 1623 available_field_types.insert(ADDRESS_HOME_LINE2); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 field.name = ASCIIToUTF16("address"); | 1661 field.name = ASCIIToUTF16("address"); |
| 1664 field.form_control_type = "text"; | 1662 field.form_control_type = "text"; |
| 1665 form.fields.push_back(field); | 1663 form.fields.push_back(field); |
| 1666 possible_field_types.push_back(FieldTypeSet()); | 1664 possible_field_types.push_back(FieldTypeSet()); |
| 1667 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1665 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 1668 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1666 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
| 1669 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1667 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
| 1670 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1668 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
| 1671 } | 1669 } |
| 1672 | 1670 |
| 1673 form_structure.reset(new FormStructure(form)); | 1671 form_structure.reset(new FormStructure(form, std::string())); |
| 1674 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1672 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1675 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1673 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1676 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1674 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1677 | 1675 |
| 1678 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 1676 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 1679 &encoded_xml)); | 1677 &encoded_xml)); |
| 1680 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 1678 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
| 1681 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " | 1679 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " |
| 1682 "formsignature=\"7816485729218079147\" autofillused=\"false\" " | 1680 "formsignature=\"7816485729218079147\" autofillused=\"false\" " |
| 1683 "datapresent=\"144200030e\">" | 1681 "datapresent=\"144200030e\">" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1702 field.label = ASCIIToUTF16("Address"); | 1700 field.label = ASCIIToUTF16("Address"); |
| 1703 field.name = ASCIIToUTF16("address"); | 1701 field.name = ASCIIToUTF16("address"); |
| 1704 field.form_control_type = "text"; | 1702 field.form_control_type = "text"; |
| 1705 form.fields.push_back(field); | 1703 form.fields.push_back(field); |
| 1706 possible_field_types.push_back(FieldTypeSet()); | 1704 possible_field_types.push_back(FieldTypeSet()); |
| 1707 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1705 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 1708 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1706 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
| 1709 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1707 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
| 1710 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1708 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
| 1711 } | 1709 } |
| 1712 form_structure.reset(new FormStructure(form)); | 1710 form_structure.reset(new FormStructure(form, std::string())); |
| 1713 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1711 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
| 1714 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1712 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 1715 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1713 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 1716 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, | 1714 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 1717 &encoded_xml)); | 1715 &encoded_xml)); |
| 1718 } | 1716 } |
| 1719 | 1717 |
| 1720 // Check that we compute the "datapresent" string correctly for the given | 1718 // Check that we compute the "datapresent" string correctly for the given |
| 1721 // |available_types|. | 1719 // |available_types|. |
| 1722 TEST(FormStructureTest, CheckDataPresence) { | 1720 TEST(FormStructureTest, CheckDataPresence) { |
| 1723 FormData form; | 1721 FormData form; |
| 1724 form.method = ASCIIToUTF16("post"); | 1722 form.method = ASCIIToUTF16("post"); |
| 1725 | 1723 |
| 1726 FormFieldData field; | 1724 FormFieldData field; |
| 1727 field.form_control_type = "text"; | 1725 field.form_control_type = "text"; |
| 1728 | 1726 |
| 1729 field.label = ASCIIToUTF16("First Name"); | 1727 field.label = ASCIIToUTF16("First Name"); |
| 1730 field.name = ASCIIToUTF16("first"); | 1728 field.name = ASCIIToUTF16("first"); |
| 1731 form.fields.push_back(field); | 1729 form.fields.push_back(field); |
| 1732 | 1730 |
| 1733 field.label = ASCIIToUTF16("Last Name"); | 1731 field.label = ASCIIToUTF16("Last Name"); |
| 1734 field.name = ASCIIToUTF16("last"); | 1732 field.name = ASCIIToUTF16("last"); |
| 1735 form.fields.push_back(field); | 1733 form.fields.push_back(field); |
| 1736 | 1734 |
| 1737 field.label = ASCIIToUTF16("Email"); | 1735 field.label = ASCIIToUTF16("Email"); |
| 1738 field.name = ASCIIToUTF16("email"); | 1736 field.name = ASCIIToUTF16("email"); |
| 1739 form.fields.push_back(field); | 1737 form.fields.push_back(field); |
| 1740 | 1738 |
| 1741 FormStructure form_structure(form); | 1739 FormStructure form_structure(form, std::string()); |
| 1742 | 1740 |
| 1743 FieldTypeSet unknown_type; | 1741 FieldTypeSet unknown_type; |
| 1744 unknown_type.insert(UNKNOWN_TYPE); | 1742 unknown_type.insert(UNKNOWN_TYPE); |
| 1745 for (size_t i = 0; i < form_structure.field_count(); ++i) | 1743 for (size_t i = 0; i < form_structure.field_count(); ++i) |
| 1746 form_structure.field(i)->set_possible_types(unknown_type); | 1744 form_structure.field(i)->set_possible_types(unknown_type); |
| 1747 | 1745 |
| 1748 // No available types. | 1746 // No available types. |
| 1749 // datapresent should be "" == trimmmed(0x0000000000000000) == | 1747 // datapresent should be "" == trimmmed(0x0000000000000000) == |
| 1750 // 0b0000000000000000000000000000000000000000000000000000000000000000 | 1748 // 0b0000000000000000000000000000000000000000000000000000000000000000 |
| 1751 FieldTypeSet available_field_types; | 1749 FieldTypeSet available_field_types; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 form.fields.push_back(field); | 1995 form.fields.push_back(field); |
| 1998 possible_field_types.push_back(FieldTypeSet()); | 1996 possible_field_types.push_back(FieldTypeSet()); |
| 1999 possible_field_types.back().insert(NAME_LAST); | 1997 possible_field_types.back().insert(NAME_LAST); |
| 2000 | 1998 |
| 2001 field.label = ASCIIToUTF16("Address"); | 1999 field.label = ASCIIToUTF16("Address"); |
| 2002 field.name = ASCIIToUTF16("address"); | 2000 field.name = ASCIIToUTF16("address"); |
| 2003 form.fields.push_back(field); | 2001 form.fields.push_back(field); |
| 2004 possible_field_types.push_back(FieldTypeSet()); | 2002 possible_field_types.push_back(FieldTypeSet()); |
| 2005 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 2003 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
| 2006 | 2004 |
| 2007 form_structure.reset(new FormStructure(form)); | 2005 form_structure.reset(new FormStructure(form, std::string())); |
| 2008 | 2006 |
| 2009 for (size_t i = 0; i < form_structure->field_count(); ++i) | 2007 for (size_t i = 0; i < form_structure->field_count(); ++i) |
| 2010 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 2008 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
| 2011 std::string encoded_xml; | 2009 std::string encoded_xml; |
| 2012 | 2010 |
| 2013 // Now we matched both fields singularly. | 2011 // Now we matched both fields singularly. |
| 2014 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 2012 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
| 2015 &encoded_xml)); | 2013 &encoded_xml)); |
| 2016 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 2014 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
| 2017 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" | 2015 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 field.form_control_type = "text"; | 2085 field.form_control_type = "text"; |
| 2088 | 2086 |
| 2089 field.label = ASCIIToUTF16("email"); | 2087 field.label = ASCIIToUTF16("email"); |
| 2090 field.name = ASCIIToUTF16("email"); | 2088 field.name = ASCIIToUTF16("email"); |
| 2091 form.fields.push_back(field); | 2089 form.fields.push_back(field); |
| 2092 | 2090 |
| 2093 field.label = ASCIIToUTF16("First Name"); | 2091 field.label = ASCIIToUTF16("First Name"); |
| 2094 field.name = ASCIIToUTF16("first"); | 2092 field.name = ASCIIToUTF16("first"); |
| 2095 form.fields.push_back(field); | 2093 form.fields.push_back(field); |
| 2096 | 2094 |
| 2097 form_structure.reset(new FormStructure(form)); | 2095 form_structure.reset(new FormStructure(form, std::string())); |
| 2098 | 2096 |
| 2099 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2097 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2100 std::string("://&&email&first")), | 2098 std::string("://&&email&first")), |
| 2101 form_structure->FormSignature()); | 2099 form_structure->FormSignature()); |
| 2102 | 2100 |
| 2103 form.origin = GURL(std::string("http://www.facebook.com")); | 2101 form.origin = GURL(std::string("http://www.facebook.com")); |
| 2104 form_structure.reset(new FormStructure(form)); | 2102 form_structure.reset(new FormStructure(form, std::string())); |
| 2105 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2103 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2106 std::string("http://www.facebook.com&&email&first")), | 2104 std::string("http://www.facebook.com&&email&first")), |
| 2107 form_structure->FormSignature()); | 2105 form_structure->FormSignature()); |
| 2108 | 2106 |
| 2109 form.action = GURL(std::string("https://login.facebook.com/path")); | 2107 form.action = GURL(std::string("https://login.facebook.com/path")); |
| 2110 form_structure.reset(new FormStructure(form)); | 2108 form_structure.reset(new FormStructure(form, std::string())); |
| 2111 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2109 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2112 std::string("https://login.facebook.com&&email&first")), | 2110 std::string("https://login.facebook.com&&email&first")), |
| 2113 form_structure->FormSignature()); | 2111 form_structure->FormSignature()); |
| 2114 | 2112 |
| 2115 form.name = ASCIIToUTF16("login_form"); | 2113 form.name = ASCIIToUTF16("login_form"); |
| 2116 form_structure.reset(new FormStructure(form)); | 2114 form_structure.reset(new FormStructure(form, std::string())); |
| 2117 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2115 EXPECT_EQ(FormStructureTest::Hash64Bit( |
| 2118 std::string("https://login.facebook.com&login_form&email&first")), | 2116 std::string("https://login.facebook.com&login_form&email&first")), |
| 2119 form_structure->FormSignature()); | 2117 form_structure->FormSignature()); |
| 2120 } | 2118 } |
| 2121 | 2119 |
| 2122 TEST(FormStructureTest, ToFormData) { | 2120 TEST(FormStructureTest, ToFormData) { |
| 2123 FormData form; | 2121 FormData form; |
| 2124 form.name = ASCIIToUTF16("the-name"); | 2122 form.name = ASCIIToUTF16("the-name"); |
| 2125 form.method = ASCIIToUTF16("POST"); | 2123 form.method = ASCIIToUTF16("POST"); |
| 2126 form.origin = GURL("http://cool.com"); | 2124 form.origin = GURL("http://cool.com"); |
| 2127 form.action = form.origin.Resolve("/login"); | 2125 form.action = form.origin.Resolve("/login"); |
| 2128 | 2126 |
| 2129 FormFieldData field; | 2127 FormFieldData field; |
| 2130 field.label = ASCIIToUTF16("username"); | 2128 field.label = ASCIIToUTF16("username"); |
| 2131 field.name = ASCIIToUTF16("username"); | 2129 field.name = ASCIIToUTF16("username"); |
| 2132 field.form_control_type = "text"; | 2130 field.form_control_type = "text"; |
| 2133 form.fields.push_back(field); | 2131 form.fields.push_back(field); |
| 2134 | 2132 |
| 2135 field.label = ASCIIToUTF16("password"); | 2133 field.label = ASCIIToUTF16("password"); |
| 2136 field.name = ASCIIToUTF16("password"); | 2134 field.name = ASCIIToUTF16("password"); |
| 2137 field.form_control_type = "password"; | 2135 field.form_control_type = "password"; |
| 2138 form.fields.push_back(field); | 2136 form.fields.push_back(field); |
| 2139 | 2137 |
| 2140 field.label = string16(); | 2138 field.label = string16(); |
| 2141 field.name = ASCIIToUTF16("Submit"); | 2139 field.name = ASCIIToUTF16("Submit"); |
| 2142 field.form_control_type = "submit"; | 2140 field.form_control_type = "submit"; |
| 2143 form.fields.push_back(field); | 2141 form.fields.push_back(field); |
| 2144 | 2142 |
| 2145 EXPECT_EQ(form, FormStructure(form).ToFormData()); | 2143 EXPECT_EQ(form, FormStructure(form, std::string()).ToFormData()); |
| 2146 | 2144 |
| 2147 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2145 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
| 2148 // false. This forces a future author that changes this to update this test. | 2146 // false. This forces a future author that changes this to update this test. |
| 2149 form.user_submitted = true; | 2147 form.user_submitted = true; |
| 2150 EXPECT_NE(form, FormStructure(form).ToFormData()); | 2148 EXPECT_NE(form, FormStructure(form, std::string()).ToFormData()); |
| 2151 } | 2149 } |
| OLD | NEW |