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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/test/base/chrome_render_view_test.h" | 6 #include "chrome/test/base/chrome_render_view_test.h" |
7 #include "components/autofill/core/common/autofill_messages.h" | 7 #include "components/autofill/core/common/autofill_messages.h" |
8 #include "components/autofill/core/common/form_data.h" | 8 #include "components/autofill/core/common/form_data.h" |
9 #include "components/autofill/core/common/form_field_data.h" | 9 #include "components/autofill/core/common/form_field_data.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 expected.max_length = WebInputElement::defaultMaxLength(); | 123 expected.max_length = WebInputElement::defaultMaxLength(); |
124 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); | 124 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); |
125 | 125 |
126 expected.name = ASCIIToUTF16("state"); | 126 expected.name = ASCIIToUTF16("state"); |
127 expected.value = ASCIIToUTF16("?"); | 127 expected.value = ASCIIToUTF16("?"); |
128 expected.form_control_type = "select-one"; | 128 expected.form_control_type = "select-one"; |
129 expected.max_length = 0; | 129 expected.max_length = 0; |
130 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); | 130 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); |
131 } | 131 } |
132 | 132 |
133 TEST_F(ChromeRenderViewTest, SendDynamicForms) { | |
134 // Don't want any delay for form state sync changes. This will still post a | |
135 // message so updates will get coalesced, but as soon as we spin the message | |
136 // loop, it will generate an update. | |
137 SendContentStateImmediately(); | |
138 | |
139 LoadHTML("<form method=\"POST\" id=\"testform\">" | |
140 " <input type=\"text\" id=\"firstname\"/>" | |
141 " <input type=\"text\" id=\"middlename\"/>" | |
142 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" | |
143 " <input type=\"hidden\" id=\"email\"/>" | |
144 " <select id=\"state\"/>" | |
145 " <option>?</option>" | |
146 " <option>California</option>" | |
147 " <option>Texas</option>" | |
148 " </select>" | |
149 "</form>"); | |
150 | |
151 // Verify that "FormsSeen" sends the expected number of fields. | |
152 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | |
153 AutofillHostMsg_FormsSeen::ID); | |
154 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | |
155 AutofillHostMsg_FormsSeen::Param params; | |
156 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
157 const std::vector<FormData>& forms = params.a; | |
158 ASSERT_EQ(1UL, forms.size()); | |
159 ASSERT_EQ(4UL, forms[0].fields.size()); | |
160 | |
161 autofill_agent_->OnAutocheckoutSupported(); | |
162 render_thread_->sink().ClearMessages(); | |
163 ExecuteJavaScript("var newInput=document.createElement(\"input\");" | |
164 "newInput.setAttribute(\"type\",\"text\");" | |
165 "newInput.setAttribute(\"id\", \"telephone\");" | |
166 "document.getElementById(\"testform\")" | |
167 ".appendChild(newInput);"); | |
168 msg_loop_.RunUntilIdle(); | |
169 | |
170 // Verify that FormsSeen is present with the new field. | |
171 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | |
172 AutofillHostMsg_FormsSeen::ID); | |
173 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | |
174 AutofillHostMsg_FormsSeen::Read(message2, ¶ms); | |
175 const std::vector<FormData>& new_forms = params.a; | |
176 ASSERT_EQ(1UL, new_forms.size()); | |
177 ASSERT_EQ(5UL, new_forms[0].fields.size()); | |
178 | |
179 FormFieldData expected; | |
180 | |
181 expected.name = ASCIIToUTF16("telephone"); | |
182 expected.value = string16(); | |
183 expected.form_control_type = "text"; | |
184 expected.max_length = WebInputElement::defaultMaxLength(); | |
185 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[4]); | |
186 } | |
187 | |
188 TEST_F(ChromeRenderViewTest, EnsureNoFormSeenIfTooFewFields) { | 133 TEST_F(ChromeRenderViewTest, EnsureNoFormSeenIfTooFewFields) { |
189 // Don't want any delay for form state sync changes. This will still post a | 134 // Don't want any delay for form state sync changes. This will still post a |
190 // message so updates will get coalesced, but as soon as we spin the message | 135 // message so updates will get coalesced, but as soon as we spin the message |
191 // loop, it will generate an update. | 136 // loop, it will generate an update. |
192 SendContentStateImmediately(); | 137 SendContentStateImmediately(); |
193 | 138 |
194 LoadHTML("<form method=\"POST\">" | 139 LoadHTML("<form method=\"POST\">" |
195 " <input type=\"text\" id=\"firstname\"/>" | 140 " <input type=\"text\" id=\"firstname\"/>" |
196 " <input type=\"text\" id=\"middlename\"/>" | 141 " <input type=\"text\" id=\"middlename\"/>" |
197 "</form>"); | 142 "</form>"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 autofill_agent_->InputElementClicked(middlename, true, true); | 196 autofill_agent_->InputElementClicked(middlename, true, true); |
252 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 197 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
253 AutofillHostMsg_QueryFormFieldAutofill::ID); | 198 AutofillHostMsg_QueryFormFieldAutofill::ID); |
254 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 199 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
255 | 200 |
256 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); | 201 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); |
257 EXPECT_TRUE(query_param.e); | 202 EXPECT_TRUE(query_param.e); |
258 } | 203 } |
259 | 204 |
260 } // namespace autofill | 205 } // namespace autofill |
OLD | NEW |