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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/test/base/chrome_render_view_test.h" | 9 #include "chrome/test/base/chrome_render_view_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using blink::WebFormElement; | 29 using blink::WebFormElement; |
30 using blink::WebFrame; | 30 using blink::WebFrame; |
31 using blink::WebLocalFrame; | 31 using blink::WebLocalFrame; |
32 using blink::WebInputElement; | 32 using blink::WebInputElement; |
33 using blink::WebString; | 33 using blink::WebString; |
34 using blink::WebURLRequest; | 34 using blink::WebURLRequest; |
35 using blink::WebVector; | 35 using blink::WebVector; |
36 | 36 |
37 namespace autofill { | 37 namespace autofill { |
38 | 38 |
39 typedef Tuple5<int, | 39 typedef Tuple<int, |
40 autofill::FormData, | 40 autofill::FormData, |
41 autofill::FormFieldData, | 41 autofill::FormFieldData, |
42 gfx::RectF, | 42 gfx::RectF, |
43 bool> AutofillQueryParam; | 43 bool> AutofillQueryParam; |
44 | 44 |
45 class AutofillRendererTest : public ChromeRenderViewTest { | 45 class AutofillRendererTest : public ChromeRenderViewTest { |
46 public: | 46 public: |
47 AutofillRendererTest() {} | 47 AutofillRendererTest() {} |
48 ~AutofillRendererTest() override {} | 48 ~AutofillRendererTest() override {} |
49 | 49 |
50 protected: | 50 protected: |
51 void SetUp() override { | 51 void SetUp() override { |
52 ChromeRenderViewTest::SetUp(); | 52 ChromeRenderViewTest::SetUp(); |
53 | 53 |
(...skipping 27 matching lines...) Expand all Loading... |
81 " <option>Texas</option>" | 81 " <option>Texas</option>" |
82 " </select>" | 82 " </select>" |
83 "</form>"); | 83 "</form>"); |
84 | 84 |
85 // Verify that "FormsSeen" sends the expected number of fields. | 85 // Verify that "FormsSeen" sends the expected number of fields. |
86 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 86 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
87 AutofillHostMsg_FormsSeen::ID); | 87 AutofillHostMsg_FormsSeen::ID); |
88 ASSERT_NE(nullptr, message); | 88 ASSERT_NE(nullptr, message); |
89 AutofillHostMsg_FormsSeen::Param params; | 89 AutofillHostMsg_FormsSeen::Param params; |
90 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 90 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
91 std::vector<FormData> forms = params.a; | 91 std::vector<FormData> forms = get<0>(params); |
92 ASSERT_EQ(1UL, forms.size()); | 92 ASSERT_EQ(1UL, forms.size()); |
93 ASSERT_EQ(4UL, forms[0].fields.size()); | 93 ASSERT_EQ(4UL, forms[0].fields.size()); |
94 | 94 |
95 FormFieldData expected; | 95 FormFieldData expected; |
96 | 96 |
97 expected.name = ASCIIToUTF16("firstname"); | 97 expected.name = ASCIIToUTF16("firstname"); |
98 expected.value = base::string16(); | 98 expected.value = base::string16(); |
99 expected.form_control_type = "text"; | 99 expected.form_control_type = "text"; |
100 expected.max_length = WebInputElement::defaultMaxLength(); | 100 expected.max_length = WebInputElement::defaultMaxLength(); |
101 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 101 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 "newForm.appendChild(newFirstname);" | 144 "newForm.appendChild(newFirstname);" |
145 "newForm.appendChild(newLastname);" | 145 "newForm.appendChild(newLastname);" |
146 "newForm.appendChild(newEmail);" | 146 "newForm.appendChild(newEmail);" |
147 "document.body.appendChild(newForm);"); | 147 "document.body.appendChild(newForm);"); |
148 msg_loop_.RunUntilIdle(); | 148 msg_loop_.RunUntilIdle(); |
149 | 149 |
150 message = render_thread_->sink().GetFirstMessageMatching( | 150 message = render_thread_->sink().GetFirstMessageMatching( |
151 AutofillHostMsg_FormsSeen::ID); | 151 AutofillHostMsg_FormsSeen::ID); |
152 ASSERT_NE(nullptr, message); | 152 ASSERT_NE(nullptr, message); |
153 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 153 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
154 forms = params.a; | 154 forms = get<0>(params); |
155 ASSERT_EQ(1UL, forms.size()); | 155 ASSERT_EQ(1UL, forms.size()); |
156 ASSERT_EQ(3UL, forms[0].fields.size()); | 156 ASSERT_EQ(3UL, forms[0].fields.size()); |
157 | 157 |
158 expected.form_control_type = "text"; | 158 expected.form_control_type = "text"; |
159 expected.max_length = WebInputElement::defaultMaxLength(); | 159 expected.max_length = WebInputElement::defaultMaxLength(); |
160 | 160 |
161 expected.name = ASCIIToUTF16("second_firstname"); | 161 expected.name = ASCIIToUTF16("second_firstname"); |
162 expected.value = ASCIIToUTF16("Bob"); | 162 expected.value = ASCIIToUTF16("Bob"); |
163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
164 | 164 |
(...skipping 11 matching lines...) Expand all Loading... |
176 " <input type='text' id='firstname'/>" | 176 " <input type='text' id='firstname'/>" |
177 " <input type='text' id='middlename'/>" | 177 " <input type='text' id='middlename'/>" |
178 "</form>"); | 178 "</form>"); |
179 | 179 |
180 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 180 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
181 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 181 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
182 AutofillHostMsg_FormsSeen::ID); | 182 AutofillHostMsg_FormsSeen::ID); |
183 ASSERT_NE(nullptr, message); | 183 ASSERT_NE(nullptr, message); |
184 AutofillHostMsg_FormsSeen::Param params; | 184 AutofillHostMsg_FormsSeen::Param params; |
185 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 185 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
186 const std::vector<FormData>& forms = params.a; | 186 const std::vector<FormData>& forms = get<0>(params); |
187 ASSERT_EQ(0UL, forms.size()); | 187 ASSERT_EQ(0UL, forms.size()); |
188 } | 188 } |
189 | 189 |
190 TEST_F(AutofillRendererTest, ShowAutofillWarning) { | 190 TEST_F(AutofillRendererTest, ShowAutofillWarning) { |
191 LoadHTML("<form method='POST' autocomplete='Off'>" | 191 LoadHTML("<form method='POST' autocomplete='Off'>" |
192 " <input id='firstname' autocomplete='OFF'/>" | 192 " <input id='firstname' autocomplete='OFF'/>" |
193 " <input id='middlename'/>" | 193 " <input id='middlename'/>" |
194 " <input id='lastname'/>" | 194 " <input id='lastname'/>" |
195 "</form>"); | 195 "</form>"); |
196 | 196 |
(...skipping 14 matching lines...) Expand all Loading... |
211 // specifies autocomplete="off". This should still trigger an IPC which | 211 // specifies autocomplete="off". This should still trigger an IPC which |
212 // shouldn't display warnings. | 212 // shouldn't display warnings. |
213 static_cast<PageClickListener*>(autofill_agent_) | 213 static_cast<PageClickListener*>(autofill_agent_) |
214 ->FormControlElementClicked(firstname, true); | 214 ->FormControlElementClicked(firstname, true); |
215 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( | 215 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( |
216 AutofillHostMsg_QueryFormFieldAutofill::ID); | 216 AutofillHostMsg_QueryFormFieldAutofill::ID); |
217 EXPECT_NE(nullptr, message1); | 217 EXPECT_NE(nullptr, message1); |
218 | 218 |
219 AutofillQueryParam query_param; | 219 AutofillQueryParam query_param; |
220 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); | 220 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); |
221 EXPECT_FALSE(query_param.e); | 221 EXPECT_FALSE(get<4>(query_param)); |
222 render_thread_->sink().ClearMessages(); | 222 render_thread_->sink().ClearMessages(); |
223 | 223 |
224 // Simulate attempting to Autofill the form from the second element, which | 224 // Simulate attempting to Autofill the form from the second element, which |
225 // does not specify autocomplete="off". This should trigger an IPC that will | 225 // does not specify autocomplete="off". This should trigger an IPC that will |
226 // show warnings, as we *do* show warnings for elements that don't themselves | 226 // show warnings, as we *do* show warnings for elements that don't themselves |
227 // set autocomplete="off", but for which the form does. | 227 // set autocomplete="off", but for which the form does. |
228 static_cast<PageClickListener*>(autofill_agent_) | 228 static_cast<PageClickListener*>(autofill_agent_) |
229 ->FormControlElementClicked(middlename, true); | 229 ->FormControlElementClicked(middlename, true); |
230 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 230 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
231 AutofillHostMsg_QueryFormFieldAutofill::ID); | 231 AutofillHostMsg_QueryFormFieldAutofill::ID); |
232 ASSERT_NE(nullptr, message2); | 232 ASSERT_NE(nullptr, message2); |
233 | 233 |
234 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); | 234 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); |
235 EXPECT_TRUE(query_param.e); | 235 EXPECT_TRUE(get<4>(query_param)); |
236 } | 236 } |
237 | 237 |
238 // Regression test for [ http://crbug.com/346010 ]. | 238 // Regression test for [ http://crbug.com/346010 ]. |
239 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 239 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
240 LoadHTML("<form id='form'>" | 240 LoadHTML("<form id='form'>" |
241 "<foo id='foo'>" | 241 "<foo id='foo'>" |
242 "<script id='script'>" | 242 "<script id='script'>" |
243 "document.documentElement.appendChild(foo);" | 243 "document.documentElement.appendChild(foo);" |
244 "newDoc = document.implementation.createDocument(" | 244 "newDoc = document.implementation.createDocument(" |
245 " 'http://www.w3.org/1999/xhtml', 'html');" | 245 " 'http://www.w3.org/1999/xhtml', 'html');" |
(...skipping 11 matching lines...) Expand all Loading... |
257 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); | 257 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); |
258 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); | 258 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); |
259 LoadHTML(html_data.c_str()); | 259 LoadHTML(html_data.c_str()); |
260 | 260 |
261 // Verify that "FormsSeen" sends the expected number of fields. | 261 // Verify that "FormsSeen" sends the expected number of fields. |
262 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 262 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
263 AutofillHostMsg_FormsSeen::ID); | 263 AutofillHostMsg_FormsSeen::ID); |
264 ASSERT_NE(nullptr, message); | 264 ASSERT_NE(nullptr, message); |
265 AutofillHostMsg_FormsSeen::Param params; | 265 AutofillHostMsg_FormsSeen::Param params; |
266 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 266 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
267 std::vector<FormData> forms = params.a; | 267 std::vector<FormData> forms = get<0>(params); |
268 ASSERT_EQ(1UL, forms.size()); | 268 ASSERT_EQ(1UL, forms.size()); |
269 ASSERT_EQ(7UL, forms[0].fields.size()); | 269 ASSERT_EQ(7UL, forms[0].fields.size()); |
270 | 270 |
271 render_thread_->sink().ClearMessages(); | 271 render_thread_->sink().ClearMessages(); |
272 | 272 |
273 ExecuteJavaScript("AddFields()"); | 273 ExecuteJavaScript("AddFields()"); |
274 msg_loop_.RunUntilIdle(); | 274 msg_loop_.RunUntilIdle(); |
275 | 275 |
276 message = render_thread_->sink().GetFirstMessageMatching( | 276 message = render_thread_->sink().GetFirstMessageMatching( |
277 AutofillHostMsg_FormsSeen::ID); | 277 AutofillHostMsg_FormsSeen::ID); |
278 ASSERT_NE(nullptr, message); | 278 ASSERT_NE(nullptr, message); |
279 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 279 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
280 forms = params.a; | 280 forms = get<0>(params); |
281 ASSERT_EQ(1UL, forms.size()); | 281 ASSERT_EQ(1UL, forms.size()); |
282 ASSERT_EQ(9UL, forms[0].fields.size()); | 282 ASSERT_EQ(9UL, forms[0].fields.size()); |
283 | 283 |
284 FormFieldData expected; | 284 FormFieldData expected; |
285 | 285 |
286 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); | 286 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); |
287 expected.value.clear(); | 287 expected.value.clear(); |
288 expected.form_control_type = "text"; | 288 expected.form_control_type = "text"; |
289 expected.max_length = WebInputElement::defaultMaxLength(); | 289 expected.max_length = WebInputElement::defaultMaxLength(); |
290 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); | 290 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 412 } |
413 | 413 |
414 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 414 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
415 // Attempting to show the requestAutocomplete dialog again should be ignored. | 415 // Attempting to show the requestAutocomplete dialog again should be ignored. |
416 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); | 416 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); |
417 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 417 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
418 AutofillHostMsg_RequestAutocomplete::ID)); | 418 AutofillHostMsg_RequestAutocomplete::ID)); |
419 } | 419 } |
420 | 420 |
421 } // namespace autofill | 421 } // namespace autofill |
OLD | NEW |