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/utf_string_conversions.h" | 5 #include "base/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/common/autofill_messages.h" | 7 #include "components/autofill/common/autofill_messages.h" |
8 #include "components/autofill/common/form_data.h" | 8 #include "components/autofill/common/form_data.h" |
9 #include "components/autofill/common/form_field_data.h" | 9 #include "components/autofill/common/form_field_data.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 expected.max_length = WebInputElement::defaultMaxLength(); | 118 expected.max_length = WebInputElement::defaultMaxLength(); |
119 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); | 119 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); |
120 | 120 |
121 expected.name = ASCIIToUTF16("state"); | 121 expected.name = ASCIIToUTF16("state"); |
122 expected.value = ASCIIToUTF16("?"); | 122 expected.value = ASCIIToUTF16("?"); |
123 expected.form_control_type = "select-one"; | 123 expected.form_control_type = "select-one"; |
124 expected.max_length = 0; | 124 expected.max_length = 0; |
125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); | 125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); |
126 } | 126 } |
127 | 127 |
| 128 TEST_F(ChromeRenderViewTest, SendDynamicForms) { |
| 129 // Don't want any delay for form state sync changes. This will still post a |
| 130 // message so updates will get coalesced, but as soon as we spin the message |
| 131 // loop, it will generate an update. |
| 132 SendContentStateImmediately(); |
| 133 |
| 134 LoadHTML("<form method=\"POST\" id=\"testform\">" |
| 135 " <input type=\"text\" id=\"firstname\"/>" |
| 136 " <input type=\"text\" id=\"middlename\"/>" |
| 137 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" |
| 138 " <input type=\"hidden\" id=\"email\"/>" |
| 139 " <select id=\"state\"/>" |
| 140 " <option>?</option>" |
| 141 " <option>California</option>" |
| 142 " <option>Texas</option>" |
| 143 " </select>" |
| 144 "</form>"); |
| 145 |
| 146 // Verify that "FormsSeen" sends the expected number of fields. |
| 147 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 148 AutofillHostMsg_FormsSeen::ID); |
| 149 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 150 AutofillHostMsg_FormsSeen::Param params; |
| 151 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
| 152 const std::vector<FormData>& forms = params.a; |
| 153 ASSERT_EQ(1UL, forms.size()); |
| 154 ASSERT_EQ(4UL, forms[0].fields.size()); |
| 155 |
| 156 autofill_agent_->OnAutocheckoutSupported(); |
| 157 render_thread_->sink().ClearMessages(); |
| 158 ExecuteJavaScript("var newInput=document.createElement(\"input\");" |
| 159 "newInput.setAttribute(\"type\",\"text\");" |
| 160 "newInput.setAttribute(\"id\", \"telephone\");" |
| 161 "document.getElementById(\"testform\")" |
| 162 ".appendChild(newInput);"); |
| 163 msg_loop_.RunUntilIdle(); |
| 164 |
| 165 // Verify that FormsSeen is present with the new field. |
| 166 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
| 167 AutofillHostMsg_FormsSeen::ID); |
| 168 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
| 169 AutofillHostMsg_FormsSeen::Read(message2, ¶ms); |
| 170 const std::vector<FormData>& new_forms = params.a; |
| 171 ASSERT_EQ(1UL, new_forms.size()); |
| 172 ASSERT_EQ(5UL, new_forms[0].fields.size()); |
| 173 |
| 174 FormFieldData expected; |
| 175 |
| 176 expected.name = ASCIIToUTF16("telephone"); |
| 177 expected.value = string16(); |
| 178 expected.form_control_type = "text"; |
| 179 expected.max_length = WebInputElement::defaultMaxLength(); |
| 180 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[4]); |
| 181 } |
| 182 |
128 TEST_F(ChromeRenderViewTest, FillFormElement) { | 183 TEST_F(ChromeRenderViewTest, FillFormElement) { |
129 // Don't want any delay for form state sync changes. This will still post a | 184 // Don't want any delay for form state sync changes. This will still post a |
130 // message so updates will get coalesced, but as soon as we spin the message | 185 // message so updates will get coalesced, but as soon as we spin the message |
131 // loop, it will generate an update. | 186 // loop, it will generate an update. |
132 SendContentStateImmediately(); | 187 SendContentStateImmediately(); |
133 | 188 |
134 LoadHTML("<form method=\"POST\">" | 189 LoadHTML("<form method=\"POST\">" |
135 " <input type=\"text\" id=\"firstname\"/>" | 190 " <input type=\"text\" id=\"firstname\"/>" |
136 " <input type=\"text\" id=\"middlename\"/>" | 191 " <input type=\"text\" id=\"middlename\"/>" |
137 "</form>"); | 192 "</form>"); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 autofill_agent_->InputElementClicked(middlename, true, true); | 272 autofill_agent_->InputElementClicked(middlename, true, true); |
218 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 273 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
219 AutofillHostMsg_QueryFormFieldAutofill::ID); | 274 AutofillHostMsg_QueryFormFieldAutofill::ID); |
220 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 275 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
221 // TODO(isherman): It would be nice to verify here that the message includes | 276 // TODO(isherman): It would be nice to verify here that the message includes |
222 // the correct data. I'm not sure how to extract that information from an | 277 // the correct data. I'm not sure how to extract that information from an |
223 // IPC::Message though. | 278 // IPC::Message though. |
224 } | 279 } |
225 | 280 |
226 } // namespace autofill | 281 } // namespace autofill |
OLD | NEW |