Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/renderer/autofill/autofill_renderer_browsertest.cc

Issue 242613006: [Autofill] Enable Autofill for dynamically created forms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, &params); 81 AutofillHostMsg_FormsSeen::Read(message, &params);
82 const std::vector<FormData>& forms = params.a; 82 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
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, &params);
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]);
113 } 163 }
114 164
115 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { 165 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) {
116 LoadHTML("<form method=\"POST\">" 166 LoadHTML("<form method=\"POST\">"
117 " <input type=\"text\" id=\"firstname\"/>" 167 " <input type=\"text\" id=\"firstname\"/>"
118 " <input type=\"text\" id=\"middlename\"/>" 168 " <input type=\"text\" id=\"middlename\"/>"
119 "</form>"); 169 "</form>");
120 170
121 // Verify that "FormsSeen" isn't sent, as there are too few fields. 171 // Verify that "FormsSeen" isn't sent, as there are too few fields.
122 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 172 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 358
309 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { 359 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) {
310 // Attempting to show the requestAutocomplete dialog again should be ignored. 360 // Attempting to show the requestAutocomplete dialog again should be ignored.
311 autofill_agent_->didRequestAutocomplete(invoking_form(), 361 autofill_agent_->didRequestAutocomplete(invoking_form(),
312 blink::WebAutocompleteParams()); 362 blink::WebAutocompleteParams());
313 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 363 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
314 AutofillHostMsg_RequestAutocomplete::ID)); 364 AutofillHostMsg_RequestAutocomplete::ID));
315 } 365 }
316 366
317 } // namespace autofill 367 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_browsertest.cc ('k') | chrome/renderer/autofill/form_autofill_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698