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

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

Issue 145010: Merge r18936.... (Closed) Base URL: svn://chrome-svn/chrome/branches/190/src/
Patch Set: Created 11 years, 6 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 | « net/base/filter.cc ('k') | net/base/sdch_filter.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <fstream> 5 #include <fstream>
6 #include <iostream> 6 #include <iostream>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 char gzip_decode_buffer[kDefaultBufferSize]; 263 char gzip_decode_buffer[kDefaultBufferSize];
264 int gzip_decode_size = kDefaultBufferSize; 264 int gzip_decode_size = kDefaultBufferSize;
265 filter->ReadData(gzip_decode_buffer, &gzip_decode_size); 265 filter->ReadData(gzip_decode_buffer, &gzip_decode_size);
266 266
267 // Compare the decoding result with source data 267 // Compare the decoding result with source data
268 EXPECT_TRUE(gzip_decode_size == source_len()); 268 EXPECT_TRUE(gzip_decode_size == source_len());
269 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); 269 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0);
270 } 270 }
271 271
272 // SDCH scenario: decoding gzip data when content type says sdch,gzip.
273 // This tests that sdch will degrade to pass through, and is what allows robust
274 // handling when the response *might* be sdch,gzip by simply adding in the
275 // tentative sdch decode.
276 // All test code is otherwise modeled after the "basic" scenario above.
277 TEST_F(GZipUnitTest, DecodeGZipWithMistakenSdch) {
278 // Decode the compressed data with filter
279 std::vector<Filter::FilterType> filter_types;
280 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
281 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
282 MockFilterContext filter_context(kDefaultBufferSize);
283 // We need a good response code to be sure that a proxy isn't injecting an
284 // error page (As is done by BlueCoat proxies and described in bug 8916).
285 filter_context.SetResponseCode(200);
286 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
287 ASSERT_TRUE(filter.get());
288 memcpy(filter->stream_buffer()->data(), gzip_encode_buffer_,
289 gzip_encode_len_);
290 filter->FlushStreamBuffer(gzip_encode_len_);
291
292 char gzip_decode_buffer[kDefaultBufferSize];
293 int gzip_decode_size = kDefaultBufferSize;
294 filter->ReadData(gzip_decode_buffer, &gzip_decode_size);
295
296 // Compare the decoding result with source data
297 EXPECT_TRUE(gzip_decode_size == source_len());
298 EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0);
299 }
300
301 // Tests we can call filter repeatedly to get all the data decoded. 272 // Tests we can call filter repeatedly to get all the data decoded.
302 // To do that, we create a filter with a small buffer that can not hold all 273 // To do that, we create a filter with a small buffer that can not hold all
303 // the input data. 274 // the input data.
304 TEST_F(GZipUnitTest, DecodeWithSmallBuffer) { 275 TEST_F(GZipUnitTest, DecodeWithSmallBuffer) {
305 std::vector<Filter::FilterType> filter_types; 276 std::vector<Filter::FilterType> filter_types;
306 filter_types.push_back(Filter::FILTER_TYPE_DEFLATE); 277 filter_types.push_back(Filter::FILTER_TYPE_DEFLATE);
307 MockFilterContext filter_context(kSmallBufferSize); 278 MockFilterContext filter_context(kSmallBufferSize);
308 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 279 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
309 ASSERT_TRUE(filter.get()); 280 ASSERT_TRUE(filter.get());
310 DecodeAndCompareWithFilter(filter.get(), source_buffer(), source_len(), 281 DecodeAndCompareWithFilter(filter.get(), source_buffer(), source_len(),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 int corrupt_decode_size = kDefaultBufferSize; 392 int corrupt_decode_size = kDefaultBufferSize;
422 393
423 int code = DecodeAllWithFilter(filter.get(), corrupt_data, corrupt_data_len, 394 int code = DecodeAllWithFilter(filter.get(), corrupt_data, corrupt_data_len,
424 corrupt_decode_buffer, &corrupt_decode_size); 395 corrupt_decode_buffer, &corrupt_decode_size);
425 396
426 // Expect failures 397 // Expect failures
427 EXPECT_TRUE(code == Filter::FILTER_ERROR); 398 EXPECT_TRUE(code == Filter::FILTER_ERROR);
428 } 399 }
429 400
430 } // namespace 401 } // namespace
OLDNEW
« no previous file with comments | « net/base/filter.cc ('k') | net/base/sdch_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698