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/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 | 2061 |
2062 FormData form; | 2062 FormData form; |
2063 FormFieldData field; | 2063 FormFieldData field; |
2064 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 2064 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
2065 input_element, | 2065 input_element, |
2066 EXTRACT_VALUE, | 2066 EXTRACT_VALUE, |
2067 &form, | 2067 &form, |
2068 &field)); | 2068 &field)); |
2069 } | 2069 } |
2070 | 2070 |
| 2071 // Tests that the |should_autocomplete| is set to false for all the fields when |
| 2072 // an autocomplete='off' attribute is set for the form in HTML. |
| 2073 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnForm) { |
| 2074 LoadHTML( |
| 2075 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " |
| 2076 "autocomplete='off'>" |
| 2077 " <LABEL for='firstname'>First name:</LABEL>" |
| 2078 " <INPUT type='text' id='firstname' value='John'/>" |
| 2079 " <LABEL for='lastname'>Last name:</LABEL>" |
| 2080 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2081 " <LABEL for='street-address'>Address:</LABEL>" |
| 2082 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" |
| 2083 "</FORM>"); |
| 2084 |
| 2085 WebFrame* frame = GetMainFrame(); |
| 2086 ASSERT_NE(nullptr, frame); |
| 2087 |
| 2088 WebFormElement web_form = |
| 2089 frame->document().getElementById("form").to<WebFormElement>(); |
| 2090 ASSERT_FALSE(web_form.isNull()); |
| 2091 |
| 2092 FormData form; |
| 2093 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2094 EXTRACT_NONE, &form, nullptr)); |
| 2095 |
| 2096 for (const FormFieldData& field : form.fields) { |
| 2097 EXPECT_FALSE(field.should_autocomplete); |
| 2098 } |
| 2099 } |
| 2100 |
| 2101 // Tests that the |should_autocomplete| is set to false only for the field |
| 2102 // which has an autocomplete='off' attribute set for it in HTML. |
| 2103 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnField) { |
| 2104 LoadHTML( |
| 2105 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post'>" |
| 2106 " <LABEL for='firstname'>First name:</LABEL>" |
| 2107 " <INPUT type='text' id='firstname' value='John' autocomplete='off'/>" |
| 2108 " <LABEL for='lastname'>Last name:</LABEL>" |
| 2109 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2110 " <LABEL for='street-address'>Address:</LABEL>" |
| 2111 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" |
| 2112 "</FORM>"); |
| 2113 |
| 2114 WebFrame* frame = GetMainFrame(); |
| 2115 ASSERT_NE(nullptr, frame); |
| 2116 |
| 2117 WebFormElement web_form = |
| 2118 frame->document().getElementById("form").to<WebFormElement>(); |
| 2119 ASSERT_FALSE(web_form.isNull()); |
| 2120 |
| 2121 FormData form; |
| 2122 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2123 EXTRACT_NONE, &form, nullptr)); |
| 2124 |
| 2125 ASSERT_EQ(3U, form.fields.size()); |
| 2126 |
| 2127 EXPECT_FALSE(form.fields[0].should_autocomplete); |
| 2128 EXPECT_TRUE(form.fields[1].should_autocomplete); |
| 2129 EXPECT_TRUE(form.fields[2].should_autocomplete); |
| 2130 } |
| 2131 |
2071 TEST_F(FormAutofillTest, ExtractForms) { | 2132 TEST_F(FormAutofillTest, ExtractForms) { |
2072 ExpectJohnSmithLabels( | 2133 ExpectJohnSmithLabels( |
2073 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2134 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2074 " First name: <INPUT type='text' id='firstname' value='John'/>" | 2135 " First name: <INPUT type='text' id='firstname' value='John'/>" |
2075 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" | 2136 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" |
2076 " Email: <INPUT type='text' id='email' value='john@example.com'/>" | 2137 " Email: <INPUT type='text' id='email' value='john@example.com'/>" |
2077 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2138 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2078 "</FORM>"); | 2139 "</FORM>"); |
2079 } | 2140 } |
2080 | 2141 |
(...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4179 ASSERT_NE(nullptr, web_frame); | 4240 ASSERT_NE(nullptr, web_frame); |
4180 | 4241 |
4181 FormCache form_cache(*web_frame); | 4242 FormCache form_cache(*web_frame); |
4182 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 4243 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
4183 EXPECT_EQ(test_case.expected_forms, forms.size()); | 4244 EXPECT_EQ(test_case.expected_forms, forms.size()); |
4184 } | 4245 } |
4185 } | 4246 } |
4186 | 4247 |
4187 } // namespace form_util | 4248 } // namespace form_util |
4188 } // namespace autofill | 4249 } // namespace autofill |
OLD | NEW |