OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/keyboard_codes.h" | 8 #include "base/keyboard_codes.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "chrome/common/content_settings.h" | 10 #include "chrome/common/content_settings.h" |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 string16(), | 1014 string16(), |
1015 ASCIIToUTF16("text"), | 1015 ASCIIToUTF16("text"), |
1016 20))) << form2.fields[1]; | 1016 20))) << form2.fields[1]; |
1017 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( | 1017 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( |
1018 FormField(string16(), | 1018 FormField(string16(), |
1019 ASCIIToUTF16("lastname"), | 1019 ASCIIToUTF16("lastname"), |
1020 string16(), | 1020 string16(), |
1021 ASCIIToUTF16("hidden"), | 1021 ASCIIToUTF16("hidden"), |
1022 0))) << form2.fields[2]; | 1022 0))) << form2.fields[2]; |
1023 } | 1023 } |
| 1024 |
| 1025 TEST_F(RenderViewTest, FillFormElement) { |
| 1026 // Don't want any delay for form state sync changes. This will still post a |
| 1027 // message so updates will get coalesced, but as soon as we spin the message |
| 1028 // loop, it will generate an update. |
| 1029 view_->set_send_content_state_immediately(true); |
| 1030 |
| 1031 LoadHTML("<form method=\"POST\">" |
| 1032 " <input type=\"text\" id=\"firstname\"/>" |
| 1033 " <input type=\"text\" id=\"middlename\"/>" |
| 1034 "</form>"); |
| 1035 |
| 1036 // Verify that "FormsSeen" sends the expected number of fields. |
| 1037 ProcessPendingMessages(); |
| 1038 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( |
| 1039 ViewHostMsg_FormsSeen::ID); |
| 1040 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 1041 ViewHostMsg_FormsSeen::Param params; |
| 1042 ViewHostMsg_FormsSeen::Read(message, ¶ms); |
| 1043 const std::vector<FormData>& forms = params.a; |
| 1044 ASSERT_EQ(1UL, forms.size()); |
| 1045 ASSERT_EQ(2UL, forms[0].fields.size()); |
| 1046 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
| 1047 FormField(string16(), |
| 1048 ASCIIToUTF16("firstname"), |
| 1049 string16(), |
| 1050 ASCIIToUTF16("text"), |
| 1051 20))) << forms[0].fields[0]; |
| 1052 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( |
| 1053 FormField(string16(), |
| 1054 ASCIIToUTF16("middlename"), |
| 1055 string16(), |
| 1056 ASCIIToUTF16("text"), |
| 1057 20))) << forms[0].fields[1]; |
| 1058 |
| 1059 // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected |
| 1060 // field. |
| 1061 WebFrame* web_frame = GetMainFrame(); |
| 1062 WebDocument document = web_frame->document(); |
| 1063 WebInputElement firstname = |
| 1064 document.getElementById("firstname").to<WebInputElement>(); |
| 1065 WebInputElement middlename = |
| 1066 document.getElementById("middlename").to<WebInputElement>(); |
| 1067 middlename.setAutofilled(true); |
| 1068 // didAcceptAutoFillSuggestions expects a non-zero number of suggestions. |
| 1069 view_->suggestions_count_ = 4; |
| 1070 |
| 1071 // Accept a suggestion in a form that has been auto-filled. This triggers |
| 1072 // the direct filling of the firstname element with value parameter. |
| 1073 view_->didAcceptAutoFillSuggestion(firstname, |
| 1074 WebKit::WebString::fromUTF8("David"), |
| 1075 WebKit::WebString(), |
| 1076 0); |
| 1077 |
| 1078 ProcessPendingMessages(); |
| 1079 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
| 1080 ViewHostMsg_FillAutoFillFormData::ID); |
| 1081 |
| 1082 // No message should be sent in this case. |firstname| is filled directly. |
| 1083 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
| 1084 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
| 1085 } |
OLD | NEW |