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

Side by Side Diff: net/base/sdch_filter_unittest.cc

Issue 6516025: Remove GetInputStreamBufferSize() method from FilterContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New approach: FactoryForTests Created 9 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <limits.h> 5 #include <limits.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 dictionary.append("\n"); 151 dictionary.append("\n");
152 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 152 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
153 return dictionary; 153 return dictionary;
154 } 154 }
155 155
156 //------------------------------------------------------------------------------ 156 //------------------------------------------------------------------------------
157 157
158 TEST_F(SdchFilterTest, EmptyInputOk) { 158 TEST_F(SdchFilterTest, EmptyInputOk) {
159 std::vector<Filter::FilterType> filter_types; 159 std::vector<Filter::FilterType> filter_types;
160 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 160 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
161 const int kInputBufferSize(30);
162 char output_buffer[20]; 161 char output_buffer[20];
163 MockFilterContext filter_context(kInputBufferSize); 162 MockFilterContext filter_context;
164 std::string url_string("http://ignore.com"); 163 std::string url_string("http://ignore.com");
165 filter_context.SetURL(GURL(url_string)); 164 filter_context.SetURL(GURL(url_string));
166 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 165 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
167 166
168 167
169 // With no input data, try to read output. 168 // With no input data, try to read output.
170 int output_bytes_or_buffer_size = sizeof(output_buffer); 169 int output_bytes_or_buffer_size = sizeof(output_buffer);
171 Filter::FilterStatus status = filter->ReadData(output_buffer, 170 Filter::FilterStatus status = filter->ReadData(output_buffer,
172 &output_bytes_or_buffer_size); 171 &output_bytes_or_buffer_size);
173 172
174 EXPECT_EQ(0, output_bytes_or_buffer_size); 173 EXPECT_EQ(0, output_bytes_or_buffer_size);
175 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); 174 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
176 } 175 }
177 176
178 TEST_F(SdchFilterTest, PassThroughWhenTentative) { 177 TEST_F(SdchFilterTest, PassThroughWhenTentative) {
179 std::vector<Filter::FilterType> filter_types; 178 std::vector<Filter::FilterType> filter_types;
180 // Selective a tentative filter (which can fall back to pass through). 179 // Selective a tentative filter (which can fall back to pass through).
181 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 180 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
182 const int kInputBufferSize(30);
183 char output_buffer[20]; 181 char output_buffer[20];
184 MockFilterContext filter_context(kInputBufferSize); 182 MockFilterContext filter_context;
185 // Response code needs to be 200 to allow a pass through. 183 // Response code needs to be 200 to allow a pass through.
186 filter_context.SetResponseCode(200); 184 filter_context.SetResponseCode(200);
187 std::string url_string("http://ignore.com"); 185 std::string url_string("http://ignore.com");
188 filter_context.SetURL(GURL(url_string)); 186 filter_context.SetURL(GURL(url_string));
189 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 187 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
190 188
191 // Supply enough data to force a pass-through mode.. 189 // Supply enough data to force a pass-through mode..
192 std::string non_gzip_content("not GZIPed data"); 190 std::string non_gzip_content("not GZIPed data");
193 191
194 char* input_buffer = filter->stream_buffer()->data(); 192 char* input_buffer = filter->stream_buffer()->data();
195 int input_buffer_size = filter->stream_buffer_size(); 193 int input_buffer_size = filter->stream_buffer_size();
196 EXPECT_EQ(kInputBufferSize, input_buffer_size);
jar (doing other things) 2011/03/01 22:44:03 This test appears to (among other things) test tha
adamk 2011/03/01 23:13:54 This test doesn't actually seem care how big the b
jar (doing other things) 2011/03/08 02:39:01 You're correct. This and the next few tests don't
197 194
198 EXPECT_LT(static_cast<int>(non_gzip_content.size()), 195 EXPECT_LT(static_cast<int>(non_gzip_content.size()),
199 input_buffer_size); 196 input_buffer_size);
200 memcpy(input_buffer, non_gzip_content.data(), 197 memcpy(input_buffer, non_gzip_content.data(),
201 non_gzip_content.size()); 198 non_gzip_content.size());
202 filter->FlushStreamBuffer(non_gzip_content.size()); 199 filter->FlushStreamBuffer(non_gzip_content.size());
203 200
204 // Try to read output. 201 // Try to read output.
205 int output_bytes_or_buffer_size = sizeof(output_buffer); 202 int output_bytes_or_buffer_size = sizeof(output_buffer);
206 Filter::FilterStatus status = filter->ReadData(output_buffer, 203 Filter::FilterStatus status = filter->ReadData(output_buffer,
207 &output_bytes_or_buffer_size); 204 &output_bytes_or_buffer_size);
208 205
209 EXPECT_EQ(non_gzip_content.size(), 206 EXPECT_EQ(non_gzip_content.size(),
210 static_cast<size_t>(output_bytes_or_buffer_size)); 207 static_cast<size_t>(output_bytes_or_buffer_size));
211 ASSERT_GT(sizeof(output_buffer), 208 ASSERT_GT(sizeof(output_buffer),
212 static_cast<size_t>(output_bytes_or_buffer_size)); 209 static_cast<size_t>(output_bytes_or_buffer_size));
213 output_buffer[output_bytes_or_buffer_size] = '\0'; 210 output_buffer[output_bytes_or_buffer_size] = '\0';
214 EXPECT_TRUE(non_gzip_content == output_buffer); 211 EXPECT_TRUE(non_gzip_content == output_buffer);
215 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); 212 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
216 } 213 }
217 214
218 TEST_F(SdchFilterTest, RefreshBadReturnCode) { 215 TEST_F(SdchFilterTest, RefreshBadReturnCode) {
219 std::vector<Filter::FilterType> filter_types; 216 std::vector<Filter::FilterType> filter_types;
220 // Selective a tentative filter (which can fall back to pass through). 217 // Selective a tentative filter (which can fall back to pass through).
221 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 218 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
222 const int kInputBufferSize(30);
223 char output_buffer[20]; 219 char output_buffer[20];
224 MockFilterContext filter_context(kInputBufferSize); 220 MockFilterContext filter_context;
225 // Response code needs to be 200 to allow a pass through. 221 // Response code needs to be 200 to allow a pass through.
226 filter_context.SetResponseCode(403); 222 filter_context.SetResponseCode(403);
227 // Meta refresh will only appear for html content 223 // Meta refresh will only appear for html content
228 filter_context.SetMimeType("text/html"); 224 filter_context.SetMimeType("text/html");
229 std::string url_string("http://ignore.com"); 225 std::string url_string("http://ignore.com");
230 filter_context.SetURL(GURL(url_string)); 226 filter_context.SetURL(GURL(url_string));
231 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 227 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
232 228
233 // Supply enough data to force a pass-through mode, which means we have 229 // Supply enough data to force a pass-through mode, which means we have
234 // provided more than 9 characters that can't be a dictionary hash. 230 // provided more than 9 characters that can't be a dictionary hash.
235 std::string non_sdch_content("This is not SDCH"); 231 std::string non_sdch_content("This is not SDCH");
236 232
237 char* input_buffer = filter->stream_buffer()->data(); 233 char* input_buffer = filter->stream_buffer()->data();
238 int input_buffer_size = filter->stream_buffer_size(); 234 int input_buffer_size = filter->stream_buffer_size();
239 EXPECT_EQ(kInputBufferSize, input_buffer_size);
240 235
241 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 236 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
242 input_buffer_size); 237 input_buffer_size);
243 memcpy(input_buffer, non_sdch_content.data(), 238 memcpy(input_buffer, non_sdch_content.data(),
244 non_sdch_content.size()); 239 non_sdch_content.size());
245 filter->FlushStreamBuffer(non_sdch_content.size()); 240 filter->FlushStreamBuffer(non_sdch_content.size());
246 241
247 // Try to read output. 242 // Try to read output.
248 int output_bytes_or_buffer_size = sizeof(output_buffer); 243 int output_bytes_or_buffer_size = sizeof(output_buffer);
249 Filter::FilterStatus status = filter->ReadData(output_buffer, 244 Filter::FilterStatus status = filter->ReadData(output_buffer,
250 &output_bytes_or_buffer_size); 245 &output_bytes_or_buffer_size);
251 246
252 // We should have read a long and complicated meta-refresh request. 247 // We should have read a long and complicated meta-refresh request.
253 EXPECT_TRUE(sizeof(output_buffer) == output_bytes_or_buffer_size); 248 EXPECT_TRUE(sizeof(output_buffer) == output_bytes_or_buffer_size);
254 // Check at least the prefix of the return. 249 // Check at least the prefix of the return.
255 EXPECT_EQ(0, strncmp(output_buffer, 250 EXPECT_EQ(0, strncmp(output_buffer,
256 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", 251 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
257 sizeof(output_buffer))); 252 sizeof(output_buffer)));
258 EXPECT_EQ(Filter::FILTER_OK, status); 253 EXPECT_EQ(Filter::FILTER_OK, status);
259 } 254 }
260 255
261 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) { 256 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) {
262 std::vector<Filter::FilterType> filter_types; 257 std::vector<Filter::FilterType> filter_types;
263 // Selective a tentative filter (which can fall back to pass through). 258 // Selective a tentative filter (which can fall back to pass through).
264 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 259 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
265 const int kInputBufferSize(30);
266 char output_buffer[20]; 260 char output_buffer[20];
267 MockFilterContext filter_context(kInputBufferSize); 261 MockFilterContext filter_context;
268 // Response code needs to be 200 to allow a pass through. 262 // Response code needs to be 200 to allow a pass through.
269 filter_context.SetResponseCode(403); 263 filter_context.SetResponseCode(403);
270 // Meta refresh will only appear for html content, so set to something else 264 // Meta refresh will only appear for html content, so set to something else
271 // to induce an error (we can't meta refresh). 265 // to induce an error (we can't meta refresh).
272 filter_context.SetMimeType("anything"); 266 filter_context.SetMimeType("anything");
273 std::string url_string("http://ignore.com"); 267 std::string url_string("http://ignore.com");
274 filter_context.SetURL(GURL(url_string)); 268 filter_context.SetURL(GURL(url_string));
275 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 269 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
276 270
277 // Supply enough data to force a pass-through mode, which means we have 271 // Supply enough data to force a pass-through mode, which means we have
278 // provided more than 9 characters that can't be a dictionary hash. 272 // provided more than 9 characters that can't be a dictionary hash.
279 std::string non_sdch_content("This is not SDCH"); 273 std::string non_sdch_content("This is not SDCH");
280 274
281 char* input_buffer = filter->stream_buffer()->data(); 275 char* input_buffer = filter->stream_buffer()->data();
282 int input_buffer_size = filter->stream_buffer_size(); 276 int input_buffer_size = filter->stream_buffer_size();
283 EXPECT_EQ(kInputBufferSize, input_buffer_size);
284 277
285 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 278 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
286 input_buffer_size); 279 input_buffer_size);
287 memcpy(input_buffer, non_sdch_content.data(), 280 memcpy(input_buffer, non_sdch_content.data(),
288 non_sdch_content.size()); 281 non_sdch_content.size());
289 filter->FlushStreamBuffer(non_sdch_content.size()); 282 filter->FlushStreamBuffer(non_sdch_content.size());
290 283
291 // Try to read output. 284 // Try to read output.
292 int output_bytes_or_buffer_size = sizeof(output_buffer); 285 int output_bytes_or_buffer_size = sizeof(output_buffer);
293 Filter::FilterStatus status = filter->ReadData(output_buffer, 286 Filter::FilterStatus status = filter->ReadData(output_buffer,
294 &output_bytes_or_buffer_size); 287 &output_bytes_or_buffer_size);
295 288
296 EXPECT_EQ(0, output_bytes_or_buffer_size); 289 EXPECT_EQ(0, output_bytes_or_buffer_size);
297 EXPECT_EQ(Filter::FILTER_ERROR, status); 290 EXPECT_EQ(Filter::FILTER_ERROR, status);
298 } 291 }
299 292
300 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) { 293 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) {
301 std::vector<Filter::FilterType> filter_types; 294 std::vector<Filter::FilterType> filter_types;
302 // Selective a tentative filter (which can fall back to pass through). 295 // Selective a tentative filter (which can fall back to pass through).
303 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 296 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
304 const int kInputBufferSize(30);
305 char output_buffer[20]; 297 char output_buffer[20];
306 MockFilterContext filter_context(kInputBufferSize); 298 MockFilterContext filter_context;
307 // Response code needs to be 200 to allow a pass through. 299 // Response code needs to be 200 to allow a pass through.
308 filter_context.SetResponseCode(403); 300 filter_context.SetResponseCode(403);
309 // Meta refresh will only appear for html content 301 // Meta refresh will only appear for html content
310 filter_context.SetMimeType("text/html"); 302 filter_context.SetMimeType("text/html");
311 std::string url_string("http://ignore.com"); 303 std::string url_string("http://ignore.com");
312 filter_context.SetURL(GURL(url_string)); 304 filter_context.SetURL(GURL(url_string));
313 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 305 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
314 306
315 // Supply enough data to force a pass-through mode, which means we have 307 // Supply enough data to force a pass-through mode, which means we have
316 // provided more than 9 characters that can't be a dictionary hash. 308 // provided more than 9 characters that can't be a dictionary hash.
317 std::string non_sdch_content("This is not SDCH"); 309 std::string non_sdch_content("This is not SDCH");
318 310
319 char* input_buffer = filter->stream_buffer()->data(); 311 char* input_buffer = filter->stream_buffer()->data();
320 int input_buffer_size = filter->stream_buffer_size(); 312 int input_buffer_size = filter->stream_buffer_size();
321 EXPECT_EQ(kInputBufferSize, input_buffer_size);
322 313
323 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 314 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
324 input_buffer_size); 315 input_buffer_size);
325 memcpy(input_buffer, non_sdch_content.data(), 316 memcpy(input_buffer, non_sdch_content.data(),
326 non_sdch_content.size()); 317 non_sdch_content.size());
327 filter->FlushStreamBuffer(non_sdch_content.size()); 318 filter->FlushStreamBuffer(non_sdch_content.size());
328 319
329 // Try to read output. 320 // Try to read output.
330 int output_bytes_or_buffer_size = sizeof(output_buffer); 321 int output_bytes_or_buffer_size = sizeof(output_buffer);
331 Filter::FilterStatus status = filter->ReadData(output_buffer, 322 Filter::FilterStatus status = filter->ReadData(output_buffer,
332 &output_bytes_or_buffer_size); 323 &output_bytes_or_buffer_size);
333 324
334 // We should have read a long and complicated meta-refresh request. 325 // We should have read a long and complicated meta-refresh request.
335 EXPECT_EQ(sizeof(output_buffer), 326 EXPECT_EQ(sizeof(output_buffer),
336 static_cast<size_t>(output_bytes_or_buffer_size)); 327 static_cast<size_t>(output_bytes_or_buffer_size));
337 // Check at least the prefix of the return. 328 // Check at least the prefix of the return.
338 EXPECT_EQ(0, strncmp(output_buffer, 329 EXPECT_EQ(0, strncmp(output_buffer,
339 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", 330 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
340 sizeof(output_buffer))); 331 sizeof(output_buffer)));
341 EXPECT_EQ(Filter::FILTER_OK, status); 332 EXPECT_EQ(Filter::FILTER_OK, status);
342 } 333 }
343 334
344 TEST_F(SdchFilterTest, BasicBadDictionary) { 335 TEST_F(SdchFilterTest, BasicBadDictionary) {
345 std::vector<Filter::FilterType> filter_types; 336 std::vector<Filter::FilterType> filter_types;
346 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 337 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
347 const int kInputBufferSize(30);
348 char output_buffer[20]; 338 char output_buffer[20];
349 MockFilterContext filter_context(kInputBufferSize); 339 MockFilterContext filter_context;
350 std::string url_string("http://ignore.com"); 340 std::string url_string("http://ignore.com");
351 filter_context.SetURL(GURL(url_string)); 341 filter_context.SetURL(GURL(url_string));
352 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 342 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
353 343
354 // Supply bogus data (which doesn't yet specify a full dictionary hash). 344 // Supply bogus data (which doesn't yet specify a full dictionary hash).
355 // Dictionary hash is 8 characters followed by a null. 345 // Dictionary hash is 8 characters followed by a null.
356 std::string dictionary_hash_prefix("123"); 346 std::string dictionary_hash_prefix("123");
357 347
358 char* input_buffer = filter->stream_buffer()->data(); 348 char* input_buffer = filter->stream_buffer()->data();
359 int input_buffer_size = filter->stream_buffer_size(); 349 int input_buffer_size = filter->stream_buffer_size();
360 EXPECT_EQ(kInputBufferSize, input_buffer_size);
361 350
362 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), 351 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()),
363 input_buffer_size); 352 input_buffer_size);
364 memcpy(input_buffer, dictionary_hash_prefix.data(), 353 memcpy(input_buffer, dictionary_hash_prefix.data(),
365 dictionary_hash_prefix.size()); 354 dictionary_hash_prefix.size());
366 filter->FlushStreamBuffer(dictionary_hash_prefix.size()); 355 filter->FlushStreamBuffer(dictionary_hash_prefix.size());
367 356
368 // With less than a dictionary specifier, try to read output. 357 // With less than a dictionary specifier, try to read output.
369 int output_bytes_or_buffer_size = sizeof(output_buffer); 358 int output_bytes_or_buffer_size = sizeof(output_buffer);
370 Filter::FilterStatus status = filter->ReadData(output_buffer, 359 Filter::FilterStatus status = filter->ReadData(output_buffer,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 std::string url_string = "http://" + kSampleDomain; 414 std::string url_string = "http://" + kSampleDomain;
426 415
427 GURL url(url_string); 416 GURL url(url_string);
428 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 417 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
429 418
430 std::string compressed(NewSdchCompressedData(dictionary)); 419 std::string compressed(NewSdchCompressedData(dictionary));
431 420
432 std::vector<Filter::FilterType> filter_types; 421 std::vector<Filter::FilterType> filter_types;
433 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 422 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
434 423
435 // Decode with a large buffer (larger than test input, or compressed data). 424 MockFilterContext filter_context;
436 const int kInputBufferSize(100);
437 MockFilterContext filter_context(kInputBufferSize);
438 filter_context.SetURL(url); 425 filter_context.SetURL(url);
439 426
440 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 427 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
441 428
442 size_t feed_block_size = 100; 429 size_t feed_block_size = 100;
443 size_t output_block_size = 100; 430 size_t output_block_size = 100;
444 std::string output; 431 std::string output;
445 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 432 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
446 filter.get(), &output)); 433 filter.get(), &output));
447 EXPECT_EQ(output, expanded_); 434 EXPECT_EQ(output, expanded_);
448 435
449 // Decode with really small buffers (size 1) to check for edge effects. 436 // Decode with really small buffers (size 1) to check for edge effects.
450 filter.reset((Filter::Factory(filter_types, filter_context))); 437 filter.reset(Filter::Factory(filter_types, filter_context));
451 438
452 feed_block_size = 1; 439 feed_block_size = 1;
453 output_block_size = 1; 440 output_block_size = 1;
454 output.clear(); 441 output.clear();
455 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 442 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
456 filter.get(), &output)); 443 filter.get(), &output));
457 EXPECT_EQ(output, expanded_); 444 EXPECT_EQ(output, expanded_);
458 } 445 }
459 446
460 TEST_F(SdchFilterTest, NoDecodeHttps) { 447 TEST_F(SdchFilterTest, NoDecodeHttps) {
461 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 448 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
462 const std::string kSampleDomain = "sdchtest.com"; 449 const std::string kSampleDomain = "sdchtest.com";
463 std::string dictionary(NewSdchDictionary(kSampleDomain)); 450 std::string dictionary(NewSdchDictionary(kSampleDomain));
464 451
465 std::string url_string = "http://" + kSampleDomain; 452 std::string url_string = "http://" + kSampleDomain;
466 453
467 GURL url(url_string); 454 GURL url(url_string);
468 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 455 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
469 456
470 std::string compressed(NewSdchCompressedData(dictionary)); 457 std::string compressed(NewSdchCompressedData(dictionary));
471 458
472 std::vector<Filter::FilterType> filter_types; 459 std::vector<Filter::FilterType> filter_types;
473 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 460 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
474 461
475 const int kInputBufferSize(100); 462 MockFilterContext filter_context;
476 MockFilterContext filter_context(kInputBufferSize);
477 filter_context.SetURL(GURL("https://" + kSampleDomain)); 463 filter_context.SetURL(GURL("https://" + kSampleDomain));
478 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 464 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
479 465
480 const size_t feed_block_size(100); 466 const size_t feed_block_size(100);
481 const size_t output_block_size(100); 467 const size_t output_block_size(100);
482 std::string output; 468 std::string output;
483 469
484 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 470 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
485 filter.get(), &output)); 471 filter.get(), &output));
486 } 472 }
(...skipping 10 matching lines...) Expand all
497 std::string url_string = "http://" + kSampleDomain; 483 std::string url_string = "http://" + kSampleDomain;
498 484
499 GURL url(url_string); 485 GURL url(url_string);
500 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 486 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
501 487
502 std::string compressed(NewSdchCompressedData(dictionary)); 488 std::string compressed(NewSdchCompressedData(dictionary));
503 489
504 std::vector<Filter::FilterType> filter_types; 490 std::vector<Filter::FilterType> filter_types;
505 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 491 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
506 492
507 const int kInputBufferSize(100); 493 MockFilterContext filter_context;
508 MockFilterContext filter_context(kInputBufferSize);
509 filter_context.SetURL(GURL("ftp://" + kSampleDomain)); 494 filter_context.SetURL(GURL("ftp://" + kSampleDomain));
510 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 495 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
511 496
512 const size_t feed_block_size(100); 497 const size_t feed_block_size(100);
513 const size_t output_block_size(100); 498 const size_t output_block_size(100);
514 std::string output; 499 std::string output;
515 500
516 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 501 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
517 filter.get(), &output)); 502 filter.get(), &output));
518 } 503 }
519 504
520 TEST_F(SdchFilterTest, NoDecodeFileColon) { 505 TEST_F(SdchFilterTest, NoDecodeFileColon) {
521 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 506 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
522 const std::string kSampleDomain = "sdchtest.com"; 507 const std::string kSampleDomain = "sdchtest.com";
523 std::string dictionary(NewSdchDictionary(kSampleDomain)); 508 std::string dictionary(NewSdchDictionary(kSampleDomain));
524 509
525 std::string url_string = "http://" + kSampleDomain; 510 std::string url_string = "http://" + kSampleDomain;
526 511
527 GURL url(url_string); 512 GURL url(url_string);
528 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 513 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
529 514
530 std::string compressed(NewSdchCompressedData(dictionary)); 515 std::string compressed(NewSdchCompressedData(dictionary));
531 516
532 std::vector<Filter::FilterType> filter_types; 517 std::vector<Filter::FilterType> filter_types;
533 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 518 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
534 519
535 const int kInputBufferSize(100); 520 MockFilterContext filter_context;
536 MockFilterContext filter_context(kInputBufferSize);
537 filter_context.SetURL(GURL("file://" + kSampleDomain)); 521 filter_context.SetURL(GURL("file://" + kSampleDomain));
538 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 522 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
539 523
540 const size_t feed_block_size(100); 524 const size_t feed_block_size(100);
541 const size_t output_block_size(100); 525 const size_t output_block_size(100);
542 std::string output; 526 std::string output;
543 527
544 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 528 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
545 filter.get(), &output)); 529 filter.get(), &output));
546 } 530 }
547 531
548 TEST_F(SdchFilterTest, NoDecodeAboutColon) { 532 TEST_F(SdchFilterTest, NoDecodeAboutColon) {
549 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 533 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
550 const std::string kSampleDomain = "sdchtest.com"; 534 const std::string kSampleDomain = "sdchtest.com";
551 std::string dictionary(NewSdchDictionary(kSampleDomain)); 535 std::string dictionary(NewSdchDictionary(kSampleDomain));
552 536
553 std::string url_string = "http://" + kSampleDomain; 537 std::string url_string = "http://" + kSampleDomain;
554 538
555 GURL url(url_string); 539 GURL url(url_string);
556 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 540 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
557 541
558 std::string compressed(NewSdchCompressedData(dictionary)); 542 std::string compressed(NewSdchCompressedData(dictionary));
559 543
560 std::vector<Filter::FilterType> filter_types; 544 std::vector<Filter::FilterType> filter_types;
561 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 545 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
562 546
563 const int kInputBufferSize(100); 547 MockFilterContext filter_context;
564 MockFilterContext filter_context(kInputBufferSize);
565 filter_context.SetURL(GURL("about://" + kSampleDomain)); 548 filter_context.SetURL(GURL("about://" + kSampleDomain));
566 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 549 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
567 550
568 const size_t feed_block_size(100); 551 const size_t feed_block_size(100);
569 const size_t output_block_size(100); 552 const size_t output_block_size(100);
570 std::string output; 553 std::string output;
571 554
572 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 555 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
573 filter.get(), &output)); 556 filter.get(), &output));
574 } 557 }
575 558
576 TEST_F(SdchFilterTest, NoDecodeJavaScript) { 559 TEST_F(SdchFilterTest, NoDecodeJavaScript) {
577 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 560 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
578 const std::string kSampleDomain = "sdchtest.com"; 561 const std::string kSampleDomain = "sdchtest.com";
579 std::string dictionary(NewSdchDictionary(kSampleDomain)); 562 std::string dictionary(NewSdchDictionary(kSampleDomain));
580 563
581 std::string url_string = "http://" + kSampleDomain; 564 std::string url_string = "http://" + kSampleDomain;
582 565
583 GURL url(url_string); 566 GURL url(url_string);
584 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 567 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
585 568
586 std::string compressed(NewSdchCompressedData(dictionary)); 569 std::string compressed(NewSdchCompressedData(dictionary));
587 570
588 std::vector<Filter::FilterType> filter_types; 571 std::vector<Filter::FilterType> filter_types;
589 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 572 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
590 573
591 const int kInputBufferSize(100); 574 MockFilterContext filter_context;
592 MockFilterContext filter_context(kInputBufferSize);
593 filter_context.SetURL(GURL("javascript://" + kSampleDomain)); 575 filter_context.SetURL(GURL("javascript://" + kSampleDomain));
594 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 576 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
595 577
596 const size_t feed_block_size(100); 578 const size_t feed_block_size(100);
597 const size_t output_block_size(100); 579 const size_t output_block_size(100);
598 std::string output; 580 std::string output;
599 581
600 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 582 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
601 filter.get(), &output)); 583 filter.get(), &output));
602 } 584 }
603 585
604 TEST_F(SdchFilterTest, CanStillDecodeHttp) { 586 TEST_F(SdchFilterTest, CanStillDecodeHttp) {
605 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 587 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
606 const std::string kSampleDomain = "sdchtest.com"; 588 const std::string kSampleDomain = "sdchtest.com";
607 std::string dictionary(NewSdchDictionary(kSampleDomain)); 589 std::string dictionary(NewSdchDictionary(kSampleDomain));
608 590
609 std::string url_string = "http://" + kSampleDomain; 591 std::string url_string = "http://" + kSampleDomain;
610 592
611 GURL url(url_string); 593 GURL url(url_string);
612 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 594 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
613 595
614 std::string compressed(NewSdchCompressedData(dictionary)); 596 std::string compressed(NewSdchCompressedData(dictionary));
615 597
616 std::vector<Filter::FilterType> filter_types; 598 std::vector<Filter::FilterType> filter_types;
617 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 599 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
618 600
619 const int kInputBufferSize(100); 601 MockFilterContext filter_context;
620 MockFilterContext filter_context(kInputBufferSize);
621 filter_context.SetURL(GURL("http://" + kSampleDomain)); 602 filter_context.SetURL(GURL("http://" + kSampleDomain));
622 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 603 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
623 604
624 const size_t feed_block_size(100); 605 const size_t feed_block_size(100);
625 const size_t output_block_size(100); 606 const size_t output_block_size(100);
626 std::string output; 607 std::string output;
627 608
628 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 609 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
629 filter.get(), &output)); 610 filter.get(), &output));
630 } 611 }
631 612
632 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { 613 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
633 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 614 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
634 const std::string kSampleDomain = "sdchtest.com"; 615 const std::string kSampleDomain = "sdchtest.com";
635 std::string dictionary(NewSdchDictionary(kSampleDomain)); 616 std::string dictionary(NewSdchDictionary(kSampleDomain));
636 617
637 std::string url_string = "http://" + kSampleDomain; 618 std::string url_string = "http://" + kSampleDomain;
638 619
639 GURL url(url_string); 620 GURL url(url_string);
640 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 621 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
641 622
642 std::string compressed(NewSdchCompressedData(dictionary)); 623 std::string compressed(NewSdchCompressedData(dictionary));
643 624
644 std::vector<Filter::FilterType> filter_types; 625 std::vector<Filter::FilterType> filter_types;
645 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 626 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
646 const int kInputBufferSize(100);
647 627
648 // Decode with content arriving from the "wrong" domain. 628 // Decode with content arriving from the "wrong" domain.
649 // This tests SdchManager::CanSet(). 629 // This tests SdchManager::CanSet().
650 MockFilterContext filter_context(kInputBufferSize); 630 MockFilterContext filter_context;
651 GURL wrong_domain_url("http://www.wrongdomain.com"); 631 GURL wrong_domain_url("http://www.wrongdomain.com");
652 filter_context.SetURL(wrong_domain_url); 632 filter_context.SetURL(wrong_domain_url);
653 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); 633 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
654 634
655 size_t feed_block_size = 100; 635 size_t feed_block_size = 100;
656 size_t output_block_size = 100; 636 size_t output_block_size = 100;
657 std::string output; 637 std::string output;
658 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 638 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
659 filter.get(), &output)); 639 filter.get(), &output));
660 EXPECT_EQ(output.size(), 0u); // No output written. 640 EXPECT_EQ(output.size(), 0u); // No output written.
661 641
662 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 642 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
663 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); 643 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url));
(...skipping 14 matching lines...) Expand all
678 // Create a dictionary with a path restriction, by prefixing dictionary. 658 // Create a dictionary with a path restriction, by prefixing dictionary.
679 const std::string path("/special_path/bin"); 659 const std::string path("/special_path/bin");
680 std::string dictionary_with_path("Path: " + path + "\n"); 660 std::string dictionary_with_path("Path: " + path + "\n");
681 dictionary_with_path.append(dictionary); 661 dictionary_with_path.append(dictionary);
682 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); 662 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url));
683 663
684 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); 664 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path));
685 665
686 std::vector<Filter::FilterType> filter_types; 666 std::vector<Filter::FilterType> filter_types;
687 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 667 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
688 const int kInputBufferSize(100);
689 668
690 // Test decode the path data, arriving from a valid path. 669 // Test decode the path data, arriving from a valid path.
691 MockFilterContext filter_context(kInputBufferSize); 670 MockFilterContext filter_context;
692 filter_context.SetURL(GURL(url_string + path)); 671 filter_context.SetURL(GURL(url_string + path));
693 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); 672 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
694 673
695 size_t feed_block_size = 100; 674 size_t feed_block_size = 100;
696 size_t output_block_size = 100; 675 size_t output_block_size = 100;
697 std::string output; 676 std::string output;
698 677
699 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, 678 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size,
700 output_block_size, filter.get(), &output)); 679 output_block_size, filter.get(), &output));
701 EXPECT_EQ(output, expanded_); 680 EXPECT_EQ(output, expanded_);
702 681
703 // Test decode the path data, arriving from a invalid path. 682 // Test decode the path data, arriving from a invalid path.
704 filter_context.SetURL(GURL(url_string)); 683 filter_context.SetURL(GURL(url_string));
705 filter.reset((Filter::Factory(filter_types, filter_context))); 684 filter.reset(Filter::Factory(filter_types, filter_context));
706 685
707 feed_block_size = 100; 686 feed_block_size = 100;
708 output_block_size = 100; 687 output_block_size = 100;
709 output.clear(); 688 output.clear();
710 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 689 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
711 output_block_size, filter.get(), &output)); 690 output_block_size, filter.get(), &output));
712 EXPECT_EQ(output.size(), 0u); // No output written. 691 EXPECT_EQ(output.size(), 0u); // No output written.
713 692
714 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 693 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
715 SdchManager::ClearBlacklistings(); 694 SdchManager::ClearBlacklistings();
(...skipping 16 matching lines...) Expand all
732 std::string dictionary_with_port("Port: " + port + "\n"); 711 std::string dictionary_with_port("Port: " + port + "\n");
733 dictionary_with_port.append("Port: 80\n"); // Add default port. 712 dictionary_with_port.append("Port: 80\n"); // Add default port.
734 dictionary_with_port.append(dictionary); 713 dictionary_with_port.append(dictionary);
735 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, 714 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port,
736 GURL(url_string + ":" + port))); 715 GURL(url_string + ":" + port)));
737 716
738 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); 717 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
739 718
740 std::vector<Filter::FilterType> filter_types; 719 std::vector<Filter::FilterType> filter_types;
741 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 720 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
742 const int kInputBufferSize(100);
743 721
744 // Test decode the port data, arriving from a valid port. 722 // Test decode the port data, arriving from a valid port.
745 MockFilterContext filter_context(kInputBufferSize); 723 MockFilterContext filter_context;
746 filter_context.SetURL(GURL(url_string + ":" + port)); 724 filter_context.SetURL(GURL(url_string + ":" + port));
747 scoped_ptr<Filter> filter((Filter::Factory(filter_types, filter_context))); 725 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
748 726
749 size_t feed_block_size = 100; 727 size_t feed_block_size = 100;
750 size_t output_block_size = 100; 728 size_t output_block_size = 100;
751 std::string output; 729 std::string output;
752 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 730 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
753 output_block_size, filter.get(), &output)); 731 output_block_size, filter.get(), &output));
754 EXPECT_EQ(output, expanded_); 732 EXPECT_EQ(output, expanded_);
755 733
756 // Test decode the port data, arriving from a valid (default) port. 734 // Test decode the port data, arriving from a valid (default) port.
757 filter_context.SetURL(GURL(url_string)); // Default port. 735 filter_context.SetURL(GURL(url_string)); // Default port.
758 filter.reset((Filter::Factory(filter_types, filter_context))); 736 filter.reset(Filter::Factory(filter_types, filter_context));
759 737
760 feed_block_size = 100; 738 feed_block_size = 100;
761 output_block_size = 100; 739 output_block_size = 100;
762 output.clear(); 740 output.clear();
763 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 741 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
764 output_block_size, filter.get(), &output)); 742 output_block_size, filter.get(), &output));
765 EXPECT_EQ(output, expanded_); 743 EXPECT_EQ(output, expanded_);
766 744
767 // Test decode the port data, arriving from a invalid port. 745 // Test decode the port data, arriving from a invalid port.
768 filter_context.SetURL(GURL(url_string + ":" + port + "1")); 746 filter_context.SetURL(GURL(url_string + ":" + port + "1"));
769 filter.reset((Filter::Factory(filter_types, filter_context))); 747 filter.reset(Filter::Factory(filter_types, filter_context));
770 748
771 feed_block_size = 100; 749 feed_block_size = 100;
772 output_block_size = 100; 750 output_block_size = 100;
773 output.clear(); 751 output.clear();
774 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 752 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
775 output_block_size, filter.get(), &output)); 753 output_block_size, filter.get(), &output));
776 EXPECT_EQ(output.size(), 0u); // No output written. 754 EXPECT_EQ(output.size(), 0u); // No output written.
777 755
778 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 756 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string)));
779 SdchManager::ClearBlacklistings(); 757 SdchManager::ClearBlacklistings();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 // Do deflate 807 // Do deflate
830 code = deflate(&zlib_stream, Z_FINISH); 808 code = deflate(&zlib_stream, Z_FINISH);
831 gzip_compressed_length -= zlib_stream.avail_out; 809 gzip_compressed_length -= zlib_stream.avail_out;
832 std::string compressed(gzip_compressed.get(), gzip_compressed_length); 810 std::string compressed(gzip_compressed.get(), gzip_compressed_length);
833 deflateEnd(&zlib_stream); 811 deflateEnd(&zlib_stream);
834 return compressed; 812 return compressed;
835 } 813 }
836 814
837 //------------------------------------------------------------------------------ 815 //------------------------------------------------------------------------------
838 816
817 class SdchFilterChainingTest {
818 public:
819 static Filter* Factory(const std::vector<Filter::FilterType>& types,
820 const FilterContext& context, int size) {
821 return Filter::FactoryForTests(types, context, size);
822 }
823 };
824
839 // Test that filters can be cascaded (chained) so that the output of one filter 825 // Test that filters can be cascaded (chained) so that the output of one filter
840 // is processed by the next one. This is most critical for SDCH, which is 826 // is processed by the next one. This is most critical for SDCH, which is
841 // routinely followed by gzip (during encoding). The filter we'll test for will 827 // routinely followed by gzip (during encoding). The filter we'll test for will
842 // do the gzip decoding first, and then decode the SDCH content. 828 // do the gzip decoding first, and then decode the SDCH content.
843 TEST_F(SdchFilterTest, FilterChaining) { 829 TEST_F(SdchFilterTest, FilterChaining) {
844 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 830 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
845 const std::string kSampleDomain = "sdchtest.com"; 831 const std::string kSampleDomain = "sdchtest.com";
846 std::string dictionary(NewSdchDictionary(kSampleDomain)); 832 std::string dictionary(NewSdchDictionary(kSampleDomain));
847 833
848 std::string url_string = "http://" + kSampleDomain; 834 std::string url_string = "http://" + kSampleDomain;
849 835
850 GURL url(url_string); 836 GURL url(url_string);
851 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 837 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
852 838
853 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 839 std::string sdch_compressed(NewSdchCompressedData(dictionary));
854 840
855 // Use Gzip to compress the sdch sdch_compressed data. 841 // Use Gzip to compress the sdch sdch_compressed data.
856 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 842 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
857 843
858 // Construct a chained filter. 844 // Construct a chained filter.
859 std::vector<Filter::FilterType> filter_types; 845 std::vector<Filter::FilterType> filter_types;
860 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 846 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
861 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 847 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
862 848
863 // First try with a large buffer (larger than test input, or compressed data). 849 // First try with a large buffer (larger than test input, or compressed data).
864 const size_t kLargeInputBufferSize(1000); // Used internally in filters. 850 const size_t kLargeInputBufferSize(1000); // Used internally in filters.
865 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); 851 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size());
866 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); 852 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size());
867 CHECK_GT(kLargeInputBufferSize, expanded_.size()); 853 CHECK_GT(kLargeInputBufferSize, expanded_.size());
868 MockFilterContext filter_context(kLargeInputBufferSize); 854 MockFilterContext filter_context;
869 filter_context.SetURL(url); 855 filter_context.SetURL(url);
870 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 856 scoped_ptr<Filter> filter(
857 SdchFilterChainingTest::Factory(filter_types, filter_context,
858 kLargeInputBufferSize));
871 859
872 // Verify that chained filter is waiting for data. 860 // Verify that chained filter is waiting for data.
873 char tiny_output_buffer[10]; 861 char tiny_output_buffer[10];
874 int tiny_output_size = sizeof(tiny_output_buffer); 862 int tiny_output_size = sizeof(tiny_output_buffer);
875 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 863 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
876 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 864 filter->ReadData(tiny_output_buffer, &tiny_output_size));
877 865
878 // Make chain process all data. 866 // Make chain process all data.
879 size_t feed_block_size = kLargeInputBufferSize; 867 size_t feed_block_size = kLargeInputBufferSize;
880 size_t output_block_size = kLargeInputBufferSize; 868 size_t output_block_size = kLargeInputBufferSize;
881 std::string output; 869 std::string output;
882 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 870 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
883 output_block_size, filter.get(), &output)); 871 output_block_size, filter.get(), &output));
884 EXPECT_EQ(output, expanded_); 872 EXPECT_EQ(output, expanded_);
885 873
886 // Next try with a mid-sized internal buffer size. 874 // Next try with a mid-sized internal buffer size.
887 const size_t kMidSizedInputBufferSize(100); 875 const size_t kMidSizedInputBufferSize(100);
888 // Buffer should be big enough to swallow whole gzip content. 876 // Buffer should be big enough to swallow whole gzip content.
889 CHECK_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size()); 877 CHECK_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size());
890 // Buffer should be small enough that entire SDCH content can't fit. 878 // Buffer should be small enough that entire SDCH content can't fit.
891 // We'll go even further, and force the chain to flush the buffer between the 879 // We'll go even further, and force the chain to flush the buffer between the
892 // two filters more than once (that is why we multiply by 2). 880 // two filters more than once (that is why we multiply by 2).
893 CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size()); 881 CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size());
894 filter_context.SetBufferSize(kMidSizedInputBufferSize);
895 filter_context.SetURL(url); 882 filter_context.SetURL(url);
896 filter.reset(Filter::Factory(filter_types, filter_context)); 883 filter.reset(
884 SdchFilterChainingTest::Factory(filter_types, filter_context,
885 kMidSizedInputBufferSize));
897 886
898 feed_block_size = kMidSizedInputBufferSize; 887 feed_block_size = kMidSizedInputBufferSize;
899 output_block_size = kMidSizedInputBufferSize; 888 output_block_size = kMidSizedInputBufferSize;
900 output.clear(); 889 output.clear();
901 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 890 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
902 output_block_size, filter.get(), &output)); 891 output_block_size, filter.get(), &output));
903 EXPECT_EQ(output, expanded_); 892 EXPECT_EQ(output, expanded_);
904 893
905 // Next try with a tiny input and output buffer to cover edge effects. 894 // Next try with a tiny input and output buffer to cover edge effects.
906 filter_context.SetBufferSize(kLargeInputBufferSize); 895 filter.reset(SdchFilterChainingTest::Factory(filter_types, filter_context,
907 filter.reset(Filter::Factory(filter_types, filter_context)); 896 kLargeInputBufferSize));
908 897
909 feed_block_size = 1; 898 feed_block_size = 1;
910 output_block_size = 1; 899 output_block_size = 1;
911 output.clear(); 900 output.clear();
912 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 901 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
913 output_block_size, filter.get(), &output)); 902 output_block_size, filter.get(), &output));
914 EXPECT_EQ(output, expanded_); 903 EXPECT_EQ(output, expanded_);
915 } 904 }
916 905
917 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { 906 TEST_F(SdchFilterTest, DefaultGzipIfSdch) {
918 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 907 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
919 const std::string kSampleDomain = "sdchtest.com"; 908 const std::string kSampleDomain = "sdchtest.com";
920 std::string dictionary(NewSdchDictionary(kSampleDomain)); 909 std::string dictionary(NewSdchDictionary(kSampleDomain));
921 910
922 std::string url_string = "http://" + kSampleDomain; 911 std::string url_string = "http://" + kSampleDomain;
923 912
924 GURL url(url_string); 913 GURL url(url_string);
925 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 914 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
926 915
927 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 916 std::string sdch_compressed(NewSdchCompressedData(dictionary));
928 917
929 // Use Gzip to compress the sdch sdch_compressed data. 918 // Use Gzip to compress the sdch sdch_compressed data.
930 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 919 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
931 920
932 // Only claim to have sdch content, but really use the gzipped sdch content. 921 // Only claim to have sdch content, but really use the gzipped sdch content.
933 // System should automatically add the missing (optional) gzip. 922 // System should automatically add the missing (optional) gzip.
934 std::vector<Filter::FilterType> filter_types; 923 std::vector<Filter::FilterType> filter_types;
935 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 924 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
936 925
937 const int kInputBufferSize(100); 926 MockFilterContext filter_context;
938 MockFilterContext filter_context(kInputBufferSize);
939 filter_context.SetMimeType("anything/mime"); 927 filter_context.SetMimeType("anything/mime");
940 filter_context.SetSdchResponse(true); 928 filter_context.SetSdchResponse(true);
941 Filter::FixupEncodingTypes(filter_context, &filter_types); 929 Filter::FixupEncodingTypes(filter_context, &filter_types);
942 ASSERT_EQ(filter_types.size(), 2u); 930 ASSERT_EQ(filter_types.size(), 2u);
943 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); 931 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH);
944 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 932 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
945 933
946 // First try with a large buffer (larger than test input, or compressed data). 934 // First try with a large buffer (larger than test input, or compressed data).
947 filter_context.SetURL(url); 935 filter_context.SetURL(url);
948 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 936 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 // Use Gzip to compress the sdch sdch_compressed data. 975 // Use Gzip to compress the sdch sdch_compressed data.
988 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 976 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
989 977
990 // Some proxies strip the content encoding statement down to a mere gzip, but 978 // Some proxies strip the content encoding statement down to a mere gzip, but
991 // pass through the original content (with full sdch,gzip encoding). 979 // pass through the original content (with full sdch,gzip encoding).
992 // Only claim to have gzip content, but really use the gzipped sdch content. 980 // Only claim to have gzip content, but really use the gzipped sdch content.
993 // System should automatically add the missing (optional) sdch. 981 // System should automatically add the missing (optional) sdch.
994 std::vector<Filter::FilterType> filter_types; 982 std::vector<Filter::FilterType> filter_types;
995 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 983 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
996 984
997 const int kInputBufferSize(100); 985 MockFilterContext filter_context;
998 MockFilterContext filter_context(kInputBufferSize);
999 filter_context.SetMimeType("anything/mime"); 986 filter_context.SetMimeType("anything/mime");
1000 filter_context.SetSdchResponse(true); 987 filter_context.SetSdchResponse(true);
1001 Filter::FixupEncodingTypes(filter_context, &filter_types); 988 Filter::FixupEncodingTypes(filter_context, &filter_types);
1002 ASSERT_EQ(filter_types.size(), 3u); 989 ASSERT_EQ(filter_types.size(), 3u);
1003 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 990 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
1004 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 991 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
1005 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); 992 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP);
1006 993
1007 // First try with a large buffer (larger than test input, or compressed data). 994 // First try with a large buffer (larger than test input, or compressed data).
1008 filter_context.SetURL(url); 995 filter_context.SetURL(url);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 1033 std::string sdch_compressed(NewSdchCompressedData(dictionary));
1047 1034
1048 // Use Gzip to compress the sdch sdch_compressed data. 1035 // Use Gzip to compress the sdch sdch_compressed data.
1049 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 1036 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
1050 1037
1051 // Only claim to have non-encoded content, but really use the gzipped sdch 1038 // Only claim to have non-encoded content, but really use the gzipped sdch
1052 // content. 1039 // content.
1053 // System should automatically add the missing (optional) sdch,gzip. 1040 // System should automatically add the missing (optional) sdch,gzip.
1054 std::vector<Filter::FilterType> filter_types; 1041 std::vector<Filter::FilterType> filter_types;
1055 1042
1056 const int kInputBufferSize(100); 1043 MockFilterContext filter_context;
1057 MockFilterContext filter_context(kInputBufferSize);
1058 filter_context.SetMimeType("anything/mime"); 1044 filter_context.SetMimeType("anything/mime");
1059 filter_context.SetSdchResponse(true); 1045 filter_context.SetSdchResponse(true);
1060 Filter::FixupEncodingTypes(filter_context, &filter_types); 1046 Filter::FixupEncodingTypes(filter_context, &filter_types);
1061 ASSERT_EQ(filter_types.size(), 2u); 1047 ASSERT_EQ(filter_types.size(), 2u);
1062 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 1048 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
1063 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 1049 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
1064 1050
1065 // First try with a large buffer (larger than test input, or compressed data). 1051 // First try with a large buffer (larger than test input, or compressed data).
1066 filter_context.SetURL(url); 1052 filter_context.SetURL(url);
1067 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 1053 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 // Use Gzip to double compress the sdch sdch_compressed data. 1095 // Use Gzip to double compress the sdch sdch_compressed data.
1110 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( 1096 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress(
1111 sdch_compressed)); 1097 sdch_compressed));
1112 1098
1113 // Only claim to have gzip content, but really use the double gzipped sdch 1099 // Only claim to have gzip content, but really use the double gzipped sdch
1114 // content. 1100 // content.
1115 // System should automatically add the missing (optional) sdch, gzip decoders. 1101 // System should automatically add the missing (optional) sdch, gzip decoders.
1116 std::vector<Filter::FilterType> filter_types; 1102 std::vector<Filter::FilterType> filter_types;
1117 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 1103 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
1118 1104
1119 const int kInputBufferSize(100); 1105 MockFilterContext filter_context;
1120 MockFilterContext filter_context(kInputBufferSize);
1121 filter_context.SetMimeType("anything/mime"); 1106 filter_context.SetMimeType("anything/mime");
1122 filter_context.SetSdchResponse(true); 1107 filter_context.SetSdchResponse(true);
1123 Filter::FixupEncodingTypes(filter_context, &filter_types); 1108 Filter::FixupEncodingTypes(filter_context, &filter_types);
1124 ASSERT_EQ(filter_types.size(), 3u); 1109 ASSERT_EQ(filter_types.size(), 3u);
1125 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 1110 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
1126 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 1111 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
1127 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); 1112 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP);
1128 1113
1129 // First try with a large buffer (larger than test input, or compressed data). 1114 // First try with a large buffer (larger than test input, or compressed data).
1130 filter_context.SetURL(url); 1115 filter_context.SetURL(url);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 sdch_manager_->SetAllowLatencyExperiment(url, false); 1386 sdch_manager_->SetAllowLatencyExperiment(url, false);
1402 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 1387 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
1403 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); 1388 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2));
1404 1389
1405 sdch_manager_->SetAllowLatencyExperiment(url2, false); 1390 sdch_manager_->SetAllowLatencyExperiment(url2, false);
1406 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); 1391 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url));
1407 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); 1392 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2));
1408 } 1393 }
1409 1394
1410 } // namespace net 1395 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698