| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/test/base/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
| 9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
| 10 #include "components/autofill/content/renderer/autofill_agent.h" | 10 #include "components/autofill/content/renderer/autofill_agent.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 " <option>Texas</option>" | 72 " <option>Texas</option>" |
| 73 " </select>" | 73 " </select>" |
| 74 "</form>"); | 74 "</form>"); |
| 75 | 75 |
| 76 // Verify that "FormsSeen" sends the expected number of fields. | 76 // Verify that "FormsSeen" sends the expected number of fields. |
| 77 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 77 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 78 AutofillHostMsg_FormsSeen::ID); | 78 AutofillHostMsg_FormsSeen::ID); |
| 79 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 79 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 80 AutofillHostMsg_FormsSeen::Param params; | 80 AutofillHostMsg_FormsSeen::Param params; |
| 81 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 81 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
| 82 std::vector<FormData> forms = params.a; | 82 const std::vector<FormData>& forms = params.a; |
| 83 ASSERT_EQ(1UL, forms.size()); | 83 ASSERT_EQ(1UL, forms.size()); |
| 84 ASSERT_EQ(4UL, forms[0].fields.size()); | 84 ASSERT_EQ(4UL, forms[0].fields.size()); |
| 85 | 85 |
| 86 FormFieldData expected; | 86 FormFieldData expected; |
| 87 | 87 |
| 88 expected.name = ASCIIToUTF16("firstname"); | 88 expected.name = ASCIIToUTF16("firstname"); |
| 89 expected.value = base::string16(); | 89 expected.value = base::string16(); |
| 90 expected.form_control_type = "text"; | 90 expected.form_control_type = "text"; |
| 91 expected.max_length = WebInputElement::defaultMaxLength(); | 91 expected.max_length = WebInputElement::defaultMaxLength(); |
| 92 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | 92 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 expected.autocomplete_attribute = "off"; | 103 expected.autocomplete_attribute = "off"; |
| 104 expected.max_length = WebInputElement::defaultMaxLength(); | 104 expected.max_length = WebInputElement::defaultMaxLength(); |
| 105 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 105 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
| 106 expected.autocomplete_attribute = std::string(); // reset | 106 expected.autocomplete_attribute = std::string(); // reset |
| 107 | 107 |
| 108 expected.name = ASCIIToUTF16("state"); | 108 expected.name = ASCIIToUTF16("state"); |
| 109 expected.value = ASCIIToUTF16("?"); | 109 expected.value = ASCIIToUTF16("?"); |
| 110 expected.form_control_type = "select-one"; | 110 expected.form_control_type = "select-one"; |
| 111 expected.max_length = 0; | 111 expected.max_length = 0; |
| 112 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); | 112 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[3]); |
| 113 | |
| 114 render_thread_->sink().ClearMessages(); | |
| 115 | |
| 116 // Dynamically create a new form. A new message should be sent for it, but | |
| 117 // not for the previous form. | |
| 118 ExecuteJavaScript( | |
| 119 "var newForm=document.createElement('form');" | |
| 120 "newForm.id='new_testform';" | |
| 121 "newForm.action='http://google.com';" | |
| 122 "newForm.method='post';" | |
| 123 "var newFirstname=document.createElement('input');" | |
| 124 "newFirstname.setAttribute('type', 'text');" | |
| 125 "newFirstname.setAttribute('id', 'second_firstname');" | |
| 126 "newFirstname.value = 'Bob';" | |
| 127 "var newLastname=document.createElement('input');" | |
| 128 "newLastname.setAttribute('type', 'text');" | |
| 129 "newLastname.setAttribute('id', 'second_lastname');" | |
| 130 "newLastname.value = 'Hope';" | |
| 131 "var newEmail=document.createElement('input');" | |
| 132 "newEmail.setAttribute('type', 'text');" | |
| 133 "newEmail.setAttribute('id', 'second_email');" | |
| 134 "newEmail.value = 'bobhope@example.com';" | |
| 135 "newForm.appendChild(newFirstname);" | |
| 136 "newForm.appendChild(newLastname);" | |
| 137 "newForm.appendChild(newEmail);" | |
| 138 "document.body.appendChild(newForm);"); | |
| 139 msg_loop_.RunUntilIdle(); | |
| 140 | |
| 141 message = render_thread_->sink().GetFirstMessageMatching( | |
| 142 AutofillHostMsg_FormsSeen::ID); | |
| 143 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | |
| 144 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | |
| 145 forms = params.a; | |
| 146 ASSERT_EQ(1UL, forms.size()); | |
| 147 ASSERT_EQ(3UL, forms[0].fields.size()); | |
| 148 | |
| 149 expected.form_control_type = "text"; | |
| 150 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 151 | |
| 152 expected.name = ASCIIToUTF16("second_firstname"); | |
| 153 expected.value = ASCIIToUTF16("Bob"); | |
| 154 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[0]); | |
| 155 | |
| 156 expected.name = ASCIIToUTF16("second_lastname"); | |
| 157 expected.value = ASCIIToUTF16("Hope"); | |
| 158 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); | |
| 159 | |
| 160 expected.name = ASCIIToUTF16("second_email"); | |
| 161 expected.value = ASCIIToUTF16("bobhope@example.com"); | |
| 162 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | |
| 163 } | 113 } |
| 164 | 114 |
| 165 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { | 115 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { |
| 166 LoadHTML("<form method=\"POST\">" | 116 LoadHTML("<form method=\"POST\">" |
| 167 " <input type=\"text\" id=\"firstname\"/>" | 117 " <input type=\"text\" id=\"firstname\"/>" |
| 168 " <input type=\"text\" id=\"middlename\"/>" | 118 " <input type=\"text\" id=\"middlename\"/>" |
| 169 "</form>"); | 119 "</form>"); |
| 170 | 120 |
| 171 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 121 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
| 172 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 122 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 308 |
| 359 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 309 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
| 360 // Attempting to show the requestAutocomplete dialog again should be ignored. | 310 // Attempting to show the requestAutocomplete dialog again should be ignored. |
| 361 autofill_agent_->didRequestAutocomplete(invoking_form(), | 311 autofill_agent_->didRequestAutocomplete(invoking_form(), |
| 362 blink::WebAutocompleteParams()); | 312 blink::WebAutocompleteParams()); |
| 363 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 313 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 364 AutofillHostMsg_RequestAutocomplete::ID)); | 314 AutofillHostMsg_RequestAutocomplete::ID)); |
| 365 } | 315 } |
| 366 | 316 |
| 367 } // namespace autofill | 317 } // namespace autofill |
| OLD | NEW |