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/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
10 #include "components/autofill/content/renderer/autofill_agent.h" | 10 #include "components/autofill/content/renderer/autofill_agent.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 protected: | 47 protected: |
48 virtual void SetUp() OVERRIDE { | 48 virtual void SetUp() OVERRIDE { |
49 ChromeRenderViewTest::SetUp(); | 49 ChromeRenderViewTest::SetUp(); |
50 | 50 |
51 // Don't want any delay for form state sync changes. This will still post a | 51 // Don't want any delay for form state sync changes. This will still post a |
52 // message so updates will get coalesced, but as soon as we spin the message | 52 // message so updates will get coalesced, but as soon as we spin the message |
53 // loop, it will generate an update. | 53 // loop, it will generate an update. |
54 SendContentStateImmediately(); | 54 SendContentStateImmediately(); |
55 } | 55 } |
56 | 56 |
| 57 void SimulateRequestAutocompleteResult( |
| 58 const blink::WebFormElement::AutocompleteResult& result, |
| 59 const base::string16& message) { |
| 60 AutofillMsg_RequestAutocompleteResult msg(0, result, message, FormData()); |
| 61 static_cast<content::RenderViewObserver*>(autofill_agent_) |
| 62 ->OnMessageReceived(msg); |
| 63 } |
| 64 |
57 private: | 65 private: |
58 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); | 66 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); |
59 }; | 67 }; |
60 | 68 |
61 TEST_F(AutofillRendererTest, SendForms) { | 69 TEST_F(AutofillRendererTest, SendForms) { |
62 LoadHTML("<form method='POST'>" | 70 LoadHTML("<form method='POST'>" |
63 " <input type='text' id='firstname'/>" | 71 " <input type='text' id='firstname'/>" |
64 " <input type='text' id='middlename'/>" | 72 " <input type='text' id='middlename'/>" |
65 " <input type='text' id='lastname' autoComplete='off'/>" | 73 " <input type='text' id='lastname' autoComplete='off'/>" |
66 " <input type='hidden' id='email'/>" | 74 " <input type='hidden' id='email'/>" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 WebFrame* web_frame = GetMainFrame(); | 200 WebFrame* web_frame = GetMainFrame(); |
193 WebDocument document = web_frame->document(); | 201 WebDocument document = web_frame->document(); |
194 WebInputElement firstname = | 202 WebInputElement firstname = |
195 document.getElementById("firstname").to<WebInputElement>(); | 203 document.getElementById("firstname").to<WebInputElement>(); |
196 WebInputElement middlename = | 204 WebInputElement middlename = |
197 document.getElementById("middlename").to<WebInputElement>(); | 205 document.getElementById("middlename").to<WebInputElement>(); |
198 | 206 |
199 // Simulate attempting to Autofill the form from the first element, which | 207 // Simulate attempting to Autofill the form from the first element, which |
200 // specifies autocomplete="off". This should still trigger an IPC which | 208 // specifies autocomplete="off". This should still trigger an IPC which |
201 // shouldn't display warnings. | 209 // shouldn't display warnings. |
202 autofill_agent_->FormControlElementClicked(firstname, true); | 210 static_cast<PageClickListener*>(autofill_agent_) |
| 211 ->FormControlElementClicked(firstname, true); |
203 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( | 212 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( |
204 AutofillHostMsg_QueryFormFieldAutofill::ID); | 213 AutofillHostMsg_QueryFormFieldAutofill::ID); |
205 EXPECT_NE(static_cast<IPC::Message*>(NULL), message1); | 214 EXPECT_NE(static_cast<IPC::Message*>(NULL), message1); |
206 | 215 |
207 AutofillQueryParam query_param; | 216 AutofillQueryParam query_param; |
208 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); | 217 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); |
209 EXPECT_FALSE(query_param.e); | 218 EXPECT_FALSE(query_param.e); |
210 render_thread_->sink().ClearMessages(); | 219 render_thread_->sink().ClearMessages(); |
211 | 220 |
212 // Simulate attempting to Autofill the form from the second element, which | 221 // Simulate attempting to Autofill the form from the second element, which |
213 // does not specify autocomplete="off". This should trigger an IPC that will | 222 // does not specify autocomplete="off". This should trigger an IPC that will |
214 // show warnings, as we *do* show warnings for elements that don't themselves | 223 // show warnings, as we *do* show warnings for elements that don't themselves |
215 // set autocomplete="off", but for which the form does. | 224 // set autocomplete="off", but for which the form does. |
216 autofill_agent_->FormControlElementClicked(middlename, true); | 225 static_cast<PageClickListener*>(autofill_agent_) |
| 226 ->FormControlElementClicked(middlename, true); |
217 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 227 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
218 AutofillHostMsg_QueryFormFieldAutofill::ID); | 228 AutofillHostMsg_QueryFormFieldAutofill::ID); |
219 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 229 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
220 | 230 |
221 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); | 231 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); |
222 EXPECT_TRUE(query_param.e); | 232 EXPECT_TRUE(query_param.e); |
223 } | 233 } |
224 | 234 |
225 // Regression test for [ http://crbug.com/346010 ]. | 235 // Regression test for [ http://crbug.com/346010 ]. |
226 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 236 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 280 |
271 WebVector<WebFormElement> forms; | 281 WebVector<WebFormElement> forms; |
272 invoking_frame()->document().forms(forms); | 282 invoking_frame()->document().forms(forms); |
273 ASSERT_EQ(1U, forms.size()); | 283 ASSERT_EQ(1U, forms.size()); |
274 invoking_form_ = forms[0]; | 284 invoking_form_ = forms[0]; |
275 ASSERT_FALSE(invoking_form().isNull()); | 285 ASSERT_FALSE(invoking_form().isNull()); |
276 | 286 |
277 render_thread_->sink().ClearMessages(); | 287 render_thread_->sink().ClearMessages(); |
278 | 288 |
279 // Invoke requestAutocomplete to show the dialog. | 289 // Invoke requestAutocomplete to show the dialog. |
280 autofill_agent_->didRequestAutocomplete(invoking_form()); | 290 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
| 291 ->didRequestAutocomplete(invoking_form()); |
281 ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 292 ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
282 AutofillHostMsg_RequestAutocomplete::ID)); | 293 AutofillHostMsg_RequestAutocomplete::ID)); |
283 | 294 |
284 render_thread_->sink().ClearMessages(); | 295 render_thread_->sink().ClearMessages(); |
285 } | 296 } |
286 | 297 |
287 virtual void TearDown() OVERRIDE { | 298 virtual void TearDown() OVERRIDE { |
288 invoking_form_.reset(); | 299 invoking_form_.reset(); |
289 AutofillRendererTest::TearDown(); | 300 AutofillRendererTest::TearDown(); |
290 } | 301 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 333 |
323 TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) { | 334 TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) { |
324 // Pretend that the top-level frame navigated. A cancel should be sent. | 335 // Pretend that the top-level frame navigated. A cancel should be sent. |
325 NavigateFrame(GetMainFrame()); | 336 NavigateFrame(GetMainFrame()); |
326 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 337 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
327 AutofillHostMsg_CancelRequestAutocomplete::ID)); | 338 AutofillHostMsg_CancelRequestAutocomplete::ID)); |
328 } | 339 } |
329 | 340 |
330 TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) { | 341 TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) { |
331 // Pretend that the dialog was cancelled. | 342 // Pretend that the dialog was cancelled. |
332 autofill_agent_->OnRequestAutocompleteResult( | 343 SimulateRequestAutocompleteResult( |
333 WebFormElement::AutocompleteResultErrorCancel, | 344 WebFormElement::AutocompleteResultErrorCancel, |
334 base::ASCIIToUTF16("Print me to the console"), | 345 base::ASCIIToUTF16("Print me to the console")); |
335 FormData()); | |
336 | 346 |
337 // Additional navigations should not crash nor send cancels. | 347 // Additional navigations should not crash nor send cancels. |
338 NavigateFrame(invoking_frame()); | 348 NavigateFrame(invoking_frame()); |
339 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 349 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
340 AutofillHostMsg_CancelRequestAutocomplete::ID)); | 350 AutofillHostMsg_CancelRequestAutocomplete::ID)); |
341 } | 351 } |
342 | 352 |
343 TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) { | 353 TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) { |
344 // Pretend that the dialog was cancelled. | 354 // Pretend that the dialog was cancelled. |
345 autofill_agent_->OnRequestAutocompleteResult( | 355 SimulateRequestAutocompleteResult( |
346 WebFormElement::AutocompleteResultErrorCancel, | 356 WebFormElement::AutocompleteResultErrorCancel, |
347 base::ASCIIToUTF16("Print me to the console"), | 357 base::ASCIIToUTF16("Print me to the console")); |
348 FormData()); | |
349 | 358 |
350 // Additional navigations should not crash nor send cancels. | 359 // Additional navigations should not crash nor send cancels. |
351 NavigateFrame(GetMainFrame()); | 360 NavigateFrame(GetMainFrame()); |
352 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 361 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
353 AutofillHostMsg_CancelRequestAutocomplete::ID)); | 362 AutofillHostMsg_CancelRequestAutocomplete::ID)); |
354 } | 363 } |
355 | 364 |
356 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 365 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
357 // Attempting to show the requestAutocomplete dialog again should be ignored. | 366 // Attempting to show the requestAutocomplete dialog again should be ignored. |
358 autofill_agent_->didRequestAutocomplete(invoking_form()); | 367 static_cast<blink::WebAutofillClient*>(autofill_agent_) |
| 368 ->didRequestAutocomplete(invoking_form()); |
359 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 369 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
360 AutofillHostMsg_RequestAutocomplete::ID)); | 370 AutofillHostMsg_RequestAutocomplete::ID)); |
361 } | 371 } |
362 | 372 |
363 } // namespace autofill | 373 } // namespace autofill |
OLD | NEW |