| 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/test/base/chrome_render_view_test.h" | 6 #include "chrome/test/base/chrome_render_view_test.h" |
| 7 #include "components/autofill/content/common/autofill_messages.h" | 7 #include "components/autofill/content/common/autofill_messages.h" |
| 8 #include "components/autofill/content/renderer/autofill_agent.h" | 8 #include "components/autofill/content/renderer/autofill_agent.h" |
| 9 #include "components/autofill/core/common/form_data.h" | 9 #include "components/autofill/core/common/form_data.h" |
| 10 #include "components/autofill/core/common/form_field_data.h" | 10 #include "components/autofill/core/common/form_field_data.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 WebFrame* web_frame = GetMainFrame(); | 126 WebFrame* web_frame = GetMainFrame(); |
| 127 WebDocument document = web_frame->document(); | 127 WebDocument document = web_frame->document(); |
| 128 WebInputElement firstname = | 128 WebInputElement firstname = |
| 129 document.getElementById("firstname").to<WebInputElement>(); | 129 document.getElementById("firstname").to<WebInputElement>(); |
| 130 WebInputElement middlename = | 130 WebInputElement middlename = |
| 131 document.getElementById("middlename").to<WebInputElement>(); | 131 document.getElementById("middlename").to<WebInputElement>(); |
| 132 | 132 |
| 133 // Simulate attempting to Autofill the form from the first element, which | 133 // Simulate attempting to Autofill the form from the first element, which |
| 134 // specifies autocomplete="off". This should still trigger an IPC which | 134 // specifies autocomplete="off". This should still trigger an IPC which |
| 135 // shouldn't display warnings. | 135 // shouldn't display warnings. |
| 136 autofill_agent_->InputElementClicked(firstname, true, true); | 136 autofill_agent_->FormControlElementClicked(firstname, true); |
| 137 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( | 137 const IPC::Message* message1 = render_thread_->sink().GetFirstMessageMatching( |
| 138 AutofillHostMsg_QueryFormFieldAutofill::ID); | 138 AutofillHostMsg_QueryFormFieldAutofill::ID); |
| 139 EXPECT_NE(static_cast<IPC::Message*>(NULL), message1); | 139 EXPECT_NE(static_cast<IPC::Message*>(NULL), message1); |
| 140 | 140 |
| 141 AutofillQueryParam query_param; | 141 AutofillQueryParam query_param; |
| 142 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); | 142 AutofillHostMsg_QueryFormFieldAutofill::Read(message1, &query_param); |
| 143 EXPECT_FALSE(query_param.e); | 143 EXPECT_FALSE(query_param.e); |
| 144 render_thread_->sink().ClearMessages(); | 144 render_thread_->sink().ClearMessages(); |
| 145 | 145 |
| 146 // Simulate attempting to Autofill the form from the second element, which | 146 // Simulate attempting to Autofill the form from the second element, which |
| 147 // does not specify autocomplete="off". This should trigger an IPC that will | 147 // does not specify autocomplete="off". This should trigger an IPC that will |
| 148 // show warnings, as we *do* show warnings for elements that don't themselves | 148 // show warnings, as we *do* show warnings for elements that don't themselves |
| 149 // set autocomplete="off", but for which the form does. | 149 // set autocomplete="off", but for which the form does. |
| 150 autofill_agent_->InputElementClicked(middlename, true, true); | 150 autofill_agent_->FormControlElementClicked(middlename, true); |
| 151 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 151 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
| 152 AutofillHostMsg_QueryFormFieldAutofill::ID); | 152 AutofillHostMsg_QueryFormFieldAutofill::ID); |
| 153 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 153 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
| 154 | 154 |
| 155 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); | 155 AutofillHostMsg_QueryFormFieldAutofill::Read(message2, &query_param); |
| 156 EXPECT_TRUE(query_param.e); | 156 EXPECT_TRUE(query_param.e); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Regression test for [ http://crbug.com/346010 ]. | 159 // Regression test for [ http://crbug.com/346010 ]. |
| 160 TEST_F(ChromeRenderViewTest, DontCrashWhileAssociatingForms) { | 160 TEST_F(ChromeRenderViewTest, DontCrashWhileAssociatingForms) { |
| 161 // Don't want any delay for form state sync changes. This will still post a | 161 // Don't want any delay for form state sync changes. This will still post a |
| 162 // message so updates will get coalesced, but as soon as we spin the message | 162 // message so updates will get coalesced, but as soon as we spin the message |
| 163 // loop, it will generate an update. | 163 // loop, it will generate an update. |
| 164 SendContentStateImmediately(); | 164 SendContentStateImmediately(); |
| 165 | 165 |
| 166 LoadHTML("<form id='form'>" | 166 LoadHTML("<form id='form'>" |
| 167 "<foo id='foo'>" | 167 "<foo id='foo'>" |
| 168 "<script id='script'>" | 168 "<script id='script'>" |
| 169 "document.documentElement.appendChild(foo);" | 169 "document.documentElement.appendChild(foo);" |
| 170 "newDoc = document.implementation.createDocument(" | 170 "newDoc = document.implementation.createDocument(" |
| 171 " \"http://www.w3.org/1999/xhtml\", \"html\");" | 171 " \"http://www.w3.org/1999/xhtml\", \"html\");" |
| 172 "foo.insertBefore(form, script);" | 172 "foo.insertBefore(form, script);" |
| 173 "newDoc.adoptNode(foo);" | 173 "newDoc.adoptNode(foo);" |
| 174 "</script>"); | 174 "</script>"); |
| 175 | 175 |
| 176 // Shouldn't crash. | 176 // Shouldn't crash. |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace autofill | 179 } // namespace autofill |
| OLD | NEW |