| 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 "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/content_settings.h" | 12 #include "chrome/common/content_settings.h" |
| 13 #include "chrome/common/native_web_keyboard_event.h" | 13 #include "chrome/common/native_web_keyboard_event.h" |
| 14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 15 #include "chrome/common/render_messages_params.h" | 15 #include "chrome/common/render_messages_params.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" |
| 21 #include "printing/native_metafile.h" | 22 #include "printing/native_metafile.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
| 25 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 view_->set_send_content_state_immediately(true); | 1019 view_->set_send_content_state_immediately(true); |
| 1019 | 1020 |
| 1020 LoadHTML("<form method=\"POST\">" | 1021 LoadHTML("<form method=\"POST\">" |
| 1021 " <input type=\"text\" id=\"firstname\"/>" | 1022 " <input type=\"text\" id=\"firstname\"/>" |
| 1022 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" | 1023 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" |
| 1023 " <input type=\"hidden\" id=\"lastname\"/>" | 1024 " <input type=\"hidden\" id=\"lastname\"/>" |
| 1024 "</form>"); | 1025 "</form>"); |
| 1025 | 1026 |
| 1026 // Verify that "FormsSeen" sends the expected number of fields. | 1027 // Verify that "FormsSeen" sends the expected number of fields. |
| 1027 ProcessPendingMessages(); | 1028 ProcessPendingMessages(); |
| 1028 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( | 1029 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
| 1029 ViewHostMsg_FormsSeen::ID); | 1030 ViewHostMsg_FormsSeen::ID); |
| 1030 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1031 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 1031 ViewHostMsg_FormsSeen::Param params; | 1032 ViewHostMsg_FormsSeen::Param params; |
| 1032 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 1033 ViewHostMsg_FormsSeen::Read(message, ¶ms); |
| 1033 const std::vector<FormData>& forms = params.a; | 1034 const std::vector<FormData>& forms = params.a; |
| 1034 ASSERT_EQ(1UL, forms.size()); | 1035 ASSERT_EQ(1UL, forms.size()); |
| 1035 ASSERT_EQ(3UL, forms[0].fields.size()); | 1036 ASSERT_EQ(3UL, forms[0].fields.size()); |
| 1036 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 1037 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
| 1037 FormField(string16(), | 1038 FormField(string16(), |
| 1038 ASCIIToUTF16("firstname"), | 1039 ASCIIToUTF16("firstname"), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1058 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of | 1059 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of |
| 1059 // fields. | 1060 // fields. |
| 1060 WebFrame* web_frame = GetMainFrame(); | 1061 WebFrame* web_frame = GetMainFrame(); |
| 1061 WebDocument document = web_frame->document(); | 1062 WebDocument document = web_frame->document(); |
| 1062 WebInputElement firstname = | 1063 WebInputElement firstname = |
| 1063 document.getElementById("firstname").to<WebInputElement>(); | 1064 document.getElementById("firstname").to<WebInputElement>(); |
| 1064 | 1065 |
| 1065 // Accept suggestion that contains a label. Labeled items indicate AutoFill | 1066 // Accept suggestion that contains a label. Labeled items indicate AutoFill |
| 1066 // as opposed to Autocomplete. We're testing this distinction below with | 1067 // as opposed to Autocomplete. We're testing this distinction below with |
| 1067 // the |ViewHostMsg_FillAutoFillFormData::ID| message. | 1068 // the |ViewHostMsg_FillAutoFillFormData::ID| message. |
| 1068 view_->didAcceptAutoFillSuggestion(firstname, | 1069 autofill_helper_->didAcceptAutoFillSuggestion( |
| 1069 WebKit::WebString::fromUTF8("Johnny"), | 1070 firstname, |
| 1070 WebKit::WebString::fromUTF8("Home"), | 1071 WebKit::WebString::fromUTF8("Johnny"), |
| 1071 1, | 1072 WebKit::WebString::fromUTF8("Home"), |
| 1072 -1); | 1073 1, |
| 1074 -1); |
| 1073 | 1075 |
| 1074 ProcessPendingMessages(); | 1076 ProcessPendingMessages(); |
| 1075 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( | 1077 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
| 1076 ViewHostMsg_FillAutoFillFormData::ID); | 1078 ViewHostMsg_FillAutoFillFormData::ID); |
| 1077 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 1079 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
| 1078 ViewHostMsg_FillAutoFillFormData::Param params2; | 1080 ViewHostMsg_FillAutoFillFormData::Param params2; |
| 1079 ViewHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); | 1081 ViewHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); |
| 1080 const FormData& form2 = params2.b; | 1082 const FormData& form2 = params2.b; |
| 1081 ASSERT_EQ(3UL, form2.fields.size()); | 1083 ASSERT_EQ(3UL, form2.fields.size()); |
| 1082 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( | 1084 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1108 // loop, it will generate an update. | 1110 // loop, it will generate an update. |
| 1109 view_->set_send_content_state_immediately(true); | 1111 view_->set_send_content_state_immediately(true); |
| 1110 | 1112 |
| 1111 LoadHTML("<form method=\"POST\">" | 1113 LoadHTML("<form method=\"POST\">" |
| 1112 " <input type=\"text\" id=\"firstname\"/>" | 1114 " <input type=\"text\" id=\"firstname\"/>" |
| 1113 " <input type=\"text\" id=\"middlename\"/>" | 1115 " <input type=\"text\" id=\"middlename\"/>" |
| 1114 "</form>"); | 1116 "</form>"); |
| 1115 | 1117 |
| 1116 // Verify that "FormsSeen" sends the expected number of fields. | 1118 // Verify that "FormsSeen" sends the expected number of fields. |
| 1117 ProcessPendingMessages(); | 1119 ProcessPendingMessages(); |
| 1118 const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( | 1120 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
| 1119 ViewHostMsg_FormsSeen::ID); | 1121 ViewHostMsg_FormsSeen::ID); |
| 1120 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1122 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 1121 ViewHostMsg_FormsSeen::Param params; | 1123 ViewHostMsg_FormsSeen::Param params; |
| 1122 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 1124 ViewHostMsg_FormsSeen::Read(message, ¶ms); |
| 1123 const std::vector<FormData>& forms = params.a; | 1125 const std::vector<FormData>& forms = params.a; |
| 1124 ASSERT_EQ(1UL, forms.size()); | 1126 ASSERT_EQ(1UL, forms.size()); |
| 1125 ASSERT_EQ(2UL, forms[0].fields.size()); | 1127 ASSERT_EQ(2UL, forms[0].fields.size()); |
| 1126 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 1128 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
| 1127 FormField(string16(), | 1129 FormField(string16(), |
| 1128 ASCIIToUTF16("firstname"), | 1130 ASCIIToUTF16("firstname"), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1143 WebFrame* web_frame = GetMainFrame(); | 1145 WebFrame* web_frame = GetMainFrame(); |
| 1144 WebDocument document = web_frame->document(); | 1146 WebDocument document = web_frame->document(); |
| 1145 WebInputElement firstname = | 1147 WebInputElement firstname = |
| 1146 document.getElementById("firstname").to<WebInputElement>(); | 1148 document.getElementById("firstname").to<WebInputElement>(); |
| 1147 WebInputElement middlename = | 1149 WebInputElement middlename = |
| 1148 document.getElementById("middlename").to<WebInputElement>(); | 1150 document.getElementById("middlename").to<WebInputElement>(); |
| 1149 middlename.setAutofilled(true); | 1151 middlename.setAutofilled(true); |
| 1150 | 1152 |
| 1151 // Accept a suggestion in a form that has been auto-filled. This triggers | 1153 // Accept a suggestion in a form that has been auto-filled. This triggers |
| 1152 // the direct filling of the firstname element with value parameter. | 1154 // the direct filling of the firstname element with value parameter. |
| 1153 view_->didAcceptAutoFillSuggestion(firstname, | 1155 autofill_helper_->didAcceptAutoFillSuggestion( |
| 1154 WebKit::WebString::fromUTF8("David"), | 1156 firstname, |
| 1155 WebKit::WebString(), | 1157 WebKit::WebString::fromUTF8("David"), |
| 1156 0, | 1158 WebKit::WebString(), |
| 1157 0); | 1159 0, |
| 1160 0); |
| 1158 | 1161 |
| 1159 ProcessPendingMessages(); | 1162 ProcessPendingMessages(); |
| 1160 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( | 1163 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
| 1161 ViewHostMsg_FillAutoFillFormData::ID); | 1164 ViewHostMsg_FillAutoFillFormData::ID); |
| 1162 | 1165 |
| 1163 // No message should be sent in this case. |firstname| is filled directly. | 1166 // No message should be sent in this case. |firstname| is filled directly. |
| 1164 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 1167 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
| 1165 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 1168 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
| 1166 } | 1169 } |
| 1167 | 1170 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 LoadHTML("<html><head><meta http-equiv=\"content-language\" " | 1229 LoadHTML("<html><head><meta http-equiv=\"content-language\" " |
| 1227 "content=\" fr , es,en \">" | 1230 "content=\" fr , es,en \">" |
| 1228 "</head><body>A random page with random content.</body></html>"); | 1231 "</head><body>A random page with random content.</body></html>"); |
| 1229 ProcessPendingMessages(); | 1232 ProcessPendingMessages(); |
| 1230 message = render_thread_.sink().GetUniqueMessageMatching( | 1233 message = render_thread_.sink().GetUniqueMessageMatching( |
| 1231 ViewHostMsg_PageContents::ID); | 1234 ViewHostMsg_PageContents::ID); |
| 1232 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1235 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 1233 ViewHostMsg_PageContents::Read(message, ¶ms); | 1236 ViewHostMsg_PageContents::Read(message, ¶ms); |
| 1234 EXPECT_EQ("fr", params.d); | 1237 EXPECT_EQ("fr", params.d); |
| 1235 } | 1238 } |
| OLD | NEW |