Chromium Code Reviews| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/format_macros.h" | |
| 7 #include "base/string16.h" | 8 #include "base/string16.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | |
| 9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/renderer/autofill/form_manager.h" | 12 #include "chrome/renderer/autofill/form_manager.h" |
| 11 #include "chrome/test/base/render_view_test.h" | 13 #include "chrome/test/base/render_view_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 31 using WebKit::WebSelectElement; | 33 using WebKit::WebSelectElement; |
| 32 using WebKit::WebNode; | 34 using WebKit::WebNode; |
| 33 using WebKit::WebString; | 35 using WebKit::WebString; |
| 34 using WebKit::WebVector; | 36 using WebKit::WebVector; |
| 35 | 37 |
| 36 using autofill::FormManager; | 38 using autofill::FormManager; |
| 37 | 39 |
| 38 using webkit_glue::FormData; | 40 using webkit_glue::FormData; |
| 39 using webkit_glue::FormField; | 41 using webkit_glue::FormField; |
| 40 | 42 |
| 43 namespace { | |
| 44 | |
| 45 void ExpectFieldEquals(const FormField& expected, const FormField& actual) { | |
| 46 EXPECT_EQ(expected.label, actual.label); | |
| 47 EXPECT_EQ(expected.name, actual.name); | |
| 48 EXPECT_EQ(expected.value, actual.value); | |
| 49 EXPECT_EQ(expected.form_control_type, actual.form_control_type); | |
| 50 EXPECT_EQ(expected.max_length, actual.max_length); | |
| 51 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 41 class FormManagerTest : public RenderViewTest { | 56 class FormManagerTest : public RenderViewTest { |
| 42 public: | 57 public: |
| 43 FormManagerTest() : RenderViewTest() {} | 58 FormManagerTest() : RenderViewTest() {} |
| 44 virtual ~FormManagerTest() {} | 59 virtual ~FormManagerTest() {} |
| 45 | 60 |
| 46 void ExpectLabels(const char* html, | 61 void ExpectLabels(const char* html, |
| 47 const std::vector<string16>& labels, | 62 const std::vector<string16>& labels, |
| 48 const std::vector<string16>& names, | 63 const std::vector<string16>& names, |
| 49 const std::vector<string16>& values) { | 64 const std::vector<string16>& values) { |
| 50 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); | 65 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 73 const FormData& form = forms[0]; | 88 const FormData& form = forms[0]; |
| 74 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 89 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 75 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 90 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 76 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 91 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 77 | 92 |
| 78 const std::vector<FormField>& fields = form.fields; | 93 const std::vector<FormField>& fields = form.fields; |
| 79 ASSERT_EQ(labels.size(), fields.size()); | 94 ASSERT_EQ(labels.size(), fields.size()); |
| 80 for (size_t i = 0; i < labels.size(); ++i) { | 95 for (size_t i = 0; i < labels.size(); ++i) { |
| 81 int max_length = control_types[i] == ASCIIToUTF16("text") ? | 96 int max_length = control_types[i] == ASCIIToUTF16("text") ? |
| 82 WebInputElement::defaultMaxLength() : 0; | 97 WebInputElement::defaultMaxLength() : 0; |
| 83 FormField expected = FormField(labels[i], | 98 FormField expected; |
| 84 names[i], | 99 expected.label = labels[i]; |
| 85 values[i], | 100 expected.name = names[i]; |
| 86 control_types[i], | 101 expected.value = values[i]; |
| 87 max_length, | 102 expected.form_control_type = control_types[i]; |
| 88 false); | 103 expected.max_length = max_length; |
| 89 EXPECT_TRUE(fields[i].StrictlyEqualsHack(expected)) | 104 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); |
| 90 << "Expected \"" << expected << "\", got \"" << fields[i] << "\""; | 105 ExpectFieldEquals(expected, fields[i]); |
| 91 } | 106 } |
| 92 } | 107 } |
| 93 | 108 |
| 94 void ExpectJohnSmithLabels(const char* html) { | 109 void ExpectJohnSmithLabels(const char* html) { |
| 95 std::vector<string16> labels, names, values; | 110 std::vector<string16> labels, names, values; |
| 96 | 111 |
| 97 labels.push_back(ASCIIToUTF16("First name:")); | 112 labels.push_back(ASCIIToUTF16("First name:")); |
| 98 names.push_back(ASCIIToUTF16("firstname")); | 113 names.push_back(ASCIIToUTF16("firstname")); |
| 99 values.push_back(ASCIIToUTF16("John")); | 114 values.push_back(ASCIIToUTF16("John")); |
| 100 | 115 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 119 | 134 |
| 120 WebFrame* frame = GetMainFrame(); | 135 WebFrame* frame = GetMainFrame(); |
| 121 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 136 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 122 | 137 |
| 123 WebElement web_element = frame->document().getElementById("element"); | 138 WebElement web_element = frame->document().getElementById("element"); |
| 124 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 139 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 125 FormField result1; | 140 FormField result1; |
| 126 FormManager::WebFormControlElementToFormField(element, | 141 FormManager::WebFormControlElementToFormField(element, |
| 127 FormManager::EXTRACT_NONE, | 142 FormManager::EXTRACT_NONE, |
| 128 &result1); | 143 &result1); |
| 129 EXPECT_TRUE(result1.StrictlyEqualsHack( | 144 |
| 130 FormField(string16(), | 145 FormField expected; |
| 131 ASCIIToUTF16("element"), | 146 expected.form_control_type = ASCIIToUTF16("text"); |
| 132 string16(), | 147 expected.max_length = WebInputElement::defaultMaxLength(); |
| 133 ASCIIToUTF16("text"), | 148 |
| 134 WebInputElement::defaultMaxLength(), | 149 expected.name = ASCIIToUTF16("element"); |
| 135 false))); | 150 expected.value = string16(); |
| 151 SCOPED_TRACE(""); | |
|
dhollowa
2011/08/08 21:40:39
This is a touch magical. It is also repeated ever
Ilya Sherman
2011/08/09 00:13:43
Done.
| |
| 152 ExpectFieldEquals(expected, result1); | |
| 153 | |
| 136 FormField result2; | 154 FormField result2; |
| 137 FormManager::WebFormControlElementToFormField(element, | 155 FormManager::WebFormControlElementToFormField(element, |
| 138 FormManager::EXTRACT_VALUE, | 156 FormManager::EXTRACT_VALUE, |
| 139 &result2); | 157 &result2); |
| 140 EXPECT_TRUE(result2.StrictlyEqualsHack( | 158 |
| 141 FormField(string16(), | 159 expected.name = ASCIIToUTF16("element"); |
| 142 ASCIIToUTF16("element"), | 160 expected.value = ASCIIToUTF16("value"); |
| 143 ASCIIToUTF16("value"), | 161 SCOPED_TRACE(""); |
| 144 ASCIIToUTF16("text"), | 162 ExpectFieldEquals(expected, result2); |
| 145 WebInputElement::defaultMaxLength(), | |
| 146 false))); | |
| 147 } | 163 } |
| 148 | 164 |
| 149 // We should be able to extract a text field with autocomplete="off". | 165 // We should be able to extract a text field with autocomplete="off". |
| 150 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { | 166 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { |
| 151 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 167 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 152 " autocomplete=\"off\"/>"); | 168 " autocomplete=\"off\"/>"); |
| 153 | 169 |
| 154 WebFrame* frame = GetMainFrame(); | 170 WebFrame* frame = GetMainFrame(); |
| 155 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 171 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 156 | 172 |
| 157 WebElement web_element = frame->document().getElementById("element"); | 173 WebElement web_element = frame->document().getElementById("element"); |
| 158 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 174 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 159 FormField result; | 175 FormField result; |
| 160 FormManager::WebFormControlElementToFormField(element, | 176 FormManager::WebFormControlElementToFormField(element, |
| 161 FormManager::EXTRACT_VALUE, | 177 FormManager::EXTRACT_VALUE, |
| 162 &result); | 178 &result); |
| 163 EXPECT_TRUE(result.StrictlyEqualsHack( | 179 |
| 164 FormField(string16(), | 180 FormField expected; |
| 165 ASCIIToUTF16("element"), | 181 expected.name = ASCIIToUTF16("element"); |
| 166 ASCIIToUTF16("value"), | 182 expected.value = ASCIIToUTF16("value"); |
| 167 ASCIIToUTF16("text"), | 183 expected.form_control_type = ASCIIToUTF16("text"); |
| 168 WebInputElement::defaultMaxLength(), | 184 expected.max_length = WebInputElement::defaultMaxLength(); |
| 169 false))); | 185 SCOPED_TRACE(""); |
| 186 ExpectFieldEquals(expected, result); | |
| 170 } | 187 } |
| 171 | 188 |
| 172 // We should be able to extract a text field with maxlength specified. | 189 // We should be able to extract a text field with maxlength specified. |
| 173 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { | 190 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { |
| 174 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 191 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 175 " maxlength=\"5\"/>"); | 192 " maxlength=\"5\"/>"); |
| 176 | 193 |
| 177 WebFrame* frame = GetMainFrame(); | 194 WebFrame* frame = GetMainFrame(); |
| 178 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 195 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 179 | 196 |
| 180 WebElement web_element = frame->document().getElementById("element"); | 197 WebElement web_element = frame->document().getElementById("element"); |
| 181 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 198 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 182 FormField result; | 199 FormField result; |
| 183 FormManager::WebFormControlElementToFormField(element, | 200 FormManager::WebFormControlElementToFormField(element, |
| 184 FormManager::EXTRACT_VALUE, | 201 FormManager::EXTRACT_VALUE, |
| 185 &result); | 202 &result); |
| 186 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 203 |
| 187 ASCIIToUTF16("element"), | 204 FormField expected; |
| 188 ASCIIToUTF16("value"), | 205 expected.name = ASCIIToUTF16("element"); |
| 189 ASCIIToUTF16("text"), | 206 expected.value = ASCIIToUTF16("value"); |
| 190 5, | 207 expected.form_control_type = ASCIIToUTF16("text"); |
| 191 false))); | 208 expected.max_length = 5; |
| 209 SCOPED_TRACE(""); | |
| 210 ExpectFieldEquals(expected, result); | |
| 192 } | 211 } |
| 193 | 212 |
| 194 // We should be able to extract a text field that has been autofilled. | 213 // We should be able to extract a text field that has been autofilled. |
| 195 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutofilled) { | 214 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutofilled) { |
| 196 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 215 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
| 197 | 216 |
| 198 WebFrame* frame = GetMainFrame(); | 217 WebFrame* frame = GetMainFrame(); |
| 199 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 218 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 200 | 219 |
| 201 WebElement web_element = frame->document().getElementById("element"); | 220 WebElement web_element = frame->document().getElementById("element"); |
| 202 WebInputElement element = web_element.to<WebInputElement>(); | 221 WebInputElement element = web_element.to<WebInputElement>(); |
| 203 element.setAutofilled(true); | 222 element.setAutofilled(true); |
| 204 FormField result; | 223 FormField result; |
| 205 FormManager::WebFormControlElementToFormField(element, | 224 FormManager::WebFormControlElementToFormField(element, |
| 206 FormManager::EXTRACT_VALUE, | 225 FormManager::EXTRACT_VALUE, |
| 207 &result); | 226 &result); |
| 208 EXPECT_TRUE(result.StrictlyEqualsHack( | 227 |
| 209 FormField(string16(), | 228 FormField expected; |
| 210 ASCIIToUTF16("element"), | 229 expected.name = ASCIIToUTF16("element"); |
| 211 ASCIIToUTF16("value"), | 230 expected.value = ASCIIToUTF16("value"); |
| 212 ASCIIToUTF16("text"), | 231 expected.form_control_type = ASCIIToUTF16("text"); |
| 213 WebInputElement::defaultMaxLength(), | 232 expected.max_length = WebInputElement::defaultMaxLength(); |
| 214 true))); | 233 expected.is_autofilled = true; |
| 234 SCOPED_TRACE(""); | |
| 235 ExpectFieldEquals(expected, result); | |
| 215 } | 236 } |
| 216 | 237 |
| 217 // We should be able to extract a <select> field. | 238 // We should be able to extract a <select> field. |
| 218 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { | 239 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { |
| 219 LoadHTML("<SELECT id=\"element\"/>" | 240 LoadHTML("<SELECT id=\"element\"/>" |
| 220 " <OPTION value=\"CA\">California</OPTION>" | 241 " <OPTION value=\"CA\">California</OPTION>" |
| 221 " <OPTION value=\"TX\">Texas</OPTION>" | 242 " <OPTION value=\"TX\">Texas</OPTION>" |
| 222 "</SELECT>"); | 243 "</SELECT>"); |
| 223 | 244 |
| 224 WebFrame* frame = GetMainFrame(); | 245 WebFrame* frame = GetMainFrame(); |
| 225 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 246 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 226 | 247 |
| 227 WebElement web_element = frame->document().getElementById("element"); | 248 WebElement web_element = frame->document().getElementById("element"); |
| 228 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 249 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 229 FormField result1; | 250 FormField result1; |
| 230 FormManager::WebFormControlElementToFormField(element, | 251 FormManager::WebFormControlElementToFormField(element, |
| 231 FormManager::EXTRACT_VALUE, | 252 FormManager::EXTRACT_VALUE, |
| 232 &result1); | 253 &result1); |
| 233 EXPECT_TRUE(result1.StrictlyEqualsHack(FormField(string16(), | 254 |
| 234 ASCIIToUTF16("element"), | 255 FormField expected; |
| 235 ASCIIToUTF16("CA"), | 256 expected.name = ASCIIToUTF16("element"); |
| 236 ASCIIToUTF16("select-one"), | 257 expected.max_length = 0; |
| 237 0, | 258 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 238 false))); | 259 |
| 260 expected.value = ASCIIToUTF16("CA"); | |
| 261 SCOPED_TRACE(""); | |
| 262 ExpectFieldEquals(expected, result1); | |
| 263 | |
| 239 FormField result2; | 264 FormField result2; |
| 240 FormManager::WebFormControlElementToFormField( | 265 FormManager::WebFormControlElementToFormField( |
| 241 element, | 266 element, |
| 242 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | | 267 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | |
| 243 FormManager::EXTRACT_OPTION_TEXT), | 268 FormManager::EXTRACT_OPTION_TEXT), |
| 244 &result2); | 269 &result2); |
| 245 EXPECT_TRUE(result2.StrictlyEqualsHack(FormField(string16(), | 270 expected.value = ASCIIToUTF16("California"); |
| 246 ASCIIToUTF16("element"), | 271 SCOPED_TRACE(""); |
| 247 ASCIIToUTF16("California"), | 272 ExpectFieldEquals(expected, result2); |
| 248 ASCIIToUTF16("select-one"), | 273 |
| 249 0, | |
| 250 false))); | |
| 251 FormField result3; | 274 FormField result3; |
| 252 FormManager::WebFormControlElementToFormField(element, | 275 FormManager::WebFormControlElementToFormField(element, |
| 253 FormManager::EXTRACT_OPTIONS, | 276 FormManager::EXTRACT_OPTIONS, |
| 254 &result3); | 277 &result3); |
| 255 EXPECT_TRUE(result3.StrictlyEqualsHack(FormField(string16(), | 278 expected.value = string16(); |
| 256 ASCIIToUTF16("element"), | 279 SCOPED_TRACE(""); |
| 257 string16(), | 280 ExpectFieldEquals(expected, result3); |
| 258 ASCIIToUTF16("select-one"), | 281 |
| 259 0, | |
| 260 false))); | |
| 261 ASSERT_EQ(2U, result3.option_values.size()); | 282 ASSERT_EQ(2U, result3.option_values.size()); |
| 262 ASSERT_EQ(2U, result3.option_contents.size()); | 283 ASSERT_EQ(2U, result3.option_contents.size()); |
| 263 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); | 284 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); |
| 264 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 285 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
| 265 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 286 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
| 266 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 287 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
| 267 } | 288 } |
| 268 | 289 |
| 269 // We should be not extract the value for non-text and non-select fields. | 290 // We should not extract the value for non-text and non-select fields. |
| 270 TEST_F(FormManagerTest, WebFormControlElementToFormFieldInvalidType) { | 291 TEST_F(FormManagerTest, WebFormControlElementToFormFieldInvalidType) { |
| 271 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 292 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 272 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" | 293 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" |
| 273 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 294 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" |
| 274 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" | 295 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" |
| 275 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" | 296 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" |
| 276 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" | 297 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" |
| 277 "</FORM>"); | 298 "</FORM>"); |
| 278 | 299 |
| 279 WebFrame* frame = GetMainFrame(); | 300 WebFrame* frame = GetMainFrame(); |
| 280 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 301 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 281 | 302 |
| 282 WebElement web_element = frame->document().getElementById("hidden"); | 303 WebElement web_element = frame->document().getElementById("hidden"); |
| 283 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 304 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 284 FormField result; | 305 FormField result; |
| 285 FormManager::WebFormControlElementToFormField(element, | 306 FormManager::WebFormControlElementToFormField(element, |
| 286 FormManager::EXTRACT_VALUE, | 307 FormManager::EXTRACT_VALUE, |
| 287 &result); | 308 &result); |
| 288 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 309 |
| 289 ASCIIToUTF16("hidden"), | 310 FormField expected; |
| 290 string16(), | 311 expected.max_length = 0; |
| 291 ASCIIToUTF16("hidden"), | 312 |
| 292 0, | 313 expected.name = ASCIIToUTF16("hidden"); |
| 293 false))); | 314 expected.form_control_type = ASCIIToUTF16("hidden"); |
| 315 SCOPED_TRACE(""); | |
| 316 ExpectFieldEquals(expected, result); | |
| 294 | 317 |
| 295 web_element = frame->document().getElementById("password"); | 318 web_element = frame->document().getElementById("password"); |
| 296 element = web_element.to<WebFormControlElement>(); | 319 element = web_element.to<WebFormControlElement>(); |
| 297 FormManager::WebFormControlElementToFormField(element, | 320 FormManager::WebFormControlElementToFormField(element, |
| 298 FormManager::EXTRACT_VALUE, | 321 FormManager::EXTRACT_VALUE, |
| 299 &result); | 322 &result); |
| 300 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 323 expected.name = ASCIIToUTF16("password"); |
| 301 ASCIIToUTF16("password"), | 324 expected.form_control_type = ASCIIToUTF16("password"); |
| 302 string16(), | 325 SCOPED_TRACE(""); |
| 303 ASCIIToUTF16("password"), | 326 ExpectFieldEquals(expected, result); |
| 304 0, | |
| 305 false))); | |
| 306 | 327 |
| 307 web_element = frame->document().getElementById("checkbox"); | 328 web_element = frame->document().getElementById("checkbox"); |
| 308 element = web_element.to<WebFormControlElement>(); | 329 element = web_element.to<WebFormControlElement>(); |
| 309 FormManager::WebFormControlElementToFormField(element, | 330 FormManager::WebFormControlElementToFormField(element, |
| 310 FormManager::EXTRACT_VALUE, | 331 FormManager::EXTRACT_VALUE, |
| 311 &result); | 332 &result); |
| 312 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 333 expected.name = ASCIIToUTF16("checkbox"); |
| 313 ASCIIToUTF16("checkbox"), | 334 expected.form_control_type = ASCIIToUTF16("checkbox"); |
| 314 string16(), | 335 SCOPED_TRACE(""); |
| 315 ASCIIToUTF16("checkbox"), | 336 ExpectFieldEquals(expected, result); |
| 316 0, | |
| 317 false))); | |
| 318 | 337 |
| 319 web_element = frame->document().getElementById("radio"); | 338 web_element = frame->document().getElementById("radio"); |
| 320 element = web_element.to<WebFormControlElement>(); | 339 element = web_element.to<WebFormControlElement>(); |
| 321 FormManager::WebFormControlElementToFormField(element, | 340 FormManager::WebFormControlElementToFormField(element, |
| 322 FormManager::EXTRACT_VALUE, | 341 FormManager::EXTRACT_VALUE, |
| 323 &result); | 342 &result); |
| 324 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 343 expected.name = ASCIIToUTF16("radio"); |
| 325 ASCIIToUTF16("radio"), | 344 expected.form_control_type = ASCIIToUTF16("radio"); |
| 326 string16(), | 345 SCOPED_TRACE(""); |
| 327 ASCIIToUTF16("radio"), | 346 ExpectFieldEquals(expected, result); |
| 328 0, | 347 |
| 329 false))); | |
| 330 | 348 |
| 331 web_element = frame->document().getElementById("submit"); | 349 web_element = frame->document().getElementById("submit"); |
| 332 element = web_element.to<WebFormControlElement>(); | 350 element = web_element.to<WebFormControlElement>(); |
| 333 FormManager::WebFormControlElementToFormField(element, | 351 FormManager::WebFormControlElementToFormField(element, |
| 334 FormManager::EXTRACT_VALUE, | 352 FormManager::EXTRACT_VALUE, |
| 335 &result); | 353 &result); |
| 336 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 354 expected.name = ASCIIToUTF16("submit"); |
| 337 ASCIIToUTF16("submit"), | 355 expected.form_control_type = ASCIIToUTF16("submit"); |
| 338 string16(), | 356 SCOPED_TRACE(""); |
| 339 ASCIIToUTF16("submit"), | 357 ExpectFieldEquals(expected, result); |
| 340 0, | |
| 341 false))); | |
| 342 } | 358 } |
| 343 | 359 |
| 344 TEST_F(FormManagerTest, WebFormElementToFormData) { | 360 TEST_F(FormManagerTest, WebFormElementToFormData) { |
| 345 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 361 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 346 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 362 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 347 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 363 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 348 " <SELECT id=\"state\"/>" | 364 " <SELECT id=\"state\"/>" |
| 349 " <OPTION value=\"CA\">California</OPTION>" | 365 " <OPTION value=\"CA\">California</OPTION>" |
| 350 " <OPTION value=\"TX\">Texas</OPTION>" | 366 " <OPTION value=\"TX\">Texas</OPTION>" |
| 351 " </SELECT>" | 367 " </SELECT>" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 366 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 382 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 367 FormManager::REQUIRE_NONE, | 383 FormManager::REQUIRE_NONE, |
| 368 FormManager::EXTRACT_VALUE, | 384 FormManager::EXTRACT_VALUE, |
| 369 &form)); | 385 &form)); |
| 370 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 386 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 371 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 387 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 372 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 388 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 373 | 389 |
| 374 const std::vector<FormField>& fields = form.fields; | 390 const std::vector<FormField>& fields = form.fields; |
| 375 ASSERT_EQ(3U, fields.size()); | 391 ASSERT_EQ(3U, fields.size()); |
| 376 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 392 |
| 377 FormField(string16(), | 393 FormField expected; |
| 378 ASCIIToUTF16("firstname"), | 394 expected.name = ASCIIToUTF16("firstname"); |
| 379 ASCIIToUTF16("John"), | 395 expected.value = ASCIIToUTF16("John"); |
| 380 ASCIIToUTF16("text"), | 396 expected.form_control_type = ASCIIToUTF16("text"); |
| 381 WebInputElement::defaultMaxLength(), | 397 expected.max_length = WebInputElement::defaultMaxLength(); |
| 382 false))); | 398 SCOPED_TRACE(""); |
| 383 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 399 ExpectFieldEquals(expected, fields[0]); |
| 384 FormField(string16(), | 400 |
| 385 ASCIIToUTF16("lastname"), | 401 expected.name = ASCIIToUTF16("lastname"); |
| 386 ASCIIToUTF16("Smith"), | 402 expected.value = ASCIIToUTF16("Smith"); |
| 387 ASCIIToUTF16("text"), | 403 expected.form_control_type = ASCIIToUTF16("text"); |
| 388 WebInputElement::defaultMaxLength(), | 404 expected.max_length = WebInputElement::defaultMaxLength(); |
| 389 false))); | 405 SCOPED_TRACE(""); |
| 390 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 406 ExpectFieldEquals(expected, fields[1]); |
| 391 FormField(string16(), | 407 |
| 392 ASCIIToUTF16("state"), | 408 expected.name = ASCIIToUTF16("state"); |
| 393 ASCIIToUTF16("CA"), | 409 expected.value = ASCIIToUTF16("CA"); |
| 394 ASCIIToUTF16("select-one"), | 410 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 395 0, | 411 expected.max_length = 0; |
| 396 false))); | 412 SCOPED_TRACE(""); |
| 413 ExpectFieldEquals(expected, fields[2]); | |
| 397 } | 414 } |
| 398 | 415 |
| 399 TEST_F(FormManagerTest, ExtractForms) { | 416 TEST_F(FormManagerTest, ExtractForms) { |
| 400 ExpectJohnSmithLabels( | 417 ExpectJohnSmithLabels( |
| 401 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 418 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 402 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 419 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 403 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 420 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 404 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 421 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
| 405 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 422 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 406 "</FORM>"); | 423 "</FORM>"); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 429 ASSERT_EQ(2U, forms.size()); | 446 ASSERT_EQ(2U, forms.size()); |
| 430 | 447 |
| 431 // First form. | 448 // First form. |
| 432 const FormData& form = forms[0]; | 449 const FormData& form = forms[0]; |
| 433 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 450 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 434 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 451 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 435 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 452 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 436 | 453 |
| 437 const std::vector<FormField>& fields = form.fields; | 454 const std::vector<FormField>& fields = form.fields; |
| 438 ASSERT_EQ(3U, fields.size()); | 455 ASSERT_EQ(3U, fields.size()); |
| 439 EXPECT_EQ(FormField(string16(), | 456 |
| 440 ASCIIToUTF16("firstname"), | 457 FormField expected; |
| 441 ASCIIToUTF16("John"), | 458 expected.form_control_type = ASCIIToUTF16("text"); |
| 442 ASCIIToUTF16("text"), | 459 expected.max_length = WebInputElement::defaultMaxLength(); |
| 443 WebInputElement::defaultMaxLength(), | 460 |
| 444 false), | 461 expected.name = ASCIIToUTF16("firstname"); |
| 445 fields[0]); | 462 expected.value = ASCIIToUTF16("John"); |
| 446 EXPECT_EQ(FormField(string16(), | 463 SCOPED_TRACE(""); |
| 447 ASCIIToUTF16("lastname"), | 464 ExpectFieldEquals(expected, fields[0]); |
| 448 ASCIIToUTF16("Smith"), | 465 |
| 449 ASCIIToUTF16("text"), | 466 expected.name = ASCIIToUTF16("lastname"); |
| 450 WebInputElement::defaultMaxLength(), | 467 expected.value = ASCIIToUTF16("Smith"); |
| 451 false), | 468 SCOPED_TRACE(""); |
| 452 fields[1]); | 469 ExpectFieldEquals(expected, fields[1]); |
| 453 EXPECT_EQ(FormField(string16(), | 470 |
| 454 ASCIIToUTF16("email"), | 471 expected.name = ASCIIToUTF16("email"); |
| 455 ASCIIToUTF16("john@example.com"), | 472 expected.value = ASCIIToUTF16("john@example.com"); |
| 456 ASCIIToUTF16("text"), | 473 SCOPED_TRACE(""); |
| 457 WebInputElement::defaultMaxLength(), | 474 ExpectFieldEquals(expected, fields[2]); |
| 458 false), | |
| 459 fields[2]); | |
| 460 | 475 |
| 461 // Second form. | 476 // Second form. |
| 462 const FormData& form2 = forms[1]; | 477 const FormData& form2 = forms[1]; |
| 463 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); | 478 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); |
| 464 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 479 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 465 EXPECT_EQ(GURL("http://zoo.com"), form2.action); | 480 EXPECT_EQ(GURL("http://zoo.com"), form2.action); |
| 466 | 481 |
| 467 const std::vector<FormField>& fields2 = form2.fields; | 482 const std::vector<FormField>& fields2 = form2.fields; |
| 468 ASSERT_EQ(3U, fields2.size()); | 483 ASSERT_EQ(3U, fields2.size()); |
| 469 EXPECT_EQ(FormField(string16(), | 484 |
| 470 ASCIIToUTF16("firstname"), | 485 expected.name = ASCIIToUTF16("firstname"); |
| 471 ASCIIToUTF16("Jack"), | 486 expected.value = ASCIIToUTF16("Jack"); |
| 472 ASCIIToUTF16("text"), | 487 SCOPED_TRACE(""); |
| 473 WebInputElement::defaultMaxLength(), | 488 ExpectFieldEquals(expected, fields2[0]); |
| 474 false), | 489 |
| 475 fields2[0]); | 490 expected.name = ASCIIToUTF16("lastname"); |
| 476 EXPECT_EQ(FormField(string16(), | 491 expected.value = ASCIIToUTF16("Adams"); |
| 477 ASCIIToUTF16("lastname"), | 492 SCOPED_TRACE(""); |
| 478 ASCIIToUTF16("Adams"), | 493 ExpectFieldEquals(expected, fields2[1]); |
| 479 ASCIIToUTF16("text"), | 494 |
| 480 WebInputElement::defaultMaxLength(), | 495 expected.name = ASCIIToUTF16("email"); |
| 481 false), | 496 expected.value = ASCIIToUTF16("jack@example.com"); |
| 482 fields2[1]); | 497 SCOPED_TRACE(""); |
| 483 EXPECT_EQ(FormField(string16(), | 498 ExpectFieldEquals(expected, fields2[2]); |
| 484 ASCIIToUTF16("email"), | |
| 485 ASCIIToUTF16("jack@example.com"), | |
| 486 ASCIIToUTF16("text"), | |
| 487 WebInputElement::defaultMaxLength(), | |
| 488 false), | |
| 489 fields[2]); | |
| 490 } | 499 } |
| 491 | 500 |
| 492 // We should not extract a form if it has too few fillable fields. | 501 // We should not extract a form if it has too few fillable fields. |
| 493 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { | 502 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { |
| 494 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 503 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 495 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 504 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 496 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 505 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 497 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 506 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 498 "</FORM>"); | 507 "</FORM>"); |
| 499 | 508 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 WebFrame* web_frame = GetMainFrame(); | 557 WebFrame* web_frame = GetMainFrame(); |
| 549 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 558 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 550 | 559 |
| 551 WebVector<WebFormElement> web_forms; | 560 WebVector<WebFormElement> web_forms; |
| 552 web_frame->document().forms(web_forms); | 561 web_frame->document().forms(web_forms); |
| 553 ASSERT_EQ(1U, web_forms.size()); | 562 ASSERT_EQ(1U, web_forms.size()); |
| 554 WebFormElement web_form = web_forms[0]; | 563 WebFormElement web_form = web_forms[0]; |
| 555 | 564 |
| 556 FormData form; | 565 FormData form; |
| 557 EXPECT_TRUE(FormManager::WebFormElementToFormData( | 566 EXPECT_TRUE(FormManager::WebFormElementToFormData( |
| 558 web_form, FormManager::REQUIRE_AUTOCOMPLETE, FormManager::EXTRACT_NONE, | 567 web_form, FormManager::REQUIRE_AUTOCOMPLETE, FormManager::EXTRACT_VALUE, |
| 559 &form)); | 568 &form)); |
| 560 | 569 |
| 561 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 570 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 562 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 571 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 563 EXPECT_EQ(GURL("http://abc.com"), form.action); | 572 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 564 | 573 |
| 565 const std::vector<FormField>& fields = form.fields; | 574 const std::vector<FormField>& fields = form.fields; |
| 566 ASSERT_EQ(3U, fields.size()); | 575 ASSERT_EQ(3U, fields.size()); |
| 567 EXPECT_EQ(FormField(string16(), | 576 |
| 568 ASCIIToUTF16("middlename"), | 577 FormField expected; |
| 569 ASCIIToUTF16("Jack"), | 578 expected.form_control_type = ASCIIToUTF16("text"); |
| 570 ASCIIToUTF16("text"), | 579 expected.max_length = WebInputElement::defaultMaxLength(); |
| 571 WebInputElement::defaultMaxLength(), | 580 |
| 572 false), | 581 expected.name = ASCIIToUTF16("middlename"); |
| 573 fields[0]); | 582 expected.value = ASCIIToUTF16("Jack"); |
| 574 EXPECT_EQ(FormField(string16(), | 583 SCOPED_TRACE(""); |
| 575 ASCIIToUTF16("lastname"), | 584 ExpectFieldEquals(expected, fields[0]); |
| 576 ASCIIToUTF16("Smith"), | 585 |
| 577 ASCIIToUTF16("text"), | 586 expected.name = ASCIIToUTF16("lastname"); |
| 578 WebInputElement::defaultMaxLength(), | 587 expected.value = ASCIIToUTF16("Smith"); |
| 579 false), | 588 SCOPED_TRACE(""); |
| 580 fields[1]); | 589 ExpectFieldEquals(expected, fields[1]); |
| 581 EXPECT_EQ(FormField(string16(), | 590 |
| 582 ASCIIToUTF16("email"), | 591 expected.name = ASCIIToUTF16("email"); |
| 583 ASCIIToUTF16("john@example.com"), | 592 expected.value = ASCIIToUTF16("john@example.com"); |
| 584 ASCIIToUTF16("text"), | 593 SCOPED_TRACE(""); |
| 585 WebInputElement::defaultMaxLength(), | 594 ExpectFieldEquals(expected, fields[2]); |
| 586 false), | |
| 587 fields[2]); | |
| 588 } | 595 } |
| 589 } | 596 } |
| 590 | 597 |
| 591 TEST_F(FormManagerTest, WebFormElementToFormDataEnabled) { | 598 TEST_F(FormManagerTest, WebFormElementToFormDataEnabled) { |
| 592 // The firstname element is not enabled due to disabled being set. | 599 // The firstname element is not enabled due to disabled being set. |
| 593 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" | 600 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" |
| 594 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" | 601 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 595 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" | 602 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" |
| 596 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 603 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 597 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" | 604 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" |
| 598 " <INPUT type=\"submit\" name=\"submit\" value=\"Send\"/>" | 605 " <INPUT type=\"submit\" name=\"submit\" value=\"Send\"/>" |
| 599 "</FORM>"); | 606 "</FORM>"); |
| 600 | 607 |
| 601 WebFrame* web_frame = GetMainFrame(); | 608 WebFrame* web_frame = GetMainFrame(); |
| 602 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 609 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 603 | 610 |
| 604 WebVector<WebFormElement> web_forms; | 611 WebVector<WebFormElement> web_forms; |
| 605 web_frame->document().forms(web_forms); | 612 web_frame->document().forms(web_forms); |
| 606 ASSERT_EQ(1U, web_forms.size()); | 613 ASSERT_EQ(1U, web_forms.size()); |
| 607 WebFormElement web_form = web_forms[0]; | 614 WebFormElement web_form = web_forms[0]; |
| 608 | 615 |
| 609 FormData form; | 616 FormData form; |
| 610 EXPECT_TRUE(FormManager::WebFormElementToFormData( | 617 EXPECT_TRUE(FormManager::WebFormElementToFormData( |
| 611 web_form, FormManager::REQUIRE_ENABLED, FormManager::EXTRACT_NONE, | 618 web_form, FormManager::REQUIRE_ENABLED, FormManager::EXTRACT_VALUE, |
| 612 &form)); | 619 &form)); |
| 613 | 620 |
| 614 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 621 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 615 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 622 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 616 EXPECT_EQ(GURL("http://xyz.com"), form.action); | 623 EXPECT_EQ(GURL("http://xyz.com"), form.action); |
| 617 | 624 |
| 618 const std::vector<FormField>& fields = form.fields; | 625 const std::vector<FormField>& fields = form.fields; |
| 619 ASSERT_EQ(3U, fields.size()); | 626 ASSERT_EQ(3U, fields.size()); |
| 620 EXPECT_EQ(FormField(string16(), | 627 |
| 621 ASCIIToUTF16("middlename"), | 628 FormField expected; |
| 622 ASCIIToUTF16("Jack"), | 629 expected.form_control_type = ASCIIToUTF16("text"); |
| 623 ASCIIToUTF16("text"), | 630 expected.max_length = WebInputElement::defaultMaxLength(); |
| 624 WebInputElement::defaultMaxLength(), | 631 |
| 625 false), | 632 expected.name = ASCIIToUTF16("middlename"); |
| 626 fields[0]); | 633 expected.value = ASCIIToUTF16("Jack"); |
| 627 EXPECT_EQ(FormField(string16(), | 634 SCOPED_TRACE(""); |
| 628 ASCIIToUTF16("lastname"), | 635 ExpectFieldEquals(expected, fields[0]); |
| 629 ASCIIToUTF16("Smith"), | 636 |
| 630 ASCIIToUTF16("text"), | 637 expected.name = ASCIIToUTF16("lastname"); |
| 631 WebInputElement::defaultMaxLength(), | 638 expected.value = ASCIIToUTF16("Smith"); |
| 632 false), | 639 SCOPED_TRACE(""); |
| 633 fields[1]); | 640 ExpectFieldEquals(expected, fields[1]); |
| 634 EXPECT_EQ(FormField(string16(), | 641 |
| 635 ASCIIToUTF16("email"), | 642 expected.name = ASCIIToUTF16("email"); |
| 636 ASCIIToUTF16("jack@example.com"), | 643 expected.value = ASCIIToUTF16("jack@example.com"); |
| 637 ASCIIToUTF16("text"), | 644 SCOPED_TRACE(""); |
| 638 WebInputElement::defaultMaxLength(), | 645 ExpectFieldEquals(expected, fields[2]); |
| 639 false), | |
| 640 fields[2]); | |
| 641 } | 646 } |
| 642 | 647 |
| 643 TEST_F(FormManagerTest, FindForm) { | 648 TEST_F(FormManagerTest, FindForm) { |
| 644 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 649 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 645 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 650 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 646 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 651 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 647 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 652 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
| 648 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 653 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 649 "</FORM>"); | 654 "</FORM>"); |
| 650 | 655 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 663 // Find the form and verify it's the correct form. | 668 // Find the form and verify it's the correct form. |
| 664 FormData form; | 669 FormData form; |
| 665 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 670 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 666 &form)); | 671 &form)); |
| 667 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 672 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 668 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 673 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 669 EXPECT_EQ(GURL("http://buh.com"), form.action); | 674 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 670 | 675 |
| 671 const std::vector<FormField>& fields = form.fields; | 676 const std::vector<FormField>& fields = form.fields; |
| 672 ASSERT_EQ(3U, fields.size()); | 677 ASSERT_EQ(3U, fields.size()); |
| 673 EXPECT_EQ(FormField(string16(), | 678 |
| 674 ASCIIToUTF16("firstname"), | 679 FormField expected; |
| 675 ASCIIToUTF16("John"), | 680 expected.form_control_type = ASCIIToUTF16("text"); |
| 676 ASCIIToUTF16("text"), | 681 expected.max_length = WebInputElement::defaultMaxLength(); |
| 677 WebInputElement::defaultMaxLength(), | 682 |
| 678 false), | 683 expected.name = ASCIIToUTF16("firstname"); |
| 679 fields[0]); | 684 expected.value = ASCIIToUTF16("John"); |
| 680 EXPECT_EQ(FormField(string16(), | 685 SCOPED_TRACE(""); |
| 681 ASCIIToUTF16("lastname"), | 686 ExpectFieldEquals(expected, fields[0]); |
| 682 ASCIIToUTF16("Smith"), | 687 |
| 683 ASCIIToUTF16("text"), | 688 expected.name = ASCIIToUTF16("lastname"); |
| 684 WebInputElement::defaultMaxLength(), | 689 expected.value = ASCIIToUTF16("Smith"); |
| 685 false), | 690 SCOPED_TRACE(""); |
| 686 fields[1]); | 691 ExpectFieldEquals(expected, fields[1]); |
| 687 EXPECT_EQ(FormField(string16(), | 692 |
| 688 ASCIIToUTF16("email"), | 693 expected.name = ASCIIToUTF16("email"); |
| 689 ASCIIToUTF16("john@example.com"), | 694 expected.value = ASCIIToUTF16("john@example.com"); |
| 690 ASCIIToUTF16("text"), | 695 SCOPED_TRACE(""); |
| 691 WebInputElement::defaultMaxLength(), | 696 ExpectFieldEquals(expected, fields[2]); |
| 692 false), | |
| 693 fields[2]); | |
| 694 } | 697 } |
| 695 | 698 |
| 696 TEST_F(FormManagerTest, FillForm) { | 699 TEST_F(FormManagerTest, FillForm) { |
| 697 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 700 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 698 " <INPUT type=\"text\" id=\"firstname\"/>" | 701 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 699 " <INPUT type=\"text\" id=\"lastname\"/>" | 702 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 700 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 703 " <INPUT type=\"hidden\" id=\"imhidden\"/>" |
| 701 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 704 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" |
| 702 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" | 705 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" |
| 703 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" | 706 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 723 // Find the form that contains the input element. | 726 // Find the form that contains the input element. |
| 724 FormData form; | 727 FormData form; |
| 725 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 728 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 726 &form)); | 729 &form)); |
| 727 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 730 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 728 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 731 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 729 EXPECT_EQ(GURL("http://buh.com"), form.action); | 732 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 730 | 733 |
| 731 const std::vector<FormField>& fields = form.fields; | 734 const std::vector<FormField>& fields = form.fields; |
| 732 ASSERT_EQ(8U, fields.size()); | 735 ASSERT_EQ(8U, fields.size()); |
| 733 EXPECT_EQ(FormField(string16(), | 736 |
| 734 ASCIIToUTF16("firstname"), | 737 FormField expected; |
| 735 string16(), | 738 expected.form_control_type = ASCIIToUTF16("text"); |
| 736 ASCIIToUTF16("text"), | 739 expected.max_length = WebInputElement::defaultMaxLength(); |
| 737 WebInputElement::defaultMaxLength(), | 740 |
| 738 false), | 741 expected.name = ASCIIToUTF16("firstname"); |
| 739 fields[0]); | 742 expected.value = string16(); |
| 740 EXPECT_EQ(FormField(string16(), | 743 SCOPED_TRACE(""); |
| 741 ASCIIToUTF16("lastname"), | 744 ExpectFieldEquals(expected, fields[0]); |
| 742 string16(), | 745 |
| 743 ASCIIToUTF16("text"), | 746 expected.name = ASCIIToUTF16("lastname"); |
| 744 WebInputElement::defaultMaxLength(), | 747 expected.value = string16(); |
| 745 false), | 748 SCOPED_TRACE(""); |
| 746 fields[1]); | 749 ExpectFieldEquals(expected, fields[1]); |
| 747 EXPECT_EQ(FormField(string16(), | 750 |
| 748 ASCIIToUTF16("notempty"), | 751 expected.name = ASCIIToUTF16("notempty"); |
| 749 ASCIIToUTF16("Hi"), | 752 expected.value = ASCIIToUTF16("Hi"); |
| 750 ASCIIToUTF16("text"), | 753 SCOPED_TRACE(""); |
| 751 WebInputElement::defaultMaxLength(), | 754 ExpectFieldEquals(expected, fields[2]); |
| 752 false), | 755 |
| 753 fields[2]); | 756 expected.name = ASCIIToUTF16("noautocomplete"); |
| 754 EXPECT_EQ(FormField(string16(), | 757 expected.value = string16(); |
| 755 ASCIIToUTF16("noautocomplete"), | 758 SCOPED_TRACE(""); |
| 756 string16(), | 759 ExpectFieldEquals(expected, fields[3]); |
| 757 ASCIIToUTF16("text"), | 760 |
| 758 WebInputElement::defaultMaxLength(), | 761 expected.name = ASCIIToUTF16("notenabled"); |
| 759 false), | 762 expected.value = string16(); |
| 760 fields[3]); | 763 SCOPED_TRACE(""); |
| 761 EXPECT_EQ(FormField(string16(), | 764 ExpectFieldEquals(expected, fields[4]); |
| 762 ASCIIToUTF16("notenabled"), | 765 |
| 763 string16(), | 766 expected.name = ASCIIToUTF16("readonly"); |
| 764 ASCIIToUTF16("text"), | 767 expected.value = string16(); |
| 765 WebInputElement::defaultMaxLength(), | 768 SCOPED_TRACE(""); |
| 766 false), | 769 ExpectFieldEquals(expected, fields[5]); |
| 767 fields[4]); | 770 |
| 768 EXPECT_EQ(FormField(string16(), | 771 expected.name = ASCIIToUTF16("invisible"); |
| 769 ASCIIToUTF16("readonly"), | 772 expected.value = string16(); |
| 770 string16(), | 773 SCOPED_TRACE(""); |
| 771 ASCIIToUTF16("text"), | 774 ExpectFieldEquals(expected, fields[6]); |
| 772 WebInputElement::defaultMaxLength(), | 775 |
| 773 false), | 776 expected.name = ASCIIToUTF16("displaynone"); |
| 774 fields[5]); | 777 expected.value = string16(); |
| 775 EXPECT_EQ(FormField(string16(), | 778 SCOPED_TRACE(""); |
| 776 ASCIIToUTF16("invisible"), | 779 ExpectFieldEquals(expected, fields[7]); |
| 777 string16(), | |
| 778 ASCIIToUTF16("text"), | |
| 779 WebInputElement::defaultMaxLength(), | |
| 780 false), | |
| 781 fields[6]); | |
| 782 EXPECT_EQ(FormField(string16(), | |
| 783 ASCIIToUTF16("displaynone"), | |
| 784 string16(), | |
| 785 ASCIIToUTF16("text"), | |
| 786 WebInputElement::defaultMaxLength(), | |
| 787 false), | |
| 788 fields[7]); | |
| 789 | 780 |
| 790 // Fill the form. | 781 // Fill the form. |
| 791 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 782 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 792 form.fields[1].value = ASCIIToUTF16("Earp"); | 783 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 793 form.fields[2].value = ASCIIToUTF16("Alpha"); | 784 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 794 form.fields[3].value = ASCIIToUTF16("Beta"); | 785 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 795 form.fields[4].value = ASCIIToUTF16("Gamma"); | 786 form.fields[4].value = ASCIIToUTF16("Gamma"); |
| 796 form.fields[5].value = ASCIIToUTF16("Delta"); | 787 form.fields[5].value = ASCIIToUTF16("Delta"); |
| 797 form.fields[6].value = ASCIIToUTF16("Epsilon"); | 788 form.fields[6].value = ASCIIToUTF16("Epsilon"); |
| 798 form.fields[7].value = ASCIIToUTF16("Zeta"); | 789 form.fields[7].value = ASCIIToUTF16("Zeta"); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 // Find the form that contains the input element. | 865 // Find the form that contains the input element. |
| 875 FormData form; | 866 FormData form; |
| 876 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 867 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 877 &form)); | 868 &form)); |
| 878 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 869 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 879 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 870 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 880 EXPECT_EQ(GURL("http://buh.com"), form.action); | 871 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 881 | 872 |
| 882 const std::vector<FormField>& fields = form.fields; | 873 const std::vector<FormField>& fields = form.fields; |
| 883 ASSERT_EQ(5U, fields.size()); | 874 ASSERT_EQ(5U, fields.size()); |
| 884 EXPECT_EQ(FormField(string16(), | 875 |
| 885 ASCIIToUTF16("firstname"), | 876 FormField expected; |
| 886 string16(), | 877 expected.form_control_type = ASCIIToUTF16("text"); |
| 887 ASCIIToUTF16("text"), | 878 expected.max_length = WebInputElement::defaultMaxLength(); |
| 888 WebInputElement::defaultMaxLength(), | 879 |
| 889 false), | 880 expected.name = ASCIIToUTF16("firstname"); |
| 890 fields[0]); | 881 expected.value = string16(); |
| 891 EXPECT_EQ(FormField(string16(), | 882 SCOPED_TRACE(""); |
| 892 ASCIIToUTF16("lastname"), | 883 ExpectFieldEquals(expected, fields[0]); |
| 893 string16(), | 884 |
| 894 ASCIIToUTF16("text"), | 885 expected.name = ASCIIToUTF16("lastname"); |
| 895 WebInputElement::defaultMaxLength(), | 886 expected.value = string16(); |
| 896 false), | 887 SCOPED_TRACE(""); |
| 897 fields[1]); | 888 ExpectFieldEquals(expected, fields[1]); |
| 898 EXPECT_EQ(FormField(string16(), | 889 |
| 899 ASCIIToUTF16("notempty"), | 890 expected.name = ASCIIToUTF16("notempty"); |
| 900 ASCIIToUTF16("Hi"), | 891 expected.value = ASCIIToUTF16("Hi"); |
| 901 ASCIIToUTF16("text"), | 892 SCOPED_TRACE(""); |
| 902 WebInputElement::defaultMaxLength(), | 893 ExpectFieldEquals(expected, fields[2]); |
| 903 false), | 894 |
| 904 fields[2]); | 895 expected.name = ASCIIToUTF16("noautocomplete"); |
| 905 EXPECT_EQ(FormField(string16(), | 896 expected.value = string16(); |
| 906 ASCIIToUTF16("noautocomplete"), | 897 SCOPED_TRACE(""); |
| 907 string16(), | 898 ExpectFieldEquals(expected, fields[3]); |
| 908 ASCIIToUTF16("text"), | 899 |
| 909 WebInputElement::defaultMaxLength(), | 900 expected.name = ASCIIToUTF16("notenabled"); |
| 910 false), | 901 expected.value = string16(); |
| 911 fields[3]); | 902 SCOPED_TRACE(""); |
| 912 EXPECT_EQ(FormField(string16(), | 903 ExpectFieldEquals(expected, fields[4]); |
| 913 ASCIIToUTF16("notenabled"), | |
| 914 string16(), | |
| 915 ASCIIToUTF16("text"), | |
| 916 WebInputElement::defaultMaxLength(), | |
| 917 false), | |
| 918 fields[4]); | |
| 919 | 904 |
| 920 // Preview the form. | 905 // Preview the form. |
| 921 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 906 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 922 form.fields[1].value = ASCIIToUTF16("Earp"); | 907 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 923 form.fields[2].value = ASCIIToUTF16("Alpha"); | 908 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 924 form.fields[3].value = ASCIIToUTF16("Beta"); | 909 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 925 form.fields[4].value = ASCIIToUTF16("Gamma"); | 910 form.fields[4].value = ASCIIToUTF16("Gamma"); |
| 926 form_manager.PreviewForm(form, input_element); | 911 form_manager.PreviewForm(form, input_element); |
| 927 | 912 |
| 928 // Verify the previewed elements. | 913 // Verify the previewed elements. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 " </TR>" | 1101 " </TR>" |
| 1117 " <TR>" | 1102 " <TR>" |
| 1118 " <TD></TD>" | 1103 " <TD></TD>" |
| 1119 " <TD>" | 1104 " <TD>" |
| 1120 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1105 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 1121 " </TD>" | 1106 " </TD>" |
| 1122 " </TR>" | 1107 " </TR>" |
| 1123 "</TABLE>" | 1108 "</TABLE>" |
| 1124 "</FORM>"); | 1109 "</FORM>"); |
| 1125 } | 1110 } |
| 1111 | |
| 1126 TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { | 1112 TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { |
| 1127 std::vector<string16> labels, names, values; | 1113 std::vector<string16> labels, names, values; |
| 1128 | 1114 |
| 1129 labels.push_back(ASCIIToUTF16("First name: Bogus")); | 1115 labels.push_back(ASCIIToUTF16("First name: Bogus")); |
| 1130 names.push_back(ASCIIToUTF16("firstname")); | 1116 names.push_back(ASCIIToUTF16("firstname")); |
| 1131 values.push_back(ASCIIToUTF16("John")); | 1117 values.push_back(ASCIIToUTF16("John")); |
| 1132 | 1118 |
| 1133 labels.push_back(ASCIIToUTF16("Last name:")); | 1119 labels.push_back(ASCIIToUTF16("Last name:")); |
| 1134 names.push_back(ASCIIToUTF16("lastname")); | 1120 names.push_back(ASCIIToUTF16("lastname")); |
| 1135 values.push_back(ASCIIToUTF16("Smith")); | 1121 values.push_back(ASCIIToUTF16("Smith")); |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 // Find the form that contains the input element. | 1825 // Find the form that contains the input element. |
| 1840 FormData form; | 1826 FormData form; |
| 1841 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1827 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1842 &form)); | 1828 &form)); |
| 1843 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1829 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1844 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1830 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1845 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1831 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1846 | 1832 |
| 1847 const std::vector<FormField>& fields = form.fields; | 1833 const std::vector<FormField>& fields = form.fields; |
| 1848 ASSERT_EQ(3U, fields.size()); | 1834 ASSERT_EQ(3U, fields.size()); |
| 1849 EXPECT_EQ(FormField(string16(), | 1835 |
| 1850 ASCIIToUTF16("firstname"), | 1836 FormField expected; |
| 1851 string16(), | 1837 expected.form_control_type = ASCIIToUTF16("text"); |
| 1852 ASCIIToUTF16("text"), | 1838 |
| 1853 5, | 1839 expected.name = ASCIIToUTF16("firstname"); |
| 1854 false), | 1840 expected.max_length = 5; |
| 1855 fields[0]); | 1841 expected.is_autofilled = false; |
| 1856 EXPECT_EQ(FormField(string16(), | 1842 SCOPED_TRACE(""); |
| 1857 ASCIIToUTF16("lastname"), | 1843 ExpectFieldEquals(expected, fields[0]); |
| 1858 string16(), | 1844 |
| 1859 ASCIIToUTF16("text"), | 1845 expected.name = ASCIIToUTF16("lastname"); |
| 1860 7, | 1846 expected.max_length = 7; |
| 1861 false), | 1847 expected.is_autofilled = false; |
| 1862 fields[1]); | 1848 SCOPED_TRACE(""); |
| 1863 EXPECT_EQ(FormField(string16(), | 1849 ExpectFieldEquals(expected, fields[1]); |
| 1864 ASCIIToUTF16("email"), | 1850 |
| 1865 string16(), | 1851 expected.name = ASCIIToUTF16("email"); |
| 1866 ASCIIToUTF16("text"), | 1852 expected.max_length = 9; |
| 1867 9, | 1853 expected.is_autofilled = false; |
| 1868 false), | 1854 SCOPED_TRACE(""); |
| 1869 fields[2]); | 1855 ExpectFieldEquals(expected, fields[2]); |
| 1870 | 1856 |
| 1871 // Fill the form. | 1857 // Fill the form. |
| 1872 form.fields[0].value = ASCIIToUTF16("Brother"); | 1858 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 1873 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 1859 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 1874 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 1860 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 1875 form_manager.FillForm(form, WebNode()); | 1861 form_manager.FillForm(form, WebNode()); |
| 1876 | 1862 |
| 1877 // Find the newly-filled form that contains the input element. | 1863 // Find the newly-filled form that contains the input element. |
| 1878 FormData form2; | 1864 FormData form2; |
| 1879 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1865 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1880 &form2)); | 1866 &form2)); |
| 1881 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1867 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1882 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1868 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1883 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1869 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1884 | 1870 |
| 1885 const std::vector<FormField>& fields2 = form2.fields; | 1871 const std::vector<FormField>& fields2 = form2.fields; |
| 1886 ASSERT_EQ(3U, fields2.size()); | 1872 ASSERT_EQ(3U, fields2.size()); |
| 1887 EXPECT_TRUE(fields2[0].StrictlyEqualsHack(FormField(string16(), | 1873 |
| 1888 ASCIIToUTF16("firstname"), | 1874 expected.form_control_type = ASCIIToUTF16("text"); |
| 1889 ASCIIToUTF16("Broth"), | 1875 |
| 1890 ASCIIToUTF16("text"), | 1876 expected.name = ASCIIToUTF16("firstname"); |
| 1891 5, | 1877 expected.value = ASCIIToUTF16("Broth"); |
| 1892 false))); | 1878 expected.max_length = 5; |
| 1893 EXPECT_TRUE(fields2[1].StrictlyEqualsHack(FormField(string16(), | 1879 expected.is_autofilled = true; |
| 1894 ASCIIToUTF16("lastname"), | 1880 SCOPED_TRACE(""); |
| 1895 ASCIIToUTF16("Jonatha"), | 1881 ExpectFieldEquals(expected, fields2[0]); |
| 1896 ASCIIToUTF16("text"), | 1882 |
| 1897 7, | 1883 expected.name = ASCIIToUTF16("lastname"); |
| 1898 false))); | 1884 expected.value = ASCIIToUTF16("Jonatha"); |
| 1899 EXPECT_TRUE(fields2[2].StrictlyEqualsHack(FormField(string16(), | 1885 expected.max_length = 7; |
| 1900 ASCIIToUTF16("email"), | 1886 expected.is_autofilled = true; |
| 1901 ASCIIToUTF16("brotherj@"), | 1887 SCOPED_TRACE(""); |
| 1902 ASCIIToUTF16("text"), | 1888 ExpectFieldEquals(expected, fields2[1]); |
| 1903 9, | 1889 |
| 1904 false))); | 1890 expected.name = ASCIIToUTF16("email"); |
| 1891 expected.value = ASCIIToUTF16("brotherj@"); | |
| 1892 expected.max_length = 9; | |
| 1893 expected.is_autofilled = true; | |
| 1894 SCOPED_TRACE(""); | |
| 1895 ExpectFieldEquals(expected, fields2[2]); | |
| 1905 } | 1896 } |
| 1906 | 1897 |
| 1907 // This test uses negative values of the maxlength attribute for input elements. | 1898 // This test uses negative values of the maxlength attribute for input elements. |
| 1908 // In this case, the maxlength of the input elements is set to the default | 1899 // In this case, the maxlength of the input elements is set to the default |
| 1909 // maxlength (defined in WebKit.) | 1900 // maxlength (defined in WebKit.) |
| 1910 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { | 1901 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { |
| 1911 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1902 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 1912 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" | 1903 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" |
| 1913 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" | 1904 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" |
| 1914 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" | 1905 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1930 // Find the form that contains the input element. | 1921 // Find the form that contains the input element. |
| 1931 FormData form; | 1922 FormData form; |
| 1932 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1923 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1933 &form)); | 1924 &form)); |
| 1934 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1925 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1935 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1926 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1936 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1927 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1937 | 1928 |
| 1938 const std::vector<FormField>& fields = form.fields; | 1929 const std::vector<FormField>& fields = form.fields; |
| 1939 ASSERT_EQ(3U, fields.size()); | 1930 ASSERT_EQ(3U, fields.size()); |
| 1940 EXPECT_EQ(FormField(string16(), | 1931 |
| 1941 ASCIIToUTF16("firstname"), | 1932 FormField expected; |
| 1942 string16(), | 1933 expected.form_control_type = ASCIIToUTF16("text"); |
| 1943 ASCIIToUTF16("text"), | 1934 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1944 WebInputElement::defaultMaxLength(), | 1935 |
| 1945 false), | 1936 expected.name = ASCIIToUTF16("firstname"); |
| 1946 fields[0]); | 1937 SCOPED_TRACE(""); |
| 1947 EXPECT_EQ(FormField(string16(), | 1938 ExpectFieldEquals(expected, fields[0]); |
| 1948 ASCIIToUTF16("lastname"), | 1939 |
| 1949 string16(), | 1940 expected.name = ASCIIToUTF16("lastname"); |
| 1950 ASCIIToUTF16("text"), | 1941 SCOPED_TRACE(""); |
| 1951 WebInputElement::defaultMaxLength(), | 1942 ExpectFieldEquals(expected, fields[1]); |
| 1952 false), | 1943 |
| 1953 fields[1]); | 1944 expected.name = ASCIIToUTF16("email"); |
| 1954 EXPECT_EQ(FormField(string16(), | 1945 SCOPED_TRACE(""); |
| 1955 ASCIIToUTF16("email"), | 1946 ExpectFieldEquals(expected, fields[2]); |
| 1956 string16(), | |
| 1957 ASCIIToUTF16("text"), | |
| 1958 WebInputElement::defaultMaxLength(), | |
| 1959 false), | |
| 1960 fields[2]); | |
| 1961 | 1947 |
| 1962 // Fill the form. | 1948 // Fill the form. |
| 1963 form.fields[0].value = ASCIIToUTF16("Brother"); | 1949 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 1964 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 1950 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 1965 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 1951 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 1966 form_manager.FillForm(form, WebNode()); | 1952 form_manager.FillForm(form, WebNode()); |
| 1967 | 1953 |
| 1968 // Find the newly-filled form that contains the input element. | 1954 // Find the newly-filled form that contains the input element. |
| 1969 FormData form2; | 1955 FormData form2; |
| 1970 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1956 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1971 &form2)); | 1957 &form2)); |
| 1972 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1958 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1973 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1959 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1974 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1960 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1975 | 1961 |
| 1976 const std::vector<FormField>& fields2 = form2.fields; | 1962 const std::vector<FormField>& fields2 = form2.fields; |
| 1977 ASSERT_EQ(3U, fields2.size()); | 1963 ASSERT_EQ(3U, fields2.size()); |
| 1978 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 1964 |
| 1979 FormField(string16(), | 1965 expected.name = ASCIIToUTF16("firstname"); |
| 1980 ASCIIToUTF16("firstname"), | 1966 expected.value = ASCIIToUTF16("Brother"); |
| 1981 ASCIIToUTF16("Brother"), | 1967 SCOPED_TRACE(""); |
| 1982 ASCIIToUTF16("text"), | 1968 ExpectFieldEquals(expected, fields[0]); |
| 1983 WebInputElement::defaultMaxLength(), | 1969 |
| 1984 false))); | 1970 expected.name = ASCIIToUTF16("lastname"); |
| 1985 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 1971 expected.value = ASCIIToUTF16("Jonathan"); |
| 1986 FormField(string16(), | 1972 SCOPED_TRACE(""); |
| 1987 ASCIIToUTF16("lastname"), | 1973 ExpectFieldEquals(expected, fields[1]); |
| 1988 ASCIIToUTF16("Jonathan"), | 1974 |
| 1989 ASCIIToUTF16("text"), | 1975 expected.name = ASCIIToUTF16("email"); |
| 1990 WebInputElement::defaultMaxLength(), | 1976 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 1991 false))); | 1977 SCOPED_TRACE(""); |
| 1992 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 1978 ExpectFieldEquals(expected, fields[2]); |
| 1993 FormField(string16(), | |
| 1994 ASCIIToUTF16("email"), | |
| 1995 ASCIIToUTF16("brotherj@example.com"), | |
| 1996 ASCIIToUTF16("text"), | |
| 1997 WebInputElement::defaultMaxLength(), | |
| 1998 false))); | |
| 1999 } | 1979 } |
| 2000 | 1980 |
| 2001 // This test sends a FormData object to FillForm with more fields than are in | 1981 // This test sends a FormData object to FillForm with more fields than are in |
| 2002 // the cached WebFormElement. In this case, we only fill out the fields that | 1982 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2003 // match between the FormData object and the WebFormElement. | 1983 // match between the FormData object and the WebFormElement. |
| 2004 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { | 1984 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { |
| 2005 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1985 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2006 " <INPUT type=\"text\" id=\"firstname\"/>" | 1986 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2007 " <INPUT type=\"text\" id=\"middlename\"/>" | 1987 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2008 " <INPUT type=\"text\" id=\"lastname\"/>" | 1988 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2020 // After the field modification, the fields in |form| will look like: | 2000 // After the field modification, the fields in |form| will look like: |
| 2021 // prefix | 2001 // prefix |
| 2022 // firstname | 2002 // firstname |
| 2023 // hidden | 2003 // hidden |
| 2024 // middlename | 2004 // middlename |
| 2025 // second | 2005 // second |
| 2026 // lastname | 2006 // lastname |
| 2027 // postfix | 2007 // postfix |
| 2028 FormData* form = &forms[0]; | 2008 FormData* form = &forms[0]; |
| 2029 | 2009 |
| 2030 FormField field1(string16(), | 2010 FormField field1; |
| 2031 ASCIIToUTF16("prefix"), | 2011 field1.name = ASCIIToUTF16("prefix"); |
| 2032 string16(), | 2012 field1.form_control_type = ASCIIToUTF16("text"); |
| 2033 ASCIIToUTF16("text"), | 2013 field1.max_length = WebInputElement::defaultMaxLength(); |
| 2034 WebInputElement::defaultMaxLength(), | |
| 2035 false); | |
| 2036 form->fields.insert(form->fields.begin(), field1); | 2014 form->fields.insert(form->fields.begin(), field1); |
| 2037 | 2015 |
| 2038 FormField field2(string16(), | 2016 FormField field2; |
| 2039 ASCIIToUTF16("hidden"), | 2017 field2.name = ASCIIToUTF16("hidden"); |
| 2040 string16(), | 2018 field2.form_control_type = ASCIIToUTF16("text"); |
| 2041 ASCIIToUTF16("text"), | 2019 field2.max_length = WebInputElement::defaultMaxLength(); |
| 2042 WebInputElement::defaultMaxLength(), | |
| 2043 false); | |
| 2044 form->fields.insert(form->fields.begin() + 2, field2); | 2020 form->fields.insert(form->fields.begin() + 2, field2); |
| 2045 | 2021 |
| 2046 FormField field3(string16(), | 2022 FormField field3; |
| 2047 ASCIIToUTF16("second"), | 2023 field3.name = ASCIIToUTF16("second"); |
| 2048 string16(), | 2024 field3.form_control_type = ASCIIToUTF16("text"); |
| 2049 ASCIIToUTF16("text"), | 2025 field3.max_length = WebInputElement::defaultMaxLength(); |
| 2050 WebInputElement::defaultMaxLength(), | |
| 2051 false); | |
| 2052 form->fields.insert(form->fields.begin() + 4, field3); | 2026 form->fields.insert(form->fields.begin() + 4, field3); |
| 2053 | 2027 |
| 2054 FormField field4(string16(), | 2028 FormField field4; |
| 2055 ASCIIToUTF16("postfix"), | 2029 field4.name = ASCIIToUTF16("postfix"); |
| 2056 string16(), | 2030 field4.form_control_type = ASCIIToUTF16("text"); |
| 2057 ASCIIToUTF16("text"), | 2031 field4.max_length = WebInputElement::defaultMaxLength(); |
| 2058 WebInputElement::defaultMaxLength(), | |
| 2059 false); | |
| 2060 form->fields.insert(form->fields.begin() + 6, field4); | 2032 form->fields.insert(form->fields.begin() + 6, field4); |
| 2061 | 2033 |
| 2062 // Fill the form. | 2034 // Fill the form. |
| 2063 form->fields[0].value = ASCIIToUTF16("Alpha"); | 2035 form->fields[0].value = ASCIIToUTF16("Alpha"); |
| 2064 form->fields[1].value = ASCIIToUTF16("Brother"); | 2036 form->fields[1].value = ASCIIToUTF16("Brother"); |
| 2065 form->fields[2].value = ASCIIToUTF16("Abracadabra"); | 2037 form->fields[2].value = ASCIIToUTF16("Abracadabra"); |
| 2066 form->fields[3].value = ASCIIToUTF16("Joseph"); | 2038 form->fields[3].value = ASCIIToUTF16("Joseph"); |
| 2067 form->fields[4].value = ASCIIToUTF16("Beta"); | 2039 form->fields[4].value = ASCIIToUTF16("Beta"); |
| 2068 form->fields[5].value = ASCIIToUTF16("Jonathan"); | 2040 form->fields[5].value = ASCIIToUTF16("Jonathan"); |
| 2069 form->fields[6].value = ASCIIToUTF16("Omega"); | 2041 form->fields[6].value = ASCIIToUTF16("Omega"); |
| 2070 form_manager.FillForm(*form, WebNode()); | 2042 form_manager.FillForm(*form, WebNode()); |
| 2071 | 2043 |
| 2072 // Get the input element we want to find. | 2044 // Get the input element we want to find. |
| 2073 WebElement element = web_frame->document().getElementById("firstname"); | 2045 WebElement element = web_frame->document().getElementById("firstname"); |
| 2074 WebInputElement input_element = element.to<WebInputElement>(); | 2046 WebInputElement input_element = element.to<WebInputElement>(); |
| 2075 | 2047 |
| 2076 // Find the newly-filled form that contains the input element. | 2048 // Find the newly-filled form that contains the input element. |
| 2077 FormData form2; | 2049 FormData form2; |
| 2078 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2050 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2079 &form2)); | 2051 &form2)); |
| 2080 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2052 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2081 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2053 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2082 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2054 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2083 | 2055 |
| 2084 const std::vector<FormField>& fields = form2.fields; | 2056 const std::vector<FormField>& fields = form2.fields; |
| 2085 ASSERT_EQ(3U, fields.size()); | 2057 ASSERT_EQ(3U, fields.size()); |
| 2086 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2058 |
| 2087 FormField(string16(), | 2059 FormField expected; |
| 2088 ASCIIToUTF16("firstname"), | 2060 expected.form_control_type = ASCIIToUTF16("text"); |
| 2089 ASCIIToUTF16("Brother"), | 2061 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2090 ASCIIToUTF16("text"), | 2062 expected.is_autofilled = true; |
| 2091 WebInputElement::defaultMaxLength(), | 2063 |
| 2092 false))); | 2064 expected.name = ASCIIToUTF16("firstname"); |
| 2093 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2065 expected.value = ASCIIToUTF16("Brother"); |
| 2094 FormField(string16(), | 2066 SCOPED_TRACE(""); |
| 2095 ASCIIToUTF16("middlename"), | 2067 ExpectFieldEquals(expected, fields[0]); |
| 2096 ASCIIToUTF16("Joseph"), | 2068 |
| 2097 ASCIIToUTF16("text"), | 2069 expected.name = ASCIIToUTF16("middlename"); |
| 2098 WebInputElement::defaultMaxLength(), | 2070 expected.value = ASCIIToUTF16("Joseph"); |
| 2099 false))); | 2071 SCOPED_TRACE(""); |
| 2100 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2072 ExpectFieldEquals(expected, fields[1]); |
| 2101 FormField(string16(), | 2073 |
| 2102 ASCIIToUTF16("lastname"), | 2074 expected.name = ASCIIToUTF16("lastname"); |
| 2103 ASCIIToUTF16("Jonathan"), | 2075 expected.value = ASCIIToUTF16("Jonathan"); |
| 2104 ASCIIToUTF16("text"), | 2076 SCOPED_TRACE(""); |
| 2105 WebInputElement::defaultMaxLength(), | 2077 ExpectFieldEquals(expected, fields[2]); |
| 2106 false))); | |
| 2107 } | 2078 } |
| 2108 | 2079 |
| 2109 // This test sends a FormData object to FillForm with fewer fields than are in | 2080 // This test sends a FormData object to FillForm with fewer fields than are in |
| 2110 // the cached WebFormElement. In this case, we only fill out the fields that | 2081 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2111 // match between the FormData object and the WebFormElement. | 2082 // match between the FormData object and the WebFormElement. |
| 2112 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { | 2083 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { |
| 2113 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2084 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2114 " <INPUT type=\"text\" id=\"prefix\"/>" | 2085 " <INPUT type=\"text\" id=\"prefix\"/>" |
| 2115 " <INPUT type=\"text\" id=\"firstname\"/>" | 2086 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2116 " <INPUT type=\"text\" id=\"hidden\"/>" | 2087 " <INPUT type=\"text\" id=\"hidden\"/>" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2152 // Find the newly-filled form that contains the input element. | 2123 // Find the newly-filled form that contains the input element. |
| 2153 FormData form2; | 2124 FormData form2; |
| 2154 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2125 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2155 &form2)); | 2126 &form2)); |
| 2156 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2127 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2157 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2128 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2158 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2129 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2159 | 2130 |
| 2160 const std::vector<FormField>& fields = form2.fields; | 2131 const std::vector<FormField>& fields = form2.fields; |
| 2161 ASSERT_EQ(7U, fields.size()); | 2132 ASSERT_EQ(7U, fields.size()); |
| 2162 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2133 |
| 2163 FormField(string16(), | 2134 FormField expected; |
| 2164 ASCIIToUTF16("prefix"), | 2135 expected.form_control_type = ASCIIToUTF16("text"); |
| 2165 string16(), | 2136 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2166 ASCIIToUTF16("text"), | 2137 |
| 2167 WebInputElement::defaultMaxLength(), | 2138 expected.name = ASCIIToUTF16("prefix"); |
| 2168 false))); | 2139 expected.value = string16(); |
| 2169 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2140 expected.is_autofilled = false; |
| 2170 FormField(string16(), | 2141 SCOPED_TRACE(""); |
| 2171 ASCIIToUTF16("firstname"), | 2142 ExpectFieldEquals(expected, fields[0]); |
| 2172 ASCIIToUTF16("Brother"), | 2143 |
| 2173 ASCIIToUTF16("text"), | 2144 expected.name = ASCIIToUTF16("firstname"); |
| 2174 WebInputElement::defaultMaxLength(), | 2145 expected.value = ASCIIToUTF16("Brother"); |
| 2175 false))); | 2146 expected.is_autofilled = true; |
| 2176 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2147 SCOPED_TRACE(""); |
| 2177 FormField(string16(), | 2148 ExpectFieldEquals(expected, fields[1]); |
| 2178 ASCIIToUTF16("hidden"), | 2149 |
| 2179 string16(), | 2150 expected.name = ASCIIToUTF16("hidden"); |
| 2180 ASCIIToUTF16("text"), | 2151 expected.value = string16(); |
| 2181 WebInputElement::defaultMaxLength(), | 2152 expected.is_autofilled = false; |
| 2182 false))); | 2153 SCOPED_TRACE(""); |
| 2183 EXPECT_TRUE(fields[3].StrictlyEqualsHack( | 2154 ExpectFieldEquals(expected, fields[2]); |
| 2184 FormField(string16(), | 2155 |
| 2185 ASCIIToUTF16("middlename"), | 2156 expected.name = ASCIIToUTF16("middlename"); |
| 2186 ASCIIToUTF16("Joseph"), | 2157 expected.value = ASCIIToUTF16("Joseph"); |
| 2187 ASCIIToUTF16("text"), | 2158 expected.is_autofilled = true; |
| 2188 WebInputElement::defaultMaxLength(), | 2159 SCOPED_TRACE(""); |
| 2189 false))); | 2160 ExpectFieldEquals(expected, fields[3]); |
| 2190 EXPECT_TRUE(fields[4].StrictlyEqualsHack( | 2161 |
| 2191 FormField(string16(), | 2162 expected.name = ASCIIToUTF16("second"); |
| 2192 ASCIIToUTF16("second"), | 2163 expected.value = string16(); |
| 2193 string16(), | 2164 expected.is_autofilled = false; |
| 2194 ASCIIToUTF16("text"), | 2165 SCOPED_TRACE(""); |
| 2195 WebInputElement::defaultMaxLength(), | 2166 ExpectFieldEquals(expected, fields[4]); |
| 2196 false))); | 2167 |
| 2197 EXPECT_TRUE(fields[5].StrictlyEqualsHack( | 2168 expected.name = ASCIIToUTF16("lastname"); |
| 2198 FormField(string16(), | 2169 expected.value = ASCIIToUTF16("Jonathan"); |
| 2199 ASCIIToUTF16("lastname"), | 2170 expected.is_autofilled = true; |
| 2200 ASCIIToUTF16("Jonathan"), | 2171 SCOPED_TRACE(""); |
| 2201 ASCIIToUTF16("text"), | 2172 ExpectFieldEquals(expected, fields[5]); |
| 2202 WebInputElement::defaultMaxLength(), | 2173 |
| 2203 false))); | 2174 expected.name = ASCIIToUTF16("postfix"); |
| 2204 EXPECT_TRUE(fields[6].StrictlyEqualsHack( | 2175 expected.value = string16(); |
| 2205 FormField(string16(), | 2176 expected.is_autofilled = false; |
| 2206 ASCIIToUTF16("postfix"), | 2177 SCOPED_TRACE(""); |
| 2207 string16(), | 2178 ExpectFieldEquals(expected, fields[6]); |
| 2208 ASCIIToUTF16("text"), | |
| 2209 WebInputElement::defaultMaxLength(), | |
| 2210 false))); | |
| 2211 } | 2179 } |
| 2212 | 2180 |
| 2213 // This test sends a FormData object to FillForm with a field changed from | 2181 // This test sends a FormData object to FillForm with a field changed from |
| 2214 // those in the cached WebFormElement. In this case, we only fill out the | 2182 // those in the cached WebFormElement. In this case, we only fill out the |
| 2215 // fields that match between the FormData object and the WebFormElement. | 2183 // fields that match between the FormData object and the WebFormElement. |
| 2216 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { | 2184 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { |
| 2217 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2185 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2218 " <INPUT type=\"text\" id=\"firstname\"/>" | 2186 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2219 " <INPUT type=\"text\" id=\"middlename\"/>" | 2187 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2220 " <INPUT type=\"text\" id=\"lastname\"/>" | 2188 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2253 // Find the newly-filled form that contains the input element. | 2221 // Find the newly-filled form that contains the input element. |
| 2254 FormData form2; | 2222 FormData form2; |
| 2255 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2223 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2256 &form2)); | 2224 &form2)); |
| 2257 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2225 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2258 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2226 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2259 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2227 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2260 | 2228 |
| 2261 const std::vector<FormField>& fields = form2.fields; | 2229 const std::vector<FormField>& fields = form2.fields; |
| 2262 ASSERT_EQ(3U, fields.size()); | 2230 ASSERT_EQ(3U, fields.size()); |
| 2263 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 2231 |
| 2264 ASCIIToUTF16("firstname"), | 2232 FormField expected; |
| 2265 ASCIIToUTF16("Brother"), | 2233 expected.form_control_type = ASCIIToUTF16("text"); |
| 2266 ASCIIToUTF16("text"), | 2234 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2267 WebInputElement::defaultMaxLength(), | 2235 |
| 2268 false))); | 2236 expected.name = ASCIIToUTF16("firstname"); |
| 2269 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 2237 expected.value = ASCIIToUTF16("Brother"); |
| 2270 ASCIIToUTF16("middlename"), | 2238 expected.is_autofilled = true; |
| 2271 string16(), | 2239 SCOPED_TRACE(""); |
| 2272 ASCIIToUTF16("text"), | 2240 ExpectFieldEquals(expected, fields[0]); |
| 2273 WebInputElement::defaultMaxLength(), | 2241 |
| 2274 false))); | 2242 expected.name = ASCIIToUTF16("middlename"); |
| 2275 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 2243 expected.value = ASCIIToUTF16(""); |
| 2276 ASCIIToUTF16("lastname"), | 2244 expected.is_autofilled = false; |
| 2277 ASCIIToUTF16("Jonathan"), | 2245 SCOPED_TRACE(""); |
| 2278 ASCIIToUTF16("text"), | 2246 ExpectFieldEquals(expected, fields[1]); |
| 2279 WebInputElement::defaultMaxLength(), | 2247 |
| 2280 false))); | 2248 expected.name = ASCIIToUTF16("lastname"); |
| 2249 expected.value = ASCIIToUTF16("Jonathan"); | |
| 2250 expected.is_autofilled = true; | |
| 2251 SCOPED_TRACE(""); | |
| 2252 ExpectFieldEquals(expected, fields[2]); | |
| 2281 } | 2253 } |
| 2282 | 2254 |
| 2283 // This test sends a FormData object to FillForm with fewer fields than are in | 2255 // This test sends a FormData object to FillForm with fewer fields than are in |
| 2284 // the cached WebFormElement. In this case, we only fill out the fields that | 2256 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2285 // match between the FormData object and the WebFormElement. | 2257 // match between the FormData object and the WebFormElement. |
| 2286 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { | 2258 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { |
| 2287 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2259 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2288 " <INPUT type=\"text\" id=\"firstname\"/>" | 2260 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2289 " <INPUT type=\"text\" id=\"middlename\"/>" | 2261 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2290 " <INPUT type=\"text\" id=\"lastname\"/>" | 2262 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2320 // Find the newly-filled form that contains the input element. | 2292 // Find the newly-filled form that contains the input element. |
| 2321 FormData form2; | 2293 FormData form2; |
| 2322 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2294 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2323 &form2)); | 2295 &form2)); |
| 2324 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2296 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2325 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2297 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2326 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2298 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2327 | 2299 |
| 2328 const std::vector<FormField>& fields = form2.fields; | 2300 const std::vector<FormField>& fields = form2.fields; |
| 2329 ASSERT_EQ(4U, fields.size()); | 2301 ASSERT_EQ(4U, fields.size()); |
| 2330 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2302 |
| 2331 FormField(string16(), | 2303 FormField expected; |
| 2332 ASCIIToUTF16("firstname"), | 2304 expected.form_control_type = ASCIIToUTF16("text"); |
| 2333 ASCIIToUTF16("Brother"), | 2305 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2334 ASCIIToUTF16("text"), | 2306 |
| 2335 WebInputElement::defaultMaxLength(), | 2307 expected.name = ASCIIToUTF16("firstname"); |
| 2336 false))); | 2308 expected.value = ASCIIToUTF16("Brother"); |
| 2337 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2309 expected.is_autofilled = true; |
| 2338 FormField(string16(), | 2310 SCOPED_TRACE(""); |
| 2339 ASCIIToUTF16("middlename"), | 2311 ExpectFieldEquals(expected, fields[0]); |
| 2340 ASCIIToUTF16("Joseph"), | 2312 |
| 2341 ASCIIToUTF16("text"), | 2313 expected.name = ASCIIToUTF16("middlename"); |
| 2342 WebInputElement::defaultMaxLength(), | 2314 expected.value = ASCIIToUTF16("Joseph"); |
| 2343 false))); | 2315 expected.is_autofilled = true; |
| 2344 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2316 SCOPED_TRACE(""); |
| 2345 FormField(string16(), | 2317 ExpectFieldEquals(expected, fields[1]); |
| 2346 ASCIIToUTF16("lastname"), | 2318 |
| 2347 ASCIIToUTF16("Jonathan"), | 2319 expected.name = ASCIIToUTF16("lastname"); |
| 2348 ASCIIToUTF16("text"), | 2320 expected.value = ASCIIToUTF16("Jonathan"); |
| 2349 WebInputElement::defaultMaxLength(), | 2321 expected.is_autofilled = true; |
| 2350 false))); | 2322 SCOPED_TRACE(""); |
| 2351 EXPECT_TRUE(fields[3].StrictlyEqualsHack( | 2323 ExpectFieldEquals(expected, fields[2]); |
| 2352 FormField(string16(), | 2324 |
| 2353 ASCIIToUTF16("postfix"), | 2325 expected.name = ASCIIToUTF16("postfix"); |
| 2354 string16(), | 2326 expected.value = string16(); |
| 2355 ASCIIToUTF16("text"), | 2327 expected.is_autofilled = false; |
| 2356 WebInputElement::defaultMaxLength(), | 2328 SCOPED_TRACE(""); |
| 2357 false))); | 2329 ExpectFieldEquals(expected, fields[3]); |
| 2358 } | 2330 } |
| 2359 | 2331 |
| 2360 TEST_F(FormManagerTest, FillFormEmptyName) { | 2332 TEST_F(FormManagerTest, FillFormEmptyName) { |
| 2361 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2333 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2362 " <INPUT type=\"text\" id=\"firstname\"/>" | 2334 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2363 " <INPUT type=\"text\" id=\"lastname\"/>" | 2335 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2364 " <INPUT type=\"text\" id=\"email\"/>" | 2336 " <INPUT type=\"text\" id=\"email\"/>" |
| 2365 " <INPUT type=\"submit\" value=\"Send\"/>" | 2337 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2366 "</FORM>"); | 2338 "</FORM>"); |
| 2367 | 2339 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2380 // Find the form that contains the input element. | 2352 // Find the form that contains the input element. |
| 2381 FormData form; | 2353 FormData form; |
| 2382 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2354 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2383 &form)); | 2355 &form)); |
| 2384 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2356 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2385 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2357 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2386 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2358 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2387 | 2359 |
| 2388 const std::vector<FormField>& fields = form.fields; | 2360 const std::vector<FormField>& fields = form.fields; |
| 2389 ASSERT_EQ(3U, fields.size()); | 2361 ASSERT_EQ(3U, fields.size()); |
| 2390 EXPECT_EQ(FormField(string16(), | 2362 |
| 2391 ASCIIToUTF16("firstname"), | 2363 FormField expected; |
| 2392 string16(), | 2364 expected.form_control_type = ASCIIToUTF16("text"); |
| 2393 ASCIIToUTF16("text"), | 2365 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2394 WebInputElement::defaultMaxLength(), | 2366 |
| 2395 false), | 2367 expected.name = ASCIIToUTF16("firstname"); |
| 2396 fields[0]); | 2368 SCOPED_TRACE(""); |
| 2397 EXPECT_EQ(FormField(string16(), | 2369 ExpectFieldEquals(expected, fields[0]); |
| 2398 ASCIIToUTF16("lastname"), | 2370 |
| 2399 string16(), | 2371 expected.name = ASCIIToUTF16("lastname"); |
| 2400 ASCIIToUTF16("text"), | 2372 SCOPED_TRACE(""); |
| 2401 WebInputElement::defaultMaxLength(), | 2373 ExpectFieldEquals(expected, fields[1]); |
| 2402 false), | 2374 |
| 2403 fields[1]); | 2375 expected.name = ASCIIToUTF16("email"); |
| 2404 EXPECT_EQ(FormField(string16(), | 2376 SCOPED_TRACE(""); |
| 2405 ASCIIToUTF16("email"), | 2377 ExpectFieldEquals(expected, fields[2]); |
| 2406 string16(), | |
| 2407 ASCIIToUTF16("text"), | |
| 2408 WebInputElement::defaultMaxLength(), | |
| 2409 false), | |
| 2410 fields[2]); | |
| 2411 | 2378 |
| 2412 // Fill the form. | 2379 // Fill the form. |
| 2413 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2380 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2414 form.fields[1].value = ASCIIToUTF16("Earp"); | 2381 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2415 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2382 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2416 form_manager.FillForm(form, WebNode()); | 2383 form_manager.FillForm(form, WebNode()); |
| 2417 | 2384 |
| 2418 // Find the newly-filled form that contains the input element. | 2385 // Find the newly-filled form that contains the input element. |
| 2419 FormData form2; | 2386 FormData form2; |
| 2420 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2387 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2421 &form2)); | 2388 &form2)); |
| 2422 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2389 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2423 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2390 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2424 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2391 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2425 | 2392 |
| 2426 const std::vector<FormField>& fields2 = form2.fields; | 2393 const std::vector<FormField>& fields2 = form2.fields; |
| 2427 ASSERT_EQ(3U, fields2.size()); | 2394 ASSERT_EQ(3U, fields2.size()); |
| 2428 EXPECT_EQ(FormField(string16(), | 2395 |
| 2429 ASCIIToUTF16("firstname"), | 2396 expected.form_control_type = ASCIIToUTF16("text"); |
| 2430 ASCIIToUTF16("Wyatt"), | 2397 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2431 ASCIIToUTF16("text"), | 2398 |
| 2432 WebInputElement::defaultMaxLength(), | 2399 expected.name = ASCIIToUTF16("firstname"); |
| 2433 false), | 2400 expected.value = ASCIIToUTF16("Wyatt"); |
| 2434 fields2[0]); | 2401 SCOPED_TRACE(""); |
| 2435 EXPECT_EQ(FormField(string16(), | 2402 ExpectFieldEquals(expected, fields[0]); |
| 2436 ASCIIToUTF16("lastname"), | 2403 |
| 2437 ASCIIToUTF16("Earp"), | 2404 expected.name = ASCIIToUTF16("lastname"); |
| 2438 ASCIIToUTF16("text"), | 2405 expected.value = ASCIIToUTF16("Earp"); |
| 2439 WebInputElement::defaultMaxLength(), | 2406 SCOPED_TRACE(""); |
| 2440 false), | 2407 ExpectFieldEquals(expected, fields[1]); |
| 2441 fields2[1]); | 2408 |
| 2442 EXPECT_EQ(FormField(string16(), | 2409 expected.name = ASCIIToUTF16("email"); |
| 2443 ASCIIToUTF16("email"), | 2410 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2444 ASCIIToUTF16("wyatt@example.com"), | 2411 SCOPED_TRACE(""); |
| 2445 ASCIIToUTF16("text"), | 2412 ExpectFieldEquals(expected, fields[2]); |
| 2446 WebInputElement::defaultMaxLength(), | |
| 2447 false), | |
| 2448 fields2[2]); | |
| 2449 } | 2413 } |
| 2450 | 2414 |
| 2451 TEST_F(FormManagerTest, FillFormEmptyFormNames) { | 2415 TEST_F(FormManagerTest, FillFormEmptyFormNames) { |
| 2452 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" | 2416 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" |
| 2453 " <INPUT type=\"text\" id=\"firstname\"/>" | 2417 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2454 " <INPUT type=\"text\" id=\"middlename\"/>" | 2418 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2455 " <INPUT type=\"text\" id=\"lastname\"/>" | 2419 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2456 " <INPUT type=\"submit\" value=\"Send\"/>" | 2420 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2457 "</FORM>" | 2421 "</FORM>" |
| 2458 "<FORM action=\"http://abc.com\" method=\"post\">" | 2422 "<FORM action=\"http://abc.com\" method=\"post\">" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2477 // Find the form that contains the input element. | 2441 // Find the form that contains the input element. |
| 2478 FormData form; | 2442 FormData form; |
| 2479 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2443 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2480 &form)); | 2444 &form)); |
| 2481 EXPECT_EQ(string16(), form.name); | 2445 EXPECT_EQ(string16(), form.name); |
| 2482 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2446 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2483 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2447 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 2484 | 2448 |
| 2485 const std::vector<FormField>& fields = form.fields; | 2449 const std::vector<FormField>& fields = form.fields; |
| 2486 ASSERT_EQ(3U, fields.size()); | 2450 ASSERT_EQ(3U, fields.size()); |
| 2487 EXPECT_EQ(FormField(string16(), | 2451 |
| 2488 ASCIIToUTF16("apple"), | 2452 FormField expected; |
| 2489 string16(), | 2453 expected.form_control_type = ASCIIToUTF16("text"); |
| 2490 ASCIIToUTF16("text"), | 2454 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2491 WebInputElement::defaultMaxLength(), | 2455 |
| 2492 false), | 2456 expected.name = ASCIIToUTF16("apple"); |
| 2493 fields[0]); | 2457 expected.is_autofilled = false; |
| 2494 EXPECT_EQ(FormField(string16(), | 2458 SCOPED_TRACE(""); |
| 2495 ASCIIToUTF16("banana"), | 2459 ExpectFieldEquals(expected, fields[0]); |
| 2496 string16(), | 2460 |
| 2497 ASCIIToUTF16("text"), | 2461 expected.name = ASCIIToUTF16("banana"); |
| 2498 WebInputElement::defaultMaxLength(), | 2462 expected.is_autofilled = false; |
| 2499 false), | 2463 SCOPED_TRACE(""); |
| 2500 fields[1]); | 2464 ExpectFieldEquals(expected, fields[1]); |
| 2501 EXPECT_EQ(FormField(string16(), | 2465 |
| 2502 ASCIIToUTF16("cantelope"), | 2466 expected.name = ASCIIToUTF16("cantelope"); |
| 2503 string16(), | 2467 expected.is_autofilled = false; |
| 2504 ASCIIToUTF16("text"), | 2468 SCOPED_TRACE(""); |
| 2505 WebInputElement::defaultMaxLength(), | 2469 ExpectFieldEquals(expected, fields[2]); |
| 2506 false), | |
| 2507 fields[2]); | |
| 2508 | 2470 |
| 2509 // Fill the form. | 2471 // Fill the form. |
| 2510 form.fields[0].value = ASCIIToUTF16("Red"); | 2472 form.fields[0].value = ASCIIToUTF16("Red"); |
| 2511 form.fields[1].value = ASCIIToUTF16("Yellow"); | 2473 form.fields[1].value = ASCIIToUTF16("Yellow"); |
| 2512 form.fields[2].value = ASCIIToUTF16("Also Yellow"); | 2474 form.fields[2].value = ASCIIToUTF16("Also Yellow"); |
| 2513 form_manager.FillForm(form, WebNode()); | 2475 form_manager.FillForm(form, WebNode()); |
| 2514 | 2476 |
| 2515 // Find the newly-filled form that contains the input element. | 2477 // Find the newly-filled form that contains the input element. |
| 2516 FormData form2; | 2478 FormData form2; |
| 2517 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2479 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2518 &form2)); | 2480 &form2)); |
| 2519 EXPECT_EQ(string16(), form2.name); | 2481 EXPECT_EQ(string16(), form2.name); |
| 2520 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2482 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2521 EXPECT_EQ(GURL("http://abc.com"), form2.action); | 2483 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
| 2522 | 2484 |
| 2523 const std::vector<FormField>& fields2 = form2.fields; | 2485 const std::vector<FormField>& fields2 = form2.fields; |
| 2524 ASSERT_EQ(3U, fields2.size()); | 2486 ASSERT_EQ(3U, fields2.size()); |
| 2525 EXPECT_EQ(FormField(string16(), | 2487 |
| 2526 ASCIIToUTF16("apple"), | 2488 expected.name = ASCIIToUTF16("apple"); |
| 2527 ASCIIToUTF16("Red"), | 2489 expected.value = ASCIIToUTF16("Red"); |
| 2528 ASCIIToUTF16("text"), | 2490 expected.is_autofilled = true; |
| 2529 WebInputElement::defaultMaxLength(), | 2491 SCOPED_TRACE(""); |
| 2530 false), | 2492 ExpectFieldEquals(expected, fields2[0]); |
| 2531 fields2[0]); | 2493 |
| 2532 EXPECT_EQ(FormField(string16(), | 2494 expected.name = ASCIIToUTF16("banana"); |
| 2533 ASCIIToUTF16("banana"), | 2495 expected.value = ASCIIToUTF16("Yellow"); |
| 2534 ASCIIToUTF16("Yellow"), | 2496 expected.is_autofilled = true; |
| 2535 ASCIIToUTF16("text"), | 2497 SCOPED_TRACE(""); |
| 2536 WebInputElement::defaultMaxLength(), | 2498 ExpectFieldEquals(expected, fields2[1]); |
| 2537 false), | 2499 |
| 2538 fields2[1]); | 2500 expected.name = ASCIIToUTF16("cantelope"); |
| 2539 EXPECT_EQ(FormField(string16(), | 2501 expected.value = ASCIIToUTF16("Also Yellow"); |
| 2540 ASCIIToUTF16("cantelope"), | 2502 expected.is_autofilled = true; |
| 2541 ASCIIToUTF16("Also Yellow"), | 2503 SCOPED_TRACE(""); |
| 2542 ASCIIToUTF16("text"), | 2504 ExpectFieldEquals(expected, fields2[2]); |
| 2543 WebInputElement::defaultMaxLength(), | |
| 2544 false), | |
| 2545 fields2[2]); | |
| 2546 } | 2505 } |
| 2547 | 2506 |
| 2548 TEST_F(FormManagerTest, ThreePartPhone) { | 2507 TEST_F(FormManagerTest, ThreePartPhone) { |
| 2549 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2508 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2550 " Phone:" | 2509 " Phone:" |
| 2551 " <input type=\"text\" name=\"dayphone1\">" | 2510 " <input type=\"text\" name=\"dayphone1\">" |
| 2552 " -" | 2511 " -" |
| 2553 " <input type=\"text\" name=\"dayphone2\">" | 2512 " <input type=\"text\" name=\"dayphone2\">" |
| 2554 " -" | 2513 " -" |
| 2555 " <input type=\"text\" name=\"dayphone3\">" | 2514 " <input type=\"text\" name=\"dayphone3\">" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2570 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2529 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 2571 FormManager::REQUIRE_NONE, | 2530 FormManager::REQUIRE_NONE, |
| 2572 FormManager::EXTRACT_VALUE, | 2531 FormManager::EXTRACT_VALUE, |
| 2573 &form)); | 2532 &form)); |
| 2574 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2533 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2575 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2534 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2576 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2535 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2577 | 2536 |
| 2578 const std::vector<FormField>& fields = form.fields; | 2537 const std::vector<FormField>& fields = form.fields; |
| 2579 ASSERT_EQ(4U, fields.size()); | 2538 ASSERT_EQ(4U, fields.size()); |
| 2580 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), | 2539 |
| 2581 ASCIIToUTF16("dayphone1"), | 2540 FormField expected; |
| 2582 string16(), | 2541 expected.form_control_type = ASCIIToUTF16("text"); |
| 2583 ASCIIToUTF16("text"), | 2542 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2584 WebInputElement::defaultMaxLength(), | 2543 |
| 2585 false), | 2544 expected.label = ASCIIToUTF16("Phone:"); |
| 2586 fields[0]); | 2545 expected.name = ASCIIToUTF16("dayphone1"); |
| 2587 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2546 SCOPED_TRACE(""); |
| 2588 ASCIIToUTF16("dayphone2"), | 2547 ExpectFieldEquals(expected, fields[0]); |
| 2589 string16(), | 2548 |
| 2590 ASCIIToUTF16("text"), | 2549 expected.label = ASCIIToUTF16("-"); |
| 2591 WebInputElement::defaultMaxLength(), | 2550 expected.name = ASCIIToUTF16("dayphone2"); |
| 2592 false), | 2551 SCOPED_TRACE(""); |
| 2593 fields[1]); | 2552 ExpectFieldEquals(expected, fields[1]); |
| 2594 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2553 |
| 2595 ASCIIToUTF16("dayphone3"), | 2554 expected.label = ASCIIToUTF16("-"); |
| 2596 string16(), | 2555 expected.name = ASCIIToUTF16("dayphone3"); |
| 2597 ASCIIToUTF16("text"), | 2556 SCOPED_TRACE(""); |
| 2598 WebInputElement::defaultMaxLength(), | 2557 ExpectFieldEquals(expected, fields[2]); |
| 2599 false), | 2558 |
| 2600 fields[2]); | 2559 expected.label = ASCIIToUTF16("ext.:"); |
| 2601 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | 2560 expected.name = ASCIIToUTF16("dayphone4"); |
| 2602 ASCIIToUTF16("dayphone4"), | 2561 SCOPED_TRACE(""); |
| 2603 string16(), | 2562 ExpectFieldEquals(expected, fields[3]); |
| 2604 ASCIIToUTF16("text"), | |
| 2605 WebInputElement::defaultMaxLength(), | |
| 2606 false), | |
| 2607 fields[3]); | |
| 2608 } | 2563 } |
| 2609 | 2564 |
| 2610 | 2565 |
| 2611 TEST_F(FormManagerTest, MaxLengthFields) { | 2566 TEST_F(FormManagerTest, MaxLengthFields) { |
| 2612 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2567 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2613 " Phone:" | 2568 " Phone:" |
| 2614 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" | 2569 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" |
| 2615 " -" | 2570 " -" |
| 2616 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" | 2571 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" |
| 2617 " -" | 2572 " -" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2635 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2590 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 2636 FormManager::REQUIRE_NONE, | 2591 FormManager::REQUIRE_NONE, |
| 2637 FormManager::EXTRACT_VALUE, | 2592 FormManager::EXTRACT_VALUE, |
| 2638 &form)); | 2593 &form)); |
| 2639 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2594 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2640 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2595 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2641 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2596 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2642 | 2597 |
| 2643 const std::vector<FormField>& fields = form.fields; | 2598 const std::vector<FormField>& fields = form.fields; |
| 2644 ASSERT_EQ(6U, fields.size()); | 2599 ASSERT_EQ(6U, fields.size()); |
| 2645 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), | 2600 |
| 2646 ASCIIToUTF16("dayphone1"), | 2601 FormField expected; |
| 2647 string16(), | 2602 expected.form_control_type = ASCIIToUTF16("text"); |
| 2648 ASCIIToUTF16("text"), | 2603 |
| 2649 3, | 2604 expected.label = ASCIIToUTF16("Phone:"); |
| 2650 false), | 2605 expected.name = ASCIIToUTF16("dayphone1"); |
| 2651 fields[0]); | 2606 expected.max_length = 3; |
| 2652 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2607 SCOPED_TRACE(""); |
| 2653 ASCIIToUTF16("dayphone2"), | 2608 ExpectFieldEquals(expected, fields[0]); |
| 2654 string16(), | 2609 |
| 2655 ASCIIToUTF16("text"), | 2610 expected.label = ASCIIToUTF16("-"); |
| 2656 3, | 2611 expected.name = ASCIIToUTF16("dayphone2"); |
| 2657 false), | 2612 expected.max_length = 3; |
| 2658 fields[1]); | 2613 SCOPED_TRACE(""); |
| 2659 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2614 ExpectFieldEquals(expected, fields[1]); |
| 2660 ASCIIToUTF16("dayphone3"), | 2615 |
| 2661 string16(), | 2616 expected.label = ASCIIToUTF16("-"); |
| 2662 ASCIIToUTF16("text"), | 2617 expected.name = ASCIIToUTF16("dayphone3"); |
| 2663 4, | 2618 expected.max_length = 4; |
| 2664 false), | 2619 SCOPED_TRACE(""); |
| 2665 fields[2]); | 2620 ExpectFieldEquals(expected, fields[2]); |
| 2666 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | 2621 |
| 2667 ASCIIToUTF16("dayphone4"), | 2622 expected.label = ASCIIToUTF16("ext.:"); |
| 2668 string16(), | 2623 expected.name = ASCIIToUTF16("dayphone4"); |
| 2669 ASCIIToUTF16("text"), | 2624 expected.max_length = 5; |
| 2670 5, | 2625 SCOPED_TRACE(""); |
| 2671 false), | 2626 ExpectFieldEquals(expected, fields[3]); |
| 2672 fields[3]); | 2627 |
| 2673 // When unspecified |size|, default is returned. | 2628 // When unspecified |size|, default is returned. |
| 2674 EXPECT_EQ(FormField(string16(), | 2629 expected.label = string16(); |
| 2675 ASCIIToUTF16("default1"), | 2630 expected.name = ASCIIToUTF16("default1"); |
| 2676 string16(), | 2631 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2677 ASCIIToUTF16("text"), | 2632 SCOPED_TRACE(""); |
| 2678 WebInputElement::defaultMaxLength(), | 2633 ExpectFieldEquals(expected, fields[4]); |
| 2679 false), | 2634 |
| 2680 fields[4]); | |
| 2681 // When invalid |size|, default is returned. | 2635 // When invalid |size|, default is returned. |
| 2682 EXPECT_EQ(FormField(string16(), | 2636 expected.label = string16(); |
| 2683 ASCIIToUTF16("invalid1"), | 2637 expected.name = ASCIIToUTF16("invalid1"); |
| 2684 string16(), | 2638 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2685 ASCIIToUTF16("text"), | 2639 SCOPED_TRACE(""); |
| 2686 WebInputElement::defaultMaxLength(), | 2640 ExpectFieldEquals(expected, fields[5]); |
| 2687 false), | |
| 2688 fields[5]); | |
| 2689 } | 2641 } |
| 2690 | 2642 |
| 2691 // This test re-creates the experience of typing in a field then selecting a | 2643 // This test re-creates the experience of typing in a field then selecting a |
| 2692 // profile from the Autofill suggestions popup. The field that is being typed | 2644 // profile from the Autofill suggestions popup. The field that is being typed |
| 2693 // into should be filled even though it's not technically empty. | 2645 // into should be filled even though it's not technically empty. |
| 2694 TEST_F(FormManagerTest, FillFormNonEmptyField) { | 2646 TEST_F(FormManagerTest, FillFormNonEmptyField) { |
| 2695 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2647 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2696 " <INPUT type=\"text\" id=\"firstname\"/>" | 2648 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2697 " <INPUT type=\"text\" id=\"lastname\"/>" | 2649 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2698 " <INPUT type=\"text\" id=\"email\"/>" | 2650 " <INPUT type=\"text\" id=\"email\"/>" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2717 // Find the form that contains the input element. | 2669 // Find the form that contains the input element. |
| 2718 FormData form; | 2670 FormData form; |
| 2719 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2671 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2720 &form)); | 2672 &form)); |
| 2721 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2673 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2722 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2674 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2723 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2675 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2724 | 2676 |
| 2725 const std::vector<FormField>& fields = form.fields; | 2677 const std::vector<FormField>& fields = form.fields; |
| 2726 ASSERT_EQ(3U, fields.size()); | 2678 ASSERT_EQ(3U, fields.size()); |
| 2727 EXPECT_EQ(FormField(string16(), | 2679 |
| 2728 ASCIIToUTF16("firstname"), | 2680 FormField expected; |
| 2729 string16(), | 2681 expected.form_control_type = ASCIIToUTF16("text"); |
| 2730 ASCIIToUTF16("text"), | 2682 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2731 WebInputElement::defaultMaxLength(), | 2683 |
| 2732 false), | 2684 expected.name = ASCIIToUTF16("firstname"); |
| 2733 fields[0]); | 2685 expected.value = ASCIIToUTF16("Wy"); |
| 2734 EXPECT_EQ(FormField(string16(), | 2686 expected.is_autofilled = false; |
| 2735 ASCIIToUTF16("lastname"), | 2687 SCOPED_TRACE(""); |
| 2736 string16(), | 2688 ExpectFieldEquals(expected, fields[0]); |
| 2737 ASCIIToUTF16("text"), | 2689 |
| 2738 WebInputElement::defaultMaxLength(), | 2690 expected.name = ASCIIToUTF16("lastname"); |
| 2739 false), | 2691 expected.value = string16(); |
| 2740 fields[1]); | 2692 expected.is_autofilled = false; |
| 2741 EXPECT_EQ(FormField(string16(), | 2693 SCOPED_TRACE(""); |
| 2742 ASCIIToUTF16("email"), | 2694 ExpectFieldEquals(expected, fields[1]); |
| 2743 string16(), | 2695 |
| 2744 ASCIIToUTF16("text"), | 2696 expected.name = ASCIIToUTF16("email"); |
| 2745 WebInputElement::defaultMaxLength(), | 2697 expected.value = string16(); |
| 2746 false), | 2698 expected.is_autofilled = false; |
| 2747 fields[2]); | 2699 SCOPED_TRACE(""); |
| 2700 ExpectFieldEquals(expected, fields[2]); | |
| 2748 | 2701 |
| 2749 // Preview the form and verify that the cursor position has been updated. | 2702 // Preview the form and verify that the cursor position has been updated. |
| 2750 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2703 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2751 form.fields[1].value = ASCIIToUTF16("Earp"); | 2704 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2752 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2705 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2753 form_manager.PreviewForm(form, input_element); | 2706 form_manager.PreviewForm(form, input_element); |
| 2754 EXPECT_EQ(2, input_element.selectionStart()); | 2707 EXPECT_EQ(2, input_element.selectionStart()); |
| 2755 EXPECT_EQ(5, input_element.selectionEnd()); | 2708 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2756 | 2709 |
| 2757 // Fill the form. | 2710 // Fill the form. |
| 2758 form_manager.FillForm(form, input_element); | 2711 form_manager.FillForm(form, input_element); |
| 2759 | 2712 |
| 2760 // Find the newly-filled form that contains the input element. | 2713 // Find the newly-filled form that contains the input element. |
| 2761 FormData form2; | 2714 FormData form2; |
| 2762 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2715 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2763 &form2)); | 2716 &form2)); |
| 2764 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2717 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2765 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2718 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2766 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2719 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2767 | 2720 |
| 2768 const std::vector<FormField>& fields2 = form2.fields; | 2721 const std::vector<FormField>& fields2 = form2.fields; |
| 2769 ASSERT_EQ(3U, fields2.size()); | 2722 ASSERT_EQ(3U, fields2.size()); |
| 2770 EXPECT_EQ(FormField(string16(), | 2723 |
| 2771 ASCIIToUTF16("firstname"), | 2724 expected.name = ASCIIToUTF16("firstname"); |
| 2772 ASCIIToUTF16("Wyatt"), | 2725 expected.value = ASCIIToUTF16("Wyatt"); |
| 2773 ASCIIToUTF16("text"), | 2726 expected.is_autofilled = true; |
| 2774 WebInputElement::defaultMaxLength(), | 2727 SCOPED_TRACE(""); |
| 2775 false), | 2728 ExpectFieldEquals(expected, fields2[0]); |
| 2776 fields2[0]); | 2729 |
| 2777 EXPECT_EQ(FormField(string16(), | 2730 expected.name = ASCIIToUTF16("lastname"); |
| 2778 ASCIIToUTF16("lastname"), | 2731 expected.value = ASCIIToUTF16("Earp"); |
| 2779 ASCIIToUTF16("Earp"), | 2732 expected.is_autofilled = true; |
| 2780 ASCIIToUTF16("text"), | 2733 SCOPED_TRACE(""); |
| 2781 WebInputElement::defaultMaxLength(), | 2734 ExpectFieldEquals(expected, fields2[1]); |
| 2782 false), | 2735 |
| 2783 fields2[1]); | 2736 expected.name = ASCIIToUTF16("email"); |
| 2784 EXPECT_EQ(FormField(string16(), | 2737 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2785 ASCIIToUTF16("email"), | 2738 expected.is_autofilled = true; |
| 2786 ASCIIToUTF16("wyatt@example.com"), | 2739 SCOPED_TRACE(""); |
| 2787 ASCIIToUTF16("text"), | 2740 ExpectFieldEquals(expected, fields2[2]); |
| 2788 WebInputElement::defaultMaxLength(), | |
| 2789 false), | |
| 2790 fields2[2]); | |
| 2791 | 2741 |
| 2792 // Verify that the cursor position has been updated. | 2742 // Verify that the cursor position has been updated. |
| 2793 EXPECT_EQ(5, input_element.selectionStart()); | 2743 EXPECT_EQ(5, input_element.selectionStart()); |
| 2794 EXPECT_EQ(5, input_element.selectionEnd()); | 2744 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2795 } | 2745 } |
| 2796 | 2746 |
| 2797 TEST_F(FormManagerTest, ClearFormWithNode) { | 2747 TEST_F(FormManagerTest, ClearFormWithNode) { |
| 2798 LoadHTML( | 2748 LoadHTML( |
| 2799 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2749 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2800 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2750 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2830 | 2780 |
| 2831 // Verify the form is cleared. | 2781 // Verify the form is cleared. |
| 2832 FormData form2; | 2782 FormData form2; |
| 2833 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); | 2783 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); |
| 2834 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2784 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2835 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2785 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2836 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2786 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2837 | 2787 |
| 2838 const std::vector<FormField>& fields2 = form2.fields; | 2788 const std::vector<FormField>& fields2 = form2.fields; |
| 2839 ASSERT_EQ(4U, fields2.size()); | 2789 ASSERT_EQ(4U, fields2.size()); |
| 2840 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2790 |
| 2841 FormField(string16(), | 2791 FormField expected; |
| 2842 ASCIIToUTF16("firstname"), | 2792 expected.form_control_type = ASCIIToUTF16("text"); |
| 2843 string16(), | 2793 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2844 ASCIIToUTF16("text"), | 2794 |
| 2845 WebInputElement::defaultMaxLength(), | 2795 expected.name = ASCIIToUTF16("firstname"); |
| 2846 false))); | 2796 expected.value = string16(); |
| 2847 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2797 SCOPED_TRACE(""); |
| 2848 FormField(string16(), | 2798 ExpectFieldEquals(expected, fields2[0]); |
| 2849 ASCIIToUTF16("lastname"), | 2799 |
| 2850 string16(), | 2800 expected.name = ASCIIToUTF16("lastname"); |
| 2851 ASCIIToUTF16("text"), | 2801 expected.value = string16(); |
| 2852 WebInputElement::defaultMaxLength(), | 2802 SCOPED_TRACE(""); |
| 2853 false))); | 2803 ExpectFieldEquals(expected, fields2[1]); |
| 2854 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2804 |
| 2855 FormField(string16(), | 2805 expected.name = ASCIIToUTF16("noAC"); |
| 2856 ASCIIToUTF16("noAC"), | 2806 expected.value = string16(); |
| 2857 string16(), | 2807 SCOPED_TRACE(""); |
| 2858 ASCIIToUTF16("text"), | 2808 ExpectFieldEquals(expected, fields2[2]); |
| 2859 WebInputElement::defaultMaxLength(), | 2809 |
| 2860 false))); | 2810 expected.name = ASCIIToUTF16("notenabled"); |
| 2861 EXPECT_TRUE(fields2[3].StrictlyEqualsHack( | 2811 expected.value = ASCIIToUTF16("no clear"); |
| 2862 FormField(string16(), | 2812 SCOPED_TRACE(""); |
| 2863 ASCIIToUTF16("notenabled"), | 2813 ExpectFieldEquals(expected, fields2[3]); |
| 2864 ASCIIToUTF16("no clear"), | |
| 2865 ASCIIToUTF16("text"), | |
| 2866 WebInputElement::defaultMaxLength(), | |
| 2867 false))); | |
| 2868 | 2814 |
| 2869 // Verify that the cursor position has been updated. | 2815 // Verify that the cursor position has been updated. |
| 2870 EXPECT_EQ(0, firstname.selectionStart()); | 2816 EXPECT_EQ(0, firstname.selectionStart()); |
| 2871 EXPECT_EQ(0, firstname.selectionEnd()); | 2817 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2872 } | 2818 } |
| 2873 | 2819 |
| 2874 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { | 2820 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { |
| 2875 LoadHTML( | 2821 LoadHTML( |
| 2876 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2822 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2877 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2823 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2911 | 2857 |
| 2912 // Verify the form is cleared. | 2858 // Verify the form is cleared. |
| 2913 FormData form2; | 2859 FormData form2; |
| 2914 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); | 2860 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); |
| 2915 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2861 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2916 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2862 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2917 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2863 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2918 | 2864 |
| 2919 const std::vector<FormField>& fields2 = form2.fields; | 2865 const std::vector<FormField>& fields2 = form2.fields; |
| 2920 ASSERT_EQ(3U, fields2.size()); | 2866 ASSERT_EQ(3U, fields2.size()); |
| 2921 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2867 |
| 2922 FormField(string16(), | 2868 FormField expected; |
| 2923 ASCIIToUTF16("firstname"), | 2869 |
| 2924 string16(), | 2870 expected.name = ASCIIToUTF16("firstname"); |
| 2925 ASCIIToUTF16("text"), | 2871 expected.value = string16(); |
| 2926 WebInputElement::defaultMaxLength(), | 2872 expected.form_control_type = ASCIIToUTF16("text"); |
| 2927 false))); | 2873 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2928 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2874 SCOPED_TRACE(""); |
| 2929 FormField(string16(), | 2875 ExpectFieldEquals(expected, fields2[0]); |
| 2930 ASCIIToUTF16("lastname"), | 2876 |
| 2931 string16(), | 2877 expected.name = ASCIIToUTF16("lastname"); |
| 2932 ASCIIToUTF16("text"), | 2878 expected.value = string16(); |
| 2933 WebInputElement::defaultMaxLength(), | 2879 expected.form_control_type = ASCIIToUTF16("text"); |
| 2934 false))); | 2880 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2935 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2881 SCOPED_TRACE(""); |
| 2936 FormField(string16(), | 2882 ExpectFieldEquals(expected, fields2[1]); |
| 2937 ASCIIToUTF16("state"), | 2883 |
| 2938 ASCIIToUTF16("?"), | 2884 expected.name = ASCIIToUTF16("state"); |
| 2939 ASCIIToUTF16("select-one"), | 2885 expected.value = ASCIIToUTF16("?"); |
| 2940 0, | 2886 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2941 false))); | 2887 expected.max_length = 0; |
| 2888 SCOPED_TRACE(""); | |
| 2889 ExpectFieldEquals(expected, fields2[2]); | |
| 2942 | 2890 |
| 2943 // Verify that the cursor position has been updated. | 2891 // Verify that the cursor position has been updated. |
| 2944 EXPECT_EQ(0, firstname.selectionStart()); | 2892 EXPECT_EQ(0, firstname.selectionStart()); |
| 2945 EXPECT_EQ(0, firstname.selectionEnd()); | 2893 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2946 } | 2894 } |
| 2947 | 2895 |
| 2948 TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { | 2896 TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { |
| 2949 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2897 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2950 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2898 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 2951 " <INPUT type=\"text\" id=\"lastname\"/>" | 2899 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3261 forms[0], FormManager::REQUIRE_NONE, | 3209 forms[0], FormManager::REQUIRE_NONE, |
| 3262 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | | 3210 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | |
| 3263 FormManager::EXTRACT_OPTION_TEXT), | 3211 FormManager::EXTRACT_OPTION_TEXT), |
| 3264 &form)); | 3212 &form)); |
| 3265 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3213 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3266 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3214 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3267 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3215 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3268 | 3216 |
| 3269 const std::vector<FormField>& fields = form.fields; | 3217 const std::vector<FormField>& fields = form.fields; |
| 3270 ASSERT_EQ(3U, fields.size()); | 3218 ASSERT_EQ(3U, fields.size()); |
| 3271 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 3219 |
| 3272 FormField(string16(), | 3220 FormField expected; |
| 3273 ASCIIToUTF16("firstname"), | 3221 |
| 3274 ASCIIToUTF16("John"), | 3222 expected.name = ASCIIToUTF16("firstname"); |
| 3275 ASCIIToUTF16("text"), | 3223 expected.value = ASCIIToUTF16("John"); |
| 3276 WebInputElement::defaultMaxLength(), | 3224 expected.form_control_type = ASCIIToUTF16("text"); |
| 3277 false))); | 3225 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3278 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 3226 SCOPED_TRACE(""); |
| 3279 FormField(string16(), | 3227 ExpectFieldEquals(expected, fields[0]); |
| 3280 ASCIIToUTF16("lastname"), | 3228 |
| 3281 ASCIIToUTF16("Smith"), | 3229 expected.name = ASCIIToUTF16("lastname"); |
| 3282 ASCIIToUTF16("text"), | 3230 expected.value = ASCIIToUTF16("Smith"); |
| 3283 WebInputElement::defaultMaxLength(), | 3231 expected.form_control_type = ASCIIToUTF16("text"); |
| 3284 false))); | 3232 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3285 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 3233 SCOPED_TRACE(""); |
| 3286 FormField(string16(), | 3234 ExpectFieldEquals(expected, fields[1]); |
| 3287 ASCIIToUTF16("country"), | 3235 |
| 3288 ASCIIToUTF16("Albania"), | 3236 expected.name = ASCIIToUTF16("country"); |
| 3289 ASCIIToUTF16("select-one"), | 3237 expected.value = ASCIIToUTF16("Albania"); |
| 3290 0, | 3238 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 3291 false))); | 3239 expected.max_length = 0; |
| 3240 SCOPED_TRACE(""); | |
| 3241 ExpectFieldEquals(expected, fields[2]); | |
| 3292 | 3242 |
| 3293 form.fields.clear(); | 3243 form.fields.clear(); |
| 3294 // Extract the country select-one value as value. | 3244 // Extract the country select-one value as value. |
| 3295 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 3245 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 3296 FormManager::REQUIRE_NONE, | 3246 FormManager::REQUIRE_NONE, |
| 3297 FormManager::EXTRACT_VALUE, | 3247 FormManager::EXTRACT_VALUE, |
| 3298 &form)); | 3248 &form)); |
| 3299 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3249 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3300 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3250 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3301 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3251 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3302 | 3252 |
| 3303 ASSERT_EQ(3U, fields.size()); | 3253 ASSERT_EQ(3U, fields.size()); |
| 3304 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 3254 |
| 3305 FormField(string16(), | 3255 expected.name = ASCIIToUTF16("firstname"); |
| 3306 ASCIIToUTF16("firstname"), | 3256 expected.value = ASCIIToUTF16("John"); |
| 3307 ASCIIToUTF16("John"), | 3257 expected.form_control_type = ASCIIToUTF16("text"); |
| 3308 ASCIIToUTF16("text"), | 3258 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3309 WebInputElement::defaultMaxLength(), | 3259 SCOPED_TRACE(""); |
| 3310 false))); | 3260 ExpectFieldEquals(expected, fields[0]); |
| 3311 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 3261 |
| 3312 FormField(string16(), | 3262 expected.name = ASCIIToUTF16("lastname"); |
| 3313 ASCIIToUTF16("lastname"), | 3263 expected.value = ASCIIToUTF16("Smith"); |
| 3314 ASCIIToUTF16("Smith"), | 3264 expected.form_control_type = ASCIIToUTF16("text"); |
| 3315 ASCIIToUTF16("text"), | 3265 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3316 WebInputElement::defaultMaxLength(), | 3266 SCOPED_TRACE(""); |
| 3317 false))); | 3267 ExpectFieldEquals(expected, fields[1]); |
| 3318 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 3268 |
| 3319 FormField(string16(), | 3269 expected.name = ASCIIToUTF16("country"); |
| 3320 ASCIIToUTF16("country"), | 3270 expected.value = ASCIIToUTF16("AL"); |
| 3321 ASCIIToUTF16("AL"), | 3271 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 3322 ASCIIToUTF16("select-one"), | 3272 expected.max_length = 0; |
| 3323 0, | 3273 SCOPED_TRACE(""); |
| 3324 false))); | 3274 ExpectFieldEquals(expected, fields[2]); |
| 3325 } | 3275 } |
| OLD | NEW |