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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // message so updates will get coalesced, but as soon as we spin the message | 52 // message so updates will get coalesced, but as soon as we spin the message |
53 // loop, it will generate an update. | 53 // loop, it will generate an update. |
54 SendContentStateImmediately(); | 54 SendContentStateImmediately(); |
55 } | 55 } |
56 | 56 |
57 private: | 57 private: |
58 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); | 58 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); |
59 }; | 59 }; |
60 | 60 |
61 TEST_F(AutofillRendererTest, SendForms) { | 61 TEST_F(AutofillRendererTest, SendForms) { |
62 LoadHTML("<form method=\"POST\">" | 62 LoadHTML("<form method='POST'>" |
63 " <input type=\"text\" id=\"firstname\"/>" | 63 " <input type='text' id='firstname'/>" |
64 " <input type=\"text\" id=\"middlename\"/>" | 64 " <input type='text' id='middlename'/>" |
65 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" | 65 " <input type='text' id='lastname' autoComplete='off'/>" |
66 " <input type=\"hidden\" id=\"email\"/>" | 66 " <input type='hidden' id='email'/>" |
67 " <select id=\"state\"/>" | 67 " <select id='state'/>" |
68 " <option>?</option>" | 68 " <option>?</option>" |
69 " <option>California</option>" | 69 " <option>California</option>" |
70 " <option>Texas</option>" | 70 " <option>Texas</option>" |
71 " </select>" | 71 " </select>" |
72 "</form>"); | 72 "</form>"); |
73 | 73 |
74 // Verify that "FormsSeen" sends the expected number of fields. | 74 // Verify that "FormsSeen" sends the expected number of fields. |
75 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 75 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
76 AutofillHostMsg_FormsSeen::ID); | 76 AutofillHostMsg_FormsSeen::ID); |
77 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 77 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 expected.name = ASCIIToUTF16("second_lastname"); | 154 expected.name = ASCIIToUTF16("second_lastname"); |
155 expected.value = ASCIIToUTF16("Hope"); | 155 expected.value = ASCIIToUTF16("Hope"); |
156 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); | 156 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[1]); |
157 | 157 |
158 expected.name = ASCIIToUTF16("second_email"); | 158 expected.name = ASCIIToUTF16("second_email"); |
159 expected.value = ASCIIToUTF16("bobhope@example.com"); | 159 expected.value = ASCIIToUTF16("bobhope@example.com"); |
160 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); | 160 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[2]); |
161 } | 161 } |
162 | 162 |
163 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { | 163 TEST_F(AutofillRendererTest, EnsureNoFormSeenIfTooFewFields) { |
164 LoadHTML("<form method=\"POST\">" | 164 LoadHTML("<form method='POST'>" |
165 " <input type=\"text\" id=\"firstname\"/>" | 165 " <input type='text' id='firstname'/>" |
166 " <input type=\"text\" id=\"middlename\"/>" | 166 " <input type='text' id='middlename'/>" |
167 "</form>"); | 167 "</form>"); |
168 | 168 |
169 // Verify that "FormsSeen" isn't sent, as there are too few fields. | 169 // Verify that "FormsSeen" isn't sent, as there are too few fields. |
170 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 170 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
171 AutofillHostMsg_FormsSeen::ID); | 171 AutofillHostMsg_FormsSeen::ID); |
172 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 172 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
173 AutofillHostMsg_FormsSeen::Param params; | 173 AutofillHostMsg_FormsSeen::Param params; |
174 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 174 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
175 const std::vector<FormData>& forms = params.a; | 175 const std::vector<FormData>& forms = params.a; |
176 ASSERT_EQ(0UL, forms.size()); | 176 ASSERT_EQ(0UL, forms.size()); |
177 } | 177 } |
178 | 178 |
179 TEST_F(AutofillRendererTest, ShowAutofillWarning) { | 179 TEST_F(AutofillRendererTest, ShowAutofillWarning) { |
180 LoadHTML("<form method=\"POST\" autocomplete=\"Off\">" | 180 LoadHTML("<form method='POST' autocomplete='Off'>" |
181 " <input id=\"firstname\" autocomplete=\"OFF\"/>" | 181 " <input id='firstname' autocomplete='OFF'/>" |
182 " <input id=\"middlename\"/>" | 182 " <input id='middlename'/>" |
183 " <input id=\"lastname\"/>" | 183 " <input id='lastname'/>" |
184 "</form>"); | 184 "</form>"); |
185 | 185 |
186 // Verify that "QueryFormFieldAutofill" isn't sent prior to a user | 186 // Verify that "QueryFormFieldAutofill" isn't sent prior to a user |
187 // interaction. | 187 // interaction. |
188 const IPC::Message* message0 = render_thread_->sink().GetFirstMessageMatching( | 188 const IPC::Message* message0 = render_thread_->sink().GetFirstMessageMatching( |
189 AutofillHostMsg_QueryFormFieldAutofill::ID); | 189 AutofillHostMsg_QueryFormFieldAutofill::ID); |
190 EXPECT_EQ(static_cast<IPC::Message*>(NULL), message0); | 190 EXPECT_EQ(static_cast<IPC::Message*>(NULL), message0); |
191 | 191 |
192 WebFrame* web_frame = GetMainFrame(); | 192 WebFrame* web_frame = GetMainFrame(); |
193 WebDocument document = web_frame->document(); | 193 WebDocument document = web_frame->document(); |
(...skipping 28 matching lines...) Expand all Loading... |
222 EXPECT_TRUE(query_param.e); | 222 EXPECT_TRUE(query_param.e); |
223 } | 223 } |
224 | 224 |
225 // Regression test for [ http://crbug.com/346010 ]. | 225 // Regression test for [ http://crbug.com/346010 ]. |
226 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { | 226 TEST_F(AutofillRendererTest, DontCrashWhileAssociatingForms) { |
227 LoadHTML("<form id='form'>" | 227 LoadHTML("<form id='form'>" |
228 "<foo id='foo'>" | 228 "<foo id='foo'>" |
229 "<script id='script'>" | 229 "<script id='script'>" |
230 "document.documentElement.appendChild(foo);" | 230 "document.documentElement.appendChild(foo);" |
231 "newDoc = document.implementation.createDocument(" | 231 "newDoc = document.implementation.createDocument(" |
232 " \"http://www.w3.org/1999/xhtml\", \"html\");" | 232 " 'http://www.w3.org/1999/xhtml', 'html');" |
233 "foo.insertBefore(form, script);" | 233 "foo.insertBefore(form, script);" |
234 "newDoc.adoptNode(foo);" | 234 "newDoc.adoptNode(foo);" |
235 "</script>"); | 235 "</script>"); |
236 | 236 |
237 // Shouldn't crash. | 237 // Shouldn't crash. |
238 } | 238 } |
239 | 239 |
240 class RequestAutocompleteRendererTest : public AutofillRendererTest { | 240 class RequestAutocompleteRendererTest : public AutofillRendererTest { |
241 public: | 241 public: |
242 RequestAutocompleteRendererTest() | 242 RequestAutocompleteRendererTest() |
243 : invoking_frame_(NULL), sibling_frame_(NULL) {} | 243 : invoking_frame_(NULL), sibling_frame_(NULL) {} |
244 virtual ~RequestAutocompleteRendererTest() {} | 244 virtual ~RequestAutocompleteRendererTest() {} |
245 | 245 |
246 protected: | 246 protected: |
247 virtual void SetUp() OVERRIDE { | 247 virtual void SetUp() OVERRIDE { |
248 AutofillRendererTest::SetUp(); | 248 AutofillRendererTest::SetUp(); |
249 | 249 |
250 // Bypass the HTTPS-only restriction to show requestAutocomplete. | 250 // Bypass the HTTPS-only restriction to show requestAutocomplete. |
251 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 251 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
252 command_line->AppendSwitch(::switches::kReduceSecurityForTesting); | 252 command_line->AppendSwitch(::switches::kReduceSecurityForTesting); |
253 | 253 |
254 GURL url("data:text/html;charset=utf-8," | 254 GURL url("data:text/html;charset=utf-8," |
255 "<form><input autocomplete=cc-number></form>"); | 255 "<form><input autocomplete=cc-number></form>"); |
256 const char kDoubleIframeHtml[] = "<iframe id=subframe src=\"%s\"></iframe>" | 256 const char kDoubleIframeHtml[] = "<iframe id=subframe src='%s'></iframe>" |
257 "<iframe id=sibling></iframe>"; | 257 "<iframe id=sibling></iframe>"; |
258 LoadHTML(base::StringPrintf(kDoubleIframeHtml, url.spec().c_str()).c_str()); | 258 LoadHTML(base::StringPrintf(kDoubleIframeHtml, url.spec().c_str()).c_str()); |
259 | 259 |
260 WebElement subframe = GetMainFrame()->document().getElementById("subframe"); | 260 WebElement subframe = GetMainFrame()->document().getElementById("subframe"); |
261 ASSERT_FALSE(subframe.isNull()); | 261 ASSERT_FALSE(subframe.isNull()); |
262 invoking_frame_ = WebLocalFrame::fromFrameOwnerElement(subframe); | 262 invoking_frame_ = WebLocalFrame::fromFrameOwnerElement(subframe); |
263 ASSERT_TRUE(invoking_frame()); | 263 ASSERT_TRUE(invoking_frame()); |
264 ASSERT_EQ(GetMainFrame(), invoking_frame()->parent()); | 264 ASSERT_EQ(GetMainFrame(), invoking_frame()->parent()); |
265 | 265 |
266 WebElement sibling = GetMainFrame()->document().getElementById("sibling"); | 266 WebElement sibling = GetMainFrame()->document().getElementById("sibling"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 354 } |
355 | 355 |
356 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 356 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
357 // Attempting to show the requestAutocomplete dialog again should be ignored. | 357 // Attempting to show the requestAutocomplete dialog again should be ignored. |
358 autofill_agent_->didRequestAutocomplete(invoking_form()); | 358 autofill_agent_->didRequestAutocomplete(invoking_form()); |
359 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 359 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
360 AutofillHostMsg_RequestAutocomplete::ID)); | 360 AutofillHostMsg_RequestAutocomplete::ID)); |
361 } | 361 } |
362 | 362 |
363 } // namespace autofill | 363 } // namespace autofill |
OLD | NEW |