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 Tuple<int, | 39 typedef Tuple<int, autofill::FormData, autofill::FormFieldData, gfx::RectF> |
40 autofill::FormData, | 40 AutofillQueryParam; |
41 autofill::FormFieldData, | |
42 gfx::RectF, | |
43 bool> AutofillQueryParam; | |
44 | 41 |
45 class AutofillRendererTest : public ChromeRenderViewTest { | 42 class AutofillRendererTest : public ChromeRenderViewTest { |
46 public: | 43 public: |
47 AutofillRendererTest() {} | 44 AutofillRendererTest() {} |
48 ~AutofillRendererTest() override {} | 45 ~AutofillRendererTest() override {} |
49 | 46 |
50 protected: | 47 protected: |
51 void SetUp() override { | 48 void SetUp() override { |
52 ChromeRenderViewTest::SetUp(); | 49 ChromeRenderViewTest::SetUp(); |
53 | 50 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 177 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
181 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 178 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
182 AutofillHostMsg_FormsSeen::ID); | 179 AutofillHostMsg_FormsSeen::ID); |
183 ASSERT_NE(nullptr, message); | 180 ASSERT_NE(nullptr, message); |
184 AutofillHostMsg_FormsSeen::Param params; | 181 AutofillHostMsg_FormsSeen::Param params; |
185 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 182 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
186 const std::vector<FormData>& forms = get<0>(params); | 183 const std::vector<FormData>& forms = get<0>(params); |
187 ASSERT_EQ(0UL, forms.size()); | 184 ASSERT_EQ(0UL, forms.size()); |
188 } | 185 } |
189 | 186 |
190 TEST_F(AutofillRendererTest, ShowAutofillWarning) { | |
191 LoadHTML("<form method='POST' autocomplete='Off'>" | |
192 " <input id='firstname' autocomplete='OFF'/>" | |
193 " <input id='middlename'/>" | |
194 " <input id='lastname'/>" | |
195 "</form>"); | |
196 | |
197 // Verify that "QueryFormFieldAutofill" isn't sent prior to a user | |
198 // interaction. | |
199 const IPC::Message* message0 = render_thread_->sink().GetFirstMessageMatching( | |
200 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
201 EXPECT_EQ(nullptr, message0); | |
202 | |
203 WebFrame* web_frame = GetMainFrame(); | |
204 WebDocument document = web_frame->document(); | |
205 WebInputElement firstname = | |
206 document.getElementById("firstname").to<WebInputElement>(); | |
207 WebInputElement middlename = | |
208 document.getElementById("middlename").to<WebInputElement>(); | |
209 | |
210 // Simulate attempting to Autofill the form from the first element, which | |
211 // specifies autocomplete="off". This should still trigger an IPC which | |
212 // shouldn't display warnings. | |
213 static_cast<PageClickListener*>(autofill_agent_) | |
214 ->FormControlElementClicked(firstname, true); | |
215 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( | |
216 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
217 EXPECT_NE(nullptr, message1); | |
218 | |
219 AutofillQueryParam query_param; | |
220 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); | |
221 EXPECT_FALSE(get<4>(query_param)); | |
222 render_thread_->sink().ClearMessages(); | |
223 | |
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 | |
226 // show warnings, as we *do* show warnings for elements that don't themselves | |
227 // set autocomplete="off", but for which the form does. | |
228 static_cast<PageClickListener*>(autofill_agent_) | |
229 ->FormControlElementClicked(middlename, true); | |
230 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | |
231 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
232 ASSERT_NE(nullptr, message2); | |
233 | |
234 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); | |
235 EXPECT_TRUE(get<4>(query_param)); | |
236 } | |
237 | |
238 // Regression test for [ http://crbug.com/346010 ]. | 187 // Regression test for [ http://crbug.com/346010 ]. |
239 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 188 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
240 LoadHTML("<form id='form'>" | 189 LoadHTML("<form id='form'>" |
241 "<foo id='foo'>" | 190 "<foo id='foo'>" |
242 "<script id='script'>" | 191 "<script id='script'>" |
243 "document.documentElement.appendChild(foo);" | 192 "document.documentElement.appendChild(foo);" |
244 "newDoc = document.implementation.createDocument(" | 193 "newDoc = document.implementation.createDocument(" |
245 " 'http://www.w3.org/1999/xhtml', 'html');" | 194 " 'http://www.w3.org/1999/xhtml', 'html');" |
246 "foo.insertBefore(form, script);" | 195 "foo.insertBefore(form, script);" |
247 "newDoc.adoptNode(foo);" | 196 "newDoc.adoptNode(foo);" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 }; | 316 }; |
368 | 317 |
369 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 318 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
370 // Attempting to show the requestAutocomplete dialog again should be ignored. | 319 // Attempting to show the requestAutocomplete dialog again should be ignored. |
371 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); | 320 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); |
372 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 321 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
373 AutofillHostMsg_RequestAutocomplete::ID)); | 322 AutofillHostMsg_RequestAutocomplete::ID)); |
374 } | 323 } |
375 | 324 |
376 } // namespace autofill | 325 } // namespace autofill |
OLD | NEW |