OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/format_macros.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 expected.value = ASCIIToUTF16("value"); | 203 expected.value = ASCIIToUTF16("value"); |
204 expected.form_control_type = "text"; | 204 expected.form_control_type = "text"; |
205 expected.max_length = WebInputElement::defaultMaxLength(); | 205 expected.max_length = WebInputElement::defaultMaxLength(); |
206 expected.is_autofilled = true; | 206 expected.is_autofilled = true; |
207 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 207 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
208 } | 208 } |
209 | 209 |
210 // We should be able to extract a radio or a checkbox field that has been | 210 // We should be able to extract a radio or a checkbox field that has been |
211 // autofilled. | 211 // autofilled. |
212 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { | 212 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
213 LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" | 213 LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\" checked/>" |
214 "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>"); | 214 "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>"); |
215 | 215 |
216 WebFrame* frame = GetMainFrame(); | 216 WebFrame* frame = GetMainFrame(); |
217 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 217 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
218 | 218 |
219 WebElement web_element = frame->document().getElementById("checkbox"); | 219 WebElement web_element = frame->document().getElementById("checkbox"); |
220 WebInputElement element = web_element.to<WebInputElement>(); | 220 WebInputElement element = web_element.to<WebInputElement>(); |
221 element.setAutofilled(true); | 221 element.setAutofilled(true); |
222 FormFieldData result; | 222 FormFieldData result; |
223 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 223 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
224 | 224 |
225 FormFieldData expected; | 225 FormFieldData expected; |
226 expected.name = ASCIIToUTF16("checkbox"); | 226 expected.name = ASCIIToUTF16("checkbox"); |
227 expected.value = ASCIIToUTF16("mail"); | 227 expected.value = ASCIIToUTF16("mail"); |
228 expected.form_control_type = "checkbox"; | 228 expected.form_control_type = "checkbox"; |
229 expected.is_autofilled = true; | 229 expected.is_autofilled = true; |
230 expected.is_checkable = true; | 230 expected.is_checkable = true; |
| 231 expected.is_checked = true; |
231 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 232 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
232 | 233 |
233 web_element = frame->document().getElementById("radio"); | 234 web_element = frame->document().getElementById("radio"); |
234 element = web_element.to<WebInputElement>(); | 235 element = web_element.to<WebInputElement>(); |
235 element.setAutofilled(true); | 236 element.setAutofilled(true); |
236 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 237 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
237 expected.name = ASCIIToUTF16("radio"); | 238 expected.name = ASCIIToUTF16("radio"); |
238 expected.value = ASCIIToUTF16("male"); | 239 expected.value = ASCIIToUTF16("male"); |
239 expected.form_control_type = "radio"; | 240 expected.form_control_type = "radio"; |
240 expected.is_autofilled = true; | 241 expected.is_autofilled = true; |
241 expected.is_checkable = true; | 242 expected.is_checkable = true; |
| 243 expected.is_checked = false; |
242 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 244 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
243 } | 245 } |
244 | 246 |
245 // We should be able to extract a <select> field. | 247 // We should be able to extract a <select> field. |
246 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 248 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
247 LoadHTML("<SELECT id=\"element\"/>" | 249 LoadHTML("<SELECT id=\"element\"/>" |
248 " <OPTION value=\"CA\">California</OPTION>" | 250 " <OPTION value=\"CA\">California</OPTION>" |
249 " <OPTION value=\"TX\">Texas</OPTION>" | 251 " <OPTION value=\"TX\">Texas</OPTION>" |
250 "</SELECT>"); | 252 "</SELECT>"); |
251 | 253 |
(...skipping 2843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3097 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3096 | 3098 |
3097 expected.name = ASCIIToUTF16("country"); | 3099 expected.name = ASCIIToUTF16("country"); |
3098 expected.value = ASCIIToUTF16("AL"); | 3100 expected.value = ASCIIToUTF16("AL"); |
3099 expected.form_control_type = "select-one"; | 3101 expected.form_control_type = "select-one"; |
3100 expected.max_length = 0; | 3102 expected.max_length = 0; |
3101 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3103 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3102 } | 3104 } |
3103 | 3105 |
3104 } // namespace autofill | 3106 } // namespace autofill |
OLD | NEW |