Chromium Code Reviews| 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/test/base/chrome_render_view_test.h" | 6 #include "chrome/test/base/chrome_render_view_test.h" |
| 7 #include "components/autofill/common/autofill_messages.h" | 7 #include "components/autofill/common/autofill_messages.h" |
| 8 #include "components/autofill/common/form_data.h" | 8 #include "components/autofill/common/form_data.h" |
| 9 #include "components/autofill/common/form_field_data.h" | 9 #include "components/autofill/common/form_field_data.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 14 | 14 |
| 15 using WebKit::WebDocument; | 15 using WebKit::WebDocument; |
| 16 using WebKit::WebFrame; | 16 using WebKit::WebFrame; |
| 17 using WebKit::WebInputElement; | 17 using WebKit::WebInputElement; |
| 18 using WebKit::WebString; | 18 using WebKit::WebString; |
| 19 | 19 |
| 20 namespace autofill { | 20 namespace autofill { |
| 21 | 21 |
| 22 TEST_F(ChromeRenderViewTest, SendForms) { | 22 TEST_F(ChromeRenderViewTest, SendForms) { |
| 23 // Don't want any delay for form state sync changes. This will still post a | 23 // Don't want any delay for form state sync changes. This will still post a |
| 24 // message so updates will get coalesced, but as soon as we spin the message | 24 // message so updates will get coalesced, but as soon as we spin the message |
| 25 // loop, it will generate an update. | 25 // loop, it will generate an update. |
| 26 SendContentStateImmediately(); | 26 SendContentStateImmediately(); |
| 27 | 27 |
| 28 LoadHTML("<form method=\"POST\">" | 28 LoadHTML("<form method=\"POST\" id=\"testform\">" |
| 29 " <input type=\"text\" id=\"firstname\"/>" | 29 " <input type=\"text\" id=\"firstname\"/>" |
| 30 " <input type=\"text\" id=\"middlename\"/>" | 30 " <input type=\"text\" id=\"middlename\"/>" |
| 31 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" | 31 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" |
| 32 " <input type=\"hidden\" id=\"email\"/>" | 32 " <input type=\"hidden\" id=\"email\"/>" |
| 33 " <select id=\"state\"/>" | 33 " <select id=\"state\"/>" |
| 34 " <option>?</option>" | 34 " <option>?</option>" |
| 35 " <option>California</option>" | 35 " <option>California</option>" |
| 36 " <option>Texas</option>" | 36 " <option>Texas</option>" |
| 37 " </select>" | 37 " </select>" |
| 38 "</form>"); | 38 "</form>"); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 expected.value = string16(); | 116 expected.value = string16(); |
| 117 expected.form_control_type = "text"; | 117 expected.form_control_type = "text"; |
| 118 expected.max_length = WebInputElement::defaultMaxLength(); | 118 expected.max_length = WebInputElement::defaultMaxLength(); |
| 119 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); | 119 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[1]); |
| 120 | 120 |
| 121 expected.name = ASCIIToUTF16("state"); | 121 expected.name = ASCIIToUTF16("state"); |
| 122 expected.value = ASCIIToUTF16("?"); | 122 expected.value = ASCIIToUTF16("?"); |
| 123 expected.form_control_type = "select-one"; | 123 expected.form_control_type = "select-one"; |
| 124 expected.max_length = 0; | 124 expected.max_length = 0; |
| 125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); | 125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, form2.fields[2]); |
| 126 | |
| 127 autofill_agent_->OnWhitelistedForAutocheckout(); | |
|
ahutter
2013/03/29 19:48:31
Might want to make this a new TEST_F
Dane Wallinga
2013/03/29 21:41:12
Done.
| |
| 128 render_thread_->sink().ClearMessages(); | |
| 129 ExecuteJavaScript("newInput=document.createElement(\"input\");" | |
|
ahutter
2013/03/29 19:48:31
nit but should this be "var newInput="
Dane Wallinga
2013/03/29 21:41:12
Done.
| |
| 130 "newInput.setAttribute(\"type\",\"text\");" | |
| 131 "newInput.setAttribute(\"id\", \"telephone\");" | |
| 132 "document.getElementById(\"testform\").appendChild(newInput) ;"); | |
| 133 msg_loop_.RunUntilIdle(); | |
| 134 // Verify that FormsSeen is resent with the new field. | |
| 135 const IPC::Message* message3 = render_thread_->sink().GetFirstMessageMatching( | |
| 136 AutofillHostMsg_FormsSeen::ID); | |
| 137 ASSERT_NE(static_cast<IPC::Message*>(NULL), message3); | |
| 138 AutofillHostMsg_FormsSeen::Read(message3, ¶ms); | |
| 139 const std::vector<FormData>& new_forms = params.a; | |
| 140 ASSERT_EQ(1UL, new_forms.size()); | |
| 141 ASSERT_EQ(5UL, new_forms[0].fields.size()); | |
| 142 | |
| 143 expected.name = ASCIIToUTF16("telephone"); | |
| 144 expected.value = string16(); | |
| 145 expected.form_control_type = "text"; | |
| 146 expected.max_length = WebInputElement::defaultMaxLength(); | |
| 147 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[4]); | |
| 126 } | 148 } |
| 127 | 149 |
| 128 TEST_F(ChromeRenderViewTest, FillFormElement) { | 150 TEST_F(ChromeRenderViewTest, FillFormElement) { |
| 129 // Don't want any delay for form state sync changes. This will still post a | 151 // Don't want any delay for form state sync changes. This will still post a |
| 130 // message so updates will get coalesced, but as soon as we spin the message | 152 // message so updates will get coalesced, but as soon as we spin the message |
| 131 // loop, it will generate an update. | 153 // loop, it will generate an update. |
| 132 SendContentStateImmediately(); | 154 SendContentStateImmediately(); |
| 133 | 155 |
| 134 LoadHTML("<form method=\"POST\">" | 156 LoadHTML("<form method=\"POST\">" |
| 135 " <input type=\"text\" id=\"firstname\"/>" | 157 " <input type=\"text\" id=\"firstname\"/>" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 autofill_agent_->InputElementClicked(middlename, true, true); | 239 autofill_agent_->InputElementClicked(middlename, true, true); |
| 218 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( | 240 const IPC::Message* message2 = render_thread_->sink().GetFirstMessageMatching( |
| 219 AutofillHostMsg_QueryFormFieldAutofill::ID); | 241 AutofillHostMsg_QueryFormFieldAutofill::ID); |
| 220 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 242 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
| 221 // TODO(isherman): It would be nice to verify here that the message includes | 243 // TODO(isherman): It would be nice to verify here that the message includes |
| 222 // the correct data. I'm not sure how to extract that information from an | 244 // the correct data. I'm not sure how to extract that information from an |
| 223 // IPC::Message though. | 245 // IPC::Message though. |
| 224 } | 246 } |
| 225 | 247 |
| 226 } // namespace autofill | 248 } // namespace autofill |
| OLD | NEW |