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/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/autofill_messages.h" |
11 #include "chrome/common/content_settings.h" | 12 #include "chrome/common/content_settings.h" |
12 #include "chrome/common/native_web_keyboard_event.h" | 13 #include "chrome/common/native_web_keyboard_event.h" |
13 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
14 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.h" |
15 #include "chrome/renderer/autofill_helper.h" | 16 #include "chrome/renderer/autofill_helper.h" |
16 #include "chrome/renderer/print_web_view_helper.h" | 17 #include "chrome/renderer/print_web_view_helper.h" |
17 #include "chrome/test/render_view_test.h" | 18 #include "chrome/test/render_view_test.h" |
18 #include "gfx/codec/jpeg_codec.h" | 19 #include "gfx/codec/jpeg_codec.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "printing/image.h" | 21 #include "printing/image.h" |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 | 1021 |
1021 LoadHTML("<form method=\"POST\">" | 1022 LoadHTML("<form method=\"POST\">" |
1022 " <input type=\"text\" id=\"firstname\"/>" | 1023 " <input type=\"text\" id=\"firstname\"/>" |
1023 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" | 1024 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" |
1024 " <input type=\"hidden\" id=\"lastname\"/>" | 1025 " <input type=\"hidden\" id=\"lastname\"/>" |
1025 "</form>"); | 1026 "</form>"); |
1026 | 1027 |
1027 // Verify that "FormsSeen" sends the expected number of fields. | 1028 // Verify that "FormsSeen" sends the expected number of fields. |
1028 ProcessPendingMessages(); | 1029 ProcessPendingMessages(); |
1029 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 1030 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
1030 ViewHostMsg_FormsSeen::ID); | 1031 AutoFillHostMsg_FormsSeen::ID); |
1031 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1032 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
1032 ViewHostMsg_FormsSeen::Param params; | 1033 AutoFillHostMsg_FormsSeen::Param params; |
1033 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 1034 AutoFillHostMsg_FormsSeen::Read(message, ¶ms); |
1034 const std::vector<FormData>& forms = params.a; | 1035 const std::vector<FormData>& forms = params.a; |
1035 ASSERT_EQ(1UL, forms.size()); | 1036 ASSERT_EQ(1UL, forms.size()); |
1036 ASSERT_EQ(3UL, forms[0].fields.size()); | 1037 ASSERT_EQ(3UL, forms[0].fields.size()); |
1037 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 1038 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
1038 FormField(string16(), | 1039 FormField(string16(), |
1039 ASCIIToUTF16("firstname"), | 1040 ASCIIToUTF16("firstname"), |
1040 string16(), | 1041 string16(), |
1041 ASCIIToUTF16("text"), | 1042 ASCIIToUTF16("text"), |
1042 kDefaultMaxLength, | 1043 kDefaultMaxLength, |
1043 false))) << forms[0].fields[0]; | 1044 false))) << forms[0].fields[0]; |
(...skipping 14 matching lines...) Expand all Loading... |
1058 | 1059 |
1059 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of | 1060 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of |
1060 // fields. | 1061 // fields. |
1061 WebFrame* web_frame = GetMainFrame(); | 1062 WebFrame* web_frame = GetMainFrame(); |
1062 WebDocument document = web_frame->document(); | 1063 WebDocument document = web_frame->document(); |
1063 WebInputElement firstname = | 1064 WebInputElement firstname = |
1064 document.getElementById("firstname").to<WebInputElement>(); | 1065 document.getElementById("firstname").to<WebInputElement>(); |
1065 | 1066 |
1066 // Accept suggestion that contains a label. Labeled items indicate AutoFill | 1067 // Accept suggestion that contains a label. Labeled items indicate AutoFill |
1067 // as opposed to Autocomplete. We're testing this distinction below with | 1068 // as opposed to Autocomplete. We're testing this distinction below with |
1068 // the |ViewHostMsg_FillAutoFillFormData::ID| message. | 1069 // the |AutoFillHostMsg_FillAutoFillFormData::ID| message. |
1069 autofill_helper_->didAcceptAutoFillSuggestion( | 1070 autofill_helper_->didAcceptAutoFillSuggestion( |
1070 firstname, | 1071 firstname, |
1071 WebKit::WebString::fromUTF8("Johnny"), | 1072 WebKit::WebString::fromUTF8("Johnny"), |
1072 WebKit::WebString::fromUTF8("Home"), | 1073 WebKit::WebString::fromUTF8("Home"), |
1073 1, | 1074 1, |
1074 -1); | 1075 -1); |
1075 | 1076 |
1076 ProcessPendingMessages(); | 1077 ProcessPendingMessages(); |
1077 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( | 1078 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
1078 ViewHostMsg_FillAutoFillFormData::ID); | 1079 AutoFillHostMsg_FillAutoFillFormData::ID); |
1079 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 1080 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
1080 ViewHostMsg_FillAutoFillFormData::Param params2; | 1081 AutoFillHostMsg_FillAutoFillFormData::Param params2; |
1081 ViewHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); | 1082 AutoFillHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); |
1082 const FormData& form2 = params2.b; | 1083 const FormData& form2 = params2.b; |
1083 ASSERT_EQ(3UL, form2.fields.size()); | 1084 ASSERT_EQ(3UL, form2.fields.size()); |
1084 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( | 1085 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( |
1085 FormField(string16(), | 1086 FormField(string16(), |
1086 ASCIIToUTF16("firstname"), | 1087 ASCIIToUTF16("firstname"), |
1087 string16(), | 1088 string16(), |
1088 ASCIIToUTF16("text"), | 1089 ASCIIToUTF16("text"), |
1089 kDefaultMaxLength, | 1090 kDefaultMaxLength, |
1090 false))) << form2.fields[0]; | 1091 false))) << form2.fields[0]; |
1091 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( | 1092 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( |
(...skipping 19 matching lines...) Expand all Loading... |
1111 view_->set_send_content_state_immediately(true); | 1112 view_->set_send_content_state_immediately(true); |
1112 | 1113 |
1113 LoadHTML("<form method=\"POST\">" | 1114 LoadHTML("<form method=\"POST\">" |
1114 " <input type=\"text\" id=\"firstname\"/>" | 1115 " <input type=\"text\" id=\"firstname\"/>" |
1115 " <input type=\"text\" id=\"middlename\"/>" | 1116 " <input type=\"text\" id=\"middlename\"/>" |
1116 "</form>"); | 1117 "</form>"); |
1117 | 1118 |
1118 // Verify that "FormsSeen" sends the expected number of fields. | 1119 // Verify that "FormsSeen" sends the expected number of fields. |
1119 ProcessPendingMessages(); | 1120 ProcessPendingMessages(); |
1120 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 1121 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
1121 ViewHostMsg_FormsSeen::ID); | 1122 AutoFillHostMsg_FormsSeen::ID); |
1122 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1123 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
1123 ViewHostMsg_FormsSeen::Param params; | 1124 AutoFillHostMsg_FormsSeen::Param params; |
1124 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 1125 AutoFillHostMsg_FormsSeen::Read(message, ¶ms); |
1125 const std::vector<FormData>& forms = params.a; | 1126 const std::vector<FormData>& forms = params.a; |
1126 ASSERT_EQ(1UL, forms.size()); | 1127 ASSERT_EQ(1UL, forms.size()); |
1127 ASSERT_EQ(2UL, forms[0].fields.size()); | 1128 ASSERT_EQ(2UL, forms[0].fields.size()); |
1128 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 1129 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
1129 FormField(string16(), | 1130 FormField(string16(), |
1130 ASCIIToUTF16("firstname"), | 1131 ASCIIToUTF16("firstname"), |
1131 string16(), | 1132 string16(), |
1132 ASCIIToUTF16("text"), | 1133 ASCIIToUTF16("text"), |
1133 kDefaultMaxLength, | 1134 kDefaultMaxLength, |
1134 false))) << forms[0].fields[0]; | 1135 false))) << forms[0].fields[0]; |
(...skipping 19 matching lines...) Expand all Loading... |
1154 // the direct filling of the firstname element with value parameter. | 1155 // the direct filling of the firstname element with value parameter. |
1155 autofill_helper_->didAcceptAutoFillSuggestion( | 1156 autofill_helper_->didAcceptAutoFillSuggestion( |
1156 firstname, | 1157 firstname, |
1157 WebKit::WebString::fromUTF8("David"), | 1158 WebKit::WebString::fromUTF8("David"), |
1158 WebKit::WebString(), | 1159 WebKit::WebString(), |
1159 0, | 1160 0, |
1160 0); | 1161 0); |
1161 | 1162 |
1162 ProcessPendingMessages(); | 1163 ProcessPendingMessages(); |
1163 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( | 1164 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
1164 ViewHostMsg_FillAutoFillFormData::ID); | 1165 AutoFillHostMsg_FillAutoFillFormData::ID); |
1165 | 1166 |
1166 // No message should be sent in this case. |firstname| is filled directly. | 1167 // No message should be sent in this case. |firstname| is filled directly. |
1167 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 1168 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
1168 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 1169 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
1169 } | 1170 } |
1170 | 1171 |
1171 // Tests that we send the right translatable for a page and that we respect the | 1172 // Tests that we send the right translatable for a page and that we respect the |
1172 // "no translate" meta-tag. | 1173 // "no translate" meta-tag. |
1173 TEST_F(RenderViewTest, TranslatablePage) { | 1174 TEST_F(RenderViewTest, TranslatablePage) { |
1174 // Suppress the normal delay that occurs when the page is loaded before which | 1175 // Suppress the normal delay that occurs when the page is loaded before which |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 LoadHTML("<html><head><meta http-equiv=\"content-language\" " | 1230 LoadHTML("<html><head><meta http-equiv=\"content-language\" " |
1230 "content=\" fr , es,en \">" | 1231 "content=\" fr , es,en \">" |
1231 "</head><body>A random page with random content.</body></html>"); | 1232 "</head><body>A random page with random content.</body></html>"); |
1232 ProcessPendingMessages(); | 1233 ProcessPendingMessages(); |
1233 message = render_thread_.sink().GetUniqueMessageMatching( | 1234 message = render_thread_.sink().GetUniqueMessageMatching( |
1234 ViewHostMsg_PageContents::ID); | 1235 ViewHostMsg_PageContents::ID); |
1235 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1236 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
1236 ViewHostMsg_PageContents::Read(message, ¶ms); | 1237 ViewHostMsg_PageContents::Read(message, ¶ms); |
1237 EXPECT_EQ("fr", params.d); | 1238 EXPECT_EQ("fr", params.d); |
1238 } | 1239 } |
OLD | NEW |