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 <tuple> | 5 #include <tuple> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/test/base/chrome_render_view_test.h" | 13 #include "chrome/test/base/chrome_render_view_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
15 #include "components/autofill/content/common/autofill_messages.h" | 15 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" |
16 #include "components/autofill/content/renderer/autofill_agent.h" | 16 #include "components/autofill/content/renderer/autofill_agent.h" |
17 #include "components/autofill/core/common/form_data.h" | 17 #include "components/autofill/core/common/form_data.h" |
18 #include "components/autofill/core/common/form_field_data.h" | 18 #include "components/autofill/core/common/form_field_data.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "content/public/renderer/render_frame.h" | 20 #include "content/public/renderer/render_frame.h" |
21 #include "content/public/renderer/render_view.h" | |
22 #include "mojo/public/cpp/bindings/binding_set.h" | |
23 #include "services/shell/public/cpp/interface_provider.h" | |
21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
23 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 26 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
24 #include "third_party/WebKit/public/platform/WebVector.h" | 27 #include "third_party/WebKit/public/platform/WebVector.h" |
25 #include "third_party/WebKit/public/web/WebDocument.h" | 28 #include "third_party/WebKit/public/web/WebDocument.h" |
26 #include "third_party/WebKit/public/web/WebFormElement.h" | 29 #include "third_party/WebKit/public/web/WebFormElement.h" |
27 #include "third_party/WebKit/public/web/WebInputElement.h" | 30 #include "third_party/WebKit/public/web/WebInputElement.h" |
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
29 #include "third_party/WebKit/public/web/WebView.h" | 32 #include "third_party/WebKit/public/web/WebView.h" |
30 | 33 |
31 using base::ASCIIToUTF16; | 34 using base::ASCIIToUTF16; |
32 using blink::WebDocument; | 35 using blink::WebDocument; |
33 using blink::WebElement; | 36 using blink::WebElement; |
34 using blink::WebFormElement; | 37 using blink::WebFormElement; |
35 using blink::WebFrame; | 38 using blink::WebFrame; |
36 using blink::WebLocalFrame; | 39 using blink::WebLocalFrame; |
37 using blink::WebInputElement; | 40 using blink::WebInputElement; |
38 using blink::WebString; | 41 using blink::WebString; |
39 using blink::WebURLRequest; | 42 using blink::WebURLRequest; |
40 using blink::WebVector; | 43 using blink::WebVector; |
41 | 44 |
42 namespace autofill { | 45 namespace autofill { |
43 | 46 |
47 namespace { | |
48 | |
49 class FakeContentAutofillDriver : public mojom::AutofillDriver { | |
50 public: | |
51 FakeContentAutofillDriver() : called_fieldchange_(false) {} | |
52 ~FakeContentAutofillDriver() override {} | |
53 | |
54 void BindRequest(mojom::AutofillDriverRequest request) { | |
55 bindings_.AddBinding(this, std::move(request)); | |
56 } | |
57 | |
58 bool GetCalledFieldChange() const { return called_fieldchange_; } | |
yzshen1
2016/07/01 15:53:52
C++ coding style says:
Getter's name should be ca
leonhsl(Using Gerrit)
2016/07/02 17:06:33
Done. Thanks for knowledge sharing.
| |
59 | |
60 const std::vector<FormData>* GetSeenForms() const { return forms_.get(); } | |
61 | |
62 void ResetSeenForms() { return forms_.reset(); } | |
63 | |
64 private: | |
65 // mojom::AutofillDriver: | |
66 void FirstUserGestureObserved() override {} | |
67 | |
68 void FormsSeen(mojo::Array<FormData> forms, | |
69 const base::TimeTicks& timestamp) override { | |
70 // FormsSeen() could be called multiple times and sometimes even with empty | |
71 // forms array for main frame, but we're interested in only the first time | |
72 // call. | |
73 if (!forms_) | |
74 forms_.reset(new std::vector<FormData>(forms.PassStorage())); | |
75 } | |
76 | |
77 void WillSubmitForm(const FormData& form, | |
78 const base::TimeTicks& timestamp) override {} | |
79 | |
80 void FormSubmitted(const FormData& form) override {} | |
81 | |
82 void TextFieldDidChange(const FormData& form, | |
83 const FormFieldData& field, | |
84 const base::TimeTicks& timestamp) override { | |
85 called_fieldchange_ = true; | |
86 } | |
87 | |
88 void QueryFormFieldAutofill(int32_t id, | |
89 const FormData& form, | |
90 const FormFieldData& field, | |
91 const gfx::RectF& bounding_box) override {} | |
92 | |
93 void HidePopup() override {} | |
94 | |
95 void PingAck() override {} | |
96 | |
97 void FocusNoLongerOnForm() override {} | |
98 | |
99 void DidFillAutofillFormData(const FormData& form, | |
100 const base::TimeTicks& timestamp) override {} | |
101 | |
102 void DidPreviewAutofillFormData() override {} | |
103 | |
104 void DidEndTextFieldEditing() override {} | |
105 | |
106 void SetDataList(mojo::Array<mojo::String> values, | |
107 mojo::Array<mojo::String> labels) override {} | |
108 | |
109 // Records whether TextFieldDidChange() get called. | |
110 bool called_fieldchange_; | |
111 // Records data received via FormSeen() call. | |
112 std::unique_ptr<std::vector<FormData>> forms_; | |
113 | |
114 mojo::BindingSet<mojom::AutofillDriver> bindings_; | |
115 }; | |
116 | |
117 } // namespace | |
118 | |
44 using AutofillQueryParam = | 119 using AutofillQueryParam = |
45 std::tuple<int, autofill::FormData, autofill::FormFieldData, gfx::RectF>; | 120 std::tuple<int, autofill::FormData, autofill::FormFieldData, gfx::RectF>; |
46 | 121 |
47 class AutofillRendererTest : public ChromeRenderViewTest { | 122 class AutofillRendererTest : public ChromeRenderViewTest { |
48 public: | 123 public: |
49 AutofillRendererTest() {} | 124 AutofillRendererTest() {} |
125 | |
50 ~AutofillRendererTest() override {} | 126 ~AutofillRendererTest() override {} |
51 | 127 |
52 protected: | 128 protected: |
53 void SetUp() override { | 129 void SetUp() override { |
54 ChromeRenderViewTest::SetUp(); | 130 ChromeRenderViewTest::SetUp(); |
131 | |
132 // We only use the fake driver for main frame | |
133 // because our test cases only involve the main frame. | |
134 shell::InterfaceProvider* remote_interfaces = | |
135 view_->GetMainRenderFrame()->GetRemoteInterfaces(); | |
136 shell::InterfaceProvider::TestApi test_api(remote_interfaces); | |
137 test_api.SetBinderForName( | |
138 mojom::AutofillDriver::Name_, | |
139 base::Bind(&AutofillRendererTest::BindAutofillDriver, | |
140 base::Unretained(this))); | |
55 } | 141 } |
56 | 142 |
143 void BindAutofillDriver(mojo::ScopedMessagePipeHandle handle) { | |
144 fake_driver_.BindRequest( | |
145 mojo::MakeRequest<mojom::AutofillDriver>(std::move(handle))); | |
146 } | |
147 | |
148 FakeContentAutofillDriver fake_driver_; | |
149 | |
57 private: | 150 private: |
58 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); | 151 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); |
59 }; | 152 }; |
60 | 153 |
61 TEST_F(AutofillRendererTest, SendForms) { | 154 TEST_F(AutofillRendererTest, SendForms) { |
62 LoadHTML("<form method='POST'>" | 155 LoadHTML("<form method='POST'>" |
63 " <input type='text' id='firstname'/>" | 156 " <input type='text' id='firstname'/>" |
64 " <input type='text' id='middlename'/>" | 157 " <input type='text' id='middlename'/>" |
65 " <input type='text' id='lastname' autoComplete='off'/>" | 158 " <input type='text' id='lastname' autoComplete='off'/>" |
66 " <input type='hidden' id='email'/>" | 159 " <input type='hidden' id='email'/>" |
67 " <select id='state'/>" | 160 " <select id='state'/>" |
68 " <option>?</option>" | 161 " <option>?</option>" |
69 " <option>California</option>" | 162 " <option>California</option>" |
70 " <option>Texas</option>" | 163 " <option>Texas</option>" |
71 " </select>" | 164 " </select>" |
72 "</form>"); | 165 "</form>"); |
73 | 166 |
167 base::RunLoop run_loop; | |
168 run_loop.RunUntilIdle(); | |
74 // Verify that "FormsSeen" sends the expected number of fields. | 169 // Verify that "FormsSeen" sends the expected number of fields. |
75 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 170 ASSERT_TRUE(fake_driver_.GetSeenForms()); |
76 AutofillHostMsg_FormsSeen::ID); | 171 std::vector<FormData> forms = *(fake_driver_.GetSeenForms()); |
77 ASSERT_NE(nullptr, message); | |
78 AutofillHostMsg_FormsSeen::Param params; | |
79 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
80 std::vector<FormData> forms = std::get<0>(params); | |
81 ASSERT_EQ(1UL, forms.size()); | 172 ASSERT_EQ(1UL, forms.size()); |
82 ASSERT_EQ(4UL, forms[0].fields.size()); | 173 ASSERT_EQ(4UL, forms[0].fields.size()); |
83 | 174 |
84 FormFieldData expected; | 175 FormFieldData expected; |
85 | 176 |
86 expected.name = ASCIIToUTF16("firstname"); | 177 expected.name = ASCIIToUTF16("firstname"); |
87 expected.value = base::string16(); | 178 expected.value = base::string16(); |
88 expected.form_control_type = "text"; | 179 expected.form_control_type = "text"; |
89 expected.max_length = WebInputElement::defaultMaxLength(); | 180 expected.max_length = WebInputElement::defaultMaxLength(); |
90 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 181 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
(...skipping 11 matching lines...) Expand all Loading... | |
102 expected.max_length = WebInputElement::defaultMaxLength(); | 193 expected.max_length = WebInputElement::defaultMaxLength(); |
103 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 194 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
104 expected.autocomplete_attribute = std::string(); // reset | 195 expected.autocomplete_attribute = std::string(); // reset |
105 | 196 |
106 expected.name = ASCIIToUTF16("state"); | 197 expected.name = ASCIIToUTF16("state"); |
107 expected.value = ASCIIToUTF16("?"); | 198 expected.value = ASCIIToUTF16("?"); |
108 expected.form_control_type = "select-one"; | 199 expected.form_control_type = "select-one"; |
109 expected.max_length = 0; | 200 expected.max_length = 0; |
110 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); | 201 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); |
111 | 202 |
112 render_thread_->sink().ClearMessages(); | 203 fake_driver_.ResetSeenForms(); |
113 | 204 |
114 // Dynamically create a new form. A new message should be sent for it, but | 205 // Dynamically create a new form. A new message should be sent for it, but |
115 // not for the previous form. | 206 // not for the previous form. |
116 ExecuteJavaScriptForTests( | 207 ExecuteJavaScriptForTests( |
117 "var newForm=document.createElement('form');" | 208 "var newForm=document.createElement('form');" |
118 "newForm.id='new_testform';" | 209 "newForm.id='new_testform';" |
119 "newForm.action='http://google.com';" | 210 "newForm.action='http://google.com';" |
120 "newForm.method='post';" | 211 "newForm.method='post';" |
121 "var newFirstname=document.createElement('input');" | 212 "var newFirstname=document.createElement('input');" |
122 "newFirstname.setAttribute('type', 'text');" | 213 "newFirstname.setAttribute('type', 'text');" |
123 "newFirstname.setAttribute('id', 'second_firstname');" | 214 "newFirstname.setAttribute('id', 'second_firstname');" |
124 "newFirstname.value = 'Bob';" | 215 "newFirstname.value = 'Bob';" |
125 "var newLastname=document.createElement('input');" | 216 "var newLastname=document.createElement('input');" |
126 "newLastname.setAttribute('type', 'text');" | 217 "newLastname.setAttribute('type', 'text');" |
127 "newLastname.setAttribute('id', 'second_lastname');" | 218 "newLastname.setAttribute('id', 'second_lastname');" |
128 "newLastname.value = 'Hope';" | 219 "newLastname.value = 'Hope';" |
129 "var newEmail=document.createElement('input');" | 220 "var newEmail=document.createElement('input');" |
130 "newEmail.setAttribute('type', 'text');" | 221 "newEmail.setAttribute('type', 'text');" |
131 "newEmail.setAttribute('id', 'second_email');" | 222 "newEmail.setAttribute('id', 'second_email');" |
132 "newEmail.value = 'bobhope@example.com';" | 223 "newEmail.value = 'bobhope@example.com';" |
133 "newForm.appendChild(newFirstname);" | 224 "newForm.appendChild(newFirstname);" |
134 "newForm.appendChild(newLastname);" | 225 "newForm.appendChild(newLastname);" |
135 "newForm.appendChild(newEmail);" | 226 "newForm.appendChild(newEmail);" |
136 "document.body.appendChild(newForm);"); | 227 "document.body.appendChild(newForm);"); |
137 base::RunLoop().RunUntilIdle(); | 228 base::RunLoop().RunUntilIdle(); |
138 | 229 |
139 message = render_thread_->sink().GetFirstMessageMatching( | 230 ASSERT_TRUE(fake_driver_.GetSeenForms()); |
140 AutofillHostMsg_FormsSeen::ID); | 231 forms = *(fake_driver_.GetSeenForms()); |
141 ASSERT_NE(nullptr, message); | |
142 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
143 forms = std::get<0>(params); | |
144 ASSERT_EQ(1UL, forms.size()); | 232 ASSERT_EQ(1UL, forms.size()); |
145 ASSERT_EQ(3UL, forms[0].fields.size()); | 233 ASSERT_EQ(3UL, forms[0].fields.size()); |
146 | 234 |
147 expected.form_control_type = "text"; | 235 expected.form_control_type = "text"; |
148 expected.max_length = WebInputElement::defaultMaxLength(); | 236 expected.max_length = WebInputElement::defaultMaxLength(); |
149 | 237 |
150 expected.name = ASCIIToUTF16("second_firstname"); | 238 expected.name = ASCIIToUTF16("second_firstname"); |
151 expected.value = ASCIIToUTF16("Bob"); | 239 expected.value = ASCIIToUTF16("Bob"); |
152 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 240 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
153 | 241 |
154 expected.name = ASCIIToUTF16("second_lastname"); | 242 expected.name = ASCIIToUTF16("second_lastname"); |
155 expected.value = ASCIIToUTF16("Hope"); | 243 expected.value = ASCIIToUTF16("Hope"); |
156 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); | 244 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); |
157 | 245 |
158 expected.name = ASCIIToUTF16("second_email"); | 246 expected.name = ASCIIToUTF16("second_email"); |
159 expected.value = ASCIIToUTF16("bobhope@example.com"); | 247 expected.value = ASCIIToUTF16("bobhope@example.com"); |
160 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 248 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
161 } | 249 } |
162 | 250 |
163 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { | 251 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { |
164 LoadHTML("<form method='POST'>" | 252 LoadHTML("<form method='POST'>" |
165 " <input type='text' id='firstname'/>" | 253 " <input type='text' id='firstname'/>" |
166 " <input type='text' id='middlename'/>" | 254 " <input type='text' id='middlename'/>" |
167 "</form>"); | 255 "</form>"); |
168 | 256 |
257 base::RunLoop run_loop; | |
258 run_loop.RunUntilIdle(); | |
169 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 259 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
170 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 260 ASSERT_TRUE(fake_driver_.GetSeenForms()); |
171 AutofillHostMsg_FormsSeen::ID); | 261 const std::vector<FormData>& forms = *(fake_driver_.GetSeenForms()); |
172 ASSERT_NE(nullptr, message); | |
173 AutofillHostMsg_FormsSeen::Param params; | |
174 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
175 const std::vector<FormData>& forms = std::get<0>(params); | |
176 ASSERT_EQ(0UL, forms.size()); | 262 ASSERT_EQ(0UL, forms.size()); |
177 } | 263 } |
178 | 264 |
179 // Regression test for [ http://crbug.com/346010 ]. | 265 // Regression test for [ http://crbug.com/346010 ]. |
180 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 266 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
181 LoadHTML("<form id='form'>" | 267 LoadHTML("<form id='form'>" |
182 "<foo id='foo'>" | 268 "<foo id='foo'>" |
183 "<script id='script'>" | 269 "<script id='script'>" |
184 "document.documentElement.appendChild(foo);" | 270 "document.documentElement.appendChild(foo);" |
185 "newDoc = document.implementation.createDocument(" | 271 "newDoc = document.implementation.createDocument(" |
186 " 'http://www.w3.org/1999/xhtml', 'html');" | 272 " 'http://www.w3.org/1999/xhtml', 'html');" |
187 "foo.insertBefore(form, script);" | 273 "foo.insertBefore(form, script);" |
188 "newDoc.adoptNode(foo);" | 274 "newDoc.adoptNode(foo);" |
189 "</script>"); | 275 "</script>"); |
190 | 276 |
191 // Shouldn't crash. | 277 // Shouldn't crash. |
192 } | 278 } |
193 | 279 |
194 TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) { | 280 TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) { |
195 std::string html_data; | 281 std::string html_data; |
196 base::FilePath test_path = ui_test_utils::GetTestFilePath( | 282 base::FilePath test_path = ui_test_utils::GetTestFilePath( |
197 base::FilePath(FILE_PATH_LITERAL("autofill")), | 283 base::FilePath(FILE_PATH_LITERAL("autofill")), |
198 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); | 284 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); |
199 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); | 285 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); |
200 LoadHTML(html_data.c_str()); | 286 LoadHTML(html_data.c_str()); |
201 | 287 |
288 base::RunLoop run_loop; | |
289 run_loop.RunUntilIdle(); | |
202 // Verify that "FormsSeen" sends the expected number of fields. | 290 // Verify that "FormsSeen" sends the expected number of fields. |
203 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 291 ASSERT_TRUE(fake_driver_.GetSeenForms()); |
204 AutofillHostMsg_FormsSeen::ID); | 292 std::vector<FormData> forms = *(fake_driver_.GetSeenForms()); |
205 ASSERT_NE(nullptr, message); | |
206 AutofillHostMsg_FormsSeen::Param params; | |
207 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
208 std::vector<FormData> forms = std::get<0>(params); | |
209 ASSERT_EQ(1UL, forms.size()); | 293 ASSERT_EQ(1UL, forms.size()); |
210 ASSERT_EQ(7UL, forms[0].fields.size()); | 294 ASSERT_EQ(7UL, forms[0].fields.size()); |
211 | 295 |
212 render_thread_->sink().ClearMessages(); | 296 fake_driver_.ResetSeenForms(); |
213 | 297 |
214 ExecuteJavaScriptForTests("AddFields()"); | 298 ExecuteJavaScriptForTests("AddFields()"); |
215 base::RunLoop().RunUntilIdle(); | 299 base::RunLoop().RunUntilIdle(); |
216 | 300 |
217 message = render_thread_->sink().GetFirstMessageMatching( | 301 ASSERT_TRUE(fake_driver_.GetSeenForms()); |
218 AutofillHostMsg_FormsSeen::ID); | 302 forms = *(fake_driver_.GetSeenForms()); |
219 ASSERT_NE(nullptr, message); | |
220 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
221 forms = std::get<0>(params); | |
222 ASSERT_EQ(1UL, forms.size()); | 303 ASSERT_EQ(1UL, forms.size()); |
223 ASSERT_EQ(9UL, forms[0].fields.size()); | 304 ASSERT_EQ(9UL, forms[0].fields.size()); |
224 | 305 |
225 FormFieldData expected; | 306 FormFieldData expected; |
226 | 307 |
227 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); | 308 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); |
228 expected.value.clear(); | 309 expected.value.clear(); |
229 expected.form_control_type = "text"; | 310 expected.form_control_type = "text"; |
230 expected.max_length = WebInputElement::defaultMaxLength(); | 311 expected.max_length = WebInputElement::defaultMaxLength(); |
231 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); | 312 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); |
(...skipping 11 matching lines...) Expand all Loading... | |
243 "</form>"); | 324 "</form>"); |
244 | 325 |
245 blink::WebInputElement full_name = | 326 blink::WebInputElement full_name = |
246 GetMainFrame()->document().getElementById("full_name") | 327 GetMainFrame()->document().getElementById("full_name") |
247 .to<blink::WebInputElement>(); | 328 .to<blink::WebInputElement>(); |
248 while (!full_name.focused()) | 329 while (!full_name.focused()) |
249 GetMainFrame()->view()->advanceFocus(false); | 330 GetMainFrame()->view()->advanceFocus(false); |
250 | 331 |
251 // Not a user gesture, so no IPC message to browser. | 332 // Not a user gesture, so no IPC message to browser. |
252 DisableUserGestureSimulationForAutofill(); | 333 DisableUserGestureSimulationForAutofill(); |
334 ASSERT_FALSE(fake_driver_.GetCalledFieldChange()); | |
253 full_name.setValue("Alice", true); | 335 full_name.setValue("Alice", true); |
254 GetMainFrame()->autofillClient()->textFieldDidChange(full_name); | 336 GetMainFrame()->autofillClient()->textFieldDidChange(full_name); |
255 base::RunLoop().RunUntilIdle(); | 337 base::RunLoop().RunUntilIdle(); |
256 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( | 338 ASSERT_FALSE(fake_driver_.GetCalledFieldChange()); |
257 AutofillHostMsg_TextFieldDidChange::ID)); | |
258 | 339 |
259 // A user gesture will send a message to the browser. | 340 // A user gesture will send a message to the browser. |
260 EnableUserGestureSimulationForAutofill(); | 341 EnableUserGestureSimulationForAutofill(); |
261 SimulateUserInputChangeForElement(&full_name, "Alice"); | 342 SimulateUserInputChangeForElement(&full_name, "Alice"); |
262 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( | 343 ASSERT_TRUE(fake_driver_.GetCalledFieldChange()); |
263 AutofillHostMsg_TextFieldDidChange::ID)); | |
264 } | 344 } |
265 | 345 |
266 } // namespace autofill | 346 } // namespace autofill |
OLD | NEW |