Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: webkit/plugins/npapi/webplugin_impl_unittest.cc

Issue 6300001: Clang: enable -Wbool-conversions and -Wunused-variables on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, undo indent Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/cpp_variant_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_util.h" 5 #include "base/string_util.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" 7 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
8 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 8 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" 9 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
10 #include "webkit/plugins/npapi/webplugin_impl.h" 10 #include "webkit/plugins/npapi/webplugin_impl.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // need to parse out some HTTP headers. Make sure it works 51 // need to parse out some HTTP headers. Make sure it works
52 // with the following tests 52 // with the following tests
53 53
54 TEST(WebPluginImplTest, PostParserSimple) { 54 TEST(WebPluginImplTest, PostParserSimple) {
55 // Test a simple case with headers & data 55 // Test a simple case with headers & data
56 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij"; 56 const char *ex1 = "foo: bar\nContent-length: 10\n\nabcdefghij";
57 WebURLRequest request; 57 WebURLRequest request;
58 request.initialize(); 58 request.initialize();
59 bool rv = WebPluginImpl::SetPostData(&request, ex1, 59 bool rv = WebPluginImpl::SetPostData(&request, ex1,
60 static_cast<uint32>(strlen(ex1))); 60 static_cast<uint32>(strlen(ex1)));
61 EXPECT_EQ(true, rv); 61 EXPECT_TRUE(rv);
62 EXPECT_EQ("bar", GetHeader(request, "foo")); 62 EXPECT_EQ("bar", GetHeader(request, "foo"));
63 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 63 EXPECT_EQ(0U, GetHeader(request, "bar").length());
64 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); 64 EXPECT_EQ(0U, GetHeader(request, "Content-length").length());
65 EXPECT_EQ("abcdefghij", GetBodyText(request)); 65 EXPECT_EQ("abcdefghij", GetBodyText(request));
66 } 66 }
67 67
68 TEST(WebPluginImplTest, PostParserLongHeader) { 68 TEST(WebPluginImplTest, PostParserLongHeader) {
69 // Test a simple case with long headers 69 // Test a simple case with long headers
70 const char *ex1 = "foo: 012345678901234567890123456789012345678901234567890123 4567890123456789012345678901234567890123456789\n\nabcdefghij"; 70 const char *ex1 = "foo: 012345678901234567890123456789012345678901234567890123 4567890123456789012345678901234567890123456789\n\nabcdefghij";
71 WebURLRequest request; 71 WebURLRequest request;
72 request.initialize(); 72 request.initialize();
73 bool rv = WebPluginImpl::SetPostData(&request, ex1, 73 bool rv = WebPluginImpl::SetPostData(&request, ex1,
74 static_cast<uint32>(strlen(ex1))); 74 static_cast<uint32>(strlen(ex1)));
75 EXPECT_EQ(true, rv); 75 EXPECT_TRUE(rv);
76 EXPECT_EQ(100U, GetHeader(request, "foo").length()); 76 EXPECT_EQ(100U, GetHeader(request, "foo").length());
77 } 77 }
78 78
79 TEST(WebPluginImplTest, PostParserManyHeaders) { 79 TEST(WebPluginImplTest, PostParserManyHeaders) {
80 // Test a simple case with long headers 80 // Test a simple case with long headers
81 const char *ex1 = "h1:h1\nh2:h2\nh3:h3\nh4:h4\nh5:h5\nh6:h6\nh7:h7\nh8:h8\nh9: h9\nh10:h10\n\nbody"; 81 const char *ex1 = "h1:h1\nh2:h2\nh3:h3\nh4:h4\nh5:h5\nh6:h6\nh7:h7\nh8:h8\nh9: h9\nh10:h10\n\nbody";
82 WebURLRequest request; 82 WebURLRequest request;
83 request.initialize(); 83 request.initialize();
84 bool rv = WebPluginImpl::SetPostData(&request, ex1, 84 bool rv = WebPluginImpl::SetPostData(&request, ex1,
85 static_cast<uint32>(strlen(ex1))); 85 static_cast<uint32>(strlen(ex1)));
86 EXPECT_EQ(true, rv); 86 EXPECT_TRUE(rv);
87 EXPECT_EQ("h1", GetHeader(request, "h1")); 87 EXPECT_EQ("h1", GetHeader(request, "h1"));
88 EXPECT_EQ("h2", GetHeader(request, "h2")); 88 EXPECT_EQ("h2", GetHeader(request, "h2"));
89 EXPECT_EQ("h3", GetHeader(request, "h3")); 89 EXPECT_EQ("h3", GetHeader(request, "h3"));
90 EXPECT_EQ("h4", GetHeader(request, "h4")); 90 EXPECT_EQ("h4", GetHeader(request, "h4"));
91 EXPECT_EQ("h5", GetHeader(request, "h5")); 91 EXPECT_EQ("h5", GetHeader(request, "h5"));
92 EXPECT_EQ("h6", GetHeader(request, "h6")); 92 EXPECT_EQ("h6", GetHeader(request, "h6"));
93 EXPECT_EQ("h7", GetHeader(request, "h7")); 93 EXPECT_EQ("h7", GetHeader(request, "h7"));
94 EXPECT_EQ("h8", GetHeader(request, "h8")); 94 EXPECT_EQ("h8", GetHeader(request, "h8"));
95 EXPECT_EQ("h9", GetHeader(request, "h9")); 95 EXPECT_EQ("h9", GetHeader(request, "h9"));
96 EXPECT_EQ("h10", GetHeader(request, "h10")); 96 EXPECT_EQ("h10", GetHeader(request, "h10"));
97 EXPECT_EQ("body", GetBodyText(request)); 97 EXPECT_EQ("body", GetBodyText(request));
98 } 98 }
99 99
100 TEST(WebPluginImplTest, PostParserDuplicateHeaders) { 100 TEST(WebPluginImplTest, PostParserDuplicateHeaders) {
101 // Test a simple case with long headers 101 // Test a simple case with long headers
102 // What value gets returned doesn't really matter. It shouldn't error 102 // What value gets returned doesn't really matter. It shouldn't error
103 // out. 103 // out.
104 const char *ex1 = "h1:h1\nh1:h2\n\nbody"; 104 const char *ex1 = "h1:h1\nh1:h2\n\nbody";
105 WebURLRequest request; 105 WebURLRequest request;
106 request.initialize(); 106 request.initialize();
107 bool rv = WebPluginImpl::SetPostData(&request, ex1, 107 bool rv = WebPluginImpl::SetPostData(&request, ex1,
108 static_cast<uint32>(strlen(ex1))); 108 static_cast<uint32>(strlen(ex1)));
109 EXPECT_EQ(true, rv); 109 EXPECT_TRUE(rv);
110 } 110 }
111 111
112 TEST(WebPluginImplTest, PostParserNoHeaders) { 112 TEST(WebPluginImplTest, PostParserNoHeaders) {
113 // Test a simple case with no headers but with data 113 // Test a simple case with no headers but with data
114 const char *ex1 = "\nabcdefghij"; 114 const char *ex1 = "\nabcdefghij";
115 WebURLRequest request; 115 WebURLRequest request;
116 request.initialize(); 116 request.initialize();
117 bool rv = WebPluginImpl::SetPostData(&request, ex1, 117 bool rv = WebPluginImpl::SetPostData(&request, ex1,
118 static_cast<uint32>(strlen(ex1))); 118 static_cast<uint32>(strlen(ex1)));
119 EXPECT_EQ(true, rv); 119 EXPECT_TRUE(rv);
120 EXPECT_EQ(0U, GetHeader(request, "foo").length()); 120 EXPECT_EQ(0U, GetHeader(request, "foo").length());
121 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 121 EXPECT_EQ(0U, GetHeader(request, "bar").length());
122 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); 122 EXPECT_EQ(0U, GetHeader(request, "Content-length").length());
123 EXPECT_EQ("abcdefghij", GetBodyText(request)); 123 EXPECT_EQ("abcdefghij", GetBodyText(request));
124 } 124 }
125 125
126 TEST(WebPluginImplTest, PostParserNoBody) { 126 TEST(WebPluginImplTest, PostParserNoBody) {
127 // Test a simple case with headers and no body 127 // Test a simple case with headers and no body
128 const char *ex1 = "Foo:bar\n\n"; 128 const char *ex1 = "Foo:bar\n\n";
129 WebURLRequest request; 129 WebURLRequest request;
130 request.initialize(); 130 request.initialize();
131 bool rv = WebPluginImpl::SetPostData(&request, ex1, 131 bool rv = WebPluginImpl::SetPostData(&request, ex1,
132 static_cast<uint32>(strlen(ex1))); 132 static_cast<uint32>(strlen(ex1)));
133 EXPECT_EQ(true, rv); 133 EXPECT_TRUE(rv);
134 EXPECT_EQ("bar", GetHeader(request, "foo")); 134 EXPECT_EQ("bar", GetHeader(request, "foo"));
135 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 135 EXPECT_EQ(0U, GetHeader(request, "bar").length());
136 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); 136 EXPECT_EQ(0U, GetHeader(request, "Content-length").length());
137 EXPECT_EQ(0U, GetBodyText(request).length()); 137 EXPECT_EQ(0U, GetBodyText(request).length());
138 } 138 }
139 139
140 TEST(WebPluginImplTest, PostParserBodyWithNewLines) { 140 TEST(WebPluginImplTest, PostParserBodyWithNewLines) {
141 // Test a simple case with headers and no body 141 // Test a simple case with headers and no body
142 const char *ex1 = "Foo:bar\n\n\n\nabcdefg\n\nabcdefg"; 142 const char *ex1 = "Foo:bar\n\n\n\nabcdefg\n\nabcdefg";
143 WebURLRequest request; 143 WebURLRequest request;
144 request.initialize(); 144 request.initialize();
145 bool rv = WebPluginImpl::SetPostData(&request, ex1, 145 bool rv = WebPluginImpl::SetPostData(&request, ex1,
146 static_cast<uint32>(strlen(ex1))); 146 static_cast<uint32>(strlen(ex1)));
147 EXPECT_EQ(true, rv); 147 EXPECT_TRUE(rv);
148 EXPECT_EQ(GetBodyText(request), "\n\nabcdefg\n\nabcdefg"); 148 EXPECT_EQ(GetBodyText(request), "\n\nabcdefg\n\nabcdefg");
149 } 149 }
150 150
151 TEST(WebPluginImplTest, PostParserErrorNoBody) { 151 TEST(WebPluginImplTest, PostParserErrorNoBody) {
152 // Test with headers and no body 152 // Test with headers and no body
153 const char *ex1 = "Foo:bar\n"; 153 const char *ex1 = "Foo:bar\n";
154 WebURLRequest request; 154 WebURLRequest request;
155 request.initialize(); 155 request.initialize();
156 bool rv = WebPluginImpl::SetPostData(&request, ex1, 156 bool rv = WebPluginImpl::SetPostData(&request, ex1,
157 static_cast<uint32>(strlen(ex1))); 157 static_cast<uint32>(strlen(ex1)));
158 EXPECT_EQ(true, rv); 158 EXPECT_TRUE(rv);
159 } 159 }
160 160
161 TEST(WebPluginImplTest, PostParserErrorEmpty) { 161 TEST(WebPluginImplTest, PostParserErrorEmpty) {
162 // Test with an empty string 162 // Test with an empty string
163 const char *ex1 = ""; 163 const char *ex1 = "";
164 WebURLRequest request; 164 WebURLRequest request;
165 request.initialize(); 165 request.initialize();
166 bool rv = WebPluginImpl::SetPostData(&request, ex1, 166 bool rv = WebPluginImpl::SetPostData(&request, ex1,
167 static_cast<uint32>(strlen(ex1))); 167 static_cast<uint32>(strlen(ex1)));
168 EXPECT_EQ(true, rv); 168 EXPECT_TRUE(rv);
169 } 169 }
170 170
171 TEST(WebPluginImplTest, PostParserEmptyName) { 171 TEST(WebPluginImplTest, PostParserEmptyName) {
172 // Test an error case with an empty header name field 172 // Test an error case with an empty header name field
173 const char *ex1 = "foo:bar\n:blat\n\nbody"; 173 const char *ex1 = "foo:bar\n:blat\n\nbody";
174 WebURLRequest request; 174 WebURLRequest request;
175 request.initialize(); 175 request.initialize();
176 bool rv = WebPluginImpl::SetPostData(&request, ex1, 176 bool rv = WebPluginImpl::SetPostData(&request, ex1,
177 static_cast<uint32>(strlen(ex1))); 177 static_cast<uint32>(strlen(ex1)));
178 EXPECT_EQ(true, rv); 178 EXPECT_TRUE(rv);
179 EXPECT_EQ("bar", GetHeader(request, "foo")); 179 EXPECT_EQ("bar", GetHeader(request, "foo"));
180 EXPECT_EQ("body", GetBodyText(request)); 180 EXPECT_EQ("body", GetBodyText(request));
181 } 181 }
182 182
183 TEST(WebPluginImplTest, PostParserEmptyValue) { 183 TEST(WebPluginImplTest, PostParserEmptyValue) {
184 // Test an error case with an empty value field 184 // Test an error case with an empty value field
185 const char *ex1 = "foo:bar\nbar:\n\nbody"; 185 const char *ex1 = "foo:bar\nbar:\n\nbody";
186 WebURLRequest request; 186 WebURLRequest request;
187 request.initialize(); 187 request.initialize();
188 bool rv = WebPluginImpl::SetPostData(&request, ex1, 188 bool rv = WebPluginImpl::SetPostData(&request, ex1,
189 static_cast<uint32>(strlen(ex1))); 189 static_cast<uint32>(strlen(ex1)));
190 EXPECT_EQ(true, rv); 190 EXPECT_TRUE(rv);
191 EXPECT_EQ("bar", GetHeader(request, "foo")); 191 EXPECT_EQ("bar", GetHeader(request, "foo"));
192 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 192 EXPECT_EQ(0U, GetHeader(request, "bar").length());
193 EXPECT_EQ("body", GetBodyText(request)); 193 EXPECT_EQ("body", GetBodyText(request));
194 } 194 }
195 195
196 TEST(WebPluginImplTest, PostParserCRLF) { 196 TEST(WebPluginImplTest, PostParserCRLF) {
197 // Test an error case with an empty value field 197 // Test an error case with an empty value field
198 const char *ex1 = "foo: bar\r\nbar:\r\n\r\nbody\r\n\r\nbody2"; 198 const char *ex1 = "foo: bar\r\nbar:\r\n\r\nbody\r\n\r\nbody2";
199 WebURLRequest request; 199 WebURLRequest request;
200 request.initialize(); 200 request.initialize();
201 bool rv = WebPluginImpl::SetPostData(&request, ex1, 201 bool rv = WebPluginImpl::SetPostData(&request, ex1,
202 static_cast<uint32>(strlen(ex1))); 202 static_cast<uint32>(strlen(ex1)));
203 EXPECT_EQ(true, rv); 203 EXPECT_TRUE(rv);
204 EXPECT_EQ("bar", GetHeader(request, "foo")); 204 EXPECT_EQ("bar", GetHeader(request, "foo"));
205 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 205 EXPECT_EQ(0U, GetHeader(request, "bar").length());
206 EXPECT_EQ("body\r\n\r\nbody2", GetBodyText(request)); 206 EXPECT_EQ("body\r\n\r\nbody2", GetBodyText(request));
207 } 207 }
208 208
209 TEST(WebPluginImplTest, PostParserBodyWithBinaryData) { 209 TEST(WebPluginImplTest, PostParserBodyWithBinaryData) {
210 // Test a simple case with headers and binary data. 210 // Test a simple case with headers and binary data.
211 char ex1[33] = "foo: bar\nContent-length: 10\n\n"; 211 char ex1[33] = "foo: bar\nContent-length: 10\n\n";
212 unsigned int binary_data = 0xFFFFFFF0; 212 unsigned int binary_data = 0xFFFFFFF0;
213 memcpy(ex1 + strlen("foo: bar\nContent-length: 10\n\n"), &binary_data, 213 memcpy(ex1 + strlen("foo: bar\nContent-length: 10\n\n"), &binary_data,
214 sizeof(binary_data)); 214 sizeof(binary_data));
215 215
216 WebURLRequest request; 216 WebURLRequest request;
217 request.initialize(); 217 request.initialize();
218 bool rv = WebPluginImpl::SetPostData(&request, ex1, 218 bool rv = WebPluginImpl::SetPostData(&request, ex1,
219 sizeof(ex1)/sizeof(ex1[0])); 219 sizeof(ex1)/sizeof(ex1[0]));
220 EXPECT_EQ(true, rv); 220 EXPECT_TRUE(rv);
221 EXPECT_EQ("bar", GetHeader(request, "foo")); 221 EXPECT_EQ("bar", GetHeader(request, "foo"));
222 EXPECT_EQ(0U, GetHeader(request, "bar").length()); 222 EXPECT_EQ(0U, GetHeader(request, "bar").length());
223 EXPECT_EQ(0U, GetHeader(request, "Content-length").length()); 223 EXPECT_EQ(0U, GetHeader(request, "Content-length").length());
224 224
225 std::string body = GetBodyText(request); 225 std::string body = GetBodyText(request);
226 226
227 EXPECT_EQ(0xF0, (unsigned char)body[0]); 227 EXPECT_EQ(0xF0, (unsigned char)body[0]);
228 EXPECT_EQ(0xFF, (unsigned char)body[1]); 228 EXPECT_EQ(0xFF, (unsigned char)body[1]);
229 EXPECT_EQ(0xFF, (unsigned char)body[2]); 229 EXPECT_EQ(0xFF, (unsigned char)body[2]);
230 EXPECT_EQ(0xFF, (unsigned char)body[3]); 230 EXPECT_EQ(0xFF, (unsigned char)body[3]);
231 } 231 }
232 232
233 } // namespace npapi 233 } // namespace npapi
234 } // namespace webkit 234 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/glue/cpp_variant_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698