| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const FormData& form = forms[0]; | 75 const FormData& form = forms[0]; |
| 74 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 76 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 75 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 77 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 76 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 78 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 77 | 79 |
| 78 const std::vector<FormField>& fields = form.fields; | 80 const std::vector<FormField>& fields = form.fields; |
| 79 ASSERT_EQ(labels.size(), fields.size()); | 81 ASSERT_EQ(labels.size(), fields.size()); |
| 80 for (size_t i = 0; i < labels.size(); ++i) { | 82 for (size_t i = 0; i < labels.size(); ++i) { |
| 81 int max_length = control_types[i] == ASCIIToUTF16("text") ? | 83 int max_length = control_types[i] == ASCIIToUTF16("text") ? |
| 82 WebInputElement::defaultMaxLength() : 0; | 84 WebInputElement::defaultMaxLength() : 0; |
| 83 FormField expected = FormField(labels[i], | 85 FormField expected; |
| 84 names[i], | 86 expected.label = labels[i]; |
| 85 values[i], | 87 expected.name = names[i]; |
| 86 control_types[i], | 88 expected.value = values[i]; |
| 87 max_length, | 89 expected.form_control_type = control_types[i]; |
| 88 false); | 90 expected.max_length = max_length; |
| 89 EXPECT_TRUE(fields[i].StrictlyEqualsHack(expected)) | 91 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); |
| 90 << "Expected \"" << expected << "\", got \"" << fields[i] << "\""; | 92 EXPECT_FORM_FIELD_EQUALS(expected, fields[i]); |
| 91 } | 93 } |
| 92 } | 94 } |
| 93 | 95 |
| 94 void ExpectJohnSmithLabels(const char* html) { | 96 void ExpectJohnSmithLabels(const char* html) { |
| 95 std::vector<string16> labels, names, values; | 97 std::vector<string16> labels, names, values; |
| 96 | 98 |
| 97 labels.push_back(ASCIIToUTF16("First name:")); | 99 labels.push_back(ASCIIToUTF16("First name:")); |
| 98 names.push_back(ASCIIToUTF16("firstname")); | 100 names.push_back(ASCIIToUTF16("firstname")); |
| 99 values.push_back(ASCIIToUTF16("John")); | 101 values.push_back(ASCIIToUTF16("John")); |
| 100 | 102 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 119 | 121 |
| 120 WebFrame* frame = GetMainFrame(); | 122 WebFrame* frame = GetMainFrame(); |
| 121 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 123 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 122 | 124 |
| 123 WebElement web_element = frame->document().getElementById("element"); | 125 WebElement web_element = frame->document().getElementById("element"); |
| 124 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 126 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 125 FormField result1; | 127 FormField result1; |
| 126 FormManager::WebFormControlElementToFormField(element, | 128 FormManager::WebFormControlElementToFormField(element, |
| 127 FormManager::EXTRACT_NONE, | 129 FormManager::EXTRACT_NONE, |
| 128 &result1); | 130 &result1); |
| 129 EXPECT_TRUE(result1.StrictlyEqualsHack( | 131 |
| 130 FormField(string16(), | 132 FormField expected; |
| 131 ASCIIToUTF16("element"), | 133 expected.form_control_type = ASCIIToUTF16("text"); |
| 132 string16(), | 134 expected.max_length = WebInputElement::defaultMaxLength(); |
| 133 ASCIIToUTF16("text"), | 135 |
| 134 WebInputElement::defaultMaxLength(), | 136 expected.name = ASCIIToUTF16("element"); |
| 135 false))); | 137 expected.value = string16(); |
| 138 EXPECT_FORM_FIELD_EQUALS(expected, result1); |
| 139 |
| 136 FormField result2; | 140 FormField result2; |
| 137 FormManager::WebFormControlElementToFormField(element, | 141 FormManager::WebFormControlElementToFormField(element, |
| 138 FormManager::EXTRACT_VALUE, | 142 FormManager::EXTRACT_VALUE, |
| 139 &result2); | 143 &result2); |
| 140 EXPECT_TRUE(result2.StrictlyEqualsHack( | 144 |
| 141 FormField(string16(), | 145 expected.name = ASCIIToUTF16("element"); |
| 142 ASCIIToUTF16("element"), | 146 expected.value = ASCIIToUTF16("value"); |
| 143 ASCIIToUTF16("value"), | 147 EXPECT_FORM_FIELD_EQUALS(expected, result2); |
| 144 ASCIIToUTF16("text"), | |
| 145 WebInputElement::defaultMaxLength(), | |
| 146 false))); | |
| 147 } | 148 } |
| 148 | 149 |
| 149 // We should be able to extract a text field with autocomplete="off". | 150 // We should be able to extract a text field with autocomplete="off". |
| 150 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { | 151 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { |
| 151 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 152 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 152 " autocomplete=\"off\"/>"); | 153 " autocomplete=\"off\"/>"); |
| 153 | 154 |
| 154 WebFrame* frame = GetMainFrame(); | 155 WebFrame* frame = GetMainFrame(); |
| 155 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 156 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 156 | 157 |
| 157 WebElement web_element = frame->document().getElementById("element"); | 158 WebElement web_element = frame->document().getElementById("element"); |
| 158 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 159 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 159 FormField result; | 160 FormField result; |
| 160 FormManager::WebFormControlElementToFormField(element, | 161 FormManager::WebFormControlElementToFormField(element, |
| 161 FormManager::EXTRACT_VALUE, | 162 FormManager::EXTRACT_VALUE, |
| 162 &result); | 163 &result); |
| 163 EXPECT_TRUE(result.StrictlyEqualsHack( | 164 |
| 164 FormField(string16(), | 165 FormField expected; |
| 165 ASCIIToUTF16("element"), | 166 expected.name = ASCIIToUTF16("element"); |
| 166 ASCIIToUTF16("value"), | 167 expected.value = ASCIIToUTF16("value"); |
| 167 ASCIIToUTF16("text"), | 168 expected.form_control_type = ASCIIToUTF16("text"); |
| 168 WebInputElement::defaultMaxLength(), | 169 expected.max_length = WebInputElement::defaultMaxLength(); |
| 169 false))); | 170 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 170 } | 171 } |
| 171 | 172 |
| 172 // We should be able to extract a text field with maxlength specified. | 173 // We should be able to extract a text field with maxlength specified. |
| 173 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { | 174 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { |
| 174 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 175 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 175 " maxlength=\"5\"/>"); | 176 " maxlength=\"5\"/>"); |
| 176 | 177 |
| 177 WebFrame* frame = GetMainFrame(); | 178 WebFrame* frame = GetMainFrame(); |
| 178 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 179 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 179 | 180 |
| 180 WebElement web_element = frame->document().getElementById("element"); | 181 WebElement web_element = frame->document().getElementById("element"); |
| 181 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 182 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 182 FormField result; | 183 FormField result; |
| 183 FormManager::WebFormControlElementToFormField(element, | 184 FormManager::WebFormControlElementToFormField(element, |
| 184 FormManager::EXTRACT_VALUE, | 185 FormManager::EXTRACT_VALUE, |
| 185 &result); | 186 &result); |
| 186 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 187 |
| 187 ASCIIToUTF16("element"), | 188 FormField expected; |
| 188 ASCIIToUTF16("value"), | 189 expected.name = ASCIIToUTF16("element"); |
| 189 ASCIIToUTF16("text"), | 190 expected.value = ASCIIToUTF16("value"); |
| 190 5, | 191 expected.form_control_type = ASCIIToUTF16("text"); |
| 191 false))); | 192 expected.max_length = 5; |
| 193 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 192 } | 194 } |
| 193 | 195 |
| 194 // We should be able to extract a text field that has been autofilled. | 196 // We should be able to extract a text field that has been autofilled. |
| 195 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutofilled) { | 197 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutofilled) { |
| 196 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 198 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
| 197 | 199 |
| 198 WebFrame* frame = GetMainFrame(); | 200 WebFrame* frame = GetMainFrame(); |
| 199 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 201 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 200 | 202 |
| 201 WebElement web_element = frame->document().getElementById("element"); | 203 WebElement web_element = frame->document().getElementById("element"); |
| 202 WebInputElement element = web_element.to<WebInputElement>(); | 204 WebInputElement element = web_element.to<WebInputElement>(); |
| 203 element.setAutofilled(true); | 205 element.setAutofilled(true); |
| 204 FormField result; | 206 FormField result; |
| 205 FormManager::WebFormControlElementToFormField(element, | 207 FormManager::WebFormControlElementToFormField(element, |
| 206 FormManager::EXTRACT_VALUE, | 208 FormManager::EXTRACT_VALUE, |
| 207 &result); | 209 &result); |
| 208 EXPECT_TRUE(result.StrictlyEqualsHack( | 210 |
| 209 FormField(string16(), | 211 FormField expected; |
| 210 ASCIIToUTF16("element"), | 212 expected.name = ASCIIToUTF16("element"); |
| 211 ASCIIToUTF16("value"), | 213 expected.value = ASCIIToUTF16("value"); |
| 212 ASCIIToUTF16("text"), | 214 expected.form_control_type = ASCIIToUTF16("text"); |
| 213 WebInputElement::defaultMaxLength(), | 215 expected.max_length = WebInputElement::defaultMaxLength(); |
| 214 true))); | 216 expected.is_autofilled = true; |
| 217 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 215 } | 218 } |
| 216 | 219 |
| 217 // We should be able to extract a <select> field. | 220 // We should be able to extract a <select> field. |
| 218 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { | 221 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { |
| 219 LoadHTML("<SELECT id=\"element\"/>" | 222 LoadHTML("<SELECT id=\"element\"/>" |
| 220 " <OPTION value=\"CA\">California</OPTION>" | 223 " <OPTION value=\"CA\">California</OPTION>" |
| 221 " <OPTION value=\"TX\">Texas</OPTION>" | 224 " <OPTION value=\"TX\">Texas</OPTION>" |
| 222 "</SELECT>"); | 225 "</SELECT>"); |
| 223 | 226 |
| 224 WebFrame* frame = GetMainFrame(); | 227 WebFrame* frame = GetMainFrame(); |
| 225 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 228 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 226 | 229 |
| 227 WebElement web_element = frame->document().getElementById("element"); | 230 WebElement web_element = frame->document().getElementById("element"); |
| 228 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 231 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 229 FormField result1; | 232 FormField result1; |
| 230 FormManager::WebFormControlElementToFormField(element, | 233 FormManager::WebFormControlElementToFormField(element, |
| 231 FormManager::EXTRACT_VALUE, | 234 FormManager::EXTRACT_VALUE, |
| 232 &result1); | 235 &result1); |
| 233 EXPECT_TRUE(result1.StrictlyEqualsHack(FormField(string16(), | 236 |
| 234 ASCIIToUTF16("element"), | 237 FormField expected; |
| 235 ASCIIToUTF16("CA"), | 238 expected.name = ASCIIToUTF16("element"); |
| 236 ASCIIToUTF16("select-one"), | 239 expected.max_length = 0; |
| 237 0, | 240 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 238 false))); | 241 |
| 242 expected.value = ASCIIToUTF16("CA"); |
| 243 EXPECT_FORM_FIELD_EQUALS(expected, result1); |
| 244 |
| 239 FormField result2; | 245 FormField result2; |
| 240 FormManager::WebFormControlElementToFormField( | 246 FormManager::WebFormControlElementToFormField( |
| 241 element, | 247 element, |
| 242 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | | 248 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | |
| 243 FormManager::EXTRACT_OPTION_TEXT), | 249 FormManager::EXTRACT_OPTION_TEXT), |
| 244 &result2); | 250 &result2); |
| 245 EXPECT_TRUE(result2.StrictlyEqualsHack(FormField(string16(), | 251 expected.value = ASCIIToUTF16("California"); |
| 246 ASCIIToUTF16("element"), | 252 EXPECT_FORM_FIELD_EQUALS(expected, result2); |
| 247 ASCIIToUTF16("California"), | 253 |
| 248 ASCIIToUTF16("select-one"), | |
| 249 0, | |
| 250 false))); | |
| 251 FormField result3; | 254 FormField result3; |
| 252 FormManager::WebFormControlElementToFormField(element, | 255 FormManager::WebFormControlElementToFormField(element, |
| 253 FormManager::EXTRACT_OPTIONS, | 256 FormManager::EXTRACT_OPTIONS, |
| 254 &result3); | 257 &result3); |
| 255 EXPECT_TRUE(result3.StrictlyEqualsHack(FormField(string16(), | 258 expected.value = string16(); |
| 256 ASCIIToUTF16("element"), | 259 EXPECT_FORM_FIELD_EQUALS(expected, result3); |
| 257 string16(), | 260 |
| 258 ASCIIToUTF16("select-one"), | |
| 259 0, | |
| 260 false))); | |
| 261 ASSERT_EQ(2U, result3.option_values.size()); | 261 ASSERT_EQ(2U, result3.option_values.size()); |
| 262 ASSERT_EQ(2U, result3.option_contents.size()); | 262 ASSERT_EQ(2U, result3.option_contents.size()); |
| 263 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); | 263 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); |
| 264 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 264 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
| 265 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 265 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
| 266 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 266 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // We should be not extract the value for non-text and non-select fields. | 269 // We should not extract the value for non-text and non-select fields. |
| 270 TEST_F(FormManagerTest, WebFormControlElementToFormFieldInvalidType) { | 270 TEST_F(FormManagerTest, WebFormControlElementToFormFieldInvalidType) { |
| 271 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 271 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 272 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" | 272 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" |
| 273 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 273 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" |
| 274 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" | 274 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" |
| 275 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" | 275 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" |
| 276 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" | 276 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" |
| 277 "</FORM>"); | 277 "</FORM>"); |
| 278 | 278 |
| 279 WebFrame* frame = GetMainFrame(); | 279 WebFrame* frame = GetMainFrame(); |
| 280 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 280 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 281 | 281 |
| 282 WebElement web_element = frame->document().getElementById("hidden"); | 282 WebElement web_element = frame->document().getElementById("hidden"); |
| 283 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 283 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 284 FormField result; | 284 FormField result; |
| 285 FormManager::WebFormControlElementToFormField(element, | 285 FormManager::WebFormControlElementToFormField(element, |
| 286 FormManager::EXTRACT_VALUE, | 286 FormManager::EXTRACT_VALUE, |
| 287 &result); | 287 &result); |
| 288 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 288 |
| 289 ASCIIToUTF16("hidden"), | 289 FormField expected; |
| 290 string16(), | 290 expected.max_length = 0; |
| 291 ASCIIToUTF16("hidden"), | 291 |
| 292 0, | 292 expected.name = ASCIIToUTF16("hidden"); |
| 293 false))); | 293 expected.form_control_type = ASCIIToUTF16("hidden"); |
| 294 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 294 | 295 |
| 295 web_element = frame->document().getElementById("password"); | 296 web_element = frame->document().getElementById("password"); |
| 296 element = web_element.to<WebFormControlElement>(); | 297 element = web_element.to<WebFormControlElement>(); |
| 297 FormManager::WebFormControlElementToFormField(element, | 298 FormManager::WebFormControlElementToFormField(element, |
| 298 FormManager::EXTRACT_VALUE, | 299 FormManager::EXTRACT_VALUE, |
| 299 &result); | 300 &result); |
| 300 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 301 expected.name = ASCIIToUTF16("password"); |
| 301 ASCIIToUTF16("password"), | 302 expected.form_control_type = ASCIIToUTF16("password"); |
| 302 string16(), | 303 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 303 ASCIIToUTF16("password"), | |
| 304 0, | |
| 305 false))); | |
| 306 | 304 |
| 307 web_element = frame->document().getElementById("checkbox"); | 305 web_element = frame->document().getElementById("checkbox"); |
| 308 element = web_element.to<WebFormControlElement>(); | 306 element = web_element.to<WebFormControlElement>(); |
| 309 FormManager::WebFormControlElementToFormField(element, | 307 FormManager::WebFormControlElementToFormField(element, |
| 310 FormManager::EXTRACT_VALUE, | 308 FormManager::EXTRACT_VALUE, |
| 311 &result); | 309 &result); |
| 312 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 310 expected.name = ASCIIToUTF16("checkbox"); |
| 313 ASCIIToUTF16("checkbox"), | 311 expected.form_control_type = ASCIIToUTF16("checkbox"); |
| 314 string16(), | 312 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 315 ASCIIToUTF16("checkbox"), | |
| 316 0, | |
| 317 false))); | |
| 318 | 313 |
| 319 web_element = frame->document().getElementById("radio"); | 314 web_element = frame->document().getElementById("radio"); |
| 320 element = web_element.to<WebFormControlElement>(); | 315 element = web_element.to<WebFormControlElement>(); |
| 321 FormManager::WebFormControlElementToFormField(element, | 316 FormManager::WebFormControlElementToFormField(element, |
| 322 FormManager::EXTRACT_VALUE, | 317 FormManager::EXTRACT_VALUE, |
| 323 &result); | 318 &result); |
| 324 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 319 expected.name = ASCIIToUTF16("radio"); |
| 325 ASCIIToUTF16("radio"), | 320 expected.form_control_type = ASCIIToUTF16("radio"); |
| 326 string16(), | 321 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 327 ASCIIToUTF16("radio"), | 322 |
| 328 0, | |
| 329 false))); | |
| 330 | 323 |
| 331 web_element = frame->document().getElementById("submit"); | 324 web_element = frame->document().getElementById("submit"); |
| 332 element = web_element.to<WebFormControlElement>(); | 325 element = web_element.to<WebFormControlElement>(); |
| 333 FormManager::WebFormControlElementToFormField(element, | 326 FormManager::WebFormControlElementToFormField(element, |
| 334 FormManager::EXTRACT_VALUE, | 327 FormManager::EXTRACT_VALUE, |
| 335 &result); | 328 &result); |
| 336 EXPECT_TRUE(result.StrictlyEqualsHack(FormField(string16(), | 329 expected.name = ASCIIToUTF16("submit"); |
| 337 ASCIIToUTF16("submit"), | 330 expected.form_control_type = ASCIIToUTF16("submit"); |
| 338 string16(), | 331 EXPECT_FORM_FIELD_EQUALS(expected, result); |
| 339 ASCIIToUTF16("submit"), | |
| 340 0, | |
| 341 false))); | |
| 342 } | 332 } |
| 343 | 333 |
| 344 TEST_F(FormManagerTest, WebFormElementToFormData) { | 334 TEST_F(FormManagerTest, WebFormElementToFormData) { |
| 345 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 335 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 346 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 336 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 347 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 337 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 348 " <SELECT id=\"state\"/>" | 338 " <SELECT id=\"state\"/>" |
| 349 " <OPTION value=\"CA\">California</OPTION>" | 339 " <OPTION value=\"CA\">California</OPTION>" |
| 350 " <OPTION value=\"TX\">Texas</OPTION>" | 340 " <OPTION value=\"TX\">Texas</OPTION>" |
| 351 " </SELECT>" | 341 " </SELECT>" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 366 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 356 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 367 FormManager::REQUIRE_NONE, | 357 FormManager::REQUIRE_NONE, |
| 368 FormManager::EXTRACT_VALUE, | 358 FormManager::EXTRACT_VALUE, |
| 369 &form)); | 359 &form)); |
| 370 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 360 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 371 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 361 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 372 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 362 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 373 | 363 |
| 374 const std::vector<FormField>& fields = form.fields; | 364 const std::vector<FormField>& fields = form.fields; |
| 375 ASSERT_EQ(3U, fields.size()); | 365 ASSERT_EQ(3U, fields.size()); |
| 376 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 366 |
| 377 FormField(string16(), | 367 FormField expected; |
| 378 ASCIIToUTF16("firstname"), | 368 expected.name = ASCIIToUTF16("firstname"); |
| 379 ASCIIToUTF16("John"), | 369 expected.value = ASCIIToUTF16("John"); |
| 380 ASCIIToUTF16("text"), | 370 expected.form_control_type = ASCIIToUTF16("text"); |
| 381 WebInputElement::defaultMaxLength(), | 371 expected.max_length = WebInputElement::defaultMaxLength(); |
| 382 false))); | 372 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 383 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 373 |
| 384 FormField(string16(), | 374 expected.name = ASCIIToUTF16("lastname"); |
| 385 ASCIIToUTF16("lastname"), | 375 expected.value = ASCIIToUTF16("Smith"); |
| 386 ASCIIToUTF16("Smith"), | 376 expected.form_control_type = ASCIIToUTF16("text"); |
| 387 ASCIIToUTF16("text"), | 377 expected.max_length = WebInputElement::defaultMaxLength(); |
| 388 WebInputElement::defaultMaxLength(), | 378 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 389 false))); | 379 |
| 390 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 380 expected.name = ASCIIToUTF16("state"); |
| 391 FormField(string16(), | 381 expected.value = ASCIIToUTF16("CA"); |
| 392 ASCIIToUTF16("state"), | 382 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 393 ASCIIToUTF16("CA"), | 383 expected.max_length = 0; |
| 394 ASCIIToUTF16("select-one"), | 384 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 395 0, | |
| 396 false))); | |
| 397 } | 385 } |
| 398 | 386 |
| 399 TEST_F(FormManagerTest, ExtractForms) { | 387 TEST_F(FormManagerTest, ExtractForms) { |
| 400 ExpectJohnSmithLabels( | 388 ExpectJohnSmithLabels( |
| 401 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 389 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 402 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 390 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 403 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 391 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 404 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 392 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
| 405 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 393 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 406 "</FORM>"); | 394 "</FORM>"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 429 ASSERT_EQ(2U, forms.size()); | 417 ASSERT_EQ(2U, forms.size()); |
| 430 | 418 |
| 431 // First form. | 419 // First form. |
| 432 const FormData& form = forms[0]; | 420 const FormData& form = forms[0]; |
| 433 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 421 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 434 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 422 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 435 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 423 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 436 | 424 |
| 437 const std::vector<FormField>& fields = form.fields; | 425 const std::vector<FormField>& fields = form.fields; |
| 438 ASSERT_EQ(3U, fields.size()); | 426 ASSERT_EQ(3U, fields.size()); |
| 439 EXPECT_EQ(FormField(string16(), | 427 |
| 440 ASCIIToUTF16("firstname"), | 428 FormField expected; |
| 441 ASCIIToUTF16("John"), | 429 expected.form_control_type = ASCIIToUTF16("text"); |
| 442 ASCIIToUTF16("text"), | 430 expected.max_length = WebInputElement::defaultMaxLength(); |
| 443 WebInputElement::defaultMaxLength(), | 431 |
| 444 false), | 432 expected.name = ASCIIToUTF16("firstname"); |
| 445 fields[0]); | 433 expected.value = ASCIIToUTF16("John"); |
| 446 EXPECT_EQ(FormField(string16(), | 434 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 447 ASCIIToUTF16("lastname"), | 435 |
| 448 ASCIIToUTF16("Smith"), | 436 expected.name = ASCIIToUTF16("lastname"); |
| 449 ASCIIToUTF16("text"), | 437 expected.value = ASCIIToUTF16("Smith"); |
| 450 WebInputElement::defaultMaxLength(), | 438 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 451 false), | 439 |
| 452 fields[1]); | 440 expected.name = ASCIIToUTF16("email"); |
| 453 EXPECT_EQ(FormField(string16(), | 441 expected.value = ASCIIToUTF16("john@example.com"); |
| 454 ASCIIToUTF16("email"), | 442 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 455 ASCIIToUTF16("john@example.com"), | |
| 456 ASCIIToUTF16("text"), | |
| 457 WebInputElement::defaultMaxLength(), | |
| 458 false), | |
| 459 fields[2]); | |
| 460 | 443 |
| 461 // Second form. | 444 // Second form. |
| 462 const FormData& form2 = forms[1]; | 445 const FormData& form2 = forms[1]; |
| 463 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); | 446 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); |
| 464 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 447 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 465 EXPECT_EQ(GURL("http://zoo.com"), form2.action); | 448 EXPECT_EQ(GURL("http://zoo.com"), form2.action); |
| 466 | 449 |
| 467 const std::vector<FormField>& fields2 = form2.fields; | 450 const std::vector<FormField>& fields2 = form2.fields; |
| 468 ASSERT_EQ(3U, fields2.size()); | 451 ASSERT_EQ(3U, fields2.size()); |
| 469 EXPECT_EQ(FormField(string16(), | 452 |
| 470 ASCIIToUTF16("firstname"), | 453 expected.name = ASCIIToUTF16("firstname"); |
| 471 ASCIIToUTF16("Jack"), | 454 expected.value = ASCIIToUTF16("Jack"); |
| 472 ASCIIToUTF16("text"), | 455 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 473 WebInputElement::defaultMaxLength(), | 456 |
| 474 false), | 457 expected.name = ASCIIToUTF16("lastname"); |
| 475 fields2[0]); | 458 expected.value = ASCIIToUTF16("Adams"); |
| 476 EXPECT_EQ(FormField(string16(), | 459 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 477 ASCIIToUTF16("lastname"), | 460 |
| 478 ASCIIToUTF16("Adams"), | 461 expected.name = ASCIIToUTF16("email"); |
| 479 ASCIIToUTF16("text"), | 462 expected.value = ASCIIToUTF16("jack@example.com"); |
| 480 WebInputElement::defaultMaxLength(), | 463 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 481 false), | |
| 482 fields2[1]); | |
| 483 EXPECT_EQ(FormField(string16(), | |
| 484 ASCIIToUTF16("email"), | |
| 485 ASCIIToUTF16("jack@example.com"), | |
| 486 ASCIIToUTF16("text"), | |
| 487 WebInputElement::defaultMaxLength(), | |
| 488 false), | |
| 489 fields[2]); | |
| 490 } | 464 } |
| 491 | 465 |
| 492 // We should not extract a form if it has too few fillable fields. | 466 // We should not extract a form if it has too few fillable fields. |
| 493 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { | 467 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { |
| 494 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 468 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 495 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 469 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 496 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 470 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 497 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 471 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 498 "</FORM>"); | 472 "</FORM>"); |
| 499 | 473 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 WebFrame* web_frame = GetMainFrame(); | 522 WebFrame* web_frame = GetMainFrame(); |
| 549 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 523 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 550 | 524 |
| 551 WebVector<WebFormElement> web_forms; | 525 WebVector<WebFormElement> web_forms; |
| 552 web_frame->document().forms(web_forms); | 526 web_frame->document().forms(web_forms); |
| 553 ASSERT_EQ(1U, web_forms.size()); | 527 ASSERT_EQ(1U, web_forms.size()); |
| 554 WebFormElement web_form = web_forms[0]; | 528 WebFormElement web_form = web_forms[0]; |
| 555 | 529 |
| 556 FormData form; | 530 FormData form; |
| 557 EXPECT_TRUE(FormManager::WebFormElementToFormData( | 531 EXPECT_TRUE(FormManager::WebFormElementToFormData( |
| 558 web_form, FormManager::REQUIRE_AUTOCOMPLETE, FormManager::EXTRACT_NONE, | 532 web_form, FormManager::REQUIRE_AUTOCOMPLETE, FormManager::EXTRACT_VALUE, |
| 559 &form)); | 533 &form)); |
| 560 | 534 |
| 561 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 535 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 562 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 536 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 563 EXPECT_EQ(GURL("http://abc.com"), form.action); | 537 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 564 | 538 |
| 565 const std::vector<FormField>& fields = form.fields; | 539 const std::vector<FormField>& fields = form.fields; |
| 566 ASSERT_EQ(3U, fields.size()); | 540 ASSERT_EQ(3U, fields.size()); |
| 567 EXPECT_EQ(FormField(string16(), | 541 |
| 568 ASCIIToUTF16("middlename"), | 542 FormField expected; |
| 569 ASCIIToUTF16("Jack"), | 543 expected.form_control_type = ASCIIToUTF16("text"); |
| 570 ASCIIToUTF16("text"), | 544 expected.max_length = WebInputElement::defaultMaxLength(); |
| 571 WebInputElement::defaultMaxLength(), | 545 |
| 572 false), | 546 expected.name = ASCIIToUTF16("middlename"); |
| 573 fields[0]); | 547 expected.value = ASCIIToUTF16("Jack"); |
| 574 EXPECT_EQ(FormField(string16(), | 548 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 575 ASCIIToUTF16("lastname"), | 549 |
| 576 ASCIIToUTF16("Smith"), | 550 expected.name = ASCIIToUTF16("lastname"); |
| 577 ASCIIToUTF16("text"), | 551 expected.value = ASCIIToUTF16("Smith"); |
| 578 WebInputElement::defaultMaxLength(), | 552 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 579 false), | 553 |
| 580 fields[1]); | 554 expected.name = ASCIIToUTF16("email"); |
| 581 EXPECT_EQ(FormField(string16(), | 555 expected.value = ASCIIToUTF16("john@example.com"); |
| 582 ASCIIToUTF16("email"), | 556 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 583 ASCIIToUTF16("john@example.com"), | |
| 584 ASCIIToUTF16("text"), | |
| 585 WebInputElement::defaultMaxLength(), | |
| 586 false), | |
| 587 fields[2]); | |
| 588 } | 557 } |
| 589 } | 558 } |
| 590 | 559 |
| 591 TEST_F(FormManagerTest, WebFormElementToFormDataEnabled) { | 560 TEST_F(FormManagerTest, WebFormElementToFormDataEnabled) { |
| 592 // The firstname element is not enabled due to disabled being set. | 561 // The firstname element is not enabled due to disabled being set. |
| 593 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" | 562 LoadHTML("<FORM name=\"TestForm\" action=\"http://xyz.com\" method=\"post\">" |
| 594 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" | 563 " <INPUT disabled type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 595 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" | 564 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" |
| 596 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 565 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 597 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" | 566 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" |
| 598 " <INPUT type=\"submit\" name=\"submit\" value=\"Send\"/>" | 567 " <INPUT type=\"submit\" name=\"submit\" value=\"Send\"/>" |
| 599 "</FORM>"); | 568 "</FORM>"); |
| 600 | 569 |
| 601 WebFrame* web_frame = GetMainFrame(); | 570 WebFrame* web_frame = GetMainFrame(); |
| 602 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 571 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 603 | 572 |
| 604 WebVector<WebFormElement> web_forms; | 573 WebVector<WebFormElement> web_forms; |
| 605 web_frame->document().forms(web_forms); | 574 web_frame->document().forms(web_forms); |
| 606 ASSERT_EQ(1U, web_forms.size()); | 575 ASSERT_EQ(1U, web_forms.size()); |
| 607 WebFormElement web_form = web_forms[0]; | 576 WebFormElement web_form = web_forms[0]; |
| 608 | 577 |
| 609 FormData form; | 578 FormData form; |
| 610 EXPECT_TRUE(FormManager::WebFormElementToFormData( | 579 EXPECT_TRUE(FormManager::WebFormElementToFormData( |
| 611 web_form, FormManager::REQUIRE_ENABLED, FormManager::EXTRACT_NONE, | 580 web_form, FormManager::REQUIRE_ENABLED, FormManager::EXTRACT_VALUE, |
| 612 &form)); | 581 &form)); |
| 613 | 582 |
| 614 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 583 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 615 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 584 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 616 EXPECT_EQ(GURL("http://xyz.com"), form.action); | 585 EXPECT_EQ(GURL("http://xyz.com"), form.action); |
| 617 | 586 |
| 618 const std::vector<FormField>& fields = form.fields; | 587 const std::vector<FormField>& fields = form.fields; |
| 619 ASSERT_EQ(3U, fields.size()); | 588 ASSERT_EQ(3U, fields.size()); |
| 620 EXPECT_EQ(FormField(string16(), | 589 |
| 621 ASCIIToUTF16("middlename"), | 590 FormField expected; |
| 622 ASCIIToUTF16("Jack"), | 591 expected.form_control_type = ASCIIToUTF16("text"); |
| 623 ASCIIToUTF16("text"), | 592 expected.max_length = WebInputElement::defaultMaxLength(); |
| 624 WebInputElement::defaultMaxLength(), | 593 |
| 625 false), | 594 expected.name = ASCIIToUTF16("middlename"); |
| 626 fields[0]); | 595 expected.value = ASCIIToUTF16("Jack"); |
| 627 EXPECT_EQ(FormField(string16(), | 596 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 628 ASCIIToUTF16("lastname"), | 597 |
| 629 ASCIIToUTF16("Smith"), | 598 expected.name = ASCIIToUTF16("lastname"); |
| 630 ASCIIToUTF16("text"), | 599 expected.value = ASCIIToUTF16("Smith"); |
| 631 WebInputElement::defaultMaxLength(), | 600 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 632 false), | 601 |
| 633 fields[1]); | 602 expected.name = ASCIIToUTF16("email"); |
| 634 EXPECT_EQ(FormField(string16(), | 603 expected.value = ASCIIToUTF16("jack@example.com"); |
| 635 ASCIIToUTF16("email"), | 604 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 636 ASCIIToUTF16("jack@example.com"), | |
| 637 ASCIIToUTF16("text"), | |
| 638 WebInputElement::defaultMaxLength(), | |
| 639 false), | |
| 640 fields[2]); | |
| 641 } | 605 } |
| 642 | 606 |
| 643 TEST_F(FormManagerTest, FindForm) { | 607 TEST_F(FormManagerTest, FindForm) { |
| 644 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 608 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 645 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 609 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 646 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 610 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 647 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 611 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
| 648 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 612 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 649 "</FORM>"); | 613 "</FORM>"); |
| 650 | 614 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 663 // Find the form and verify it's the correct form. | 627 // Find the form and verify it's the correct form. |
| 664 FormData form; | 628 FormData form; |
| 665 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 629 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 666 &form)); | 630 &form)); |
| 667 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 631 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 668 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 632 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 669 EXPECT_EQ(GURL("http://buh.com"), form.action); | 633 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 670 | 634 |
| 671 const std::vector<FormField>& fields = form.fields; | 635 const std::vector<FormField>& fields = form.fields; |
| 672 ASSERT_EQ(3U, fields.size()); | 636 ASSERT_EQ(3U, fields.size()); |
| 673 EXPECT_EQ(FormField(string16(), | 637 |
| 674 ASCIIToUTF16("firstname"), | 638 FormField expected; |
| 675 ASCIIToUTF16("John"), | 639 expected.form_control_type = ASCIIToUTF16("text"); |
| 676 ASCIIToUTF16("text"), | 640 expected.max_length = WebInputElement::defaultMaxLength(); |
| 677 WebInputElement::defaultMaxLength(), | 641 |
| 678 false), | 642 expected.name = ASCIIToUTF16("firstname"); |
| 679 fields[0]); | 643 expected.value = ASCIIToUTF16("John"); |
| 680 EXPECT_EQ(FormField(string16(), | 644 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 681 ASCIIToUTF16("lastname"), | 645 |
| 682 ASCIIToUTF16("Smith"), | 646 expected.name = ASCIIToUTF16("lastname"); |
| 683 ASCIIToUTF16("text"), | 647 expected.value = ASCIIToUTF16("Smith"); |
| 684 WebInputElement::defaultMaxLength(), | 648 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 685 false), | 649 |
| 686 fields[1]); | 650 expected.name = ASCIIToUTF16("email"); |
| 687 EXPECT_EQ(FormField(string16(), | 651 expected.value = ASCIIToUTF16("john@example.com"); |
| 688 ASCIIToUTF16("email"), | 652 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 689 ASCIIToUTF16("john@example.com"), | |
| 690 ASCIIToUTF16("text"), | |
| 691 WebInputElement::defaultMaxLength(), | |
| 692 false), | |
| 693 fields[2]); | |
| 694 } | 653 } |
| 695 | 654 |
| 696 TEST_F(FormManagerTest, FillForm) { | 655 TEST_F(FormManagerTest, FillForm) { |
| 697 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 656 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 698 " <INPUT type=\"text\" id=\"firstname\"/>" | 657 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 699 " <INPUT type=\"text\" id=\"lastname\"/>" | 658 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 700 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 659 " <INPUT type=\"hidden\" id=\"imhidden\"/>" |
| 701 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 660 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" |
| 702 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" | 661 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" |
| 703 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" | 662 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 723 // Find the form that contains the input element. | 682 // Find the form that contains the input element. |
| 724 FormData form; | 683 FormData form; |
| 725 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 684 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 726 &form)); | 685 &form)); |
| 727 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 686 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 728 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 687 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 729 EXPECT_EQ(GURL("http://buh.com"), form.action); | 688 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 730 | 689 |
| 731 const std::vector<FormField>& fields = form.fields; | 690 const std::vector<FormField>& fields = form.fields; |
| 732 ASSERT_EQ(8U, fields.size()); | 691 ASSERT_EQ(8U, fields.size()); |
| 733 EXPECT_EQ(FormField(string16(), | 692 |
| 734 ASCIIToUTF16("firstname"), | 693 FormField expected; |
| 735 string16(), | 694 expected.form_control_type = ASCIIToUTF16("text"); |
| 736 ASCIIToUTF16("text"), | 695 expected.max_length = WebInputElement::defaultMaxLength(); |
| 737 WebInputElement::defaultMaxLength(), | 696 |
| 738 false), | 697 expected.name = ASCIIToUTF16("firstname"); |
| 739 fields[0]); | 698 expected.value = string16(); |
| 740 EXPECT_EQ(FormField(string16(), | 699 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 741 ASCIIToUTF16("lastname"), | 700 |
| 742 string16(), | 701 expected.name = ASCIIToUTF16("lastname"); |
| 743 ASCIIToUTF16("text"), | 702 expected.value = string16(); |
| 744 WebInputElement::defaultMaxLength(), | 703 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 745 false), | 704 |
| 746 fields[1]); | 705 expected.name = ASCIIToUTF16("notempty"); |
| 747 EXPECT_EQ(FormField(string16(), | 706 expected.value = ASCIIToUTF16("Hi"); |
| 748 ASCIIToUTF16("notempty"), | 707 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 749 ASCIIToUTF16("Hi"), | 708 |
| 750 ASCIIToUTF16("text"), | 709 expected.name = ASCIIToUTF16("noautocomplete"); |
| 751 WebInputElement::defaultMaxLength(), | 710 expected.value = string16(); |
| 752 false), | 711 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 753 fields[2]); | 712 |
| 754 EXPECT_EQ(FormField(string16(), | 713 expected.name = ASCIIToUTF16("notenabled"); |
| 755 ASCIIToUTF16("noautocomplete"), | 714 expected.value = string16(); |
| 756 string16(), | 715 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); |
| 757 ASCIIToUTF16("text"), | 716 |
| 758 WebInputElement::defaultMaxLength(), | 717 expected.name = ASCIIToUTF16("readonly"); |
| 759 false), | 718 expected.value = string16(); |
| 760 fields[3]); | 719 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); |
| 761 EXPECT_EQ(FormField(string16(), | 720 |
| 762 ASCIIToUTF16("notenabled"), | 721 expected.name = ASCIIToUTF16("invisible"); |
| 763 string16(), | 722 expected.value = string16(); |
| 764 ASCIIToUTF16("text"), | 723 EXPECT_FORM_FIELD_EQUALS(expected, fields[6]); |
| 765 WebInputElement::defaultMaxLength(), | 724 |
| 766 false), | 725 expected.name = ASCIIToUTF16("displaynone"); |
| 767 fields[4]); | 726 expected.value = string16(); |
| 768 EXPECT_EQ(FormField(string16(), | 727 EXPECT_FORM_FIELD_EQUALS(expected, fields[7]); |
| 769 ASCIIToUTF16("readonly"), | |
| 770 string16(), | |
| 771 ASCIIToUTF16("text"), | |
| 772 WebInputElement::defaultMaxLength(), | |
| 773 false), | |
| 774 fields[5]); | |
| 775 EXPECT_EQ(FormField(string16(), | |
| 776 ASCIIToUTF16("invisible"), | |
| 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 | 728 |
| 790 // Fill the form. | 729 // Fill the form. |
| 791 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 730 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 792 form.fields[1].value = ASCIIToUTF16("Earp"); | 731 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 793 form.fields[2].value = ASCIIToUTF16("Alpha"); | 732 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 794 form.fields[3].value = ASCIIToUTF16("Beta"); | 733 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 795 form.fields[4].value = ASCIIToUTF16("Gamma"); | 734 form.fields[4].value = ASCIIToUTF16("Gamma"); |
| 796 form.fields[5].value = ASCIIToUTF16("Delta"); | 735 form.fields[5].value = ASCIIToUTF16("Delta"); |
| 797 form.fields[6].value = ASCIIToUTF16("Epsilon"); | 736 form.fields[6].value = ASCIIToUTF16("Epsilon"); |
| 798 form.fields[7].value = ASCIIToUTF16("Zeta"); | 737 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. | 813 // Find the form that contains the input element. |
| 875 FormData form; | 814 FormData form; |
| 876 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 815 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 877 &form)); | 816 &form)); |
| 878 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 817 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 879 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 818 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 880 EXPECT_EQ(GURL("http://buh.com"), form.action); | 819 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 881 | 820 |
| 882 const std::vector<FormField>& fields = form.fields; | 821 const std::vector<FormField>& fields = form.fields; |
| 883 ASSERT_EQ(5U, fields.size()); | 822 ASSERT_EQ(5U, fields.size()); |
| 884 EXPECT_EQ(FormField(string16(), | 823 |
| 885 ASCIIToUTF16("firstname"), | 824 FormField expected; |
| 886 string16(), | 825 expected.form_control_type = ASCIIToUTF16("text"); |
| 887 ASCIIToUTF16("text"), | 826 expected.max_length = WebInputElement::defaultMaxLength(); |
| 888 WebInputElement::defaultMaxLength(), | 827 |
| 889 false), | 828 expected.name = ASCIIToUTF16("firstname"); |
| 890 fields[0]); | 829 expected.value = string16(); |
| 891 EXPECT_EQ(FormField(string16(), | 830 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 892 ASCIIToUTF16("lastname"), | 831 |
| 893 string16(), | 832 expected.name = ASCIIToUTF16("lastname"); |
| 894 ASCIIToUTF16("text"), | 833 expected.value = string16(); |
| 895 WebInputElement::defaultMaxLength(), | 834 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 896 false), | 835 |
| 897 fields[1]); | 836 expected.name = ASCIIToUTF16("notempty"); |
| 898 EXPECT_EQ(FormField(string16(), | 837 expected.value = ASCIIToUTF16("Hi"); |
| 899 ASCIIToUTF16("notempty"), | 838 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 900 ASCIIToUTF16("Hi"), | 839 |
| 901 ASCIIToUTF16("text"), | 840 expected.name = ASCIIToUTF16("noautocomplete"); |
| 902 WebInputElement::defaultMaxLength(), | 841 expected.value = string16(); |
| 903 false), | 842 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 904 fields[2]); | 843 |
| 905 EXPECT_EQ(FormField(string16(), | 844 expected.name = ASCIIToUTF16("notenabled"); |
| 906 ASCIIToUTF16("noautocomplete"), | 845 expected.value = string16(); |
| 907 string16(), | 846 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); |
| 908 ASCIIToUTF16("text"), | |
| 909 WebInputElement::defaultMaxLength(), | |
| 910 false), | |
| 911 fields[3]); | |
| 912 EXPECT_EQ(FormField(string16(), | |
| 913 ASCIIToUTF16("notenabled"), | |
| 914 string16(), | |
| 915 ASCIIToUTF16("text"), | |
| 916 WebInputElement::defaultMaxLength(), | |
| 917 false), | |
| 918 fields[4]); | |
| 919 | 847 |
| 920 // Preview the form. | 848 // Preview the form. |
| 921 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 849 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 922 form.fields[1].value = ASCIIToUTF16("Earp"); | 850 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 923 form.fields[2].value = ASCIIToUTF16("Alpha"); | 851 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 924 form.fields[3].value = ASCIIToUTF16("Beta"); | 852 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 925 form.fields[4].value = ASCIIToUTF16("Gamma"); | 853 form.fields[4].value = ASCIIToUTF16("Gamma"); |
| 926 form_manager.PreviewForm(form, input_element); | 854 form_manager.PreviewForm(form, input_element); |
| 927 | 855 |
| 928 // Verify the previewed elements. | 856 // Verify the previewed elements. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 " </TR>" | 1044 " </TR>" |
| 1117 " <TR>" | 1045 " <TR>" |
| 1118 " <TD></TD>" | 1046 " <TD></TD>" |
| 1119 " <TD>" | 1047 " <TD>" |
| 1120 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1048 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 1121 " </TD>" | 1049 " </TD>" |
| 1122 " </TR>" | 1050 " </TR>" |
| 1123 "</TABLE>" | 1051 "</TABLE>" |
| 1124 "</FORM>"); | 1052 "</FORM>"); |
| 1125 } | 1053 } |
| 1054 |
| 1126 TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { | 1055 TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { |
| 1127 std::vector<string16> labels, names, values; | 1056 std::vector<string16> labels, names, values; |
| 1128 | 1057 |
| 1129 labels.push_back(ASCIIToUTF16("First name: Bogus")); | 1058 labels.push_back(ASCIIToUTF16("First name: Bogus")); |
| 1130 names.push_back(ASCIIToUTF16("firstname")); | 1059 names.push_back(ASCIIToUTF16("firstname")); |
| 1131 values.push_back(ASCIIToUTF16("John")); | 1060 values.push_back(ASCIIToUTF16("John")); |
| 1132 | 1061 |
| 1133 labels.push_back(ASCIIToUTF16("Last name:")); | 1062 labels.push_back(ASCIIToUTF16("Last name:")); |
| 1134 names.push_back(ASCIIToUTF16("lastname")); | 1063 names.push_back(ASCIIToUTF16("lastname")); |
| 1135 values.push_back(ASCIIToUTF16("Smith")); | 1064 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. | 1768 // Find the form that contains the input element. |
| 1840 FormData form; | 1769 FormData form; |
| 1841 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1770 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1842 &form)); | 1771 &form)); |
| 1843 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1772 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1844 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1773 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1845 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1774 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1846 | 1775 |
| 1847 const std::vector<FormField>& fields = form.fields; | 1776 const std::vector<FormField>& fields = form.fields; |
| 1848 ASSERT_EQ(3U, fields.size()); | 1777 ASSERT_EQ(3U, fields.size()); |
| 1849 EXPECT_EQ(FormField(string16(), | 1778 |
| 1850 ASCIIToUTF16("firstname"), | 1779 FormField expected; |
| 1851 string16(), | 1780 expected.form_control_type = ASCIIToUTF16("text"); |
| 1852 ASCIIToUTF16("text"), | 1781 |
| 1853 5, | 1782 expected.name = ASCIIToUTF16("firstname"); |
| 1854 false), | 1783 expected.max_length = 5; |
| 1855 fields[0]); | 1784 expected.is_autofilled = false; |
| 1856 EXPECT_EQ(FormField(string16(), | 1785 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 1857 ASCIIToUTF16("lastname"), | 1786 |
| 1858 string16(), | 1787 expected.name = ASCIIToUTF16("lastname"); |
| 1859 ASCIIToUTF16("text"), | 1788 expected.max_length = 7; |
| 1860 7, | 1789 expected.is_autofilled = false; |
| 1861 false), | 1790 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 1862 fields[1]); | 1791 |
| 1863 EXPECT_EQ(FormField(string16(), | 1792 expected.name = ASCIIToUTF16("email"); |
| 1864 ASCIIToUTF16("email"), | 1793 expected.max_length = 9; |
| 1865 string16(), | 1794 expected.is_autofilled = false; |
| 1866 ASCIIToUTF16("text"), | 1795 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 1867 9, | |
| 1868 false), | |
| 1869 fields[2]); | |
| 1870 | 1796 |
| 1871 // Fill the form. | 1797 // Fill the form. |
| 1872 form.fields[0].value = ASCIIToUTF16("Brother"); | 1798 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 1873 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 1799 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 1874 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 1800 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 1875 form_manager.FillForm(form, WebNode()); | 1801 form_manager.FillForm(form, WebNode()); |
| 1876 | 1802 |
| 1877 // Find the newly-filled form that contains the input element. | 1803 // Find the newly-filled form that contains the input element. |
| 1878 FormData form2; | 1804 FormData form2; |
| 1879 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1805 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1880 &form2)); | 1806 &form2)); |
| 1881 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1807 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1882 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1808 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1883 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1809 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1884 | 1810 |
| 1885 const std::vector<FormField>& fields2 = form2.fields; | 1811 const std::vector<FormField>& fields2 = form2.fields; |
| 1886 ASSERT_EQ(3U, fields2.size()); | 1812 ASSERT_EQ(3U, fields2.size()); |
| 1887 EXPECT_TRUE(fields2[0].StrictlyEqualsHack(FormField(string16(), | 1813 |
| 1888 ASCIIToUTF16("firstname"), | 1814 expected.form_control_type = ASCIIToUTF16("text"); |
| 1889 ASCIIToUTF16("Broth"), | 1815 |
| 1890 ASCIIToUTF16("text"), | 1816 expected.name = ASCIIToUTF16("firstname"); |
| 1891 5, | 1817 expected.value = ASCIIToUTF16("Broth"); |
| 1892 false))); | 1818 expected.max_length = 5; |
| 1893 EXPECT_TRUE(fields2[1].StrictlyEqualsHack(FormField(string16(), | 1819 expected.is_autofilled = true; |
| 1894 ASCIIToUTF16("lastname"), | 1820 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 1895 ASCIIToUTF16("Jonatha"), | 1821 |
| 1896 ASCIIToUTF16("text"), | 1822 expected.name = ASCIIToUTF16("lastname"); |
| 1897 7, | 1823 expected.value = ASCIIToUTF16("Jonatha"); |
| 1898 false))); | 1824 expected.max_length = 7; |
| 1899 EXPECT_TRUE(fields2[2].StrictlyEqualsHack(FormField(string16(), | 1825 expected.is_autofilled = true; |
| 1900 ASCIIToUTF16("email"), | 1826 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 1901 ASCIIToUTF16("brotherj@"), | 1827 |
| 1902 ASCIIToUTF16("text"), | 1828 expected.name = ASCIIToUTF16("email"); |
| 1903 9, | 1829 expected.value = ASCIIToUTF16("brotherj@"); |
| 1904 false))); | 1830 expected.max_length = 9; |
| 1831 expected.is_autofilled = true; |
| 1832 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 1905 } | 1833 } |
| 1906 | 1834 |
| 1907 // This test uses negative values of the maxlength attribute for input elements. | 1835 // 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 | 1836 // In this case, the maxlength of the input elements is set to the default |
| 1909 // maxlength (defined in WebKit.) | 1837 // maxlength (defined in WebKit.) |
| 1910 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { | 1838 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { |
| 1911 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1839 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 1912 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" | 1840 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" |
| 1913 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" | 1841 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" |
| 1914 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" | 1842 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1930 // Find the form that contains the input element. | 1858 // Find the form that contains the input element. |
| 1931 FormData form; | 1859 FormData form; |
| 1932 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1860 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1933 &form)); | 1861 &form)); |
| 1934 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1862 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1935 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1863 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1936 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1864 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1937 | 1865 |
| 1938 const std::vector<FormField>& fields = form.fields; | 1866 const std::vector<FormField>& fields = form.fields; |
| 1939 ASSERT_EQ(3U, fields.size()); | 1867 ASSERT_EQ(3U, fields.size()); |
| 1940 EXPECT_EQ(FormField(string16(), | 1868 |
| 1941 ASCIIToUTF16("firstname"), | 1869 FormField expected; |
| 1942 string16(), | 1870 expected.form_control_type = ASCIIToUTF16("text"); |
| 1943 ASCIIToUTF16("text"), | 1871 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1944 WebInputElement::defaultMaxLength(), | 1872 |
| 1945 false), | 1873 expected.name = ASCIIToUTF16("firstname"); |
| 1946 fields[0]); | 1874 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 1947 EXPECT_EQ(FormField(string16(), | 1875 |
| 1948 ASCIIToUTF16("lastname"), | 1876 expected.name = ASCIIToUTF16("lastname"); |
| 1949 string16(), | 1877 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 1950 ASCIIToUTF16("text"), | 1878 |
| 1951 WebInputElement::defaultMaxLength(), | 1879 expected.name = ASCIIToUTF16("email"); |
| 1952 false), | 1880 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 1953 fields[1]); | |
| 1954 EXPECT_EQ(FormField(string16(), | |
| 1955 ASCIIToUTF16("email"), | |
| 1956 string16(), | |
| 1957 ASCIIToUTF16("text"), | |
| 1958 WebInputElement::defaultMaxLength(), | |
| 1959 false), | |
| 1960 fields[2]); | |
| 1961 | 1881 |
| 1962 // Fill the form. | 1882 // Fill the form. |
| 1963 form.fields[0].value = ASCIIToUTF16("Brother"); | 1883 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 1964 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 1884 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 1965 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 1885 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 1966 form_manager.FillForm(form, WebNode()); | 1886 form_manager.FillForm(form, WebNode()); |
| 1967 | 1887 |
| 1968 // Find the newly-filled form that contains the input element. | 1888 // Find the newly-filled form that contains the input element. |
| 1969 FormData form2; | 1889 FormData form2; |
| 1970 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1890 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 1971 &form2)); | 1891 &form2)); |
| 1972 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1892 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1973 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1893 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1974 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1894 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1975 | 1895 |
| 1976 const std::vector<FormField>& fields2 = form2.fields; | 1896 const std::vector<FormField>& fields2 = form2.fields; |
| 1977 ASSERT_EQ(3U, fields2.size()); | 1897 ASSERT_EQ(3U, fields2.size()); |
| 1978 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 1898 |
| 1979 FormField(string16(), | 1899 expected.name = ASCIIToUTF16("firstname"); |
| 1980 ASCIIToUTF16("firstname"), | 1900 expected.value = ASCIIToUTF16("Brother"); |
| 1981 ASCIIToUTF16("Brother"), | 1901 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 1982 ASCIIToUTF16("text"), | 1902 |
| 1983 WebInputElement::defaultMaxLength(), | 1903 expected.name = ASCIIToUTF16("lastname"); |
| 1984 false))); | 1904 expected.value = ASCIIToUTF16("Jonathan"); |
| 1985 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 1905 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 1986 FormField(string16(), | 1906 |
| 1987 ASCIIToUTF16("lastname"), | 1907 expected.name = ASCIIToUTF16("email"); |
| 1988 ASCIIToUTF16("Jonathan"), | 1908 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 1989 ASCIIToUTF16("text"), | 1909 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 1990 WebInputElement::defaultMaxLength(), | |
| 1991 false))); | |
| 1992 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | |
| 1993 FormField(string16(), | |
| 1994 ASCIIToUTF16("email"), | |
| 1995 ASCIIToUTF16("brotherj@example.com"), | |
| 1996 ASCIIToUTF16("text"), | |
| 1997 WebInputElement::defaultMaxLength(), | |
| 1998 false))); | |
| 1999 } | 1910 } |
| 2000 | 1911 |
| 2001 // This test sends a FormData object to FillForm with more fields than are in | 1912 // 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 | 1913 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2003 // match between the FormData object and the WebFormElement. | 1914 // match between the FormData object and the WebFormElement. |
| 2004 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { | 1915 TEST_F(FormManagerTest, FillFormMoreFormDataFields) { |
| 2005 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1916 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2006 " <INPUT type=\"text\" id=\"firstname\"/>" | 1917 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2007 " <INPUT type=\"text\" id=\"middlename\"/>" | 1918 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2008 " <INPUT type=\"text\" id=\"lastname\"/>" | 1919 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2020 // After the field modification, the fields in |form| will look like: | 1931 // After the field modification, the fields in |form| will look like: |
| 2021 // prefix | 1932 // prefix |
| 2022 // firstname | 1933 // firstname |
| 2023 // hidden | 1934 // hidden |
| 2024 // middlename | 1935 // middlename |
| 2025 // second | 1936 // second |
| 2026 // lastname | 1937 // lastname |
| 2027 // postfix | 1938 // postfix |
| 2028 FormData* form = &forms[0]; | 1939 FormData* form = &forms[0]; |
| 2029 | 1940 |
| 2030 FormField field1(string16(), | 1941 FormField field1; |
| 2031 ASCIIToUTF16("prefix"), | 1942 field1.name = ASCIIToUTF16("prefix"); |
| 2032 string16(), | 1943 field1.form_control_type = ASCIIToUTF16("text"); |
| 2033 ASCIIToUTF16("text"), | 1944 field1.max_length = WebInputElement::defaultMaxLength(); |
| 2034 WebInputElement::defaultMaxLength(), | |
| 2035 false); | |
| 2036 form->fields.insert(form->fields.begin(), field1); | 1945 form->fields.insert(form->fields.begin(), field1); |
| 2037 | 1946 |
| 2038 FormField field2(string16(), | 1947 FormField field2; |
| 2039 ASCIIToUTF16("hidden"), | 1948 field2.name = ASCIIToUTF16("hidden"); |
| 2040 string16(), | 1949 field2.form_control_type = ASCIIToUTF16("text"); |
| 2041 ASCIIToUTF16("text"), | 1950 field2.max_length = WebInputElement::defaultMaxLength(); |
| 2042 WebInputElement::defaultMaxLength(), | |
| 2043 false); | |
| 2044 form->fields.insert(form->fields.begin() + 2, field2); | 1951 form->fields.insert(form->fields.begin() + 2, field2); |
| 2045 | 1952 |
| 2046 FormField field3(string16(), | 1953 FormField field3; |
| 2047 ASCIIToUTF16("second"), | 1954 field3.name = ASCIIToUTF16("second"); |
| 2048 string16(), | 1955 field3.form_control_type = ASCIIToUTF16("text"); |
| 2049 ASCIIToUTF16("text"), | 1956 field3.max_length = WebInputElement::defaultMaxLength(); |
| 2050 WebInputElement::defaultMaxLength(), | |
| 2051 false); | |
| 2052 form->fields.insert(form->fields.begin() + 4, field3); | 1957 form->fields.insert(form->fields.begin() + 4, field3); |
| 2053 | 1958 |
| 2054 FormField field4(string16(), | 1959 FormField field4; |
| 2055 ASCIIToUTF16("postfix"), | 1960 field4.name = ASCIIToUTF16("postfix"); |
| 2056 string16(), | 1961 field4.form_control_type = ASCIIToUTF16("text"); |
| 2057 ASCIIToUTF16("text"), | 1962 field4.max_length = WebInputElement::defaultMaxLength(); |
| 2058 WebInputElement::defaultMaxLength(), | |
| 2059 false); | |
| 2060 form->fields.insert(form->fields.begin() + 6, field4); | 1963 form->fields.insert(form->fields.begin() + 6, field4); |
| 2061 | 1964 |
| 2062 // Fill the form. | 1965 // Fill the form. |
| 2063 form->fields[0].value = ASCIIToUTF16("Alpha"); | 1966 form->fields[0].value = ASCIIToUTF16("Alpha"); |
| 2064 form->fields[1].value = ASCIIToUTF16("Brother"); | 1967 form->fields[1].value = ASCIIToUTF16("Brother"); |
| 2065 form->fields[2].value = ASCIIToUTF16("Abracadabra"); | 1968 form->fields[2].value = ASCIIToUTF16("Abracadabra"); |
| 2066 form->fields[3].value = ASCIIToUTF16("Joseph"); | 1969 form->fields[3].value = ASCIIToUTF16("Joseph"); |
| 2067 form->fields[4].value = ASCIIToUTF16("Beta"); | 1970 form->fields[4].value = ASCIIToUTF16("Beta"); |
| 2068 form->fields[5].value = ASCIIToUTF16("Jonathan"); | 1971 form->fields[5].value = ASCIIToUTF16("Jonathan"); |
| 2069 form->fields[6].value = ASCIIToUTF16("Omega"); | 1972 form->fields[6].value = ASCIIToUTF16("Omega"); |
| 2070 form_manager.FillForm(*form, WebNode()); | 1973 form_manager.FillForm(*form, WebNode()); |
| 2071 | 1974 |
| 2072 // Get the input element we want to find. | 1975 // Get the input element we want to find. |
| 2073 WebElement element = web_frame->document().getElementById("firstname"); | 1976 WebElement element = web_frame->document().getElementById("firstname"); |
| 2074 WebInputElement input_element = element.to<WebInputElement>(); | 1977 WebInputElement input_element = element.to<WebInputElement>(); |
| 2075 | 1978 |
| 2076 // Find the newly-filled form that contains the input element. | 1979 // Find the newly-filled form that contains the input element. |
| 2077 FormData form2; | 1980 FormData form2; |
| 2078 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 1981 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2079 &form2)); | 1982 &form2)); |
| 2080 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1983 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2081 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1984 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2082 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1985 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2083 | 1986 |
| 2084 const std::vector<FormField>& fields = form2.fields; | 1987 const std::vector<FormField>& fields = form2.fields; |
| 2085 ASSERT_EQ(3U, fields.size()); | 1988 ASSERT_EQ(3U, fields.size()); |
| 2086 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 1989 |
| 2087 FormField(string16(), | 1990 FormField expected; |
| 2088 ASCIIToUTF16("firstname"), | 1991 expected.form_control_type = ASCIIToUTF16("text"); |
| 2089 ASCIIToUTF16("Brother"), | 1992 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2090 ASCIIToUTF16("text"), | 1993 expected.is_autofilled = true; |
| 2091 WebInputElement::defaultMaxLength(), | 1994 |
| 2092 false))); | 1995 expected.name = ASCIIToUTF16("firstname"); |
| 2093 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 1996 expected.value = ASCIIToUTF16("Brother"); |
| 2094 FormField(string16(), | 1997 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2095 ASCIIToUTF16("middlename"), | 1998 |
| 2096 ASCIIToUTF16("Joseph"), | 1999 expected.name = ASCIIToUTF16("middlename"); |
| 2097 ASCIIToUTF16("text"), | 2000 expected.value = ASCIIToUTF16("Joseph"); |
| 2098 WebInputElement::defaultMaxLength(), | 2001 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2099 false))); | 2002 |
| 2100 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2003 expected.name = ASCIIToUTF16("lastname"); |
| 2101 FormField(string16(), | 2004 expected.value = ASCIIToUTF16("Jonathan"); |
| 2102 ASCIIToUTF16("lastname"), | 2005 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2103 ASCIIToUTF16("Jonathan"), | |
| 2104 ASCIIToUTF16("text"), | |
| 2105 WebInputElement::defaultMaxLength(), | |
| 2106 false))); | |
| 2107 } | 2006 } |
| 2108 | 2007 |
| 2109 // This test sends a FormData object to FillForm with fewer fields than are in | 2008 // 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 | 2009 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2111 // match between the FormData object and the WebFormElement. | 2010 // match between the FormData object and the WebFormElement. |
| 2112 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { | 2011 TEST_F(FormManagerTest, FillFormFewerFormDataFields) { |
| 2113 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2012 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2114 " <INPUT type=\"text\" id=\"prefix\"/>" | 2013 " <INPUT type=\"text\" id=\"prefix\"/>" |
| 2115 " <INPUT type=\"text\" id=\"firstname\"/>" | 2014 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2116 " <INPUT type=\"text\" id=\"hidden\"/>" | 2015 " <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. | 2051 // Find the newly-filled form that contains the input element. |
| 2153 FormData form2; | 2052 FormData form2; |
| 2154 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2053 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2155 &form2)); | 2054 &form2)); |
| 2156 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2055 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2157 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2056 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2158 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2057 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2159 | 2058 |
| 2160 const std::vector<FormField>& fields = form2.fields; | 2059 const std::vector<FormField>& fields = form2.fields; |
| 2161 ASSERT_EQ(7U, fields.size()); | 2060 ASSERT_EQ(7U, fields.size()); |
| 2162 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2061 |
| 2163 FormField(string16(), | 2062 FormField expected; |
| 2164 ASCIIToUTF16("prefix"), | 2063 expected.form_control_type = ASCIIToUTF16("text"); |
| 2165 string16(), | 2064 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2166 ASCIIToUTF16("text"), | 2065 |
| 2167 WebInputElement::defaultMaxLength(), | 2066 expected.name = ASCIIToUTF16("prefix"); |
| 2168 false))); | 2067 expected.value = string16(); |
| 2169 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2068 expected.is_autofilled = false; |
| 2170 FormField(string16(), | 2069 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2171 ASCIIToUTF16("firstname"), | 2070 |
| 2172 ASCIIToUTF16("Brother"), | 2071 expected.name = ASCIIToUTF16("firstname"); |
| 2173 ASCIIToUTF16("text"), | 2072 expected.value = ASCIIToUTF16("Brother"); |
| 2174 WebInputElement::defaultMaxLength(), | 2073 expected.is_autofilled = true; |
| 2175 false))); | 2074 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2176 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2075 |
| 2177 FormField(string16(), | 2076 expected.name = ASCIIToUTF16("hidden"); |
| 2178 ASCIIToUTF16("hidden"), | 2077 expected.value = string16(); |
| 2179 string16(), | 2078 expected.is_autofilled = false; |
| 2180 ASCIIToUTF16("text"), | 2079 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2181 WebInputElement::defaultMaxLength(), | 2080 |
| 2182 false))); | 2081 expected.name = ASCIIToUTF16("middlename"); |
| 2183 EXPECT_TRUE(fields[3].StrictlyEqualsHack( | 2082 expected.value = ASCIIToUTF16("Joseph"); |
| 2184 FormField(string16(), | 2083 expected.is_autofilled = true; |
| 2185 ASCIIToUTF16("middlename"), | 2084 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 2186 ASCIIToUTF16("Joseph"), | 2085 |
| 2187 ASCIIToUTF16("text"), | 2086 expected.name = ASCIIToUTF16("second"); |
| 2188 WebInputElement::defaultMaxLength(), | 2087 expected.value = string16(); |
| 2189 false))); | 2088 expected.is_autofilled = false; |
| 2190 EXPECT_TRUE(fields[4].StrictlyEqualsHack( | 2089 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); |
| 2191 FormField(string16(), | 2090 |
| 2192 ASCIIToUTF16("second"), | 2091 expected.name = ASCIIToUTF16("lastname"); |
| 2193 string16(), | 2092 expected.value = ASCIIToUTF16("Jonathan"); |
| 2194 ASCIIToUTF16("text"), | 2093 expected.is_autofilled = true; |
| 2195 WebInputElement::defaultMaxLength(), | 2094 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); |
| 2196 false))); | 2095 |
| 2197 EXPECT_TRUE(fields[5].StrictlyEqualsHack( | 2096 expected.name = ASCIIToUTF16("postfix"); |
| 2198 FormField(string16(), | 2097 expected.value = string16(); |
| 2199 ASCIIToUTF16("lastname"), | 2098 expected.is_autofilled = false; |
| 2200 ASCIIToUTF16("Jonathan"), | 2099 EXPECT_FORM_FIELD_EQUALS(expected, fields[6]); |
| 2201 ASCIIToUTF16("text"), | |
| 2202 WebInputElement::defaultMaxLength(), | |
| 2203 false))); | |
| 2204 EXPECT_TRUE(fields[6].StrictlyEqualsHack( | |
| 2205 FormField(string16(), | |
| 2206 ASCIIToUTF16("postfix"), | |
| 2207 string16(), | |
| 2208 ASCIIToUTF16("text"), | |
| 2209 WebInputElement::defaultMaxLength(), | |
| 2210 false))); | |
| 2211 } | 2100 } |
| 2212 | 2101 |
| 2213 // This test sends a FormData object to FillForm with a field changed from | 2102 // 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 | 2103 // those in the cached WebFormElement. In this case, we only fill out the |
| 2215 // fields that match between the FormData object and the WebFormElement. | 2104 // fields that match between the FormData object and the WebFormElement. |
| 2216 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { | 2105 TEST_F(FormManagerTest, FillFormChangedFormDataFields) { |
| 2217 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2106 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2218 " <INPUT type=\"text\" id=\"firstname\"/>" | 2107 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2219 " <INPUT type=\"text\" id=\"middlename\"/>" | 2108 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2220 " <INPUT type=\"text\" id=\"lastname\"/>" | 2109 " <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. | 2142 // Find the newly-filled form that contains the input element. |
| 2254 FormData form2; | 2143 FormData form2; |
| 2255 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2144 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2256 &form2)); | 2145 &form2)); |
| 2257 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2146 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2258 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2147 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2259 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2148 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2260 | 2149 |
| 2261 const std::vector<FormField>& fields = form2.fields; | 2150 const std::vector<FormField>& fields = form2.fields; |
| 2262 ASSERT_EQ(3U, fields.size()); | 2151 ASSERT_EQ(3U, fields.size()); |
| 2263 EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(), | 2152 |
| 2264 ASCIIToUTF16("firstname"), | 2153 FormField expected; |
| 2265 ASCIIToUTF16("Brother"), | 2154 expected.form_control_type = ASCIIToUTF16("text"); |
| 2266 ASCIIToUTF16("text"), | 2155 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2267 WebInputElement::defaultMaxLength(), | 2156 |
| 2268 false))); | 2157 expected.name = ASCIIToUTF16("firstname"); |
| 2269 EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(), | 2158 expected.value = ASCIIToUTF16("Brother"); |
| 2270 ASCIIToUTF16("middlename"), | 2159 expected.is_autofilled = true; |
| 2271 string16(), | 2160 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2272 ASCIIToUTF16("text"), | 2161 |
| 2273 WebInputElement::defaultMaxLength(), | 2162 expected.name = ASCIIToUTF16("middlename"); |
| 2274 false))); | 2163 expected.value = ASCIIToUTF16(""); |
| 2275 EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(), | 2164 expected.is_autofilled = false; |
| 2276 ASCIIToUTF16("lastname"), | 2165 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2277 ASCIIToUTF16("Jonathan"), | 2166 |
| 2278 ASCIIToUTF16("text"), | 2167 expected.name = ASCIIToUTF16("lastname"); |
| 2279 WebInputElement::defaultMaxLength(), | 2168 expected.value = ASCIIToUTF16("Jonathan"); |
| 2280 false))); | 2169 expected.is_autofilled = true; |
| 2170 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2281 } | 2171 } |
| 2282 | 2172 |
| 2283 // This test sends a FormData object to FillForm with fewer fields than are in | 2173 // 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 | 2174 // the cached WebFormElement. In this case, we only fill out the fields that |
| 2285 // match between the FormData object and the WebFormElement. | 2175 // match between the FormData object and the WebFormElement. |
| 2286 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { | 2176 TEST_F(FormManagerTest, FillFormExtraFieldInCache) { |
| 2287 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2177 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2288 " <INPUT type=\"text\" id=\"firstname\"/>" | 2178 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2289 " <INPUT type=\"text\" id=\"middlename\"/>" | 2179 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2290 " <INPUT type=\"text\" id=\"lastname\"/>" | 2180 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2320 // Find the newly-filled form that contains the input element. | 2210 // Find the newly-filled form that contains the input element. |
| 2321 FormData form2; | 2211 FormData form2; |
| 2322 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2212 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2323 &form2)); | 2213 &form2)); |
| 2324 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2214 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2325 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2215 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2326 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2216 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2327 | 2217 |
| 2328 const std::vector<FormField>& fields = form2.fields; | 2218 const std::vector<FormField>& fields = form2.fields; |
| 2329 ASSERT_EQ(4U, fields.size()); | 2219 ASSERT_EQ(4U, fields.size()); |
| 2330 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 2220 |
| 2331 FormField(string16(), | 2221 FormField expected; |
| 2332 ASCIIToUTF16("firstname"), | 2222 expected.form_control_type = ASCIIToUTF16("text"); |
| 2333 ASCIIToUTF16("Brother"), | 2223 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2334 ASCIIToUTF16("text"), | 2224 |
| 2335 WebInputElement::defaultMaxLength(), | 2225 expected.name = ASCIIToUTF16("firstname"); |
| 2336 false))); | 2226 expected.value = ASCIIToUTF16("Brother"); |
| 2337 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 2227 expected.is_autofilled = true; |
| 2338 FormField(string16(), | 2228 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2339 ASCIIToUTF16("middlename"), | 2229 |
| 2340 ASCIIToUTF16("Joseph"), | 2230 expected.name = ASCIIToUTF16("middlename"); |
| 2341 ASCIIToUTF16("text"), | 2231 expected.value = ASCIIToUTF16("Joseph"); |
| 2342 WebInputElement::defaultMaxLength(), | 2232 expected.is_autofilled = true; |
| 2343 false))); | 2233 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2344 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 2234 |
| 2345 FormField(string16(), | 2235 expected.name = ASCIIToUTF16("lastname"); |
| 2346 ASCIIToUTF16("lastname"), | 2236 expected.value = ASCIIToUTF16("Jonathan"); |
| 2347 ASCIIToUTF16("Jonathan"), | 2237 expected.is_autofilled = true; |
| 2348 ASCIIToUTF16("text"), | 2238 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2349 WebInputElement::defaultMaxLength(), | 2239 |
| 2350 false))); | 2240 expected.name = ASCIIToUTF16("postfix"); |
| 2351 EXPECT_TRUE(fields[3].StrictlyEqualsHack( | 2241 expected.value = string16(); |
| 2352 FormField(string16(), | 2242 expected.is_autofilled = false; |
| 2353 ASCIIToUTF16("postfix"), | 2243 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 2354 string16(), | |
| 2355 ASCIIToUTF16("text"), | |
| 2356 WebInputElement::defaultMaxLength(), | |
| 2357 false))); | |
| 2358 } | 2244 } |
| 2359 | 2245 |
| 2360 TEST_F(FormManagerTest, FillFormEmptyName) { | 2246 TEST_F(FormManagerTest, FillFormEmptyName) { |
| 2361 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2247 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2362 " <INPUT type=\"text\" id=\"firstname\"/>" | 2248 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2363 " <INPUT type=\"text\" id=\"lastname\"/>" | 2249 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2364 " <INPUT type=\"text\" id=\"email\"/>" | 2250 " <INPUT type=\"text\" id=\"email\"/>" |
| 2365 " <INPUT type=\"submit\" value=\"Send\"/>" | 2251 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2366 "</FORM>"); | 2252 "</FORM>"); |
| 2367 | 2253 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2380 // Find the form that contains the input element. | 2266 // Find the form that contains the input element. |
| 2381 FormData form; | 2267 FormData form; |
| 2382 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2268 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2383 &form)); | 2269 &form)); |
| 2384 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2270 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2385 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2271 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2386 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2272 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2387 | 2273 |
| 2388 const std::vector<FormField>& fields = form.fields; | 2274 const std::vector<FormField>& fields = form.fields; |
| 2389 ASSERT_EQ(3U, fields.size()); | 2275 ASSERT_EQ(3U, fields.size()); |
| 2390 EXPECT_EQ(FormField(string16(), | 2276 |
| 2391 ASCIIToUTF16("firstname"), | 2277 FormField expected; |
| 2392 string16(), | 2278 expected.form_control_type = ASCIIToUTF16("text"); |
| 2393 ASCIIToUTF16("text"), | 2279 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2394 WebInputElement::defaultMaxLength(), | 2280 |
| 2395 false), | 2281 expected.name = ASCIIToUTF16("firstname"); |
| 2396 fields[0]); | 2282 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2397 EXPECT_EQ(FormField(string16(), | 2283 |
| 2398 ASCIIToUTF16("lastname"), | 2284 expected.name = ASCIIToUTF16("lastname"); |
| 2399 string16(), | 2285 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2400 ASCIIToUTF16("text"), | 2286 |
| 2401 WebInputElement::defaultMaxLength(), | 2287 expected.name = ASCIIToUTF16("email"); |
| 2402 false), | 2288 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2403 fields[1]); | |
| 2404 EXPECT_EQ(FormField(string16(), | |
| 2405 ASCIIToUTF16("email"), | |
| 2406 string16(), | |
| 2407 ASCIIToUTF16("text"), | |
| 2408 WebInputElement::defaultMaxLength(), | |
| 2409 false), | |
| 2410 fields[2]); | |
| 2411 | 2289 |
| 2412 // Fill the form. | 2290 // Fill the form. |
| 2413 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2291 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2414 form.fields[1].value = ASCIIToUTF16("Earp"); | 2292 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2415 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2293 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2416 form_manager.FillForm(form, WebNode()); | 2294 form_manager.FillForm(form, WebNode()); |
| 2417 | 2295 |
| 2418 // Find the newly-filled form that contains the input element. | 2296 // Find the newly-filled form that contains the input element. |
| 2419 FormData form2; | 2297 FormData form2; |
| 2420 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2298 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2421 &form2)); | 2299 &form2)); |
| 2422 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2300 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2423 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2301 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2424 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2302 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2425 | 2303 |
| 2426 const std::vector<FormField>& fields2 = form2.fields; | 2304 const std::vector<FormField>& fields2 = form2.fields; |
| 2427 ASSERT_EQ(3U, fields2.size()); | 2305 ASSERT_EQ(3U, fields2.size()); |
| 2428 EXPECT_EQ(FormField(string16(), | 2306 |
| 2429 ASCIIToUTF16("firstname"), | 2307 expected.form_control_type = ASCIIToUTF16("text"); |
| 2430 ASCIIToUTF16("Wyatt"), | 2308 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2431 ASCIIToUTF16("text"), | 2309 |
| 2432 WebInputElement::defaultMaxLength(), | 2310 expected.name = ASCIIToUTF16("firstname"); |
| 2433 false), | 2311 expected.value = ASCIIToUTF16("Wyatt"); |
| 2434 fields2[0]); | 2312 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2435 EXPECT_EQ(FormField(string16(), | 2313 |
| 2436 ASCIIToUTF16("lastname"), | 2314 expected.name = ASCIIToUTF16("lastname"); |
| 2437 ASCIIToUTF16("Earp"), | 2315 expected.value = ASCIIToUTF16("Earp"); |
| 2438 ASCIIToUTF16("text"), | 2316 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2439 WebInputElement::defaultMaxLength(), | 2317 |
| 2440 false), | 2318 expected.name = ASCIIToUTF16("email"); |
| 2441 fields2[1]); | 2319 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2442 EXPECT_EQ(FormField(string16(), | 2320 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2443 ASCIIToUTF16("email"), | |
| 2444 ASCIIToUTF16("wyatt@example.com"), | |
| 2445 ASCIIToUTF16("text"), | |
| 2446 WebInputElement::defaultMaxLength(), | |
| 2447 false), | |
| 2448 fields2[2]); | |
| 2449 } | 2321 } |
| 2450 | 2322 |
| 2451 TEST_F(FormManagerTest, FillFormEmptyFormNames) { | 2323 TEST_F(FormManagerTest, FillFormEmptyFormNames) { |
| 2452 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" | 2324 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" |
| 2453 " <INPUT type=\"text\" id=\"firstname\"/>" | 2325 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2454 " <INPUT type=\"text\" id=\"middlename\"/>" | 2326 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2455 " <INPUT type=\"text\" id=\"lastname\"/>" | 2327 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2456 " <INPUT type=\"submit\" value=\"Send\"/>" | 2328 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2457 "</FORM>" | 2329 "</FORM>" |
| 2458 "<FORM action=\"http://abc.com\" method=\"post\">" | 2330 "<FORM action=\"http://abc.com\" method=\"post\">" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2477 // Find the form that contains the input element. | 2349 // Find the form that contains the input element. |
| 2478 FormData form; | 2350 FormData form; |
| 2479 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2351 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2480 &form)); | 2352 &form)); |
| 2481 EXPECT_EQ(string16(), form.name); | 2353 EXPECT_EQ(string16(), form.name); |
| 2482 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2354 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2483 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2355 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 2484 | 2356 |
| 2485 const std::vector<FormField>& fields = form.fields; | 2357 const std::vector<FormField>& fields = form.fields; |
| 2486 ASSERT_EQ(3U, fields.size()); | 2358 ASSERT_EQ(3U, fields.size()); |
| 2487 EXPECT_EQ(FormField(string16(), | 2359 |
| 2488 ASCIIToUTF16("apple"), | 2360 FormField expected; |
| 2489 string16(), | 2361 expected.form_control_type = ASCIIToUTF16("text"); |
| 2490 ASCIIToUTF16("text"), | 2362 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2491 WebInputElement::defaultMaxLength(), | 2363 |
| 2492 false), | 2364 expected.name = ASCIIToUTF16("apple"); |
| 2493 fields[0]); | 2365 expected.is_autofilled = false; |
| 2494 EXPECT_EQ(FormField(string16(), | 2366 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2495 ASCIIToUTF16("banana"), | 2367 |
| 2496 string16(), | 2368 expected.name = ASCIIToUTF16("banana"); |
| 2497 ASCIIToUTF16("text"), | 2369 expected.is_autofilled = false; |
| 2498 WebInputElement::defaultMaxLength(), | 2370 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2499 false), | 2371 |
| 2500 fields[1]); | 2372 expected.name = ASCIIToUTF16("cantelope"); |
| 2501 EXPECT_EQ(FormField(string16(), | 2373 expected.is_autofilled = false; |
| 2502 ASCIIToUTF16("cantelope"), | 2374 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2503 string16(), | |
| 2504 ASCIIToUTF16("text"), | |
| 2505 WebInputElement::defaultMaxLength(), | |
| 2506 false), | |
| 2507 fields[2]); | |
| 2508 | 2375 |
| 2509 // Fill the form. | 2376 // Fill the form. |
| 2510 form.fields[0].value = ASCIIToUTF16("Red"); | 2377 form.fields[0].value = ASCIIToUTF16("Red"); |
| 2511 form.fields[1].value = ASCIIToUTF16("Yellow"); | 2378 form.fields[1].value = ASCIIToUTF16("Yellow"); |
| 2512 form.fields[2].value = ASCIIToUTF16("Also Yellow"); | 2379 form.fields[2].value = ASCIIToUTF16("Also Yellow"); |
| 2513 form_manager.FillForm(form, WebNode()); | 2380 form_manager.FillForm(form, WebNode()); |
| 2514 | 2381 |
| 2515 // Find the newly-filled form that contains the input element. | 2382 // Find the newly-filled form that contains the input element. |
| 2516 FormData form2; | 2383 FormData form2; |
| 2517 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2384 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2518 &form2)); | 2385 &form2)); |
| 2519 EXPECT_EQ(string16(), form2.name); | 2386 EXPECT_EQ(string16(), form2.name); |
| 2520 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2387 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2521 EXPECT_EQ(GURL("http://abc.com"), form2.action); | 2388 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
| 2522 | 2389 |
| 2523 const std::vector<FormField>& fields2 = form2.fields; | 2390 const std::vector<FormField>& fields2 = form2.fields; |
| 2524 ASSERT_EQ(3U, fields2.size()); | 2391 ASSERT_EQ(3U, fields2.size()); |
| 2525 EXPECT_EQ(FormField(string16(), | 2392 |
| 2526 ASCIIToUTF16("apple"), | 2393 expected.name = ASCIIToUTF16("apple"); |
| 2527 ASCIIToUTF16("Red"), | 2394 expected.value = ASCIIToUTF16("Red"); |
| 2528 ASCIIToUTF16("text"), | 2395 expected.is_autofilled = true; |
| 2529 WebInputElement::defaultMaxLength(), | 2396 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 2530 false), | 2397 |
| 2531 fields2[0]); | 2398 expected.name = ASCIIToUTF16("banana"); |
| 2532 EXPECT_EQ(FormField(string16(), | 2399 expected.value = ASCIIToUTF16("Yellow"); |
| 2533 ASCIIToUTF16("banana"), | 2400 expected.is_autofilled = true; |
| 2534 ASCIIToUTF16("Yellow"), | 2401 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 2535 ASCIIToUTF16("text"), | 2402 |
| 2536 WebInputElement::defaultMaxLength(), | 2403 expected.name = ASCIIToUTF16("cantelope"); |
| 2537 false), | 2404 expected.value = ASCIIToUTF16("Also Yellow"); |
| 2538 fields2[1]); | 2405 expected.is_autofilled = true; |
| 2539 EXPECT_EQ(FormField(string16(), | 2406 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 2540 ASCIIToUTF16("cantelope"), | |
| 2541 ASCIIToUTF16("Also Yellow"), | |
| 2542 ASCIIToUTF16("text"), | |
| 2543 WebInputElement::defaultMaxLength(), | |
| 2544 false), | |
| 2545 fields2[2]); | |
| 2546 } | 2407 } |
| 2547 | 2408 |
| 2548 TEST_F(FormManagerTest, ThreePartPhone) { | 2409 TEST_F(FormManagerTest, ThreePartPhone) { |
| 2549 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2410 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2550 " Phone:" | 2411 " Phone:" |
| 2551 " <input type=\"text\" name=\"dayphone1\">" | 2412 " <input type=\"text\" name=\"dayphone1\">" |
| 2552 " -" | 2413 " -" |
| 2553 " <input type=\"text\" name=\"dayphone2\">" | 2414 " <input type=\"text\" name=\"dayphone2\">" |
| 2554 " -" | 2415 " -" |
| 2555 " <input type=\"text\" name=\"dayphone3\">" | 2416 " <input type=\"text\" name=\"dayphone3\">" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2570 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2431 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 2571 FormManager::REQUIRE_NONE, | 2432 FormManager::REQUIRE_NONE, |
| 2572 FormManager::EXTRACT_VALUE, | 2433 FormManager::EXTRACT_VALUE, |
| 2573 &form)); | 2434 &form)); |
| 2574 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2435 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2575 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2436 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2576 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2437 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2577 | 2438 |
| 2578 const std::vector<FormField>& fields = form.fields; | 2439 const std::vector<FormField>& fields = form.fields; |
| 2579 ASSERT_EQ(4U, fields.size()); | 2440 ASSERT_EQ(4U, fields.size()); |
| 2580 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), | 2441 |
| 2581 ASCIIToUTF16("dayphone1"), | 2442 FormField expected; |
| 2582 string16(), | 2443 expected.form_control_type = ASCIIToUTF16("text"); |
| 2583 ASCIIToUTF16("text"), | 2444 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2584 WebInputElement::defaultMaxLength(), | 2445 |
| 2585 false), | 2446 expected.label = ASCIIToUTF16("Phone:"); |
| 2586 fields[0]); | 2447 expected.name = ASCIIToUTF16("dayphone1"); |
| 2587 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2448 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2588 ASCIIToUTF16("dayphone2"), | 2449 |
| 2589 string16(), | 2450 expected.label = ASCIIToUTF16("-"); |
| 2590 ASCIIToUTF16("text"), | 2451 expected.name = ASCIIToUTF16("dayphone2"); |
| 2591 WebInputElement::defaultMaxLength(), | 2452 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2592 false), | 2453 |
| 2593 fields[1]); | 2454 expected.label = ASCIIToUTF16("-"); |
| 2594 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2455 expected.name = ASCIIToUTF16("dayphone3"); |
| 2595 ASCIIToUTF16("dayphone3"), | 2456 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2596 string16(), | 2457 |
| 2597 ASCIIToUTF16("text"), | 2458 expected.label = ASCIIToUTF16("ext.:"); |
| 2598 WebInputElement::defaultMaxLength(), | 2459 expected.name = ASCIIToUTF16("dayphone4"); |
| 2599 false), | 2460 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 2600 fields[2]); | |
| 2601 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | |
| 2602 ASCIIToUTF16("dayphone4"), | |
| 2603 string16(), | |
| 2604 ASCIIToUTF16("text"), | |
| 2605 WebInputElement::defaultMaxLength(), | |
| 2606 false), | |
| 2607 fields[3]); | |
| 2608 } | 2461 } |
| 2609 | 2462 |
| 2610 | 2463 |
| 2611 TEST_F(FormManagerTest, MaxLengthFields) { | 2464 TEST_F(FormManagerTest, MaxLengthFields) { |
| 2612 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2465 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2613 " Phone:" | 2466 " Phone:" |
| 2614 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" | 2467 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" |
| 2615 " -" | 2468 " -" |
| 2616 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" | 2469 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" |
| 2617 " -" | 2470 " -" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2635 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2488 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 2636 FormManager::REQUIRE_NONE, | 2489 FormManager::REQUIRE_NONE, |
| 2637 FormManager::EXTRACT_VALUE, | 2490 FormManager::EXTRACT_VALUE, |
| 2638 &form)); | 2491 &form)); |
| 2639 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2492 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2640 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2493 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2641 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2494 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2642 | 2495 |
| 2643 const std::vector<FormField>& fields = form.fields; | 2496 const std::vector<FormField>& fields = form.fields; |
| 2644 ASSERT_EQ(6U, fields.size()); | 2497 ASSERT_EQ(6U, fields.size()); |
| 2645 EXPECT_EQ(FormField(ASCIIToUTF16("Phone:"), | 2498 |
| 2646 ASCIIToUTF16("dayphone1"), | 2499 FormField expected; |
| 2647 string16(), | 2500 expected.form_control_type = ASCIIToUTF16("text"); |
| 2648 ASCIIToUTF16("text"), | 2501 |
| 2649 3, | 2502 expected.label = ASCIIToUTF16("Phone:"); |
| 2650 false), | 2503 expected.name = ASCIIToUTF16("dayphone1"); |
| 2651 fields[0]); | 2504 expected.max_length = 3; |
| 2652 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2505 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2653 ASCIIToUTF16("dayphone2"), | 2506 |
| 2654 string16(), | 2507 expected.label = ASCIIToUTF16("-"); |
| 2655 ASCIIToUTF16("text"), | 2508 expected.name = ASCIIToUTF16("dayphone2"); |
| 2656 3, | 2509 expected.max_length = 3; |
| 2657 false), | 2510 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2658 fields[1]); | 2511 |
| 2659 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2512 expected.label = ASCIIToUTF16("-"); |
| 2660 ASCIIToUTF16("dayphone3"), | 2513 expected.name = ASCIIToUTF16("dayphone3"); |
| 2661 string16(), | 2514 expected.max_length = 4; |
| 2662 ASCIIToUTF16("text"), | 2515 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2663 4, | 2516 |
| 2664 false), | 2517 expected.label = ASCIIToUTF16("ext.:"); |
| 2665 fields[2]); | 2518 expected.name = ASCIIToUTF16("dayphone4"); |
| 2666 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | 2519 expected.max_length = 5; |
| 2667 ASCIIToUTF16("dayphone4"), | 2520 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); |
| 2668 string16(), | 2521 |
| 2669 ASCIIToUTF16("text"), | |
| 2670 5, | |
| 2671 false), | |
| 2672 fields[3]); | |
| 2673 // When unspecified |size|, default is returned. | 2522 // When unspecified |size|, default is returned. |
| 2674 EXPECT_EQ(FormField(string16(), | 2523 expected.label = string16(); |
| 2675 ASCIIToUTF16("default1"), | 2524 expected.name = ASCIIToUTF16("default1"); |
| 2676 string16(), | 2525 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2677 ASCIIToUTF16("text"), | 2526 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); |
| 2678 WebInputElement::defaultMaxLength(), | 2527 |
| 2679 false), | |
| 2680 fields[4]); | |
| 2681 // When invalid |size|, default is returned. | 2528 // When invalid |size|, default is returned. |
| 2682 EXPECT_EQ(FormField(string16(), | 2529 expected.label = string16(); |
| 2683 ASCIIToUTF16("invalid1"), | 2530 expected.name = ASCIIToUTF16("invalid1"); |
| 2684 string16(), | 2531 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2685 ASCIIToUTF16("text"), | 2532 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); |
| 2686 WebInputElement::defaultMaxLength(), | |
| 2687 false), | |
| 2688 fields[5]); | |
| 2689 } | 2533 } |
| 2690 | 2534 |
| 2691 // This test re-creates the experience of typing in a field then selecting a | 2535 // 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 | 2536 // profile from the Autofill suggestions popup. The field that is being typed |
| 2693 // into should be filled even though it's not technically empty. | 2537 // into should be filled even though it's not technically empty. |
| 2694 TEST_F(FormManagerTest, FillFormNonEmptyField) { | 2538 TEST_F(FormManagerTest, FillFormNonEmptyField) { |
| 2695 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2539 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2696 " <INPUT type=\"text\" id=\"firstname\"/>" | 2540 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2697 " <INPUT type=\"text\" id=\"lastname\"/>" | 2541 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2698 " <INPUT type=\"text\" id=\"email\"/>" | 2542 " <INPUT type=\"text\" id=\"email\"/>" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2717 // Find the form that contains the input element. | 2561 // Find the form that contains the input element. |
| 2718 FormData form; | 2562 FormData form; |
| 2719 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2563 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2720 &form)); | 2564 &form)); |
| 2721 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2565 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2722 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2566 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2723 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2567 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2724 | 2568 |
| 2725 const std::vector<FormField>& fields = form.fields; | 2569 const std::vector<FormField>& fields = form.fields; |
| 2726 ASSERT_EQ(3U, fields.size()); | 2570 ASSERT_EQ(3U, fields.size()); |
| 2727 EXPECT_EQ(FormField(string16(), | 2571 |
| 2728 ASCIIToUTF16("firstname"), | 2572 FormField expected; |
| 2729 string16(), | 2573 expected.form_control_type = ASCIIToUTF16("text"); |
| 2730 ASCIIToUTF16("text"), | 2574 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2731 WebInputElement::defaultMaxLength(), | 2575 |
| 2732 false), | 2576 expected.name = ASCIIToUTF16("firstname"); |
| 2733 fields[0]); | 2577 expected.value = ASCIIToUTF16("Wy"); |
| 2734 EXPECT_EQ(FormField(string16(), | 2578 expected.is_autofilled = false; |
| 2735 ASCIIToUTF16("lastname"), | 2579 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 2736 string16(), | 2580 |
| 2737 ASCIIToUTF16("text"), | 2581 expected.name = ASCIIToUTF16("lastname"); |
| 2738 WebInputElement::defaultMaxLength(), | 2582 expected.value = string16(); |
| 2739 false), | 2583 expected.is_autofilled = false; |
| 2740 fields[1]); | 2584 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2741 EXPECT_EQ(FormField(string16(), | 2585 |
| 2742 ASCIIToUTF16("email"), | 2586 expected.name = ASCIIToUTF16("email"); |
| 2743 string16(), | 2587 expected.value = string16(); |
| 2744 ASCIIToUTF16("text"), | 2588 expected.is_autofilled = false; |
| 2745 WebInputElement::defaultMaxLength(), | 2589 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2746 false), | |
| 2747 fields[2]); | |
| 2748 | 2590 |
| 2749 // Preview the form and verify that the cursor position has been updated. | 2591 // Preview the form and verify that the cursor position has been updated. |
| 2750 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2592 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2751 form.fields[1].value = ASCIIToUTF16("Earp"); | 2593 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2752 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2594 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2753 form_manager.PreviewForm(form, input_element); | 2595 form_manager.PreviewForm(form, input_element); |
| 2754 EXPECT_EQ(2, input_element.selectionStart()); | 2596 EXPECT_EQ(2, input_element.selectionStart()); |
| 2755 EXPECT_EQ(5, input_element.selectionEnd()); | 2597 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2756 | 2598 |
| 2757 // Fill the form. | 2599 // Fill the form. |
| 2758 form_manager.FillForm(form, input_element); | 2600 form_manager.FillForm(form, input_element); |
| 2759 | 2601 |
| 2760 // Find the newly-filled form that contains the input element. | 2602 // Find the newly-filled form that contains the input element. |
| 2761 FormData form2; | 2603 FormData form2; |
| 2762 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, | 2604 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(input_element, |
| 2763 &form2)); | 2605 &form2)); |
| 2764 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2606 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2765 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2607 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2766 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2608 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2767 | 2609 |
| 2768 const std::vector<FormField>& fields2 = form2.fields; | 2610 const std::vector<FormField>& fields2 = form2.fields; |
| 2769 ASSERT_EQ(3U, fields2.size()); | 2611 ASSERT_EQ(3U, fields2.size()); |
| 2770 EXPECT_EQ(FormField(string16(), | 2612 |
| 2771 ASCIIToUTF16("firstname"), | 2613 expected.name = ASCIIToUTF16("firstname"); |
| 2772 ASCIIToUTF16("Wyatt"), | 2614 expected.value = ASCIIToUTF16("Wyatt"); |
| 2773 ASCIIToUTF16("text"), | 2615 expected.is_autofilled = true; |
| 2774 WebInputElement::defaultMaxLength(), | 2616 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 2775 false), | 2617 |
| 2776 fields2[0]); | 2618 expected.name = ASCIIToUTF16("lastname"); |
| 2777 EXPECT_EQ(FormField(string16(), | 2619 expected.value = ASCIIToUTF16("Earp"); |
| 2778 ASCIIToUTF16("lastname"), | 2620 expected.is_autofilled = true; |
| 2779 ASCIIToUTF16("Earp"), | 2621 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 2780 ASCIIToUTF16("text"), | 2622 |
| 2781 WebInputElement::defaultMaxLength(), | 2623 expected.name = ASCIIToUTF16("email"); |
| 2782 false), | 2624 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2783 fields2[1]); | 2625 expected.is_autofilled = true; |
| 2784 EXPECT_EQ(FormField(string16(), | 2626 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 2785 ASCIIToUTF16("email"), | |
| 2786 ASCIIToUTF16("wyatt@example.com"), | |
| 2787 ASCIIToUTF16("text"), | |
| 2788 WebInputElement::defaultMaxLength(), | |
| 2789 false), | |
| 2790 fields2[2]); | |
| 2791 | 2627 |
| 2792 // Verify that the cursor position has been updated. | 2628 // Verify that the cursor position has been updated. |
| 2793 EXPECT_EQ(5, input_element.selectionStart()); | 2629 EXPECT_EQ(5, input_element.selectionStart()); |
| 2794 EXPECT_EQ(5, input_element.selectionEnd()); | 2630 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2795 } | 2631 } |
| 2796 | 2632 |
| 2797 TEST_F(FormManagerTest, ClearFormWithNode) { | 2633 TEST_F(FormManagerTest, ClearFormWithNode) { |
| 2798 LoadHTML( | 2634 LoadHTML( |
| 2799 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2635 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2800 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2636 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2830 | 2666 |
| 2831 // Verify the form is cleared. | 2667 // Verify the form is cleared. |
| 2832 FormData form2; | 2668 FormData form2; |
| 2833 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); | 2669 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); |
| 2834 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2670 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2835 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2671 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2836 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2672 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2837 | 2673 |
| 2838 const std::vector<FormField>& fields2 = form2.fields; | 2674 const std::vector<FormField>& fields2 = form2.fields; |
| 2839 ASSERT_EQ(4U, fields2.size()); | 2675 ASSERT_EQ(4U, fields2.size()); |
| 2840 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2676 |
| 2841 FormField(string16(), | 2677 FormField expected; |
| 2842 ASCIIToUTF16("firstname"), | 2678 expected.form_control_type = ASCIIToUTF16("text"); |
| 2843 string16(), | 2679 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2844 ASCIIToUTF16("text"), | 2680 |
| 2845 WebInputElement::defaultMaxLength(), | 2681 expected.name = ASCIIToUTF16("firstname"); |
| 2846 false))); | 2682 expected.value = string16(); |
| 2847 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2683 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 2848 FormField(string16(), | 2684 |
| 2849 ASCIIToUTF16("lastname"), | 2685 expected.name = ASCIIToUTF16("lastname"); |
| 2850 string16(), | 2686 expected.value = string16(); |
| 2851 ASCIIToUTF16("text"), | 2687 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 2852 WebInputElement::defaultMaxLength(), | 2688 |
| 2853 false))); | 2689 expected.name = ASCIIToUTF16("noAC"); |
| 2854 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2690 expected.value = string16(); |
| 2855 FormField(string16(), | 2691 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 2856 ASCIIToUTF16("noAC"), | 2692 |
| 2857 string16(), | 2693 expected.name = ASCIIToUTF16("notenabled"); |
| 2858 ASCIIToUTF16("text"), | 2694 expected.value = ASCIIToUTF16("no clear"); |
| 2859 WebInputElement::defaultMaxLength(), | 2695 EXPECT_FORM_FIELD_EQUALS(expected, fields2[3]); |
| 2860 false))); | |
| 2861 EXPECT_TRUE(fields2[3].StrictlyEqualsHack( | |
| 2862 FormField(string16(), | |
| 2863 ASCIIToUTF16("notenabled"), | |
| 2864 ASCIIToUTF16("no clear"), | |
| 2865 ASCIIToUTF16("text"), | |
| 2866 WebInputElement::defaultMaxLength(), | |
| 2867 false))); | |
| 2868 | 2696 |
| 2869 // Verify that the cursor position has been updated. | 2697 // Verify that the cursor position has been updated. |
| 2870 EXPECT_EQ(0, firstname.selectionStart()); | 2698 EXPECT_EQ(0, firstname.selectionStart()); |
| 2871 EXPECT_EQ(0, firstname.selectionEnd()); | 2699 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2872 } | 2700 } |
| 2873 | 2701 |
| 2874 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { | 2702 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { |
| 2875 LoadHTML( | 2703 LoadHTML( |
| 2876 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2704 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2877 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2705 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2911 | 2739 |
| 2912 // Verify the form is cleared. | 2740 // Verify the form is cleared. |
| 2913 FormData form2; | 2741 FormData form2; |
| 2914 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); | 2742 EXPECT_TRUE(form_manager.FindFormWithFormControlElement(firstname, &form2)); |
| 2915 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2743 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2916 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2744 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2917 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2745 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2918 | 2746 |
| 2919 const std::vector<FormField>& fields2 = form2.fields; | 2747 const std::vector<FormField>& fields2 = form2.fields; |
| 2920 ASSERT_EQ(3U, fields2.size()); | 2748 ASSERT_EQ(3U, fields2.size()); |
| 2921 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 2749 |
| 2922 FormField(string16(), | 2750 FormField expected; |
| 2923 ASCIIToUTF16("firstname"), | 2751 |
| 2924 string16(), | 2752 expected.name = ASCIIToUTF16("firstname"); |
| 2925 ASCIIToUTF16("text"), | 2753 expected.value = string16(); |
| 2926 WebInputElement::defaultMaxLength(), | 2754 expected.form_control_type = ASCIIToUTF16("text"); |
| 2927 false))); | 2755 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2928 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 2756 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); |
| 2929 FormField(string16(), | 2757 |
| 2930 ASCIIToUTF16("lastname"), | 2758 expected.name = ASCIIToUTF16("lastname"); |
| 2931 string16(), | 2759 expected.value = string16(); |
| 2932 ASCIIToUTF16("text"), | 2760 expected.form_control_type = ASCIIToUTF16("text"); |
| 2933 WebInputElement::defaultMaxLength(), | 2761 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2934 false))); | 2762 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); |
| 2935 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 2763 |
| 2936 FormField(string16(), | 2764 expected.name = ASCIIToUTF16("state"); |
| 2937 ASCIIToUTF16("state"), | 2765 expected.value = ASCIIToUTF16("?"); |
| 2938 ASCIIToUTF16("?"), | 2766 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2939 ASCIIToUTF16("select-one"), | 2767 expected.max_length = 0; |
| 2940 0, | 2768 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); |
| 2941 false))); | |
| 2942 | 2769 |
| 2943 // Verify that the cursor position has been updated. | 2770 // Verify that the cursor position has been updated. |
| 2944 EXPECT_EQ(0, firstname.selectionStart()); | 2771 EXPECT_EQ(0, firstname.selectionStart()); |
| 2945 EXPECT_EQ(0, firstname.selectionEnd()); | 2772 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2946 } | 2773 } |
| 2947 | 2774 |
| 2948 TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { | 2775 TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { |
| 2949 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2776 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2950 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2777 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 2951 " <INPUT type=\"text\" id=\"lastname\"/>" | 2778 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3261 forms[0], FormManager::REQUIRE_NONE, | 3088 forms[0], FormManager::REQUIRE_NONE, |
| 3262 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | | 3089 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | |
| 3263 FormManager::EXTRACT_OPTION_TEXT), | 3090 FormManager::EXTRACT_OPTION_TEXT), |
| 3264 &form)); | 3091 &form)); |
| 3265 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3092 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3266 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3093 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3267 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3094 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3268 | 3095 |
| 3269 const std::vector<FormField>& fields = form.fields; | 3096 const std::vector<FormField>& fields = form.fields; |
| 3270 ASSERT_EQ(3U, fields.size()); | 3097 ASSERT_EQ(3U, fields.size()); |
| 3271 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 3098 |
| 3272 FormField(string16(), | 3099 FormField expected; |
| 3273 ASCIIToUTF16("firstname"), | 3100 |
| 3274 ASCIIToUTF16("John"), | 3101 expected.name = ASCIIToUTF16("firstname"); |
| 3275 ASCIIToUTF16("text"), | 3102 expected.value = ASCIIToUTF16("John"); |
| 3276 WebInputElement::defaultMaxLength(), | 3103 expected.form_control_type = ASCIIToUTF16("text"); |
| 3277 false))); | 3104 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3278 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 3105 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 3279 FormField(string16(), | 3106 |
| 3280 ASCIIToUTF16("lastname"), | 3107 expected.name = ASCIIToUTF16("lastname"); |
| 3281 ASCIIToUTF16("Smith"), | 3108 expected.value = ASCIIToUTF16("Smith"); |
| 3282 ASCIIToUTF16("text"), | 3109 expected.form_control_type = ASCIIToUTF16("text"); |
| 3283 WebInputElement::defaultMaxLength(), | 3110 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3284 false))); | 3111 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 3285 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 3112 |
| 3286 FormField(string16(), | 3113 expected.name = ASCIIToUTF16("country"); |
| 3287 ASCIIToUTF16("country"), | 3114 expected.value = ASCIIToUTF16("Albania"); |
| 3288 ASCIIToUTF16("Albania"), | 3115 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 3289 ASCIIToUTF16("select-one"), | 3116 expected.max_length = 0; |
| 3290 0, | 3117 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 3291 false))); | |
| 3292 | 3118 |
| 3293 form.fields.clear(); | 3119 form.fields.clear(); |
| 3294 // Extract the country select-one value as value. | 3120 // Extract the country select-one value as value. |
| 3295 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 3121 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 3296 FormManager::REQUIRE_NONE, | 3122 FormManager::REQUIRE_NONE, |
| 3297 FormManager::EXTRACT_VALUE, | 3123 FormManager::EXTRACT_VALUE, |
| 3298 &form)); | 3124 &form)); |
| 3299 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3125 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 3300 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3126 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 3301 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3127 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 3302 | 3128 |
| 3303 ASSERT_EQ(3U, fields.size()); | 3129 ASSERT_EQ(3U, fields.size()); |
| 3304 EXPECT_TRUE(fields[0].StrictlyEqualsHack( | 3130 |
| 3305 FormField(string16(), | 3131 expected.name = ASCIIToUTF16("firstname"); |
| 3306 ASCIIToUTF16("firstname"), | 3132 expected.value = ASCIIToUTF16("John"); |
| 3307 ASCIIToUTF16("John"), | 3133 expected.form_control_type = ASCIIToUTF16("text"); |
| 3308 ASCIIToUTF16("text"), | 3134 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3309 WebInputElement::defaultMaxLength(), | 3135 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); |
| 3310 false))); | 3136 |
| 3311 EXPECT_TRUE(fields[1].StrictlyEqualsHack( | 3137 expected.name = ASCIIToUTF16("lastname"); |
| 3312 FormField(string16(), | 3138 expected.value = ASCIIToUTF16("Smith"); |
| 3313 ASCIIToUTF16("lastname"), | 3139 expected.form_control_type = ASCIIToUTF16("text"); |
| 3314 ASCIIToUTF16("Smith"), | 3140 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3315 ASCIIToUTF16("text"), | 3141 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 3316 WebInputElement::defaultMaxLength(), | 3142 |
| 3317 false))); | 3143 expected.name = ASCIIToUTF16("country"); |
| 3318 EXPECT_TRUE(fields[2].StrictlyEqualsHack( | 3144 expected.value = ASCIIToUTF16("AL"); |
| 3319 FormField(string16(), | 3145 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 3320 ASCIIToUTF16("country"), | 3146 expected.max_length = 0; |
| 3321 ASCIIToUTF16("AL"), | 3147 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 3322 ASCIIToUTF16("select-one"), | |
| 3323 0, | |
| 3324 false))); | |
| 3325 } | 3148 } |
| OLD | NEW |