Chromium Code Reviews| 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 // Records whether TextFieldDidChange() get called. | |
| 59 bool called_fieldchange_; | |
| 60 // Records data received via FormSeen() call. | |
| 61 std::unique_ptr<std::vector<FormData>> forms_; | |
| 62 | |
| 63 private: | |
| 64 // mojom::AutofillDriver: | |
| 65 void FirstUserGestureObserved() override {} | |
|
vabr (Chromium)
2016/06/23 14:21:21
nit: Please separate methods with a blank line.
leonhsl(Using Gerrit)
2016/06/24 15:44:31
Done.
| |
| 66 void FormsSeen(mojo::Array<FormData> forms, | |
| 67 const base::TimeTicks& timestamp) override { | |
| 68 // FormsSeen() could be called multiple times and sometimes even with empty | |
| 69 // forms array for main frame, but we're interested in only the first time | |
| 70 // call. | |
| 71 if (!forms_) | |
| 72 forms_.reset(new std::vector<FormData>(forms.PassStorage())); | |
| 73 } | |
| 74 void WillSubmitForm(const FormData& form, | |
| 75 const base::TimeTicks& timestamp) override {} | |
| 76 void FormSubmitted(const FormData& form) override {} | |
| 77 void TextFieldDidChange(const FormData& form, | |
| 78 const FormFieldData& field, | |
| 79 const base::TimeTicks& timestamp) override { | |
| 80 called_fieldchange_ = true; | |
| 81 } | |
| 82 void QueryFormFieldAutofill(int32_t id, | |
| 83 const FormData& form, | |
| 84 const FormFieldData& field, | |
| 85 const gfx::RectF& bounding_box) override {} | |
| 86 void HidePopup() override {} | |
| 87 void PingAck() override {} | |
| 88 void FocusNoLongerOnForm() override {} | |
| 89 void DidFillAutofillFormData(const FormData& form, | |
| 90 const base::TimeTicks& timestamp) override {} | |
| 91 void DidPreviewAutofillFormData() override {} | |
| 92 void DidEndTextFieldEditing() override {} | |
| 93 void SetDataList(mojo::Array<mojo::String> values, | |
| 94 mojo::Array<mojo::String> labels) override {} | |
| 95 | |
| 96 mojo::BindingSet<mojom::AutofillDriver> bindings_; | |
| 97 }; | |
| 98 | |
| 99 } // namespace | |
| 100 | |
| 44 using AutofillQueryParam = | 101 using AutofillQueryParam = |
| 45 std::tuple<int, autofill::FormData, autofill::FormFieldData, gfx::RectF>; | 102 std::tuple<int, autofill::FormData, autofill::FormFieldData, gfx::RectF>; |
| 46 | 103 |
| 47 class AutofillRendererTest : public ChromeRenderViewTest { | 104 class AutofillRendererTest : public ChromeRenderViewTest { |
| 48 public: | 105 public: |
| 49 AutofillRendererTest() {} | 106 AutofillRendererTest() {} |
| 50 ~AutofillRendererTest() override {} | 107 ~AutofillRendererTest() override {} |
| 51 | 108 |
| 52 protected: | 109 protected: |
| 53 void SetUp() override { | 110 void SetUp() override { |
| 54 ChromeRenderViewTest::SetUp(); | 111 ChromeRenderViewTest::SetUp(); |
| 112 | |
| 113 // We only use the fake driver for main frame | |
|
vabr (Chromium)
2016/06/23 14:21:21
Just out of curiosity, could the added code go to
leonhsl(Using Gerrit)
2016/06/24 15:44:31
OK now I understand the rule, thanks for the shari
| |
| 114 // because our test cases only involve the main frame. | |
| 115 shell::InterfaceProvider* remote_interfaces = | |
| 116 view_->GetMainRenderFrame()->GetRemoteInterfaces(); | |
| 117 shell::InterfaceProvider::TestApi test_api(remote_interfaces); | |
| 118 test_api.SetBinderForName( | |
| 119 mojom::AutofillDriver::Name_, | |
| 120 base::Bind(&AutofillRendererTest::BindAutofillDriver, | |
| 121 base::Unretained(this))); | |
| 55 } | 122 } |
| 56 | 123 |
| 124 void BindAutofillDriver(mojo::ScopedMessagePipeHandle handle) { | |
| 125 fake_driver_.BindRequest( | |
| 126 mojo::MakeRequest<mojom::AutofillDriver>(std::move(handle))); | |
| 127 } | |
| 128 | |
| 129 FakeContentAutofillDriver fake_driver_; | |
| 130 | |
| 57 private: | 131 private: |
| 58 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); | 132 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); |
| 59 }; | 133 }; |
| 60 | 134 |
| 61 TEST_F(AutofillRendererTest, SendForms) { | 135 TEST_F(AutofillRendererTest, SendForms) { |
| 62 LoadHTML("<form method='POST'>" | 136 LoadHTML("<form method='POST'>" |
| 63 " <input type='text' id='firstname'/>" | 137 " <input type='text' id='firstname'/>" |
| 64 " <input type='text' id='middlename'/>" | 138 " <input type='text' id='middlename'/>" |
| 65 " <input type='text' id='lastname' autoComplete='off'/>" | 139 " <input type='text' id='lastname' autoComplete='off'/>" |
| 66 " <input type='hidden' id='email'/>" | 140 " <input type='hidden' id='email'/>" |
| 67 " <select id='state'/>" | 141 " <select id='state'/>" |
| 68 " <option>?</option>" | 142 " <option>?</option>" |
| 69 " <option>California</option>" | 143 " <option>California</option>" |
| 70 " <option>Texas</option>" | 144 " <option>Texas</option>" |
| 71 " </select>" | 145 " </select>" |
| 72 "</form>"); | 146 "</form>"); |
| 73 | 147 |
| 148 base::RunLoop run_loop; | |
| 149 run_loop.RunUntilIdle(); | |
| 74 // Verify that "FormsSeen" sends the expected number of fields. | 150 // Verify that "FormsSeen" sends the expected number of fields. |
| 75 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 151 ASSERT_NE(nullptr, fake_driver_.forms_); |
|
vabr (Chromium)
2016/06/23 14:21:21
nit: This is the usual way to write the pointer te
leonhsl(Using Gerrit)
2016/06/24 15:44:31
Done and Thanks!
| |
| 76 AutofillHostMsg_FormsSeen::ID); | 152 std::vector<FormData> forms = *(fake_driver_.forms_.get()); |
| 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()); | 153 ASSERT_EQ(1UL, forms.size()); |
| 82 ASSERT_EQ(4UL, forms[0].fields.size()); | 154 ASSERT_EQ(4UL, forms[0].fields.size()); |
| 83 | 155 |
| 84 FormFieldData expected; | 156 FormFieldData expected; |
| 85 | 157 |
| 86 expected.name = ASCIIToUTF16("firstname"); | 158 expected.name = ASCIIToUTF16("firstname"); |
| 87 expected.value = base::string16(); | 159 expected.value = base::string16(); |
| 88 expected.form_control_type = "text"; | 160 expected.form_control_type = "text"; |
| 89 expected.max_length = WebInputElement::defaultMaxLength(); | 161 expected.max_length = WebInputElement::defaultMaxLength(); |
| 90 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 162 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 102 expected.max_length = WebInputElement::defaultMaxLength(); | 174 expected.max_length = WebInputElement::defaultMaxLength(); |
| 103 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 175 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
| 104 expected.autocomplete_attribute = std::string(); // reset | 176 expected.autocomplete_attribute = std::string(); // reset |
| 105 | 177 |
| 106 expected.name = ASCIIToUTF16("state"); | 178 expected.name = ASCIIToUTF16("state"); |
| 107 expected.value = ASCIIToUTF16("?"); | 179 expected.value = ASCIIToUTF16("?"); |
| 108 expected.form_control_type = "select-one"; | 180 expected.form_control_type = "select-one"; |
| 109 expected.max_length = 0; | 181 expected.max_length = 0; |
| 110 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); | 182 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); |
| 111 | 183 |
| 112 render_thread_->sink().ClearMessages(); | 184 fake_driver_.forms_.reset(); |
| 113 | 185 |
| 114 // Dynamically create a new form. A new message should be sent for it, but | 186 // Dynamically create a new form. A new message should be sent for it, but |
| 115 // not for the previous form. | 187 // not for the previous form. |
| 116 ExecuteJavaScriptForTests( | 188 ExecuteJavaScriptForTests( |
| 117 "var newForm=document.createElement('form');" | 189 "var newForm=document.createElement('form');" |
| 118 "newForm.id='new_testform';" | 190 "newForm.id='new_testform';" |
| 119 "newForm.action='http://google.com';" | 191 "newForm.action='http://google.com';" |
| 120 "newForm.method='post';" | 192 "newForm.method='post';" |
| 121 "var newFirstname=document.createElement('input');" | 193 "var newFirstname=document.createElement('input');" |
| 122 "newFirstname.setAttribute('type', 'text');" | 194 "newFirstname.setAttribute('type', 'text');" |
| 123 "newFirstname.setAttribute('id', 'second_firstname');" | 195 "newFirstname.setAttribute('id', 'second_firstname');" |
| 124 "newFirstname.value = 'Bob';" | 196 "newFirstname.value = 'Bob';" |
| 125 "var newLastname=document.createElement('input');" | 197 "var newLastname=document.createElement('input');" |
| 126 "newLastname.setAttribute('type', 'text');" | 198 "newLastname.setAttribute('type', 'text');" |
| 127 "newLastname.setAttribute('id', 'second_lastname');" | 199 "newLastname.setAttribute('id', 'second_lastname');" |
| 128 "newLastname.value = 'Hope';" | 200 "newLastname.value = 'Hope';" |
| 129 "var newEmail=document.createElement('input');" | 201 "var newEmail=document.createElement('input');" |
| 130 "newEmail.setAttribute('type', 'text');" | 202 "newEmail.setAttribute('type', 'text');" |
| 131 "newEmail.setAttribute('id', 'second_email');" | 203 "newEmail.setAttribute('id', 'second_email');" |
| 132 "newEmail.value = 'bobhope@example.com';" | 204 "newEmail.value = 'bobhope@example.com';" |
| 133 "newForm.appendChild(newFirstname);" | 205 "newForm.appendChild(newFirstname);" |
| 134 "newForm.appendChild(newLastname);" | 206 "newForm.appendChild(newLastname);" |
| 135 "newForm.appendChild(newEmail);" | 207 "newForm.appendChild(newEmail);" |
| 136 "document.body.appendChild(newForm);"); | 208 "document.body.appendChild(newForm);"); |
| 137 msg_loop_.RunUntilIdle(); | 209 msg_loop_.RunUntilIdle(); |
| 138 | 210 |
| 139 message = render_thread_->sink().GetFirstMessageMatching( | 211 ASSERT_NE(nullptr, fake_driver_.forms_); |
| 140 AutofillHostMsg_FormsSeen::ID); | 212 forms = *(fake_driver_.forms_.get()); |
| 141 ASSERT_NE(nullptr, message); | |
| 142 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
| 143 forms = std::get<0>(params); | |
| 144 ASSERT_EQ(1UL, forms.size()); | 213 ASSERT_EQ(1UL, forms.size()); |
| 145 ASSERT_EQ(3UL, forms[0].fields.size()); | 214 ASSERT_EQ(3UL, forms[0].fields.size()); |
| 146 | 215 |
| 147 expected.form_control_type = "text"; | 216 expected.form_control_type = "text"; |
| 148 expected.max_length = WebInputElement::defaultMaxLength(); | 217 expected.max_length = WebInputElement::defaultMaxLength(); |
| 149 | 218 |
| 150 expected.name = ASCIIToUTF16("second_firstname"); | 219 expected.name = ASCIIToUTF16("second_firstname"); |
| 151 expected.value = ASCIIToUTF16("Bob"); | 220 expected.value = ASCIIToUTF16("Bob"); |
| 152 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 221 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
| 153 | 222 |
| 154 expected.name = ASCIIToUTF16("second_lastname"); | 223 expected.name = ASCIIToUTF16("second_lastname"); |
| 155 expected.value = ASCIIToUTF16("Hope"); | 224 expected.value = ASCIIToUTF16("Hope"); |
| 156 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); | 225 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); |
| 157 | 226 |
| 158 expected.name = ASCIIToUTF16("second_email"); | 227 expected.name = ASCIIToUTF16("second_email"); |
| 159 expected.value = ASCIIToUTF16("bobhope@example.com"); | 228 expected.value = ASCIIToUTF16("bobhope@example.com"); |
| 160 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 229 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
| 161 } | 230 } |
| 162 | 231 |
| 163 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { | 232 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { |
| 164 LoadHTML("<form method='POST'>" | 233 LoadHTML("<form method='POST'>" |
| 165 " <input type='text' id='firstname'/>" | 234 " <input type='text' id='firstname'/>" |
| 166 " <input type='text' id='middlename'/>" | 235 " <input type='text' id='middlename'/>" |
| 167 "</form>"); | 236 "</form>"); |
| 168 | 237 |
| 238 base::RunLoop run_loop; | |
| 239 run_loop.RunUntilIdle(); | |
| 169 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 240 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
| 170 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 241 ASSERT_NE(nullptr, fake_driver_.forms_); |
| 171 AutofillHostMsg_FormsSeen::ID); | 242 const std::vector<FormData>& forms = *(fake_driver_.forms_.get()); |
| 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()); | 243 ASSERT_EQ(0UL, forms.size()); |
| 177 } | 244 } |
| 178 | 245 |
| 179 // Regression test for [ http://crbug.com/346010 ]. | 246 // Regression test for [ http://crbug.com/346010 ]. |
| 180 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 247 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
| 181 LoadHTML("<form id='form'>" | 248 LoadHTML("<form id='form'>" |
| 182 "<foo id='foo'>" | 249 "<foo id='foo'>" |
| 183 "<script id='script'>" | 250 "<script id='script'>" |
| 184 "document.documentElement.appendChild(foo);" | 251 "document.documentElement.appendChild(foo);" |
| 185 "newDoc = document.implementation.createDocument(" | 252 "newDoc = document.implementation.createDocument(" |
| 186 " 'http://www.w3.org/1999/xhtml', 'html');" | 253 " 'http://www.w3.org/1999/xhtml', 'html');" |
| 187 "foo.insertBefore(form, script);" | 254 "foo.insertBefore(form, script);" |
| 188 "newDoc.adoptNode(foo);" | 255 "newDoc.adoptNode(foo);" |
| 189 "</script>"); | 256 "</script>"); |
| 190 | 257 |
| 191 // Shouldn't crash. | 258 // Shouldn't crash. |
| 192 } | 259 } |
| 193 | 260 |
| 194 TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) { | 261 TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) { |
| 195 std::string html_data; | 262 std::string html_data; |
| 196 base::FilePath test_path = ui_test_utils::GetTestFilePath( | 263 base::FilePath test_path = ui_test_utils::GetTestFilePath( |
| 197 base::FilePath(FILE_PATH_LITERAL("autofill")), | 264 base::FilePath(FILE_PATH_LITERAL("autofill")), |
| 198 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); | 265 base::FilePath(FILE_PATH_LITERAL("autofill_noform_dynamic.html"))); |
| 199 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); | 266 ASSERT_TRUE(base::ReadFileToString(test_path, &html_data)); |
| 200 LoadHTML(html_data.c_str()); | 267 LoadHTML(html_data.c_str()); |
| 201 | 268 |
| 269 base::RunLoop run_loop; | |
| 270 run_loop.RunUntilIdle(); | |
| 202 // Verify that "FormsSeen" sends the expected number of fields. | 271 // Verify that "FormsSeen" sends the expected number of fields. |
| 203 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 272 ASSERT_NE(nullptr, fake_driver_.forms_); |
| 204 AutofillHostMsg_FormsSeen::ID); | 273 std::vector<FormData> forms = *(fake_driver_.forms_.get()); |
| 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()); | 274 ASSERT_EQ(1UL, forms.size()); |
| 210 ASSERT_EQ(7UL, forms[0].fields.size()); | 275 ASSERT_EQ(7UL, forms[0].fields.size()); |
| 211 | 276 |
| 212 render_thread_->sink().ClearMessages(); | 277 fake_driver_.forms_.reset(); |
| 213 | 278 |
| 214 ExecuteJavaScriptForTests("AddFields()"); | 279 ExecuteJavaScriptForTests("AddFields()"); |
| 215 msg_loop_.RunUntilIdle(); | 280 msg_loop_.RunUntilIdle(); |
| 216 | 281 |
| 217 message = render_thread_->sink().GetFirstMessageMatching( | 282 ASSERT_NE(nullptr, fake_driver_.forms_); |
| 218 AutofillHostMsg_FormsSeen::ID); | 283 forms = *(fake_driver_.forms_.get()); |
| 219 ASSERT_NE(nullptr, message); | |
| 220 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
| 221 forms = std::get<0>(params); | |
| 222 ASSERT_EQ(1UL, forms.size()); | 284 ASSERT_EQ(1UL, forms.size()); |
| 223 ASSERT_EQ(9UL, forms[0].fields.size()); | 285 ASSERT_EQ(9UL, forms[0].fields.size()); |
| 224 | 286 |
| 225 FormFieldData expected; | 287 FormFieldData expected; |
| 226 | 288 |
| 227 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); | 289 expected.name = ASCIIToUTF16("EMAIL_ADDRESS"); |
| 228 expected.value.clear(); | 290 expected.value.clear(); |
| 229 expected.form_control_type = "text"; | 291 expected.form_control_type = "text"; |
| 230 expected.max_length = WebInputElement::defaultMaxLength(); | 292 expected.max_length = WebInputElement::defaultMaxLength(); |
| 231 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); | 293 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 243 "</form>"); | 305 "</form>"); |
| 244 | 306 |
| 245 blink::WebInputElement full_name = | 307 blink::WebInputElement full_name = |
| 246 GetMainFrame()->document().getElementById("full_name") | 308 GetMainFrame()->document().getElementById("full_name") |
| 247 .to<blink::WebInputElement>(); | 309 .to<blink::WebInputElement>(); |
| 248 while (!full_name.focused()) | 310 while (!full_name.focused()) |
| 249 GetMainFrame()->view()->advanceFocus(false); | 311 GetMainFrame()->view()->advanceFocus(false); |
| 250 | 312 |
| 251 // Not a user gesture, so no IPC message to browser. | 313 // Not a user gesture, so no IPC message to browser. |
| 252 DisableUserGestureSimulationForAutofill(); | 314 DisableUserGestureSimulationForAutofill(); |
| 315 ASSERT_FALSE(fake_driver_.called_fieldchange_); | |
| 253 full_name.setValue("Alice", true); | 316 full_name.setValue("Alice", true); |
| 254 GetMainFrame()->autofillClient()->textFieldDidChange(full_name); | 317 GetMainFrame()->autofillClient()->textFieldDidChange(full_name); |
| 255 base::RunLoop().RunUntilIdle(); | 318 base::RunLoop().RunUntilIdle(); |
| 256 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( | 319 ASSERT_FALSE(fake_driver_.called_fieldchange_); |
| 257 AutofillHostMsg_TextFieldDidChange::ID)); | |
| 258 | 320 |
| 259 // A user gesture will send a message to the browser. | 321 // A user gesture will send a message to the browser. |
| 260 EnableUserGestureSimulationForAutofill(); | 322 EnableUserGestureSimulationForAutofill(); |
| 261 SimulateUserInputChangeForElement(&full_name, "Alice"); | 323 SimulateUserInputChangeForElement(&full_name, "Alice"); |
| 262 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( | 324 ASSERT_TRUE(fake_driver_.called_fieldchange_); |
| 263 AutofillHostMsg_TextFieldDidChange::ID)); | |
| 264 } | 325 } |
| 265 | 326 |
| 266 } // namespace autofill | 327 } // namespace autofill |
| OLD | NEW |