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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 using WebKit::WebDocument; | 32 using WebKit::WebDocument; |
33 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
34 using WebKit::WebInputElement; | 34 using WebKit::WebInputElement; |
35 using WebKit::WebString; | 35 using WebKit::WebString; |
36 using WebKit::WebTextDirection; | 36 using WebKit::WebTextDirection; |
37 using WebKit::WebURLError; | 37 using WebKit::WebURLError; |
38 using webkit_glue::FormData; | 38 using webkit_glue::FormData; |
39 using webkit_glue::FormField; | 39 using webkit_glue::FormField; |
40 | 40 |
41 namespace { | |
42 | |
43 // TODO(isherman): Pull this as a named constant from WebKit | |
44 const int kDefaultMaxLength = 0x80000; | |
45 | |
46 } | |
dhollowa
2010/11/19 15:45:22
nit: } // namespace
| |
47 | |
41 // Test that we get form state change notifications when input fields change. | 48 // Test that we get form state change notifications when input fields change. |
42 TEST_F(RenderViewTest, OnNavStateChanged) { | 49 TEST_F(RenderViewTest, OnNavStateChanged) { |
43 // Don't want any delay for form state sync changes. This will still post a | 50 // Don't want any delay for form state sync changes. This will still post a |
44 // message so updates will get coalesced, but as soon as we spin the message | 51 // message so updates will get coalesced, but as soon as we spin the message |
45 // loop, it will generate an update. | 52 // loop, it will generate an update. |
46 view_->set_send_content_state_immediately(true); | 53 view_->set_send_content_state_immediately(true); |
47 | 54 |
48 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); | 55 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); |
49 | 56 |
50 // We should NOT have gotten a form state change notification yet. | 57 // We should NOT have gotten a form state change notification yet. |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 ViewHostMsg_FormsSeen::Param params; | 942 ViewHostMsg_FormsSeen::Param params; |
936 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 943 ViewHostMsg_FormsSeen::Read(message, ¶ms); |
937 const std::vector<FormData>& forms = params.a; | 944 const std::vector<FormData>& forms = params.a; |
938 ASSERT_EQ(1UL, forms.size()); | 945 ASSERT_EQ(1UL, forms.size()); |
939 ASSERT_EQ(3UL, forms[0].fields.size()); | 946 ASSERT_EQ(3UL, forms[0].fields.size()); |
940 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 947 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
941 FormField(string16(), | 948 FormField(string16(), |
942 ASCIIToUTF16("firstname"), | 949 ASCIIToUTF16("firstname"), |
943 string16(), | 950 string16(), |
944 ASCIIToUTF16("text"), | 951 ASCIIToUTF16("text"), |
945 20))) << forms[0].fields[0]; | 952 kDefaultMaxLength))) << forms[0].fields[0]; |
946 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( | 953 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( |
947 FormField(string16(), | 954 FormField(string16(), |
948 ASCIIToUTF16("middlename"), | 955 ASCIIToUTF16("middlename"), |
949 string16(), | 956 string16(), |
950 ASCIIToUTF16("text"), | 957 ASCIIToUTF16("text"), |
951 20))) << forms[0].fields[1]; | 958 kDefaultMaxLength))) << forms[0].fields[1]; |
952 EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( | 959 EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( |
953 FormField(string16(), | 960 FormField(string16(), |
954 ASCIIToUTF16("lastname"), | 961 ASCIIToUTF16("lastname"), |
955 string16(), | 962 string16(), |
956 ASCIIToUTF16("hidden"), | 963 ASCIIToUTF16("hidden"), |
957 0))) << forms[0].fields[2]; | 964 0))) << forms[0].fields[2]; |
958 | 965 |
959 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of | 966 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of |
960 // fields. | 967 // fields. |
961 WebFrame* web_frame = GetMainFrame(); | 968 WebFrame* web_frame = GetMainFrame(); |
(...skipping 16 matching lines...) Expand all Loading... | |
978 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); | 985 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); |
979 ViewHostMsg_FillAutoFillFormData::Param params2; | 986 ViewHostMsg_FillAutoFillFormData::Param params2; |
980 ViewHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); | 987 ViewHostMsg_FillAutoFillFormData::Read(message2, ¶ms2); |
981 const FormData& form2 = params2.b; | 988 const FormData& form2 = params2.b; |
982 ASSERT_EQ(3UL, form2.fields.size()); | 989 ASSERT_EQ(3UL, form2.fields.size()); |
983 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( | 990 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( |
984 FormField(string16(), | 991 FormField(string16(), |
985 ASCIIToUTF16("firstname"), | 992 ASCIIToUTF16("firstname"), |
986 string16(), | 993 string16(), |
987 ASCIIToUTF16("text"), | 994 ASCIIToUTF16("text"), |
988 20))) << form2.fields[0]; | 995 kDefaultMaxLength))) << form2.fields[0]; |
989 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( | 996 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( |
990 FormField(string16(), | 997 FormField(string16(), |
991 ASCIIToUTF16("middlename"), | 998 ASCIIToUTF16("middlename"), |
992 string16(), | 999 string16(), |
993 ASCIIToUTF16("text"), | 1000 ASCIIToUTF16("text"), |
994 20))) << form2.fields[1]; | 1001 kDefaultMaxLength))) << form2.fields[1]; |
995 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( | 1002 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( |
996 FormField(string16(), | 1003 FormField(string16(), |
997 ASCIIToUTF16("lastname"), | 1004 ASCIIToUTF16("lastname"), |
998 string16(), | 1005 string16(), |
999 ASCIIToUTF16("hidden"), | 1006 ASCIIToUTF16("hidden"), |
1000 0))) << form2.fields[2]; | 1007 0))) << form2.fields[2]; |
1001 } | 1008 } |
1002 | 1009 |
1003 TEST_F(RenderViewTest, FillFormElement) { | 1010 TEST_F(RenderViewTest, FillFormElement) { |
1004 // Don't want any delay for form state sync changes. This will still post a | 1011 // Don't want any delay for form state sync changes. This will still post a |
(...skipping 14 matching lines...) Expand all Loading... | |
1019 ViewHostMsg_FormsSeen::Param params; | 1026 ViewHostMsg_FormsSeen::Param params; |
1020 ViewHostMsg_FormsSeen::Read(message, ¶ms); | 1027 ViewHostMsg_FormsSeen::Read(message, ¶ms); |
1021 const std::vector<FormData>& forms = params.a; | 1028 const std::vector<FormData>& forms = params.a; |
1022 ASSERT_EQ(1UL, forms.size()); | 1029 ASSERT_EQ(1UL, forms.size()); |
1023 ASSERT_EQ(2UL, forms[0].fields.size()); | 1030 ASSERT_EQ(2UL, forms[0].fields.size()); |
1024 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( | 1031 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( |
1025 FormField(string16(), | 1032 FormField(string16(), |
1026 ASCIIToUTF16("firstname"), | 1033 ASCIIToUTF16("firstname"), |
1027 string16(), | 1034 string16(), |
1028 ASCIIToUTF16("text"), | 1035 ASCIIToUTF16("text"), |
1029 20))) << forms[0].fields[0]; | 1036 kDefaultMaxLength))) << forms[0].fields[0]; |
1030 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( | 1037 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( |
1031 FormField(string16(), | 1038 FormField(string16(), |
1032 ASCIIToUTF16("middlename"), | 1039 ASCIIToUTF16("middlename"), |
1033 string16(), | 1040 string16(), |
1034 ASCIIToUTF16("text"), | 1041 ASCIIToUTF16("text"), |
1035 20))) << forms[0].fields[1]; | 1042 kDefaultMaxLength))) << forms[0].fields[1]; |
1036 | 1043 |
1037 // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected | 1044 // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected |
1038 // field. | 1045 // field. |
1039 WebFrame* web_frame = GetMainFrame(); | 1046 WebFrame* web_frame = GetMainFrame(); |
1040 WebDocument document = web_frame->document(); | 1047 WebDocument document = web_frame->document(); |
1041 WebInputElement firstname = | 1048 WebInputElement firstname = |
1042 document.getElementById("firstname").to<WebInputElement>(); | 1049 document.getElementById("firstname").to<WebInputElement>(); |
1043 WebInputElement middlename = | 1050 WebInputElement middlename = |
1044 document.getElementById("middlename").to<WebInputElement>(); | 1051 document.getElementById("middlename").to<WebInputElement>(); |
1045 middlename.setAutofilled(true); | 1052 middlename.setAutofilled(true); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 LoadHTML("<html><head><meta http-equiv=\"content-language\" " | 1129 LoadHTML("<html><head><meta http-equiv=\"content-language\" " |
1123 "content=\" fr , es,en \">" | 1130 "content=\" fr , es,en \">" |
1124 "</head><body>A random page with random content.</body></html>"); | 1131 "</head><body>A random page with random content.</body></html>"); |
1125 ProcessPendingMessages(); | 1132 ProcessPendingMessages(); |
1126 message = render_thread_.sink().GetUniqueMessageMatching( | 1133 message = render_thread_.sink().GetUniqueMessageMatching( |
1127 ViewHostMsg_PageContents::ID); | 1134 ViewHostMsg_PageContents::ID); |
1128 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1135 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
1129 ViewHostMsg_PageContents::Read(message, ¶ms); | 1136 ViewHostMsg_PageContents::Read(message, ¶ms); |
1130 EXPECT_EQ("fr", params.d); | 1137 EXPECT_EQ("fr", params.d); |
1131 } | 1138 } |
OLD | NEW |