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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/common/autofill_messages.h" | 6 #include "chrome/common/autofill_messages.h" |
7 #include "chrome/common/form_data.h" | 7 #include "chrome/common/form_data.h" |
8 #include "chrome/common/form_field_data.h" | 8 #include "chrome/common/form_field_data.h" |
9 #include "chrome/test/base/chrome_render_view_test.h" | 9 #include "chrome/test/base/chrome_render_view_test.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 ProcessPendingMessages(); | 166 ProcessPendingMessages(); |
167 const IPC::Message* message2 = | 167 const IPC::Message* message2 = |
168 render_thread_->sink().GetUniqueMessageMatching( | 168 render_thread_->sink().GetUniqueMessageMatching( |
169 AutofillHostMsg_FillAutofillFormData::ID); | 169 AutofillHostMsg_FillAutofillFormData::ID); |
170 | 170 |
171 // No message should be sent in this case. |firstname| is filled directly. | 171 // No message should be sent in this case. |firstname| is filled directly. |
172 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 172 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
173 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 173 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
174 } | 174 } |
175 | 175 |
176 TEST_F(ChromeRenderViewTest, ShowAutofillWarning) { | |
Dan Beam
2012/11/06 02:24:11
btw, I don't have a ton of experience with these k
Ilya Sherman
2012/11/06 03:45:08
Yeah, I haven't figured out how to write great tes
| |
177 // Don't want any delay for form state sync changes. This will still post a | |
Dan Beam
2012/11/06 02:22:17
nit: shouldn't this be a double space?
Ilya Sherman
2012/11/06 03:45:08
Done.
| |
178 // message so updates will get coalesced, but as soon as we spin the message | |
179 // loop, it will generate an update. | |
180 SendContentStateImmediately(); | |
181 | |
182 LoadHTML("<form method=\"POST\" autocomplete=\"Off\">" | |
183 " <input id=\"firstname\" autocomplete=\"OFF\"/>" | |
184 " <input id=\"middlename\"/>" | |
185 " <input id=\"lastname\"/>" | |
186 "</form>"); | |
187 | |
188 // Verify that "QueryFormFieldAutofill" isn't sent prior to a user | |
189 // interaction. | |
190 const IPC::Message* message0 = render_thread_->sink().GetFirstMessageMatching( | |
191 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
192 EXPECT_EQ(static_cast<IPC::Message*>(NULL), message0); | |
193 | |
194 WebFrame* web_frame = GetMainFrame(); | |
195 WebDocument document = web_frame->document(); | |
196 WebInputElement firstname = | |
197 document.getElementById("firstname").to<WebInputElement>(); | |
198 WebInputElement middlename = | |
199 document.getElementById("middlename").to<WebInputElement>(); | |
200 | |
201 // Simulate attempting to Autofill the form from the first element, which | |
202 // specifies autocomplete="off". This should still not trigger an IPC, as we | |
203 // don't show warnings for elements that have autocomplete="off". | |
204 autofill_agent_->InputElementClicked(firstname, true, true); | |
205 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( | |
206 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
207 EXPECT_EQ(static_cast<IPC::Message*>(NULL), message1); | |
208 | |
209 // Simulate attempting to Autofill the form from the second element, which | |
210 // does not specify autocomplete="off". This *should* trigger an IPC, as we | |
211 // *do* show warnings for elements that don't themselves set | |
212 // autocomplete="off", but for which the form does. | |
213 autofill_agent_->InputElementClicked(middlename, true, true); | |
214 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | |
215 AutofillHostMsg_QueryFormFieldAutofill::ID); | |
216 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | |
217 // TODO(isherman): It would be nice to verify here that the message includes | |
218 // the correct data. I'm not sure how to extract that information from an | |
219 // IPC::Message though. | |
220 } | |
221 | |
176 } // namespace autofill | 222 } // namespace autofill |
OLD | NEW |