OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/string16.h" | 7 #include "base/string16.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/renderer/autofill/form_manager.h" | 10 #include "chrome/renderer/autofill/form_manager.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using WebKit::WebSelectElement; | 31 using WebKit::WebSelectElement; |
32 using WebKit::WebNode; | 32 using WebKit::WebNode; |
33 using WebKit::WebString; | 33 using WebKit::WebString; |
34 using WebKit::WebVector; | 34 using WebKit::WebVector; |
35 | 35 |
36 using autofill::FormManager; | 36 using autofill::FormManager; |
37 | 37 |
38 using webkit_glue::FormData; | 38 using webkit_glue::FormData; |
39 using webkit_glue::FormField; | 39 using webkit_glue::FormField; |
40 | 40 |
41 namespace { | |
42 | |
43 // TODO(isherman): Pull this as a named constant from WebKit | |
44 const int kDefaultMaxLength = 0x80000; | |
45 | |
46 } // namespace | |
47 | |
48 class FormManagerTest : public RenderViewTest { | 41 class FormManagerTest : public RenderViewTest { |
49 public: | 42 public: |
50 FormManagerTest() : RenderViewTest() {} | 43 FormManagerTest() : RenderViewTest() {} |
51 virtual ~FormManagerTest() {} | 44 virtual ~FormManagerTest() {} |
52 | 45 |
53 void ExpectLabels(const char* html, | 46 void ExpectLabels(const char* html, |
54 const std::vector<string16>& labels, | 47 const std::vector<string16>& labels, |
55 const std::vector<string16>& names, | 48 const std::vector<string16>& names, |
56 const std::vector<string16>& values) { | 49 const std::vector<string16>& values) { |
57 ASSERT_EQ(labels.size(), names.size()); | 50 ASSERT_EQ(labels.size(), names.size()); |
(...skipping 17 matching lines...) Expand all Loading... |
75 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 68 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
76 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 69 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
77 | 70 |
78 const std::vector<FormField>& fields = form.fields; | 71 const std::vector<FormField>& fields = form.fields; |
79 ASSERT_EQ(labels.size(), fields.size()); | 72 ASSERT_EQ(labels.size(), fields.size()); |
80 for (size_t i = 0; i < labels.size(); ++i) { | 73 for (size_t i = 0; i < labels.size(); ++i) { |
81 FormField expected = FormField(labels[i], | 74 FormField expected = FormField(labels[i], |
82 names[i], | 75 names[i], |
83 values[i], | 76 values[i], |
84 ASCIIToUTF16("text"), | 77 ASCIIToUTF16("text"), |
85 kDefaultMaxLength, | 78 WebInputElement::defaultMaxLength(), |
86 false); | 79 false); |
87 EXPECT_TRUE(fields[i].StrictlyEqualsHack(expected)) | 80 EXPECT_TRUE(fields[i].StrictlyEqualsHack(expected)) |
88 << "Expected \"" << expected << "\", got \"" << fields[i] << "\""; | 81 << "Expected \"" << expected << "\", got \"" << fields[i] << "\""; |
89 } | 82 } |
90 } | 83 } |
91 | 84 |
92 void ExpectJohnSmithLabels(const char* html) { | 85 void ExpectJohnSmithLabels(const char* html) { |
93 std::vector<string16> labels, names, values; | 86 std::vector<string16> labels, names, values; |
94 | 87 |
95 labels.push_back(ASCIIToUTF16("First name:")); | 88 labels.push_back(ASCIIToUTF16("First name:")); |
96 names.push_back(ASCIIToUTF16("firstname")); | 89 names.push_back(ASCIIToUTF16("firstname")); |
97 values.push_back(ASCIIToUTF16("John")); | 90 values.push_back(ASCIIToUTF16("John")); |
98 | 91 |
99 labels.push_back(ASCIIToUTF16("Last name:")); | 92 labels.push_back(ASCIIToUTF16("Last name:")); |
100 names.push_back(ASCIIToUTF16("lastname")); | 93 names.push_back(ASCIIToUTF16("lastname")); |
101 values.push_back(ASCIIToUTF16("Smith")); | 94 values.push_back(ASCIIToUTF16("Smith")); |
102 | 95 |
103 labels.push_back(ASCIIToUTF16("Email:")); | 96 labels.push_back(ASCIIToUTF16("Email:")); |
104 names.push_back(ASCIIToUTF16("email")); | 97 names.push_back(ASCIIToUTF16("email")); |
105 values.push_back(ASCIIToUTF16("john@example.com")); | 98 values.push_back(ASCIIToUTF16("john@example.com")); |
106 | 99 |
107 ExpectLabels(html, labels, names, values); | 100 ExpectLabels(html, labels, names, values); |
108 } | 101 } |
109 | 102 |
110 | |
111 private: | 103 private: |
112 DISALLOW_COPY_AND_ASSIGN(FormManagerTest); | 104 DISALLOW_COPY_AND_ASSIGN(FormManagerTest); |
113 }; | 105 }; |
114 | 106 |
115 // We should be able to extract a normal text field. | 107 // We should be able to extract a normal text field. |
116 TEST_F(FormManagerTest, WebFormControlElementToFormField) { | 108 TEST_F(FormManagerTest, WebFormControlElementToFormField) { |
117 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 109 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
118 | 110 |
119 WebFrame* frame = GetMainFrame(); | 111 WebFrame* frame = GetMainFrame(); |
120 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 112 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
121 | 113 |
122 WebElement web_element = frame->document().getElementById("element"); | 114 WebElement web_element = frame->document().getElementById("element"); |
123 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 115 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
124 FormField result1; | 116 FormField result1; |
125 FormManager::WebFormControlElementToFormField(element, | 117 FormManager::WebFormControlElementToFormField(element, |
126 FormManager::EXTRACT_NONE, | 118 FormManager::EXTRACT_NONE, |
127 &result1); | 119 &result1); |
128 EXPECT_TRUE(result1.StrictlyEqualsHack(FormField(string16(), | 120 EXPECT_TRUE(result1.StrictlyEqualsHack( |
129 ASCIIToUTF16("element"), | 121 FormField(string16(), |
130 string16(), | 122 ASCIIToUTF16("element"), |
131 ASCIIToUTF16("text"), | 123 string16(), |
132 kDefaultMaxLength, | 124 ASCIIToUTF16("text"), |
133 false))); | 125 WebInputElement::defaultMaxLength(), |
| 126 false))); |
134 FormField result2; | 127 FormField result2; |
135 FormManager::WebFormControlElementToFormField(element, | 128 FormManager::WebFormControlElementToFormField(element, |
136 FormManager::EXTRACT_VALUE, | 129 FormManager::EXTRACT_VALUE, |
137 &result2); | 130 &result2); |
138 EXPECT_TRUE(result2.StrictlyEqualsHack(FormField(string16(), | 131 EXPECT_TRUE(result2.StrictlyEqualsHack( |
139 ASCIIToUTF16("element"), | 132 FormField(string16(), |
140 ASCIIToUTF16("value"), | 133 ASCIIToUTF16("element"), |
141 ASCIIToUTF16("text"), | 134 ASCIIToUTF16("value"), |
142 kDefaultMaxLength, | 135 ASCIIToUTF16("text"), |
143 false))); | 136 WebInputElement::defaultMaxLength(), |
| 137 false))); |
144 } | 138 } |
145 | 139 |
146 // We should be able to extract a text field with autocomplete="off". | 140 // We should be able to extract a text field with autocomplete="off". |
147 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { | 141 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { |
148 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 142 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
149 " autocomplete=\"off\"/>"); | 143 " autocomplete=\"off\"/>"); |
150 | 144 |
151 WebFrame* frame = GetMainFrame(); | 145 WebFrame* frame = GetMainFrame(); |
152 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 146 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
153 | 147 |
154 WebElement web_element = frame->document().getElementById("element"); | 148 WebElement web_element = frame->document().getElementById("element"); |
155 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 149 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
156 FormField result; | 150 FormField result; |
157 FormManager::WebFormControlElementToFormField(element, | 151 FormManager::WebFormControlElementToFormField(element, |
158 FormManager::EXTRACT_VALUE, | 152 FormManager::EXTRACT_VALUE, |
159 &result); | 153 &result); |
160 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 154 EXPECT_TRUE(result.StrictlyEqualsHack( |
161 ASCIIToUTF16("element"), | 155 FormField(string16(), |
162 ASCIIToUTF16("value"), | 156 ASCIIToUTF16("element"), |
163 ASCIIToUTF16("text"), | 157 ASCIIToUTF16("value"), |
164 kDefaultMaxLength, | 158 ASCIIToUTF16("text"), |
165 false))); | 159 WebInputElement::defaultMaxLength(), |
| 160 false))); |
166 } | 161 } |
167 | 162 |
168 // We should be able to extract a text field with maxlength specified. | 163 // We should be able to extract a text field with maxlength specified. |
169 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { | 164 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { |
170 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 165 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
171 " maxlength=\"5\"/>"); | 166 " maxlength=\"5\"/>"); |
172 | 167 |
173 WebFrame* frame = GetMainFrame(); | 168 WebFrame* frame = GetMainFrame(); |
174 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 169 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
175 | 170 |
(...skipping 18 matching lines...) Expand all Loading... |
194 WebFrame* frame = GetMainFrame(); | 189 WebFrame* frame = GetMainFrame(); |
195 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 190 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
196 | 191 |
197 WebElement web_element = frame->document().getElementById("element"); | 192 WebElement web_element = frame->document().getElementById("element"); |
198 WebInputElement element = web_element.to<WebInputElement>(); | 193 WebInputElement element = web_element.to<WebInputElement>(); |
199 element.setAutofilled(true); | 194 element.setAutofilled(true); |
200 FormField result; | 195 FormField result; |
201 FormManager::WebFormControlElementToFormField(element, | 196 FormManager::WebFormControlElementToFormField(element, |
202 FormManager::EXTRACT_VALUE, | 197 FormManager::EXTRACT_VALUE, |
203 &result); | 198 &result); |
204 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 199 EXPECT_TRUE(result.StrictlyEqualsHack( |
205 ASCIIToUTF16("element"), | 200 FormField(string16(), |
206 ASCIIToUTF16("value"), | 201 ASCIIToUTF16("element"), |
207 ASCIIToUTF16("text"), | 202 ASCIIToUTF16("value"), |
208 kDefaultMaxLength, | 203 ASCIIToUTF16("text"), |
209 true))); | 204 WebInputElement::defaultMaxLength(), |
| 205 true))); |
210 } | 206 } |
211 | 207 |
212 // We should be able to extract a <select> field. | 208 // We should be able to extract a <select> field. |
213 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { | 209 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { |
214 LoadHTML("<SELECT id=\"element\"/>" | 210 LoadHTML("<SELECT id=\"element\"/>" |
215 " <OPTION value=\"CA\">California</OPTION>" | 211 " <OPTION value=\"CA\">California</OPTION>" |
216 " <OPTION value=\"TX\">Texas</OPTION>" | 212 " <OPTION value=\"TX\">Texas</OPTION>" |
217 "</SELECT>"); | 213 "</SELECT>"); |
218 | 214 |
219 WebFrame* frame = GetMainFrame(); | 215 WebFrame* frame = GetMainFrame(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 EXPECT_EQ(GURL(frame->url()), form.origin); | 359 EXPECT_EQ(GURL(frame->url()), form.origin); |
364 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 360 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
365 | 361 |
366 const std::vector<FormField>& fields = form.fields; | 362 const std::vector<FormField>& fields = form.fields; |
367 ASSERT_EQ(3U, fields.size()); | 363 ASSERT_EQ(3U, fields.size()); |
368 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 364 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
369 FormField(string16(), | 365 FormField(string16(), |
370 ASCIIToUTF16("firstname"), | 366 ASCIIToUTF16("firstname"), |
371 ASCIIToUTF16("John"), | 367 ASCIIToUTF16("John"), |
372 ASCIIToUTF16("text"), | 368 ASCIIToUTF16("text"), |
373 kDefaultMaxLength, | 369 WebInputElement::defaultMaxLength(), |
374 false))); | 370 false))); |
375 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 371 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
376 FormField(string16(), | 372 FormField(string16(), |
377 ASCIIToUTF16("lastname"), | 373 ASCIIToUTF16("lastname"), |
378 ASCIIToUTF16("Smith"), | 374 ASCIIToUTF16("Smith"), |
379 ASCIIToUTF16("text"), | 375 ASCIIToUTF16("text"), |
380 kDefaultMaxLength, | 376 WebInputElement::defaultMaxLength(), |
381 false))); | 377 false))); |
382 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 378 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
383 FormField(string16(), | 379 FormField(string16(), |
384 ASCIIToUTF16("state"), | 380 ASCIIToUTF16("state"), |
385 ASCIIToUTF16("CA"), | 381 ASCIIToUTF16("CA"), |
386 ASCIIToUTF16("select-one"), | 382 ASCIIToUTF16("select-one"), |
387 0, | 383 0, |
388 false))); | 384 false))); |
389 } | 385 } |
390 | 386 |
(...skipping 19 matching lines...) Expand all Loading... |
410 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 406 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
411 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 407 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
412 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 408 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
413 | 409 |
414 const std::vector<FormField>& fields = form.fields; | 410 const std::vector<FormField>& fields = form.fields; |
415 ASSERT_EQ(3U, fields.size()); | 411 ASSERT_EQ(3U, fields.size()); |
416 EXPECT_EQ(FormField(string16(), | 412 EXPECT_EQ(FormField(string16(), |
417 ASCIIToUTF16("firstname"), | 413 ASCIIToUTF16("firstname"), |
418 ASCIIToUTF16("John"), | 414 ASCIIToUTF16("John"), |
419 ASCIIToUTF16("text"), | 415 ASCIIToUTF16("text"), |
420 kDefaultMaxLength, | 416 WebInputElement::defaultMaxLength(), |
421 false), | 417 false), |
422 fields[0]); | 418 fields[0]); |
423 EXPECT_EQ(FormField(string16(), | 419 EXPECT_EQ(FormField(string16(), |
424 ASCIIToUTF16("lastname"), | 420 ASCIIToUTF16("lastname"), |
425 ASCIIToUTF16("Smith"), | 421 ASCIIToUTF16("Smith"), |
426 ASCIIToUTF16("text"), | 422 ASCIIToUTF16("text"), |
427 kDefaultMaxLength, | 423 WebInputElement::defaultMaxLength(), |
428 false), | 424 false), |
429 fields[1]); | 425 fields[1]); |
430 EXPECT_EQ(FormField(string16(), | 426 EXPECT_EQ(FormField(string16(), |
431 ASCIIToUTF16("email"), | 427 ASCIIToUTF16("email"), |
432 ASCIIToUTF16("john@example.com"), | 428 ASCIIToUTF16("john@example.com"), |
433 ASCIIToUTF16("text"), | 429 ASCIIToUTF16("text"), |
434 kDefaultMaxLength, | 430 WebInputElement::defaultMaxLength(), |
435 false), | 431 false), |
436 fields[2]); | 432 fields[2]); |
437 } | 433 } |
438 | 434 |
439 TEST_F(FormManagerTest, ExtractMultipleForms) { | 435 TEST_F(FormManagerTest, ExtractMultipleForms) { |
440 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 436 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
441 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 437 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
442 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 438 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
443 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 439 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
444 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 440 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
(...skipping 20 matching lines...) Expand all Loading... |
465 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 461 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
466 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 462 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
467 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 463 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
468 | 464 |
469 const std::vector<FormField>& fields = form.fields; | 465 const std::vector<FormField>& fields = form.fields; |
470 ASSERT_EQ(3U, fields.size()); | 466 ASSERT_EQ(3U, fields.size()); |
471 EXPECT_EQ(FormField(string16(), | 467 EXPECT_EQ(FormField(string16(), |
472 ASCIIToUTF16("firstname"), | 468 ASCIIToUTF16("firstname"), |
473 ASCIIToUTF16("John"), | 469 ASCIIToUTF16("John"), |
474 ASCIIToUTF16("text"), | 470 ASCIIToUTF16("text"), |
475 kDefaultMaxLength, | 471 WebInputElement::defaultMaxLength(), |
476 false), | 472 false), |
477 fields[0]); | 473 fields[0]); |
478 EXPECT_EQ(FormField(string16(), | 474 EXPECT_EQ(FormField(string16(), |
479 ASCIIToUTF16("lastname"), | 475 ASCIIToUTF16("lastname"), |
480 ASCIIToUTF16("Smith"), | 476 ASCIIToUTF16("Smith"), |
481 ASCIIToUTF16("text"), | 477 ASCIIToUTF16("text"), |
482 kDefaultMaxLength, | 478 WebInputElement::defaultMaxLength(), |
483 false), | 479 false), |
484 fields[1]); | 480 fields[1]); |
485 EXPECT_EQ(FormField(string16(), | 481 EXPECT_EQ(FormField(string16(), |
486 ASCIIToUTF16("email"), | 482 ASCIIToUTF16("email"), |
487 ASCIIToUTF16("john@example.com"), | 483 ASCIIToUTF16("john@example.com"), |
488 ASCIIToUTF16("text"), | 484 ASCIIToUTF16("text"), |
489 kDefaultMaxLength, | 485 WebInputElement::defaultMaxLength(), |
490 false), | 486 false), |
491 fields[2]); | 487 fields[2]); |
492 | 488 |
493 // Second form. | 489 // Second form. |
494 const FormData& form2 = forms[1]; | 490 const FormData& form2 = forms[1]; |
495 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); | 491 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); |
496 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 492 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
497 EXPECT_EQ(GURL("http://zoo.com"), form2.action); | 493 EXPECT_EQ(GURL("http://zoo.com"), form2.action); |
498 | 494 |
499 const std::vector<FormField>& fields2 = form2.fields; | 495 const std::vector<FormField>& fields2 = form2.fields; |
500 ASSERT_EQ(3U, fields2.size()); | 496 ASSERT_EQ(3U, fields2.size()); |
501 EXPECT_EQ(FormField(string16(), | 497 EXPECT_EQ(FormField(string16(), |
502 ASCIIToUTF16("firstname"), | 498 ASCIIToUTF16("firstname"), |
503 ASCIIToUTF16("Jack"), | 499 ASCIIToUTF16("Jack"), |
504 ASCIIToUTF16("text"), | 500 ASCIIToUTF16("text"), |
505 kDefaultMaxLength, | 501 WebInputElement::defaultMaxLength(), |
506 false), | 502 false), |
507 fields2[0]); | 503 fields2[0]); |
508 EXPECT_EQ(FormField(string16(), | 504 EXPECT_EQ(FormField(string16(), |
509 ASCIIToUTF16("lastname"), | 505 ASCIIToUTF16("lastname"), |
510 ASCIIToUTF16("Adams"), | 506 ASCIIToUTF16("Adams"), |
511 ASCIIToUTF16("text"), | 507 ASCIIToUTF16("text"), |
512 kDefaultMaxLength, | 508 WebInputElement::defaultMaxLength(), |
513 false), | 509 false), |
514 fields2[1]); | 510 fields2[1]); |
515 EXPECT_EQ(FormField(string16(), | 511 EXPECT_EQ(FormField(string16(), |
516 ASCIIToUTF16("email"), | 512 ASCIIToUTF16("email"), |
517 ASCIIToUTF16("jack@example.com"), | 513 ASCIIToUTF16("jack@example.com"), |
518 ASCIIToUTF16("text"), | 514 ASCIIToUTF16("text"), |
519 kDefaultMaxLength, | 515 WebInputElement::defaultMaxLength(), |
520 false), | 516 false), |
521 fields[2]); | 517 fields[2]); |
522 } | 518 } |
523 | 519 |
524 // We should not extract a form if it has too few fillable fields. | 520 // We should not extract a form if it has too few fillable fields. |
525 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { | 521 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { |
526 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 522 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
527 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 523 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
528 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 524 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
529 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 525 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 588 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
593 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 589 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
594 EXPECT_EQ(GURL("http://abc.com"), form.action); | 590 EXPECT_EQ(GURL("http://abc.com"), form.action); |
595 | 591 |
596 const std::vector<FormField>& fields = form.fields; | 592 const std::vector<FormField>& fields = form.fields; |
597 ASSERT_EQ(3U, fields.size()); | 593 ASSERT_EQ(3U, fields.size()); |
598 EXPECT_EQ(FormField(string16(), | 594 EXPECT_EQ(FormField(string16(), |
599 ASCIIToUTF16("middlename"), | 595 ASCIIToUTF16("middlename"), |
600 ASCIIToUTF16("Jack"), | 596 ASCIIToUTF16("Jack"), |
601 ASCIIToUTF16("text"), | 597 ASCIIToUTF16("text"), |
602 kDefaultMaxLength, | 598 WebInputElement::defaultMaxLength(), |
603 false), | 599 false), |
604 fields[0]); | 600 fields[0]); |
605 EXPECT_EQ(FormField(string16(), | 601 EXPECT_EQ(FormField(string16(), |
606 ASCIIToUTF16("lastname"), | 602 ASCIIToUTF16("lastname"), |
607 ASCIIToUTF16("Smith"), | 603 ASCIIToUTF16("Smith"), |
608 ASCIIToUTF16("text"), | 604 ASCIIToUTF16("text"), |
609 kDefaultMaxLength, | 605 WebInputElement::defaultMaxLength(), |
610 false), | 606 false), |
611 fields[1]); | 607 fields[1]); |
612 EXPECT_EQ(FormField(string16(), | 608 EXPECT_EQ(FormField(string16(), |
613 ASCIIToUTF16("email"), | 609 ASCIIToUTF16("email"), |
614 ASCIIToUTF16("john@example.com"), | 610 ASCIIToUTF16("john@example.com"), |
615 ASCIIToUTF16("text"), | 611 ASCIIToUTF16("text"), |
616 kDefaultMaxLength, | 612 WebInputElement::defaultMaxLength(), |
617 false), | 613 false), |
618 fields[2]); | 614 fields[2]); |
619 } | 615 } |
620 | 616 |
621 TEST_F(FormManagerTest, GetFormsElementsEnabled) { | 617 TEST_F(FormManagerTest, GetFormsElementsEnabled) { |
622 // The firstname element is not enabled due to disabled being set. | 618 // The firstname element is not enabled due to disabled being set. |
623 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" | 619 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" |
624 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" | 620 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" |
625 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" | 621 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" |
626 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 622 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
(...skipping 15 matching lines...) Expand all Loading... |
642 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 638 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
643 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 639 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
644 EXPECT_EQ(GURL("http://xyz.com"), form.action); | 640 EXPECT_EQ(GURL("http://xyz.com"), form.action); |
645 | 641 |
646 const std::vector<FormField>& fields = form.fields; | 642 const std::vector<FormField>& fields = form.fields; |
647 ASSERT_EQ(3U, fields.size()); | 643 ASSERT_EQ(3U, fields.size()); |
648 EXPECT_EQ(FormField(string16(), | 644 EXPECT_EQ(FormField(string16(), |
649 ASCIIToUTF16("middlename"), | 645 ASCIIToUTF16("middlename"), |
650 ASCIIToUTF16("Jack"), | 646 ASCIIToUTF16("Jack"), |
651 ASCIIToUTF16("text"), | 647 ASCIIToUTF16("text"), |
652 kDefaultMaxLength, | 648 WebInputElement::defaultMaxLength(), |
653 false), | 649 false), |
654 fields[0]); | 650 fields[0]); |
655 EXPECT_EQ(FormField(string16(), | 651 EXPECT_EQ(FormField(string16(), |
656 ASCIIToUTF16("lastname"), | 652 ASCIIToUTF16("lastname"), |
657 ASCIIToUTF16("Smith"), | 653 ASCIIToUTF16("Smith"), |
658 ASCIIToUTF16("text"), | 654 ASCIIToUTF16("text"), |
659 kDefaultMaxLength, | 655 WebInputElement::defaultMaxLength(), |
660 false), | 656 false), |
661 fields[1]); | 657 fields[1]); |
662 EXPECT_EQ(FormField(string16(), | 658 EXPECT_EQ(FormField(string16(), |
663 ASCIIToUTF16("email"), | 659 ASCIIToUTF16("email"), |
664 ASCIIToUTF16("jack@example.com"), | 660 ASCIIToUTF16("jack@example.com"), |
665 ASCIIToUTF16("text"), | 661 ASCIIToUTF16("text"), |
666 kDefaultMaxLength, | 662 WebInputElement::defaultMaxLength(), |
667 false), | 663 false), |
668 fields[2]); | 664 fields[2]); |
669 } | 665 } |
670 | 666 |
671 TEST_F(FormManagerTest, FindForm) { | 667 TEST_F(FormManagerTest, FindForm) { |
672 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 668 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
673 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 669 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
674 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 670 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
675 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 671 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
676 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 672 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
(...skipping 21 matching lines...) Expand all Loading... |
698 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 694 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
699 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 695 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
700 EXPECT_EQ(GURL("http://buh.com"), form.action); | 696 EXPECT_EQ(GURL("http://buh.com"), form.action); |
701 | 697 |
702 const std::vector<FormField>& fields = form.fields; | 698 const std::vector<FormField>& fields = form.fields; |
703 ASSERT_EQ(3U, fields.size()); | 699 ASSERT_EQ(3U, fields.size()); |
704 EXPECT_EQ(FormField(string16(), | 700 EXPECT_EQ(FormField(string16(), |
705 ASCIIToUTF16("firstname"), | 701 ASCIIToUTF16("firstname"), |
706 ASCIIToUTF16("John"), | 702 ASCIIToUTF16("John"), |
707 ASCIIToUTF16("text"), | 703 ASCIIToUTF16("text"), |
708 kDefaultMaxLength, | 704 WebInputElement::defaultMaxLength(), |
709 false), | 705 false), |
710 fields[0]); | 706 fields[0]); |
711 EXPECT_EQ(FormField(string16(), | 707 EXPECT_EQ(FormField(string16(), |
712 ASCIIToUTF16("lastname"), | 708 ASCIIToUTF16("lastname"), |
713 ASCIIToUTF16("Smith"), | 709 ASCIIToUTF16("Smith"), |
714 ASCIIToUTF16("text"), | 710 ASCIIToUTF16("text"), |
715 kDefaultMaxLength, | 711 WebInputElement::defaultMaxLength(), |
716 false), | 712 false), |
717 fields[1]); | 713 fields[1]); |
718 EXPECT_EQ(FormField(string16(), | 714 EXPECT_EQ(FormField(string16(), |
719 ASCIIToUTF16("email"), | 715 ASCIIToUTF16("email"), |
720 ASCIIToUTF16("john@example.com"), | 716 ASCIIToUTF16("john@example.com"), |
721 ASCIIToUTF16("text"), | 717 ASCIIToUTF16("text"), |
722 kDefaultMaxLength, | 718 WebInputElement::defaultMaxLength(), |
723 false), | 719 false), |
724 fields[2]); | 720 fields[2]); |
725 } | 721 } |
726 | 722 |
727 TEST_F(FormManagerTest, FillForm) { | 723 TEST_F(FormManagerTest, FillForm) { |
728 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 724 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
729 " <INPUT type=\"text\" id=\"firstname\"/>" | 725 " <INPUT type=\"text\" id=\"firstname\"/>" |
730 " <INPUT type=\"text\" id=\"lastname\"/>" | 726 " <INPUT type=\"text\" id=\"lastname\"/>" |
731 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 727 " <INPUT type=\"hidden\" id=\"imhidden\"/>" |
732 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 728 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" |
(...skipping 24 matching lines...) Expand all Loading... |
757 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 753 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
758 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 754 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
759 EXPECT_EQ(GURL("http://buh.com"), form.action); | 755 EXPECT_EQ(GURL("http://buh.com"), form.action); |
760 | 756 |
761 const std::vector<FormField>& fields = form.fields; | 757 const std::vector<FormField>& fields = form.fields; |
762 ASSERT_EQ(5U, fields.size()); | 758 ASSERT_EQ(5U, fields.size()); |
763 EXPECT_EQ(FormField(string16(), | 759 EXPECT_EQ(FormField(string16(), |
764 ASCIIToUTF16("firstname"), | 760 ASCIIToUTF16("firstname"), |
765 string16(), | 761 string16(), |
766 ASCIIToUTF16("text"), | 762 ASCIIToUTF16("text"), |
767 kDefaultMaxLength, | 763 WebInputElement::defaultMaxLength(), |
768 false), | 764 false), |
769 fields[0]); | 765 fields[0]); |
770 EXPECT_EQ(FormField(string16(), | 766 EXPECT_EQ(FormField(string16(), |
771 ASCIIToUTF16("lastname"), | 767 ASCIIToUTF16("lastname"), |
772 string16(), | 768 string16(), |
773 ASCIIToUTF16("text"), | 769 ASCIIToUTF16("text"), |
774 kDefaultMaxLength, | 770 WebInputElement::defaultMaxLength(), |
775 false), | 771 false), |
776 fields[1]); | 772 fields[1]); |
777 EXPECT_EQ(FormField(string16(), | 773 EXPECT_EQ(FormField(string16(), |
778 ASCIIToUTF16("notempty"), | 774 ASCIIToUTF16("notempty"), |
779 ASCIIToUTF16("Hi"), | 775 ASCIIToUTF16("Hi"), |
780 ASCIIToUTF16("text"), | 776 ASCIIToUTF16("text"), |
781 kDefaultMaxLength, | 777 WebInputElement::defaultMaxLength(), |
782 false), | 778 false), |
783 fields[2]); | 779 fields[2]); |
784 EXPECT_EQ(FormField(string16(), | 780 EXPECT_EQ(FormField(string16(), |
785 ASCIIToUTF16("noautocomplete"), | 781 ASCIIToUTF16("noautocomplete"), |
786 string16(), | 782 string16(), |
787 ASCIIToUTF16("text"), | 783 ASCIIToUTF16("text"), |
788 kDefaultMaxLength, | 784 WebInputElement::defaultMaxLength(), |
789 false), | 785 false), |
790 fields[3]); | 786 fields[3]); |
791 EXPECT_EQ(FormField(string16(), | 787 EXPECT_EQ(FormField(string16(), |
792 ASCIIToUTF16("notenabled"), | 788 ASCIIToUTF16("notenabled"), |
793 string16(), | 789 string16(), |
794 ASCIIToUTF16("text"), | 790 ASCIIToUTF16("text"), |
795 kDefaultMaxLength, | 791 WebInputElement::defaultMaxLength(), |
796 false), | 792 false), |
797 fields[4]); | 793 fields[4]); |
798 | 794 |
799 // Fill the form. | 795 // Fill the form. |
800 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); | 796 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); |
801 form.fields[1].set_value(ASCIIToUTF16("Earp")); | 797 form.fields[1].set_value(ASCIIToUTF16("Earp")); |
802 form.fields[2].set_value(ASCIIToUTF16("Alpha")); | 798 form.fields[2].set_value(ASCIIToUTF16("Alpha")); |
803 form.fields[3].set_value(ASCIIToUTF16("Beta")); | 799 form.fields[3].set_value(ASCIIToUTF16("Beta")); |
804 form.fields[4].set_value(ASCIIToUTF16("Gamma")); | 800 form.fields[4].set_value(ASCIIToUTF16("Gamma")); |
805 EXPECT_TRUE(form_manager.FillForm(form, input_element)); | 801 EXPECT_TRUE(form_manager.FillForm(form, input_element)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 865 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
870 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 866 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
871 EXPECT_EQ(GURL("http://buh.com"), form.action); | 867 EXPECT_EQ(GURL("http://buh.com"), form.action); |
872 | 868 |
873 const std::vector<FormField>& fields = form.fields; | 869 const std::vector<FormField>& fields = form.fields; |
874 ASSERT_EQ(5U, fields.size()); | 870 ASSERT_EQ(5U, fields.size()); |
875 EXPECT_EQ(FormField(string16(), | 871 EXPECT_EQ(FormField(string16(), |
876 ASCIIToUTF16("firstname"), | 872 ASCIIToUTF16("firstname"), |
877 string16(), | 873 string16(), |
878 ASCIIToUTF16("text"), | 874 ASCIIToUTF16("text"), |
879 kDefaultMaxLength, | 875 WebInputElement::defaultMaxLength(), |
880 false), | 876 false), |
881 fields[0]); | 877 fields[0]); |
882 EXPECT_EQ(FormField(string16(), | 878 EXPECT_EQ(FormField(string16(), |
883 ASCIIToUTF16("lastname"), | 879 ASCIIToUTF16("lastname"), |
884 string16(), | 880 string16(), |
885 ASCIIToUTF16("text"), | 881 ASCIIToUTF16("text"), |
886 kDefaultMaxLength, | 882 WebInputElement::defaultMaxLength(), |
887 false), | 883 false), |
888 fields[1]); | 884 fields[1]); |
889 EXPECT_EQ(FormField(string16(), | 885 EXPECT_EQ(FormField(string16(), |
890 ASCIIToUTF16("notempty"), | 886 ASCIIToUTF16("notempty"), |
891 ASCIIToUTF16("Hi"), | 887 ASCIIToUTF16("Hi"), |
892 ASCIIToUTF16("text"), | 888 ASCIIToUTF16("text"), |
893 kDefaultMaxLength, | 889 WebInputElement::defaultMaxLength(), |
894 false), | 890 false), |
895 fields[2]); | 891 fields[2]); |
896 EXPECT_EQ(FormField(string16(), | 892 EXPECT_EQ(FormField(string16(), |
897 ASCIIToUTF16("noautocomplete"), | 893 ASCIIToUTF16("noautocomplete"), |
898 string16(), | 894 string16(), |
899 ASCIIToUTF16("text"), | 895 ASCIIToUTF16("text"), |
900 kDefaultMaxLength, | 896 WebInputElement::defaultMaxLength(), |
901 false), | 897 false), |
902 fields[3]); | 898 fields[3]); |
903 EXPECT_EQ(FormField(string16(), | 899 EXPECT_EQ(FormField(string16(), |
904 ASCIIToUTF16("notenabled"), | 900 ASCIIToUTF16("notenabled"), |
905 string16(), | 901 string16(), |
906 ASCIIToUTF16("text"), | 902 ASCIIToUTF16("text"), |
907 kDefaultMaxLength, | 903 WebInputElement::defaultMaxLength(), |
908 false), | 904 false), |
909 fields[4]); | 905 fields[4]); |
910 | 906 |
911 // Preview the form. | 907 // Preview the form. |
912 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); | 908 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); |
913 form.fields[1].set_value(ASCIIToUTF16("Earp")); | 909 form.fields[1].set_value(ASCIIToUTF16("Earp")); |
914 form.fields[2].set_value(ASCIIToUTF16("Alpha")); | 910 form.fields[2].set_value(ASCIIToUTF16("Alpha")); |
915 form.fields[3].set_value(ASCIIToUTF16("Beta")); | 911 form.fields[3].set_value(ASCIIToUTF16("Beta")); |
916 form.fields[4].set_value(ASCIIToUTF16("Gamma")); | 912 form.fields[4].set_value(ASCIIToUTF16("Gamma")); |
917 EXPECT_TRUE(form_manager.PreviewForm(form, input_element)); | 913 EXPECT_TRUE(form_manager.PreviewForm(form, input_element)); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1552 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1557 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 1553 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
1558 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1554 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1559 | 1555 |
1560 const std::vector<FormField>& fields = form.fields; | 1556 const std::vector<FormField>& fields = form.fields; |
1561 ASSERT_EQ(3U, fields.size()); | 1557 ASSERT_EQ(3U, fields.size()); |
1562 EXPECT_EQ(FormField(string16(), | 1558 EXPECT_EQ(FormField(string16(), |
1563 ASCIIToUTF16("firstname"), | 1559 ASCIIToUTF16("firstname"), |
1564 string16(), | 1560 string16(), |
1565 ASCIIToUTF16("text"), | 1561 ASCIIToUTF16("text"), |
1566 kDefaultMaxLength, | 1562 WebInputElement::defaultMaxLength(), |
1567 false), | 1563 false), |
1568 fields[0]); | 1564 fields[0]); |
1569 EXPECT_EQ(FormField(string16(), | 1565 EXPECT_EQ(FormField(string16(), |
1570 ASCIIToUTF16("lastname"), | 1566 ASCIIToUTF16("lastname"), |
1571 string16(), | 1567 string16(), |
1572 ASCIIToUTF16("text"), | 1568 ASCIIToUTF16("text"), |
1573 kDefaultMaxLength, | 1569 WebInputElement::defaultMaxLength(), |
1574 false), | 1570 false), |
1575 fields[1]); | 1571 fields[1]); |
1576 EXPECT_EQ(FormField(string16(), | 1572 EXPECT_EQ(FormField(string16(), |
1577 ASCIIToUTF16("email"), | 1573 ASCIIToUTF16("email"), |
1578 string16(), | 1574 string16(), |
1579 ASCIIToUTF16("text"), | 1575 ASCIIToUTF16("text"), |
1580 kDefaultMaxLength, | 1576 WebInputElement::defaultMaxLength(), |
1581 false), | 1577 false), |
1582 fields[2]); | 1578 fields[2]); |
1583 | 1579 |
1584 // Fill the form. | 1580 // Fill the form. |
1585 form.fields[0].set_value(ASCIIToUTF16("Brother")); | 1581 form.fields[0].set_value(ASCIIToUTF16("Brother")); |
1586 form.fields[1].set_value(ASCIIToUTF16("Jonathan")); | 1582 form.fields[1].set_value(ASCIIToUTF16("Jonathan")); |
1587 form.fields[2].set_value(ASCIIToUTF16("brotherj@example.com")); | 1583 form.fields[2].set_value(ASCIIToUTF16("brotherj@example.com")); |
1588 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); | 1584 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); |
1589 | 1585 |
1590 // Find the newly-filled form that contains the input element. | 1586 // Find the newly-filled form that contains the input element. |
1591 FormData form2; | 1587 FormData form2; |
1592 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 1588 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
1593 input_element, FormManager::REQUIRE_NONE, &form2)); | 1589 input_element, FormManager::REQUIRE_NONE, &form2)); |
1594 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1590 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1595 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1591 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1596 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1592 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1597 | 1593 |
1598 const std::vector<FormField>& fields2 = form2.fields; | 1594 const std::vector<FormField>& fields2 = form2.fields; |
1599 ASSERT_EQ(3U, fields2.size()); | 1595 ASSERT_EQ(3U, fields2.size()); |
1600 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 1596 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( |
1601 FormField(string16(), | 1597 FormField(string16(), |
1602 ASCIIToUTF16("firstname"), | 1598 ASCIIToUTF16("firstname"), |
1603 ASCIIToUTF16("Brother"), | 1599 ASCIIToUTF16("Brother"), |
1604 ASCIIToUTF16("text"), | 1600 ASCIIToUTF16("text"), |
1605 kDefaultMaxLength, | 1601 WebInputElement::defaultMaxLength(), |
1606 false))); | 1602 false))); |
1607 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 1603 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( |
1608 FormField(string16(), | 1604 FormField(string16(), |
1609 ASCIIToUTF16("lastname"), | 1605 ASCIIToUTF16("lastname"), |
1610 ASCIIToUTF16("Jonathan"), | 1606 ASCIIToUTF16("Jonathan"), |
1611 ASCIIToUTF16("text"), | 1607 ASCIIToUTF16("text"), |
1612 kDefaultMaxLength, | 1608 WebInputElement::defaultMaxLength(), |
1613 false))); | 1609 false))); |
1614 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 1610 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( |
1615 FormField(string16(), | 1611 FormField(string16(), |
1616 ASCIIToUTF16("email"), | 1612 ASCIIToUTF16("email"), |
1617 ASCIIToUTF16("brotherj@example.com"), | 1613 ASCIIToUTF16("brotherj@example.com"), |
1618 ASCIIToUTF16("text"), | 1614 ASCIIToUTF16("text"), |
1619 kDefaultMaxLength, | 1615 WebInputElement::defaultMaxLength(), |
1620 false))); | 1616 false))); |
1621 } | 1617 } |
1622 | 1618 |
1623 // This test sends a FormData object to FillForm with more fields than are in | 1619 // This test sends a FormData object to FillForm with more fields than are in |
1624 // the cached WebFormElement. In this case, we only fill out the fields that | 1620 // the cached WebFormElement. In this case, we only fill out the fields that |
1625 // match between the FormData object and the WebFormElement. | 1621 // match between the FormData object and the WebFormElement. |
1626 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { | 1622 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { |
1627 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1623 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
1628 " <INPUT type=\"text\" id=\"firstname\"/>" | 1624 " <INPUT type=\"text\" id=\"firstname\"/>" |
1629 " <INPUT type=\"text\" id=\"middlename\"/>" | 1625 " <INPUT type=\"text\" id=\"middlename\"/>" |
(...skipping 19 matching lines...) Expand all Loading... |
1649 // middlename | 1645 // middlename |
1650 // second | 1646 // second |
1651 // lastname | 1647 // lastname |
1652 // postfix | 1648 // postfix |
1653 FormData* form = &forms[0]; | 1649 FormData* form = &forms[0]; |
1654 | 1650 |
1655 FormField field1(string16(), | 1651 FormField field1(string16(), |
1656 ASCIIToUTF16("prefix"), | 1652 ASCIIToUTF16("prefix"), |
1657 string16(), | 1653 string16(), |
1658 ASCIIToUTF16("text"), | 1654 ASCIIToUTF16("text"), |
1659 kDefaultMaxLength, | 1655 WebInputElement::defaultMaxLength(), |
1660 false); | 1656 false); |
1661 form->fields.insert(form->fields.begin(), field1); | 1657 form->fields.insert(form->fields.begin(), field1); |
1662 | 1658 |
1663 FormField field2(string16(), | 1659 FormField field2(string16(), |
1664 ASCIIToUTF16("hidden"), | 1660 ASCIIToUTF16("hidden"), |
1665 string16(), | 1661 string16(), |
1666 ASCIIToUTF16("text"), | 1662 ASCIIToUTF16("text"), |
1667 kDefaultMaxLength, | 1663 WebInputElement::defaultMaxLength(), |
1668 false); | 1664 false); |
1669 form->fields.insert(form->fields.begin() + 2, field2); | 1665 form->fields.insert(form->fields.begin() + 2, field2); |
1670 | 1666 |
1671 FormField field3(string16(), | 1667 FormField field3(string16(), |
1672 ASCIIToUTF16("second"), | 1668 ASCIIToUTF16("second"), |
1673 string16(), | 1669 string16(), |
1674 ASCIIToUTF16("text"), | 1670 ASCIIToUTF16("text"), |
1675 kDefaultMaxLength, | 1671 WebInputElement::defaultMaxLength(), |
1676 false); | 1672 false); |
1677 form->fields.insert(form->fields.begin() + 4, field3); | 1673 form->fields.insert(form->fields.begin() + 4, field3); |
1678 | 1674 |
1679 FormField field4(string16(), | 1675 FormField field4(string16(), |
1680 ASCIIToUTF16("postfix"), | 1676 ASCIIToUTF16("postfix"), |
1681 string16(), | 1677 string16(), |
1682 ASCIIToUTF16("text"), | 1678 ASCIIToUTF16("text"), |
1683 kDefaultMaxLength, | 1679 WebInputElement::defaultMaxLength(), |
1684 false); | 1680 false); |
1685 form->fields.insert(form->fields.begin() + 6, field4); | 1681 form->fields.insert(form->fields.begin() + 6, field4); |
1686 | 1682 |
1687 // Fill the form. | 1683 // Fill the form. |
1688 form->fields[0].set_value(ASCIIToUTF16("Alpha")); | 1684 form->fields[0].set_value(ASCIIToUTF16("Alpha")); |
1689 form->fields[1].set_value(ASCIIToUTF16("Brother")); | 1685 form->fields[1].set_value(ASCIIToUTF16("Brother")); |
1690 form->fields[2].set_value(ASCIIToUTF16("Abracadabra")); | 1686 form->fields[2].set_value(ASCIIToUTF16("Abracadabra")); |
1691 form->fields[3].set_value(ASCIIToUTF16("Joseph")); | 1687 form->fields[3].set_value(ASCIIToUTF16("Joseph")); |
1692 form->fields[4].set_value(ASCIIToUTF16("Beta")); | 1688 form->fields[4].set_value(ASCIIToUTF16("Beta")); |
1693 form->fields[5].set_value(ASCIIToUTF16("Jonathan")); | 1689 form->fields[5].set_value(ASCIIToUTF16("Jonathan")); |
1694 form->fields[6].set_value(ASCIIToUTF16("Omega")); | 1690 form->fields[6].set_value(ASCIIToUTF16("Omega")); |
1695 EXPECT_TRUE(form_manager.FillForm(*form, WebNode())); | 1691 EXPECT_TRUE(form_manager.FillForm(*form, WebNode())); |
1696 | 1692 |
1697 // Get the input element we want to find. | 1693 // Get the input element we want to find. |
1698 WebElement element = web_frame->document().getElementById("firstname"); | 1694 WebElement element = web_frame->document().getElementById("firstname"); |
1699 WebInputElement input_element = element.to<WebInputElement>(); | 1695 WebInputElement input_element = element.to<WebInputElement>(); |
1700 | 1696 |
1701 // Find the newly-filled form that contains the input element. | 1697 // Find the newly-filled form that contains the input element. |
1702 FormData form2; | 1698 FormData form2; |
1703 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 1699 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
1704 input_element, FormManager::REQUIRE_NONE, &form2)); | 1700 input_element, FormManager::REQUIRE_NONE, &form2)); |
1705 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1701 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1706 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1702 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1707 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1703 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1708 | 1704 |
1709 const std::vector<FormField>& fields = form2.fields; | 1705 const std::vector<FormField>& fields = form2.fields; |
1710 ASSERT_EQ(3U, fields.size()); | 1706 ASSERT_EQ(3U, fields.size()); |
1711 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 1707 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
1712 ASCIIToUTF16("firstname"), | 1708 FormField(string16(), |
1713 ASCIIToUTF16("Brother"), | 1709 ASCIIToUTF16("firstname"), |
1714 ASCIIToUTF16("text"), | 1710 ASCIIToUTF16("Brother"), |
1715 kDefaultMaxLength, | 1711 ASCIIToUTF16("text"), |
1716 false))); | 1712 WebInputElement::defaultMaxLength(), |
1717 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 1713 false))); |
1718 ASCIIToUTF16("middlename"), | 1714 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
1719 ASCIIToUTF16("Joseph"), | 1715 FormField(string16(), |
1720 ASCIIToUTF16("text"), | 1716 ASCIIToUTF16("middlename"), |
1721 kDefaultMaxLength, | 1717 ASCIIToUTF16("Joseph"), |
1722 false))); | 1718 ASCIIToUTF16("text"), |
1723 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 1719 WebInputElement::defaultMaxLength(), |
1724 ASCIIToUTF16("lastname"), | 1720 false))); |
1725 ASCIIToUTF16("Jonathan"), | 1721 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
1726 ASCIIToUTF16("text"), | 1722 FormField(string16(), |
1727 kDefaultMaxLength, | 1723 ASCIIToUTF16("lastname"), |
1728 false))); | 1724 ASCIIToUTF16("Jonathan"), |
| 1725 ASCIIToUTF16("text"), |
| 1726 WebInputElement::defaultMaxLength(), |
| 1727 false))); |
1729 } | 1728 } |
1730 | 1729 |
1731 // This test sends a FormData object to FillForm with fewer fields than are in | 1730 // This test sends a FormData object to FillForm with fewer fields than are in |
1732 // the cached WebFormElement. In this case, we only fill out the fields that | 1731 // the cached WebFormElement. In this case, we only fill out the fields that |
1733 // match between the FormData object and the WebFormElement. | 1732 // match between the FormData object and the WebFormElement. |
1734 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { | 1733 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { |
1735 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1734 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
1736 " <INPUT type=\"text\" id=\"prefix\"/>" | 1735 " <INPUT type=\"text\" id=\"prefix\"/>" |
1737 " <INPUT type=\"text\" id=\"firstname\"/>" | 1736 " <INPUT type=\"text\" id=\"firstname\"/>" |
1738 " <INPUT type=\"text\" id=\"hidden\"/>" | 1737 " <INPUT type=\"text\" id=\"hidden\"/>" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 // Find the newly-filled form that contains the input element. | 1776 // Find the newly-filled form that contains the input element. |
1778 FormData form2; | 1777 FormData form2; |
1779 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 1778 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
1780 input_element, FormManager::REQUIRE_NONE, &form2)); | 1779 input_element, FormManager::REQUIRE_NONE, &form2)); |
1781 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1780 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1782 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1781 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1783 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1782 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1784 | 1783 |
1785 const std::vector<FormField>& fields = form2.fields; | 1784 const std::vector<FormField>& fields = form2.fields; |
1786 ASSERT_EQ(7U, fields.size()); | 1785 ASSERT_EQ(7U, fields.size()); |
1787 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 1786 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
1788 ASCIIToUTF16("prefix"), | 1787 FormField(string16(), |
1789 string16(), | 1788 ASCIIToUTF16("prefix"), |
1790 ASCIIToUTF16("text"), | 1789 string16(), |
1791 kDefaultMaxLength, | 1790 ASCIIToUTF16("text"), |
1792 false))); | 1791 WebInputElement::defaultMaxLength(), |
1793 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 1792 false))); |
1794 ASCIIToUTF16("firstname"), | 1793 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
1795 ASCIIToUTF16("Brother"), | 1794 FormField(string16(), |
1796 ASCIIToUTF16("text"), | 1795 ASCIIToUTF16("firstname"), |
1797 kDefaultMaxLength, | 1796 ASCIIToUTF16("Brother"), |
1798 false))); | 1797 ASCIIToUTF16("text"), |
1799 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 1798 WebInputElement::defaultMaxLength(), |
1800 ASCIIToUTF16("hidden"), | 1799 false))); |
1801 string16(), | 1800 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
1802 ASCIIToUTF16("text"), | 1801 FormField(string16(), |
1803 kDefaultMaxLength, | 1802 ASCIIToUTF16("hidden"), |
1804 false))); | 1803 string16(), |
1805 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), | 1804 ASCIIToUTF16("text"), |
1806 ASCIIToUTF16("middlename"), | 1805 WebInputElement::defaultMaxLength(), |
1807 ASCIIToUTF16("Joseph"), | 1806 false))); |
1808 ASCIIToUTF16("text"), | 1807 EXPECT_TRUE(fields[3].StrictlyEqualsHack( |
1809 kDefaultMaxLength, | 1808 FormField(string16(), |
1810 false))); | 1809 ASCIIToUTF16("middlename"), |
1811 EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(), | 1810 ASCIIToUTF16("Joseph"), |
1812 ASCIIToUTF16("second"), | 1811 ASCIIToUTF16("text"), |
1813 string16(), | 1812 WebInputElement::defaultMaxLength(), |
1814 ASCIIToUTF16("text"), | 1813 false))); |
1815 kDefaultMaxLength, | 1814 EXPECT_TRUE(fields[4].StrictlyEqualsHack( |
1816 false))); | 1815 FormField(string16(), |
1817 EXPECT_TRUE(fields[5].StrictlyEqualsHack(FormField(string16(), | 1816 ASCIIToUTF16("second"), |
1818 ASCIIToUTF16("lastname"), | 1817 string16(), |
1819 ASCIIToUTF16("Jonathan"), | 1818 ASCIIToUTF16("text"), |
1820 ASCIIToUTF16("text"), | 1819 WebInputElement::defaultMaxLength(), |
1821 kDefaultMaxLength, | 1820 false))); |
1822 false))); | 1821 EXPECT_TRUE(fields[5].StrictlyEqualsHack( |
1823 EXPECT_TRUE(fields[6].StrictlyEqualsHack(FormField(string16(), | 1822 FormField(string16(), |
1824 ASCIIToUTF16("postfix"), | 1823 ASCIIToUTF16("lastname"), |
1825 string16(), | 1824 ASCIIToUTF16("Jonathan"), |
1826 ASCIIToUTF16("text"), | 1825 ASCIIToUTF16("text"), |
1827 kDefaultMaxLength, | 1826 WebInputElement::defaultMaxLength(), |
1828 false))); | 1827 false))); |
| 1828 EXPECT_TRUE(fields[6].StrictlyEqualsHack( |
| 1829 FormField(string16(), |
| 1830 ASCIIToUTF16("postfix"), |
| 1831 string16(), |
| 1832 ASCIIToUTF16("text"), |
| 1833 WebInputElement::defaultMaxLength(), |
| 1834 false))); |
1829 } | 1835 } |
1830 | 1836 |
1831 // This test sends a FormData object to FillForm with a field changed from | 1837 // This test sends a FormData object to FillForm with a field changed from |
1832 // those in the cached WebFormElement. In this case, we only fill out the | 1838 // those in the cached WebFormElement. In this case, we only fill out the |
1833 // fields that match between the FormData object and the WebFormElement. | 1839 // fields that match between the FormData object and the WebFormElement. |
1834 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { | 1840 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { |
1835 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1841 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
1836 " <INPUT type=\"text\" id=\"firstname\"/>" | 1842 " <INPUT type=\"text\" id=\"firstname\"/>" |
1837 " <INPUT type=\"text\" id=\"middlename\"/>" | 1843 " <INPUT type=\"text\" id=\"middlename\"/>" |
1838 " <INPUT type=\"text\" id=\"lastname\"/>" | 1844 " <INPUT type=\"text\" id=\"lastname\"/>" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1884 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1879 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1885 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1880 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1886 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1881 | 1887 |
1882 const std::vector<FormField>& fields = form2.fields; | 1888 const std::vector<FormField>& fields = form2.fields; |
1883 ASSERT_EQ(3U, fields.size()); | 1889 ASSERT_EQ(3U, fields.size()); |
1884 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 1890 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), |
1885 ASCIIToUTF16("firstname"), | 1891 ASCIIToUTF16("firstname"), |
1886 ASCIIToUTF16("Brother"), | 1892 ASCIIToUTF16("Brother"), |
1887 ASCIIToUTF16("text"), | 1893 ASCIIToUTF16("text"), |
1888 kDefaultMaxLength, | 1894 WebInputElement::defaultMaxLength(), |
1889 false))); | 1895 false))); |
1890 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 1896 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), |
1891 ASCIIToUTF16("middlename"), | 1897 ASCIIToUTF16("middlename"), |
1892 string16(), | 1898 string16(), |
1893 ASCIIToUTF16("text"), | 1899 ASCIIToUTF16("text"), |
1894 kDefaultMaxLength, | 1900 WebInputElement::defaultMaxLength(), |
1895 false))); | 1901 false))); |
1896 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 1902 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), |
1897 ASCIIToUTF16("lastname"), | 1903 ASCIIToUTF16("lastname"), |
1898 ASCIIToUTF16("Jonathan"), | 1904 ASCIIToUTF16("Jonathan"), |
1899 ASCIIToUTF16("text"), | 1905 ASCIIToUTF16("text"), |
1900 kDefaultMaxLength, | 1906 WebInputElement::defaultMaxLength(), |
1901 false))); | 1907 false))); |
1902 } | 1908 } |
1903 | 1909 |
1904 // This test sends a FormData object to FillForm with fewer fields than are in | 1910 // This test sends a FormData object to FillForm with fewer fields than are in |
1905 // the cached WebFormElement. In this case, we only fill out the fields that | 1911 // the cached WebFormElement. In this case, we only fill out the fields that |
1906 // match between the FormData object and the WebFormElement. | 1912 // match between the FormData object and the WebFormElement. |
1907 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { | 1913 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { |
1908 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1914 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
1909 " <INPUT type=\"text\" id=\"firstname\"/>" | 1915 " <INPUT type=\"text\" id=\"firstname\"/>" |
1910 " <INPUT type=\"text\" id=\"middlename\"/>" | 1916 " <INPUT type=\"text\" id=\"middlename\"/>" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 // Find the newly-filled form that contains the input element. | 1950 // Find the newly-filled form that contains the input element. |
1945 FormData form2; | 1951 FormData form2; |
1946 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 1952 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
1947 input_element, FormManager::REQUIRE_NONE, &form2)); | 1953 input_element, FormManager::REQUIRE_NONE, &form2)); |
1948 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1954 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1949 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1955 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1950 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1956 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1951 | 1957 |
1952 const std::vector<FormField>& fields = form2.fields; | 1958 const std::vector<FormField>& fields = form2.fields; |
1953 ASSERT_EQ(4U, fields.size()); | 1959 ASSERT_EQ(4U, fields.size()); |
1954 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 1960 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
1955 ASCIIToUTF16("firstname"), | 1961 FormField(string16(), |
1956 ASCIIToUTF16("Brother"), | 1962 ASCIIToUTF16("firstname"), |
1957 ASCIIToUTF16("text"), | 1963 ASCIIToUTF16("Brother"), |
1958 kDefaultMaxLength, | 1964 ASCIIToUTF16("text"), |
1959 false))); | 1965 WebInputElement::defaultMaxLength(), |
1960 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 1966 false))); |
1961 ASCIIToUTF16("middlename"), | 1967 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
1962 ASCIIToUTF16("Joseph"), | 1968 FormField(string16(), |
1963 ASCIIToUTF16("text"), | 1969 ASCIIToUTF16("middlename"), |
1964 kDefaultMaxLength, | 1970 ASCIIToUTF16("Joseph"), |
1965 false))); | 1971 ASCIIToUTF16("text"), |
1966 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 1972 WebInputElement::defaultMaxLength(), |
1967 ASCIIToUTF16("lastname"), | 1973 false))); |
1968 ASCIIToUTF16("Jonathan"), | 1974 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
1969 ASCIIToUTF16("text"), | 1975 FormField(string16(), |
1970 kDefaultMaxLength, | 1976 ASCIIToUTF16("lastname"), |
1971 false))); | 1977 ASCIIToUTF16("Jonathan"), |
1972 EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(), | 1978 ASCIIToUTF16("text"), |
1973 ASCIIToUTF16("postfix"), | 1979 WebInputElement::defaultMaxLength(), |
1974 string16(), | 1980 false))); |
1975 ASCIIToUTF16("text"), | 1981 EXPECT_TRUE(fields[3].StrictlyEqualsHack( |
1976 kDefaultMaxLength, | 1982 FormField(string16(), |
1977 false))); | 1983 ASCIIToUTF16("postfix"), |
| 1984 string16(), |
| 1985 ASCIIToUTF16("text"), |
| 1986 WebInputElement::defaultMaxLength(), |
| 1987 false))); |
1978 } | 1988 } |
1979 | 1989 |
1980 TEST_F(FormManagerTest, FillFormEmptyName) { | 1990 TEST_F(FormManagerTest, FillFormEmptyName) { |
1981 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1991 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
1982 " <INPUT type=\"text\" id=\"firstname\"/>" | 1992 " <INPUT type=\"text\" id=\"firstname\"/>" |
1983 " <INPUT type=\"text\" id=\"lastname\"/>" | 1993 " <INPUT type=\"text\" id=\"lastname\"/>" |
1984 " <INPUT type=\"text\" id=\"email\"/>" | 1994 " <INPUT type=\"text\" id=\"email\"/>" |
1985 " <INPUT type=\"submit\" value=\"Send\"/>" | 1995 " <INPUT type=\"submit\" value=\"Send\"/>" |
1986 "</FORM>"); | 1996 "</FORM>"); |
1987 | 1997 |
(...skipping 19 matching lines...) Expand all Loading... |
2007 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2017 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2008 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 2018 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
2009 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2019 EXPECT_EQ(GURL("http://buh.com"), form.action); |
2010 | 2020 |
2011 const std::vector<FormField>& fields = form.fields; | 2021 const std::vector<FormField>& fields = form.fields; |
2012 ASSERT_EQ(3U, fields.size()); | 2022 ASSERT_EQ(3U, fields.size()); |
2013 EXPECT_EQ(FormField(string16(), | 2023 EXPECT_EQ(FormField(string16(), |
2014 ASCIIToUTF16("firstname"), | 2024 ASCIIToUTF16("firstname"), |
2015 string16(), | 2025 string16(), |
2016 ASCIIToUTF16("text"), | 2026 ASCIIToUTF16("text"), |
2017 kDefaultMaxLength, | 2027 WebInputElement::defaultMaxLength(), |
2018 false), | 2028 false), |
2019 fields[0]); | 2029 fields[0]); |
2020 EXPECT_EQ(FormField(string16(), | 2030 EXPECT_EQ(FormField(string16(), |
2021 ASCIIToUTF16("lastname"), | 2031 ASCIIToUTF16("lastname"), |
2022 string16(), | 2032 string16(), |
2023 ASCIIToUTF16("text"), | 2033 ASCIIToUTF16("text"), |
2024 kDefaultMaxLength, | 2034 WebInputElement::defaultMaxLength(), |
2025 false), | 2035 false), |
2026 fields[1]); | 2036 fields[1]); |
2027 EXPECT_EQ(FormField(string16(), | 2037 EXPECT_EQ(FormField(string16(), |
2028 ASCIIToUTF16("email"), | 2038 ASCIIToUTF16("email"), |
2029 string16(), | 2039 string16(), |
2030 ASCIIToUTF16("text"), | 2040 ASCIIToUTF16("text"), |
2031 kDefaultMaxLength, | 2041 WebInputElement::defaultMaxLength(), |
2032 false), | 2042 false), |
2033 fields[2]); | 2043 fields[2]); |
2034 | 2044 |
2035 // Fill the form. | 2045 // Fill the form. |
2036 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); | 2046 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); |
2037 form.fields[1].set_value(ASCIIToUTF16("Earp")); | 2047 form.fields[1].set_value(ASCIIToUTF16("Earp")); |
2038 form.fields[2].set_value(ASCIIToUTF16("wyatt@example.com")); | 2048 form.fields[2].set_value(ASCIIToUTF16("wyatt@example.com")); |
2039 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); | 2049 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); |
2040 | 2050 |
2041 // Find the newly-filled form that contains the input element. | 2051 // Find the newly-filled form that contains the input element. |
2042 FormData form2; | 2052 FormData form2; |
2043 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 2053 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
2044 input_element, FormManager::REQUIRE_NONE, &form2)); | 2054 input_element, FormManager::REQUIRE_NONE, &form2)); |
2045 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2055 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
2046 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 2056 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
2047 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2057 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2048 | 2058 |
2049 const std::vector<FormField>& fields2 = form2.fields; | 2059 const std::vector<FormField>& fields2 = form2.fields; |
2050 ASSERT_EQ(3U, fields2.size()); | 2060 ASSERT_EQ(3U, fields2.size()); |
2051 EXPECT_EQ(FormField(string16(), | 2061 EXPECT_EQ(FormField(string16(), |
2052 ASCIIToUTF16("firstname"), | 2062 ASCIIToUTF16("firstname"), |
2053 ASCIIToUTF16("Wyatt"), | 2063 ASCIIToUTF16("Wyatt"), |
2054 ASCIIToUTF16("text"), | 2064 ASCIIToUTF16("text"), |
2055 kDefaultMaxLength, | 2065 WebInputElement::defaultMaxLength(), |
2056 false), | 2066 false), |
2057 fields2[0]); | 2067 fields2[0]); |
2058 EXPECT_EQ(FormField(string16(), | 2068 EXPECT_EQ(FormField(string16(), |
2059 ASCIIToUTF16("lastname"), | 2069 ASCIIToUTF16("lastname"), |
2060 ASCIIToUTF16("Earp"), | 2070 ASCIIToUTF16("Earp"), |
2061 ASCIIToUTF16("text"), | 2071 ASCIIToUTF16("text"), |
2062 kDefaultMaxLength, | 2072 WebInputElement::defaultMaxLength(), |
2063 false), | 2073 false), |
2064 fields2[1]); | 2074 fields2[1]); |
2065 EXPECT_EQ(FormField(string16(), | 2075 EXPECT_EQ(FormField(string16(), |
2066 ASCIIToUTF16("email"), | 2076 ASCIIToUTF16("email"), |
2067 ASCIIToUTF16("wyatt@example.com"), | 2077 ASCIIToUTF16("wyatt@example.com"), |
2068 ASCIIToUTF16("text"), | 2078 ASCIIToUTF16("text"), |
2069 kDefaultMaxLength, | 2079 WebInputElement::defaultMaxLength(), |
2070 false), | 2080 false), |
2071 fields2[2]); | 2081 fields2[2]); |
2072 } | 2082 } |
2073 | 2083 |
2074 TEST_F(FormManagerTest, FillFormEmptyFormNames) { | 2084 TEST_F(FormManagerTest, FillFormEmptyFormNames) { |
2075 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" | 2085 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" |
2076 " <INPUT type=\"text\" id=\"firstname\"/>" | 2086 " <INPUT type=\"text\" id=\"firstname\"/>" |
2077 " <INPUT type=\"text\" id=\"middlename\"/>" | 2087 " <INPUT type=\"text\" id=\"middlename\"/>" |
2078 " <INPUT type=\"text\" id=\"lastname\"/>" | 2088 " <INPUT type=\"text\" id=\"lastname\"/>" |
2079 " <INPUT type=\"submit\" value=\"Send\"/>" | 2089 " <INPUT type=\"submit\" value=\"Send\"/>" |
(...skipping 27 matching lines...) Expand all Loading... |
2107 EXPECT_EQ(string16(), form.name); | 2117 EXPECT_EQ(string16(), form.name); |
2108 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 2118 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
2109 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2119 EXPECT_EQ(GURL("http://abc.com"), form.action); |
2110 | 2120 |
2111 const std::vector<FormField>& fields = form.fields; | 2121 const std::vector<FormField>& fields = form.fields; |
2112 ASSERT_EQ(3U, fields.size()); | 2122 ASSERT_EQ(3U, fields.size()); |
2113 EXPECT_EQ(FormField(string16(), | 2123 EXPECT_EQ(FormField(string16(), |
2114 ASCIIToUTF16("apple"), | 2124 ASCIIToUTF16("apple"), |
2115 string16(), | 2125 string16(), |
2116 ASCIIToUTF16("text"), | 2126 ASCIIToUTF16("text"), |
2117 kDefaultMaxLength, | 2127 WebInputElement::defaultMaxLength(), |
2118 false), | 2128 false), |
2119 fields[0]); | 2129 fields[0]); |
2120 EXPECT_EQ(FormField(string16(), | 2130 EXPECT_EQ(FormField(string16(), |
2121 ASCIIToUTF16("banana"), | 2131 ASCIIToUTF16("banana"), |
2122 string16(), | 2132 string16(), |
2123 ASCIIToUTF16("text"), | 2133 ASCIIToUTF16("text"), |
2124 kDefaultMaxLength, | 2134 WebInputElement::defaultMaxLength(), |
2125 false), | 2135 false), |
2126 fields[1]); | 2136 fields[1]); |
2127 EXPECT_EQ(FormField(string16(), | 2137 EXPECT_EQ(FormField(string16(), |
2128 ASCIIToUTF16("cantelope"), | 2138 ASCIIToUTF16("cantelope"), |
2129 string16(), | 2139 string16(), |
2130 ASCIIToUTF16("text"), | 2140 ASCIIToUTF16("text"), |
2131 kDefaultMaxLength, | 2141 WebInputElement::defaultMaxLength(), |
2132 false), | 2142 false), |
2133 fields[2]); | 2143 fields[2]); |
2134 | 2144 |
2135 // Fill the form. | 2145 // Fill the form. |
2136 form.fields[0].set_value(ASCIIToUTF16("Red")); | 2146 form.fields[0].set_value(ASCIIToUTF16("Red")); |
2137 form.fields[1].set_value(ASCIIToUTF16("Yellow")); | 2147 form.fields[1].set_value(ASCIIToUTF16("Yellow")); |
2138 form.fields[2].set_value(ASCIIToUTF16("Also Yellow")); | 2148 form.fields[2].set_value(ASCIIToUTF16("Also Yellow")); |
2139 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); | 2149 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); |
2140 | 2150 |
2141 // Find the newly-filled form that contains the input element. | 2151 // Find the newly-filled form that contains the input element. |
2142 FormData form2; | 2152 FormData form2; |
2143 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 2153 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
2144 input_element, FormManager::REQUIRE_NONE, &form2)); | 2154 input_element, FormManager::REQUIRE_NONE, &form2)); |
2145 EXPECT_EQ(string16(), form2.name); | 2155 EXPECT_EQ(string16(), form2.name); |
2146 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 2156 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
2147 EXPECT_EQ(GURL("http://abc.com"), form2.action); | 2157 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
2148 | 2158 |
2149 const std::vector<FormField>& fields2 = form2.fields; | 2159 const std::vector<FormField>& fields2 = form2.fields; |
2150 ASSERT_EQ(3U, fields2.size()); | 2160 ASSERT_EQ(3U, fields2.size()); |
2151 EXPECT_EQ(FormField(string16(), | 2161 EXPECT_EQ(FormField(string16(), |
2152 ASCIIToUTF16("apple"), | 2162 ASCIIToUTF16("apple"), |
2153 ASCIIToUTF16("Red"), | 2163 ASCIIToUTF16("Red"), |
2154 ASCIIToUTF16("text"), | 2164 ASCIIToUTF16("text"), |
2155 kDefaultMaxLength, | 2165 WebInputElement::defaultMaxLength(), |
2156 false), | 2166 false), |
2157 fields2[0]); | 2167 fields2[0]); |
2158 EXPECT_EQ(FormField(string16(), | 2168 EXPECT_EQ(FormField(string16(), |
2159 ASCIIToUTF16("banana"), | 2169 ASCIIToUTF16("banana"), |
2160 ASCIIToUTF16("Yellow"), | 2170 ASCIIToUTF16("Yellow"), |
2161 ASCIIToUTF16("text"), | 2171 ASCIIToUTF16("text"), |
2162 kDefaultMaxLength, | 2172 WebInputElement::defaultMaxLength(), |
2163 false), | 2173 false), |
2164 fields2[1]); | 2174 fields2[1]); |
2165 EXPECT_EQ(FormField(string16(), | 2175 EXPECT_EQ(FormField(string16(), |
2166 ASCIIToUTF16("cantelope"), | 2176 ASCIIToUTF16("cantelope"), |
2167 ASCIIToUTF16("Also Yellow"), | 2177 ASCIIToUTF16("Also Yellow"), |
2168 ASCIIToUTF16("text"), | 2178 ASCIIToUTF16("text"), |
2169 kDefaultMaxLength, | 2179 WebInputElement::defaultMaxLength(), |
2170 false), | 2180 false), |
2171 fields2[2]); | 2181 fields2[2]); |
2172 } | 2182 } |
2173 | 2183 |
2174 TEST_F(FormManagerTest, ThreePartPhone) { | 2184 TEST_F(FormManagerTest, ThreePartPhone) { |
2175 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2185 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
2176 " Phone:" | 2186 " Phone:" |
2177 " <input type=\"text\" name=\"dayphone1\">" | 2187 " <input type=\"text\" name=\"dayphone1\">" |
2178 " -" | 2188 " -" |
2179 " <input type=\"text\" name=\"dayphone2\">" | 2189 " <input type=\"text\" name=\"dayphone2\">" |
(...skipping 20 matching lines...) Expand all Loading... |
2200 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2210 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2201 EXPECT_EQ(GURL(frame->url()), form.origin); | 2211 EXPECT_EQ(GURL(frame->url()), form.origin); |
2202 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2212 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2203 | 2213 |
2204 const std::vector<FormField>& fields = form.fields; | 2214 const std::vector<FormField>& fields = form.fields; |
2205 ASSERT_EQ(4U, fields.size()); | 2215 ASSERT_EQ(4U, fields.size()); |
2206 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), | 2216 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), |
2207 ASCIIToUTF16("dayphone1"), | 2217 ASCIIToUTF16("dayphone1"), |
2208 string16(), | 2218 string16(), |
2209 ASCIIToUTF16("text"), | 2219 ASCIIToUTF16("text"), |
2210 kDefaultMaxLength, | 2220 WebInputElement::defaultMaxLength(), |
2211 false), | 2221 false), |
2212 fields[0]); | 2222 fields[0]); |
2213 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2223 EXPECT_EQ(FormField(ASCIIToUTF16("-"), |
2214 ASCIIToUTF16("dayphone2"), | 2224 ASCIIToUTF16("dayphone2"), |
2215 string16(), | 2225 string16(), |
2216 ASCIIToUTF16("text"), | 2226 ASCIIToUTF16("text"), |
2217 kDefaultMaxLength, | 2227 WebInputElement::defaultMaxLength(), |
2218 false), | 2228 false), |
2219 fields[1]); | 2229 fields[1]); |
2220 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2230 EXPECT_EQ(FormField(ASCIIToUTF16("-"), |
2221 ASCIIToUTF16("dayphone3"), | 2231 ASCIIToUTF16("dayphone3"), |
2222 string16(), | 2232 string16(), |
2223 ASCIIToUTF16("text"), | 2233 ASCIIToUTF16("text"), |
2224 kDefaultMaxLength, | 2234 WebInputElement::defaultMaxLength(), |
2225 false), | 2235 false), |
2226 fields[2]); | 2236 fields[2]); |
2227 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | 2237 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), |
2228 ASCIIToUTF16("dayphone4"), | 2238 ASCIIToUTF16("dayphone4"), |
2229 string16(), | 2239 string16(), |
2230 ASCIIToUTF16("text"), | 2240 ASCIIToUTF16("text"), |
2231 kDefaultMaxLength, | 2241 WebInputElement::defaultMaxLength(), |
2232 false), | 2242 false), |
2233 fields[3]); | 2243 fields[3]); |
2234 } | 2244 } |
2235 | 2245 |
2236 | 2246 |
2237 TEST_F(FormManagerTest, MaxLengthFields) { | 2247 TEST_F(FormManagerTest, MaxLengthFields) { |
2238 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2248 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
2239 " Phone:" | 2249 " Phone:" |
2240 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" | 2250 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" |
2241 " -" | 2251 " -" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 string16(), | 2304 string16(), |
2295 ASCIIToUTF16("text"), | 2305 ASCIIToUTF16("text"), |
2296 5, | 2306 5, |
2297 false), | 2307 false), |
2298 fields[3]); | 2308 fields[3]); |
2299 // When unspecified |size|, default is returned. | 2309 // When unspecified |size|, default is returned. |
2300 EXPECT_EQ(FormField(string16(), | 2310 EXPECT_EQ(FormField(string16(), |
2301 ASCIIToUTF16("default1"), | 2311 ASCIIToUTF16("default1"), |
2302 string16(), | 2312 string16(), |
2303 ASCIIToUTF16("text"), | 2313 ASCIIToUTF16("text"), |
2304 kDefaultMaxLength, | 2314 WebInputElement::defaultMaxLength(), |
2305 false), | 2315 false), |
2306 fields[4]); | 2316 fields[4]); |
2307 // When invalid |size|, default is returned. | 2317 // When invalid |size|, default is returned. |
2308 EXPECT_EQ(FormField(string16(), | 2318 EXPECT_EQ(FormField(string16(), |
2309 ASCIIToUTF16("invalid1"), | 2319 ASCIIToUTF16("invalid1"), |
2310 string16(), | 2320 string16(), |
2311 ASCIIToUTF16("text"), | 2321 ASCIIToUTF16("text"), |
2312 kDefaultMaxLength, | 2322 WebInputElement::defaultMaxLength(), |
2313 false), | 2323 false), |
2314 fields[5]); | 2324 fields[5]); |
2315 } | 2325 } |
2316 | 2326 |
2317 // This test re-creates the experience of typing in a field then selecting a | 2327 // This test re-creates the experience of typing in a field then selecting a |
2318 // profile from the AutoFill suggestions popup. The field that is being typed | 2328 // profile from the AutoFill suggestions popup. The field that is being typed |
2319 // into should be filled even though it's not technically empty. | 2329 // into should be filled even though it's not technically empty. |
2320 TEST_F(FormManagerTest, FillFormNonEmptyField) { | 2330 TEST_F(FormManagerTest, FillFormNonEmptyField) { |
2321 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2331 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
2322 " <INPUT type=\"text\" id=\"firstname\"/>" | 2332 " <INPUT type=\"text\" id=\"firstname\"/>" |
(...skipping 27 matching lines...) Expand all Loading... |
2350 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2360 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2351 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 2361 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
2352 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2362 EXPECT_EQ(GURL("http://buh.com"), form.action); |
2353 | 2363 |
2354 const std::vector<FormField>& fields = form.fields; | 2364 const std::vector<FormField>& fields = form.fields; |
2355 ASSERT_EQ(3U, fields.size()); | 2365 ASSERT_EQ(3U, fields.size()); |
2356 EXPECT_EQ(FormField(string16(), | 2366 EXPECT_EQ(FormField(string16(), |
2357 ASCIIToUTF16("firstname"), | 2367 ASCIIToUTF16("firstname"), |
2358 string16(), | 2368 string16(), |
2359 ASCIIToUTF16("text"), | 2369 ASCIIToUTF16("text"), |
2360 kDefaultMaxLength, | 2370 WebInputElement::defaultMaxLength(), |
2361 false), | 2371 false), |
2362 fields[0]); | 2372 fields[0]); |
2363 EXPECT_EQ(FormField(string16(), | 2373 EXPECT_EQ(FormField(string16(), |
2364 ASCIIToUTF16("lastname"), | 2374 ASCIIToUTF16("lastname"), |
2365 string16(), | 2375 string16(), |
2366 ASCIIToUTF16("text"), | 2376 ASCIIToUTF16("text"), |
2367 kDefaultMaxLength, | 2377 WebInputElement::defaultMaxLength(), |
2368 false), | 2378 false), |
2369 fields[1]); | 2379 fields[1]); |
2370 EXPECT_EQ(FormField(string16(), | 2380 EXPECT_EQ(FormField(string16(), |
2371 ASCIIToUTF16("email"), | 2381 ASCIIToUTF16("email"), |
2372 string16(), | 2382 string16(), |
2373 ASCIIToUTF16("text"), | 2383 ASCIIToUTF16("text"), |
2374 kDefaultMaxLength, | 2384 WebInputElement::defaultMaxLength(), |
2375 false), | 2385 false), |
2376 fields[2]); | 2386 fields[2]); |
2377 | 2387 |
2378 // Fill the form. | 2388 // Fill the form. |
2379 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); | 2389 form.fields[0].set_value(ASCIIToUTF16("Wyatt")); |
2380 form.fields[1].set_value(ASCIIToUTF16("Earp")); | 2390 form.fields[1].set_value(ASCIIToUTF16("Earp")); |
2381 form.fields[2].set_value(ASCIIToUTF16("wyatt@example.com")); | 2391 form.fields[2].set_value(ASCIIToUTF16("wyatt@example.com")); |
2382 EXPECT_TRUE(form_manager.FillForm(form, input_element)); | 2392 EXPECT_TRUE(form_manager.FillForm(form, input_element)); |
2383 | 2393 |
2384 // Find the newly-filled form that contains the input element. | 2394 // Find the newly-filled form that contains the input element. |
2385 FormData form2; | 2395 FormData form2; |
2386 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 2396 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
2387 input_element, FormManager::REQUIRE_NONE, &form2)); | 2397 input_element, FormManager::REQUIRE_NONE, &form2)); |
2388 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2398 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
2389 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 2399 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
2390 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2400 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2391 | 2401 |
2392 const std::vector<FormField>& fields2 = form2.fields; | 2402 const std::vector<FormField>& fields2 = form2.fields; |
2393 ASSERT_EQ(3U, fields2.size()); | 2403 ASSERT_EQ(3U, fields2.size()); |
2394 EXPECT_EQ(FormField(string16(), | 2404 EXPECT_EQ(FormField(string16(), |
2395 ASCIIToUTF16("firstname"), | 2405 ASCIIToUTF16("firstname"), |
2396 ASCIIToUTF16("Wyatt"), | 2406 ASCIIToUTF16("Wyatt"), |
2397 ASCIIToUTF16("text"), | 2407 ASCIIToUTF16("text"), |
2398 kDefaultMaxLength, | 2408 WebInputElement::defaultMaxLength(), |
2399 false), | 2409 false), |
2400 fields2[0]); | 2410 fields2[0]); |
2401 EXPECT_EQ(FormField(string16(), | 2411 EXPECT_EQ(FormField(string16(), |
2402 ASCIIToUTF16("lastname"), | 2412 ASCIIToUTF16("lastname"), |
2403 ASCIIToUTF16("Earp"), | 2413 ASCIIToUTF16("Earp"), |
2404 ASCIIToUTF16("text"), | 2414 ASCIIToUTF16("text"), |
2405 kDefaultMaxLength, | 2415 WebInputElement::defaultMaxLength(), |
2406 false), | 2416 false), |
2407 fields2[1]); | 2417 fields2[1]); |
2408 EXPECT_EQ(FormField(string16(), | 2418 EXPECT_EQ(FormField(string16(), |
2409 ASCIIToUTF16("email"), | 2419 ASCIIToUTF16("email"), |
2410 ASCIIToUTF16("wyatt@example.com"), | 2420 ASCIIToUTF16("wyatt@example.com"), |
2411 ASCIIToUTF16("text"), | 2421 ASCIIToUTF16("text"), |
2412 kDefaultMaxLength, | 2422 WebInputElement::defaultMaxLength(), |
2413 false), | 2423 false), |
2414 fields2[2]); | 2424 fields2[2]); |
2415 | 2425 |
2416 // Verify that the cursor position has been updated. | 2426 // Verify that the cursor position has been updated. |
2417 EXPECT_EQ(5, input_element.selectionStart()); | 2427 EXPECT_EQ(5, input_element.selectionStart()); |
2418 EXPECT_EQ(5, input_element.selectionEnd()); | 2428 EXPECT_EQ(5, input_element.selectionEnd()); |
2419 } | 2429 } |
2420 | 2430 |
2421 TEST_F(FormManagerTest, ClearFormWithNode) { | 2431 TEST_F(FormManagerTest, ClearFormWithNode) { |
2422 LoadHTML( | 2432 LoadHTML( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2463 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 2473 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
2464 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2474 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2465 | 2475 |
2466 const std::vector<FormField>& fields2 = form2.fields; | 2476 const std::vector<FormField>& fields2 = form2.fields; |
2467 ASSERT_EQ(4U, fields2.size()); | 2477 ASSERT_EQ(4U, fields2.size()); |
2468 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2478 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( |
2469 FormField(string16(), | 2479 FormField(string16(), |
2470 ASCIIToUTF16("firstname"), | 2480 ASCIIToUTF16("firstname"), |
2471 string16(), | 2481 string16(), |
2472 ASCIIToUTF16("text"), | 2482 ASCIIToUTF16("text"), |
2473 kDefaultMaxLength, | 2483 WebInputElement::defaultMaxLength(), |
2474 false))); | 2484 false))); |
2475 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2485 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( |
2476 FormField(string16(), | 2486 FormField(string16(), |
2477 ASCIIToUTF16("lastname"), | 2487 ASCIIToUTF16("lastname"), |
2478 string16(), | 2488 string16(), |
2479 ASCIIToUTF16("text"), | 2489 ASCIIToUTF16("text"), |
2480 kDefaultMaxLength, | 2490 WebInputElement::defaultMaxLength(), |
2481 false))); | 2491 false))); |
2482 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2492 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( |
2483 FormField(string16(), | 2493 FormField(string16(), |
2484 ASCIIToUTF16("noAC"), | 2494 ASCIIToUTF16("noAC"), |
2485 string16(), | 2495 string16(), |
2486 ASCIIToUTF16("text"), | 2496 ASCIIToUTF16("text"), |
2487 kDefaultMaxLength, | 2497 WebInputElement::defaultMaxLength(), |
2488 false))); | 2498 false))); |
2489 EXPECT_TRUE(fields2[3].StrictlyEqualsHack( | 2499 EXPECT_TRUE(fields2[3].StrictlyEqualsHack( |
2490 FormField(string16(), | 2500 FormField(string16(), |
2491 ASCIIToUTF16("notenabled"), | 2501 ASCIIToUTF16("notenabled"), |
2492 ASCIIToUTF16("no clear"), | 2502 ASCIIToUTF16("no clear"), |
2493 ASCIIToUTF16("text"), | 2503 ASCIIToUTF16("text"), |
2494 kDefaultMaxLength, | 2504 WebInputElement::defaultMaxLength(), |
2495 false))); | 2505 false))); |
2496 | 2506 |
2497 // Verify that the cursor position has been updated. | 2507 // Verify that the cursor position has been updated. |
2498 EXPECT_EQ(0, firstname.selectionStart()); | 2508 EXPECT_EQ(0, firstname.selectionStart()); |
2499 EXPECT_EQ(0, firstname.selectionEnd()); | 2509 EXPECT_EQ(0, firstname.selectionEnd()); |
2500 } | 2510 } |
2501 | 2511 |
2502 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { | 2512 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { |
2503 LoadHTML( | 2513 LoadHTML( |
2504 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2514 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2548 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 2558 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
2549 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2559 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2550 | 2560 |
2551 const std::vector<FormField>& fields2 = form2.fields; | 2561 const std::vector<FormField>& fields2 = form2.fields; |
2552 ASSERT_EQ(3U, fields2.size()); | 2562 ASSERT_EQ(3U, fields2.size()); |
2553 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2563 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( |
2554 FormField(string16(), | 2564 FormField(string16(), |
2555 ASCIIToUTF16("firstname"), | 2565 ASCIIToUTF16("firstname"), |
2556 string16(), | 2566 string16(), |
2557 ASCIIToUTF16("text"), | 2567 ASCIIToUTF16("text"), |
2558 kDefaultMaxLength, | 2568 WebInputElement::defaultMaxLength(), |
2559 false))); | 2569 false))); |
2560 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2570 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( |
2561 FormField(string16(), | 2571 FormField(string16(), |
2562 ASCIIToUTF16("lastname"), | 2572 ASCIIToUTF16("lastname"), |
2563 string16(), | 2573 string16(), |
2564 ASCIIToUTF16("text"), | 2574 ASCIIToUTF16("text"), |
2565 kDefaultMaxLength, | 2575 WebInputElement::defaultMaxLength(), |
2566 false))); | 2576 false))); |
2567 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2577 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( |
2568 FormField(string16(), | 2578 FormField(string16(), |
2569 ASCIIToUTF16("state"), | 2579 ASCIIToUTF16("state"), |
2570 ASCIIToUTF16("?"), | 2580 ASCIIToUTF16("?"), |
2571 ASCIIToUTF16("select-one"), | 2581 ASCIIToUTF16("select-one"), |
2572 0, | 2582 0, |
2573 false))); | 2583 false))); |
2574 | 2584 |
2575 // Verify that the cursor position has been updated. | 2585 // Verify that the cursor position has been updated. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2878 EXPECT_EQ(GURL(frame->url()), form.origin); | 2888 EXPECT_EQ(GURL(frame->url()), form.origin); |
2879 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2889 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2880 | 2890 |
2881 const std::vector<FormField>& fields = form.fields; | 2891 const std::vector<FormField>& fields = form.fields; |
2882 ASSERT_EQ(3U, fields.size()); | 2892 ASSERT_EQ(3U, fields.size()); |
2883 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2893 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
2884 FormField(string16(), | 2894 FormField(string16(), |
2885 ASCIIToUTF16("firstname"), | 2895 ASCIIToUTF16("firstname"), |
2886 ASCIIToUTF16("John"), | 2896 ASCIIToUTF16("John"), |
2887 ASCIIToUTF16("text"), | 2897 ASCIIToUTF16("text"), |
2888 kDefaultMaxLength, | 2898 WebInputElement::defaultMaxLength(), |
2889 false))); | 2899 false))); |
2890 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2900 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
2891 FormField(string16(), | 2901 FormField(string16(), |
2892 ASCIIToUTF16("lastname"), | 2902 ASCIIToUTF16("lastname"), |
2893 ASCIIToUTF16("Smith"), | 2903 ASCIIToUTF16("Smith"), |
2894 ASCIIToUTF16("text"), | 2904 ASCIIToUTF16("text"), |
2895 kDefaultMaxLength, | 2905 WebInputElement::defaultMaxLength(), |
2896 false))); | 2906 false))); |
2897 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2907 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
2898 FormField(string16(), | 2908 FormField(string16(), |
2899 ASCIIToUTF16("country"), | 2909 ASCIIToUTF16("country"), |
2900 ASCIIToUTF16("Albania"), | 2910 ASCIIToUTF16("Albania"), |
2901 ASCIIToUTF16("select-one"), | 2911 ASCIIToUTF16("select-one"), |
2902 0, | 2912 0, |
2903 false))); | 2913 false))); |
2904 | 2914 |
2905 form.fields.clear(); | 2915 form.fields.clear(); |
2906 // Extract the country select-one value as value. | 2916 // Extract the country select-one value as value. |
2907 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2917 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
2908 FormManager::REQUIRE_NONE, | 2918 FormManager::REQUIRE_NONE, |
2909 FormManager::EXTRACT_VALUE, | 2919 FormManager::EXTRACT_VALUE, |
2910 &form)); | 2920 &form)); |
2911 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2921 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2912 EXPECT_EQ(GURL(frame->url()), form.origin); | 2922 EXPECT_EQ(GURL(frame->url()), form.origin); |
2913 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2923 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2914 | 2924 |
2915 ASSERT_EQ(3U, fields.size()); | 2925 ASSERT_EQ(3U, fields.size()); |
2916 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2926 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
2917 FormField(string16(), | 2927 FormField(string16(), |
2918 ASCIIToUTF16("firstname"), | 2928 ASCIIToUTF16("firstname"), |
2919 ASCIIToUTF16("John"), | 2929 ASCIIToUTF16("John"), |
2920 ASCIIToUTF16("text"), | 2930 ASCIIToUTF16("text"), |
2921 kDefaultMaxLength, | 2931 WebInputElement::defaultMaxLength(), |
2922 false))); | 2932 false))); |
2923 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2933 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
2924 FormField(string16(), | 2934 FormField(string16(), |
2925 ASCIIToUTF16("lastname"), | 2935 ASCIIToUTF16("lastname"), |
2926 ASCIIToUTF16("Smith"), | 2936 ASCIIToUTF16("Smith"), |
2927 ASCIIToUTF16("text"), | 2937 ASCIIToUTF16("text"), |
2928 kDefaultMaxLength, | 2938 WebInputElement::defaultMaxLength(), |
2929 false))); | 2939 false))); |
2930 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2940 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
2931 FormField(string16(), | 2941 FormField(string16(), |
2932 ASCIIToUTF16("country"), | 2942 ASCIIToUTF16("country"), |
2933 ASCIIToUTF16("AL"), | 2943 ASCIIToUTF16("AL"), |
2934 ASCIIToUTF16("select-one"), | 2944 ASCIIToUTF16("select-one"), |
2935 0, | 2945 0, |
2936 false))); | 2946 false))); |
2937 } | 2947 } |
OLD | NEW |