OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <tuple> | 5 #include <tuple> |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
9 #include "build/build_config.h" | 10 #include "build/build_config.h" |
10 #include "chrome/test/base/chrome_render_view_test.h" | 11 #include "chrome/test/base/chrome_render_view_test.h" |
11 #include "components/autofill/content/common/autofill_messages.h" | 12 #include "components/autofill/content/common/autofill_messages.h" |
12 #include "components/autofill/content/renderer/autofill_agent.h" | 13 #include "components/autofill/content/renderer/autofill_agent.h" |
13 #include "components/autofill/core/common/form_data.h" | 14 #include "components/autofill/core/common/form_data.h" |
14 #include "content/public/test/mock_render_thread.h" | 15 #include "content/public/test/mock_render_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/public/web/WebDocument.h" | 17 #include "third_party/WebKit/public/web/WebDocument.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const IPC::Message* will_submit_message = | 81 const IPC::Message* will_submit_message = |
81 render_thread->sink().GetFirstMessageMatching( | 82 render_thread->sink().GetFirstMessageMatching( |
82 AutofillHostMsg_WillSubmitForm::ID); | 83 AutofillHostMsg_WillSubmitForm::ID); |
83 const IPC::Message* submitted_message = | 84 const IPC::Message* submitted_message = |
84 render_thread->sink().GetFirstMessageMatching( | 85 render_thread->sink().GetFirstMessageMatching( |
85 AutofillHostMsg_FormSubmitted::ID); | 86 AutofillHostMsg_FormSubmitted::ID); |
86 EXPECT_EQ(NULL, will_submit_message); | 87 EXPECT_EQ(NULL, will_submit_message); |
87 EXPECT_EQ(NULL, submitted_message); | 88 EXPECT_EQ(NULL, submitted_message); |
88 } | 89 } |
89 | 90 |
| 91 void DummyDidFillAutofillFormData(const FormData& filled, int64_t timestamp) {} |
| 92 |
90 // Simulates receiving a message from the browser to fill a form. | 93 // Simulates receiving a message from the browser to fill a form. |
91 void SimulateOnFillForm(content::MockRenderThread* render_thread, | 94 void SimulateOnFillForm(content::MockRenderThread* render_thread, |
92 autofill::AutofillAgent* autofill_agent, | 95 autofill::AutofillAgent* autofill_agent, |
93 blink::WebFrame* main_frame) { | 96 blink::WebFrame* main_frame) { |
94 WebDocument document = main_frame->document(); | 97 WebDocument document = main_frame->document(); |
95 WebElement element = | 98 WebElement element = |
96 document.getElementById(WebString::fromUTF8("fname")); | 99 document.getElementById(WebString::fromUTF8("fname")); |
97 ASSERT_FALSE(element.isNull()); | 100 ASSERT_FALSE(element.isNull()); |
98 | 101 |
99 // This call is necessary to setup the autofill agent appropriate for the | 102 // This call is necessary to setup the autofill agent appropriate for the |
(...skipping 12 matching lines...) Expand all Loading... |
112 field_data.name = base::ASCIIToUTF16("fname"); | 115 field_data.name = base::ASCIIToUTF16("fname"); |
113 field_data.value = base::ASCIIToUTF16("John"); | 116 field_data.value = base::ASCIIToUTF16("John"); |
114 field_data.is_autofilled = true; | 117 field_data.is_autofilled = true; |
115 data.fields.push_back(field_data); | 118 data.fields.push_back(field_data); |
116 | 119 |
117 field_data.name = base::ASCIIToUTF16("lname"); | 120 field_data.name = base::ASCIIToUTF16("lname"); |
118 field_data.value = base::ASCIIToUTF16("Smith"); | 121 field_data.value = base::ASCIIToUTF16("Smith"); |
119 field_data.is_autofilled = true; | 122 field_data.is_autofilled = true; |
120 data.fields.push_back(field_data); | 123 data.fields.push_back(field_data); |
121 | 124 |
122 AutofillMsg_FillForm msg(0, 0, data); | 125 autofill_agent->FillForm(0, data, base::Bind(&DummyDidFillAutofillFormData)); |
123 static_cast<content::RenderFrameObserver*>(autofill_agent) | |
124 ->OnMessageReceived(msg); | |
125 } | 126 } |
126 | 127 |
127 } // end namespace | 128 } // end namespace |
128 | 129 |
129 // Tests that submitting a form generates WillSubmitForm and FormSubmitted | 130 // Tests that submitting a form generates WillSubmitForm and FormSubmitted |
130 // messages with the form fields. | 131 // messages with the form fields. |
131 TEST_F(FormAutocompleteTest, NormalFormSubmit) { | 132 TEST_F(FormAutocompleteTest, NormalFormSubmit) { |
132 // Load a form. | 133 // Load a form. |
133 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 134 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" |
134 "<input name='lname' value='Deckard'/></form></html>"); | 135 "<input name='lname' value='Deckard'/></form></html>"); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 508 |
508 // Submit the form. | 509 // Submit the form. |
509 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 510 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
510 ProcessPendingMessages(); | 511 ProcessPendingMessages(); |
511 | 512 |
512 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", | 513 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", |
513 true /* expect_submitted_message */); | 514 true /* expect_submitted_message */); |
514 } | 515 } |
515 | 516 |
516 } // namespace autofill | 517 } // namespace autofill |
OLD | NEW |