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

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

Issue 298063006: Make SdchManager per-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments and changed test name. Created 6 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/filter/sdch_filter.cc ('k') | net/url_request/url_request_context.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/filter/mock_filter_context.h" 14 #include "net/filter/mock_filter_context.h"
15 #include "net/filter/sdch_filter.h" 15 #include "net/filter/sdch_filter.h"
16 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_http_job.h" 17 #include "net/url_request/url_request_http_job.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/zlib/zlib.h" 19 #include "third_party/zlib/zlib.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 //------------------------------------------------------------------------------ 23 //------------------------------------------------------------------------------
23 // Provide sample data and compression results with a sample VCDIFF dictionary. 24 // Provide sample data and compression results with a sample VCDIFF dictionary.
24 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 25 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
25 static const char kTestVcdiffDictionary[] = "DictionaryFor" 26 static const char kTestVcdiffDictionary[] = "DictionaryFor"
(...skipping 21 matching lines...) Expand all
47 //------------------------------------------------------------------------------ 48 //------------------------------------------------------------------------------
48 49
49 class SdchFilterTest : public testing::Test { 50 class SdchFilterTest : public testing::Test {
50 protected: 51 protected:
51 SdchFilterTest() 52 SdchFilterTest()
52 : test_vcdiff_dictionary_(kTestVcdiffDictionary, 53 : test_vcdiff_dictionary_(kTestVcdiffDictionary,
53 sizeof(kTestVcdiffDictionary) - 1), 54 sizeof(kTestVcdiffDictionary) - 1),
54 vcdiff_compressed_data_(kSdchCompressedTestData, 55 vcdiff_compressed_data_(kSdchCompressedTestData,
55 sizeof(kSdchCompressedTestData) - 1), 56 sizeof(kSdchCompressedTestData) - 1),
56 expanded_(kTestData, sizeof(kTestData) - 1), 57 expanded_(kTestData, sizeof(kTestData) - 1),
57 sdch_manager_(new SdchManager) { 58 sdch_manager_(new SdchManager),
59 filter_context_(new MockFilterContext) {
60 URLRequestContext* url_request_context =
61 filter_context_->GetModifiableURLRequestContext();
62
63 url_request_context->set_sdch_manager(sdch_manager_.get());
58 } 64 }
59 65
66 MockFilterContext* filter_context() { return filter_context_.get(); }
67
60 std::string NewSdchCompressedData(const std::string dictionary); 68 std::string NewSdchCompressedData(const std::string dictionary);
61 69
62 const std::string test_vcdiff_dictionary_; 70 const std::string test_vcdiff_dictionary_;
63 const std::string vcdiff_compressed_data_; 71 const std::string vcdiff_compressed_data_;
64 const std::string expanded_; // Desired final, decompressed data. 72 const std::string expanded_; // Desired final, decompressed data.
65 73
66 scoped_ptr<SdchManager> sdch_manager_; // A singleton database. 74 scoped_ptr<SdchManager> sdch_manager_;
75 scoped_ptr<MockFilterContext> filter_context_;
67 }; 76 };
68 77
69 std::string SdchFilterTest::NewSdchCompressedData( 78 std::string SdchFilterTest::NewSdchCompressedData(
70 const std::string dictionary) { 79 const std::string dictionary) {
71 std::string client_hash; 80 std::string client_hash;
72 std::string server_hash; 81 std::string server_hash;
73 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash); 82 SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
74 83
75 // Build compressed data that refers to our dictionary. 84 // Build compressed data that refers to our dictionary.
76 std::string compressed(server_hash); 85 std::string compressed(server_hash);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 154 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
146 return dictionary; 155 return dictionary;
147 } 156 }
148 157
149 //------------------------------------------------------------------------------ 158 //------------------------------------------------------------------------------
150 159
151 TEST_F(SdchFilterTest, EmptyInputOk) { 160 TEST_F(SdchFilterTest, EmptyInputOk) {
152 std::vector<Filter::FilterType> filter_types; 161 std::vector<Filter::FilterType> filter_types;
153 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 162 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
154 char output_buffer[20]; 163 char output_buffer[20];
155 MockFilterContext filter_context;
156 std::string url_string("http://ignore.com"); 164 std::string url_string("http://ignore.com");
157 filter_context.SetURL(GURL(url_string)); 165 filter_context()->SetURL(GURL(url_string));
158 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 166 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
159 167
160 168
161 // With no input data, try to read output. 169 // With no input data, try to read output.
162 int output_bytes_or_buffer_size = sizeof(output_buffer); 170 int output_bytes_or_buffer_size = sizeof(output_buffer);
163 Filter::FilterStatus status = filter->ReadData(output_buffer, 171 Filter::FilterStatus status = filter->ReadData(output_buffer,
164 &output_bytes_or_buffer_size); 172 &output_bytes_or_buffer_size);
165 173
166 EXPECT_EQ(0, output_bytes_or_buffer_size); 174 EXPECT_EQ(0, output_bytes_or_buffer_size);
167 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); 175 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
168 } 176 }
169 177
170 TEST_F(SdchFilterTest, PassThroughWhenTentative) { 178 TEST_F(SdchFilterTest, PassThroughWhenTentative) {
171 std::vector<Filter::FilterType> filter_types; 179 std::vector<Filter::FilterType> filter_types;
172 // Selective a tentative filter (which can fall back to pass through). 180 // Selective a tentative filter (which can fall back to pass through).
173 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 181 filter_types.push_back(Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
174 char output_buffer[20]; 182 char output_buffer[20];
175 MockFilterContext filter_context;
176 // Response code needs to be 200 to allow a pass through. 183 // Response code needs to be 200 to allow a pass through.
177 filter_context.SetResponseCode(200); 184 filter_context()->SetResponseCode(200);
178 std::string url_string("http://ignore.com"); 185 std::string url_string("http://ignore.com");
179 filter_context.SetURL(GURL(url_string)); 186 filter_context()->SetURL(GURL(url_string));
180 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 187 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
181 188
182 // Supply enough data to force a pass-through mode.. 189 // Supply enough data to force a pass-through mode..
183 std::string non_gzip_content("not GZIPed data"); 190 std::string non_gzip_content("not GZIPed data");
184 191
185 char* input_buffer = filter->stream_buffer()->data(); 192 char* input_buffer = filter->stream_buffer()->data();
186 int input_buffer_size = filter->stream_buffer_size(); 193 int input_buffer_size = filter->stream_buffer_size();
187 194
188 EXPECT_LT(static_cast<int>(non_gzip_content.size()), 195 EXPECT_LT(static_cast<int>(non_gzip_content.size()),
189 input_buffer_size); 196 input_buffer_size);
190 memcpy(input_buffer, non_gzip_content.data(), 197 memcpy(input_buffer, non_gzip_content.data(),
(...skipping 12 matching lines...) Expand all
203 output_buffer[output_bytes_or_buffer_size] = '\0'; 210 output_buffer[output_bytes_or_buffer_size] = '\0';
204 EXPECT_TRUE(non_gzip_content == output_buffer); 211 EXPECT_TRUE(non_gzip_content == output_buffer);
205 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); 212 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
206 } 213 }
207 214
208 TEST_F(SdchFilterTest, RefreshBadReturnCode) { 215 TEST_F(SdchFilterTest, RefreshBadReturnCode) {
209 std::vector<Filter::FilterType> filter_types; 216 std::vector<Filter::FilterType> filter_types;
210 // Selective a tentative filter (which can fall back to pass through). 217 // Selective a tentative filter (which can fall back to pass through).
211 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 218 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
212 char output_buffer[20]; 219 char output_buffer[20];
213 MockFilterContext filter_context;
214 // Response code needs to be 200 to allow a pass through. 220 // Response code needs to be 200 to allow a pass through.
215 filter_context.SetResponseCode(403); 221 filter_context()->SetResponseCode(403);
216 // Meta refresh will only appear for html content 222 // Meta refresh will only appear for html content
217 filter_context.SetMimeType("text/html"); 223 filter_context()->SetMimeType("text/html");
218 std::string url_string("http://ignore.com"); 224 std::string url_string("http://ignore.com");
219 filter_context.SetURL(GURL(url_string)); 225 filter_context()->SetURL(GURL(url_string));
220 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 226 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
221 227
222 // Supply enough data to force a pass-through mode, which means we have 228 // Supply enough data to force a pass-through mode, which means we have
223 // provided more than 9 characters that can't be a dictionary hash. 229 // provided more than 9 characters that can't be a dictionary hash.
224 std::string non_sdch_content("This is not SDCH"); 230 std::string non_sdch_content("This is not SDCH");
225 231
226 char* input_buffer = filter->stream_buffer()->data(); 232 char* input_buffer = filter->stream_buffer()->data();
227 int input_buffer_size = filter->stream_buffer_size(); 233 int input_buffer_size = filter->stream_buffer_size();
228 234
229 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 235 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
230 input_buffer_size); 236 input_buffer_size);
(...skipping 13 matching lines...) Expand all
244 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", 250 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
245 sizeof(output_buffer))); 251 sizeof(output_buffer)));
246 EXPECT_EQ(Filter::FILTER_OK, status); 252 EXPECT_EQ(Filter::FILTER_OK, status);
247 } 253 }
248 254
249 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) { 255 TEST_F(SdchFilterTest, ErrorOnBadReturnCode) {
250 std::vector<Filter::FilterType> filter_types; 256 std::vector<Filter::FilterType> filter_types;
251 // Selective a tentative filter (which can fall back to pass through). 257 // Selective a tentative filter (which can fall back to pass through).
252 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 258 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
253 char output_buffer[20]; 259 char output_buffer[20];
254 MockFilterContext filter_context;
255 // Response code needs to be 200 to allow a pass through. 260 // Response code needs to be 200 to allow a pass through.
256 filter_context.SetResponseCode(403); 261 filter_context()->SetResponseCode(403);
257 // Meta refresh will only appear for html content, so set to something else 262 // Meta refresh will only appear for html content, so set to something else
258 // to induce an error (we can't meta refresh). 263 // to induce an error (we can't meta refresh).
259 filter_context.SetMimeType("anything"); 264 filter_context()->SetMimeType("anything");
260 std::string url_string("http://ignore.com"); 265 std::string url_string("http://ignore.com");
261 filter_context.SetURL(GURL(url_string)); 266 filter_context()->SetURL(GURL(url_string));
262 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 267 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
263 268
264 // Supply enough data to force a pass-through mode, which means we have 269 // Supply enough data to force a pass-through mode, which means we have
265 // provided more than 9 characters that can't be a dictionary hash. 270 // provided more than 9 characters that can't be a dictionary hash.
266 std::string non_sdch_content("This is not SDCH"); 271 std::string non_sdch_content("This is not SDCH");
267 272
268 char* input_buffer = filter->stream_buffer()->data(); 273 char* input_buffer = filter->stream_buffer()->data();
269 int input_buffer_size = filter->stream_buffer_size(); 274 int input_buffer_size = filter->stream_buffer_size();
270 275
271 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 276 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
272 input_buffer_size); 277 input_buffer_size);
273 memcpy(input_buffer, non_sdch_content.data(), 278 memcpy(input_buffer, non_sdch_content.data(),
274 non_sdch_content.size()); 279 non_sdch_content.size());
275 filter->FlushStreamBuffer(non_sdch_content.size()); 280 filter->FlushStreamBuffer(non_sdch_content.size());
276 281
277 // Try to read output. 282 // Try to read output.
278 int output_bytes_or_buffer_size = sizeof(output_buffer); 283 int output_bytes_or_buffer_size = sizeof(output_buffer);
279 Filter::FilterStatus status = filter->ReadData(output_buffer, 284 Filter::FilterStatus status = filter->ReadData(output_buffer,
280 &output_bytes_or_buffer_size); 285 &output_bytes_or_buffer_size);
281 286
282 EXPECT_EQ(0, output_bytes_or_buffer_size); 287 EXPECT_EQ(0, output_bytes_or_buffer_size);
283 EXPECT_EQ(Filter::FILTER_ERROR, status); 288 EXPECT_EQ(Filter::FILTER_ERROR, status);
284 } 289 }
285 290
286 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) { 291 TEST_F(SdchFilterTest, ErrorOnBadReturnCodeWithHtml) {
287 std::vector<Filter::FilterType> filter_types; 292 std::vector<Filter::FilterType> filter_types;
288 // Selective a tentative filter (which can fall back to pass through). 293 // Selective a tentative filter (which can fall back to pass through).
289 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE); 294 filter_types.push_back(Filter::FILTER_TYPE_SDCH_POSSIBLE);
290 char output_buffer[20]; 295 char output_buffer[20];
291 MockFilterContext filter_context;
292 // Response code needs to be 200 to allow a pass through. 296 // Response code needs to be 200 to allow a pass through.
293 filter_context.SetResponseCode(403); 297 filter_context()->SetResponseCode(403);
294 // Meta refresh will only appear for html content 298 // Meta refresh will only appear for html content
295 filter_context.SetMimeType("text/html"); 299 filter_context()->SetMimeType("text/html");
296 std::string url_string("http://ignore.com"); 300 std::string url_string("http://ignore.com");
297 filter_context.SetURL(GURL(url_string)); 301 filter_context()->SetURL(GURL(url_string));
298 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 302 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
299 303
300 // Supply enough data to force a pass-through mode, which means we have 304 // Supply enough data to force a pass-through mode, which means we have
301 // provided more than 9 characters that can't be a dictionary hash. 305 // provided more than 9 characters that can't be a dictionary hash.
302 std::string non_sdch_content("This is not SDCH"); 306 std::string non_sdch_content("This is not SDCH");
303 307
304 char* input_buffer = filter->stream_buffer()->data(); 308 char* input_buffer = filter->stream_buffer()->data();
305 int input_buffer_size = filter->stream_buffer_size(); 309 int input_buffer_size = filter->stream_buffer_size();
306 310
307 EXPECT_LT(static_cast<int>(non_sdch_content.size()), 311 EXPECT_LT(static_cast<int>(non_sdch_content.size()),
308 input_buffer_size); 312 input_buffer_size);
(...skipping 13 matching lines...) Expand all
322 EXPECT_EQ(0, strncmp(output_buffer, 326 EXPECT_EQ(0, strncmp(output_buffer,
323 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>", 327 "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\"></head>",
324 sizeof(output_buffer))); 328 sizeof(output_buffer)));
325 EXPECT_EQ(Filter::FILTER_OK, status); 329 EXPECT_EQ(Filter::FILTER_OK, status);
326 } 330 }
327 331
328 TEST_F(SdchFilterTest, BasicBadDictionary) { 332 TEST_F(SdchFilterTest, BasicBadDictionary) {
329 std::vector<Filter::FilterType> filter_types; 333 std::vector<Filter::FilterType> filter_types;
330 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 334 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
331 char output_buffer[20]; 335 char output_buffer[20];
332 MockFilterContext filter_context;
333 std::string url_string("http://ignore.com"); 336 std::string url_string("http://ignore.com");
334 filter_context.SetURL(GURL(url_string)); 337 filter_context()->SetURL(GURL(url_string));
335 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 338 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
336 339
337 // Supply bogus data (which doesn't yet specify a full dictionary hash). 340 // Supply bogus data (which doesn't yet specify a full dictionary hash).
338 // Dictionary hash is 8 characters followed by a null. 341 // Dictionary hash is 8 characters followed by a null.
339 std::string dictionary_hash_prefix("123"); 342 std::string dictionary_hash_prefix("123");
340 343
341 char* input_buffer = filter->stream_buffer()->data(); 344 char* input_buffer = filter->stream_buffer()->data();
342 int input_buffer_size = filter->stream_buffer_size(); 345 int input_buffer_size = filter->stream_buffer_size();
343 346
344 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), 347 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()),
345 input_buffer_size); 348 input_buffer_size);
(...skipping 19 matching lines...) Expand all
365 dictionary_hash_postfix.size()); 368 dictionary_hash_postfix.size());
366 filter->FlushStreamBuffer(dictionary_hash_postfix.size()); 369 filter->FlushStreamBuffer(dictionary_hash_postfix.size());
367 370
368 // With a non-existant dictionary specifier, try to read output. 371 // With a non-existant dictionary specifier, try to read output.
369 output_bytes_or_buffer_size = sizeof(output_buffer); 372 output_bytes_or_buffer_size = sizeof(output_buffer);
370 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size); 373 status = filter->ReadData(output_buffer, &output_bytes_or_buffer_size);
371 374
372 EXPECT_EQ(0, output_bytes_or_buffer_size); 375 EXPECT_EQ(0, output_bytes_or_buffer_size);
373 EXPECT_EQ(Filter::FILTER_ERROR, status); 376 EXPECT_EQ(Filter::FILTER_ERROR, status);
374 377
375 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 378 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
376 SdchManager::ClearBlacklistings(); 379 sdch_manager_->ClearBlacklistings();
377 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 380 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
378 } 381 }
379 382
380 TEST_F(SdchFilterTest, DictionaryAddOnce) { 383 TEST_F(SdchFilterTest, DictionaryAddOnce) {
381 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 384 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
382 const std::string kSampleDomain = "sdchtest.com"; 385 const std::string kSampleDomain = "sdchtest.com";
383 std::string dictionary(NewSdchDictionary(kSampleDomain)); 386 std::string dictionary(NewSdchDictionary(kSampleDomain));
384 387
385 std::string url_string = "http://" + kSampleDomain; 388 std::string url_string = "http://" + kSampleDomain;
386 GURL url(url_string); 389 GURL url(url_string);
387 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 390 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
(...skipping 19 matching lines...) Expand all
407 std::string url_string = "http://" + kSampleDomain; 410 std::string url_string = "http://" + kSampleDomain;
408 411
409 GURL url(url_string); 412 GURL url(url_string);
410 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 413 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
411 414
412 std::string compressed(NewSdchCompressedData(dictionary)); 415 std::string compressed(NewSdchCompressedData(dictionary));
413 416
414 std::vector<Filter::FilterType> filter_types; 417 std::vector<Filter::FilterType> filter_types;
415 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 418 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
416 419
417 MockFilterContext filter_context; 420 filter_context()->SetURL(url);
418 filter_context.SetURL(url);
419 421
420 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 422 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
421 423
422 size_t feed_block_size = 100; 424 size_t feed_block_size = 100;
423 size_t output_block_size = 100; 425 size_t output_block_size = 100;
424 std::string output; 426 std::string output;
425 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 427 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
426 filter.get(), &output)); 428 filter.get(), &output));
427 EXPECT_EQ(output, expanded_); 429 EXPECT_EQ(output, expanded_);
428 430
429 // Decode with really small buffers (size 1) to check for edge effects. 431 // Decode with really small buffers (size 1) to check for edge effects.
430 filter.reset(Filter::Factory(filter_types, filter_context)); 432 filter.reset(Filter::Factory(filter_types, *filter_context()));
431 433
432 feed_block_size = 1; 434 feed_block_size = 1;
433 output_block_size = 1; 435 output_block_size = 1;
434 output.clear(); 436 output.clear();
435 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 437 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
436 filter.get(), &output)); 438 filter.get(), &output));
437 EXPECT_EQ(output, expanded_); 439 EXPECT_EQ(output, expanded_);
438 } 440 }
439 441
440 TEST_F(SdchFilterTest, NoDecodeHttps) { 442 TEST_F(SdchFilterTest, NoDecodeHttps) {
441 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 443 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
442 const std::string kSampleDomain = "sdchtest.com"; 444 const std::string kSampleDomain = "sdchtest.com";
443 std::string dictionary(NewSdchDictionary(kSampleDomain)); 445 std::string dictionary(NewSdchDictionary(kSampleDomain));
444 446
445 std::string url_string = "http://" + kSampleDomain; 447 std::string url_string = "http://" + kSampleDomain;
446 448
447 GURL url(url_string); 449 GURL url(url_string);
448 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 450 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
449 451
450 std::string compressed(NewSdchCompressedData(dictionary)); 452 std::string compressed(NewSdchCompressedData(dictionary));
451 453
452 std::vector<Filter::FilterType> filter_types; 454 std::vector<Filter::FilterType> filter_types;
453 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 455 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
454 456
455 MockFilterContext filter_context; 457 filter_context()->SetURL(GURL("https://" + kSampleDomain));
456 filter_context.SetURL(GURL("https://" + kSampleDomain)); 458 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
457 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
458 459
459 const size_t feed_block_size(100); 460 const size_t feed_block_size(100);
460 const size_t output_block_size(100); 461 const size_t output_block_size(100);
461 std::string output; 462 std::string output;
462 463
463 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 464 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
464 filter.get(), &output)); 465 filter.get(), &output));
465 } 466 }
466 467
467 // Current failsafe TODO/hack refuses to decode any content that doesn't use 468 // Current failsafe TODO/hack refuses to decode any content that doesn't use
468 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP). 469 // http as the scheme (see use of DICTIONARY_SELECTED_FOR_NON_HTTP).
469 // The following tests this blockage. Note that blacklisting results, so we 470 // The following tests this blockage. Note that blacklisting results, so we
470 // we need separate tests for each of these. 471 // we need separate tests for each of these.
471 TEST_F(SdchFilterTest, NoDecodeFtp) { 472 TEST_F(SdchFilterTest, NoDecodeFtp) {
472 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 473 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
473 const std::string kSampleDomain = "sdchtest.com"; 474 const std::string kSampleDomain = "sdchtest.com";
474 std::string dictionary(NewSdchDictionary(kSampleDomain)); 475 std::string dictionary(NewSdchDictionary(kSampleDomain));
475 476
476 std::string url_string = "http://" + kSampleDomain; 477 std::string url_string = "http://" + kSampleDomain;
477 478
478 GURL url(url_string); 479 GURL url(url_string);
479 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 480 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
480 481
481 std::string compressed(NewSdchCompressedData(dictionary)); 482 std::string compressed(NewSdchCompressedData(dictionary));
482 483
483 std::vector<Filter::FilterType> filter_types; 484 std::vector<Filter::FilterType> filter_types;
484 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 485 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
485 486
486 MockFilterContext filter_context; 487 filter_context()->SetURL(GURL("ftp://" + kSampleDomain));
487 filter_context.SetURL(GURL("ftp://" + kSampleDomain)); 488 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
488 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
489 489
490 const size_t feed_block_size(100); 490 const size_t feed_block_size(100);
491 const size_t output_block_size(100); 491 const size_t output_block_size(100);
492 std::string output; 492 std::string output;
493 493
494 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 494 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
495 filter.get(), &output)); 495 filter.get(), &output));
496 } 496 }
497 497
498 TEST_F(SdchFilterTest, NoDecodeFileColon) { 498 TEST_F(SdchFilterTest, NoDecodeFileColon) {
499 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 499 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
500 const std::string kSampleDomain = "sdchtest.com"; 500 const std::string kSampleDomain = "sdchtest.com";
501 std::string dictionary(NewSdchDictionary(kSampleDomain)); 501 std::string dictionary(NewSdchDictionary(kSampleDomain));
502 502
503 std::string url_string = "http://" + kSampleDomain; 503 std::string url_string = "http://" + kSampleDomain;
504 504
505 GURL url(url_string); 505 GURL url(url_string);
506 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 506 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
507 507
508 std::string compressed(NewSdchCompressedData(dictionary)); 508 std::string compressed(NewSdchCompressedData(dictionary));
509 509
510 std::vector<Filter::FilterType> filter_types; 510 std::vector<Filter::FilterType> filter_types;
511 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 511 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
512 512
513 MockFilterContext filter_context; 513 filter_context()->SetURL(GURL("file://" + kSampleDomain));
514 filter_context.SetURL(GURL("file://" + kSampleDomain)); 514 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
515 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
516 515
517 const size_t feed_block_size(100); 516 const size_t feed_block_size(100);
518 const size_t output_block_size(100); 517 const size_t output_block_size(100);
519 std::string output; 518 std::string output;
520 519
521 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 520 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
522 filter.get(), &output)); 521 filter.get(), &output));
523 } 522 }
524 523
525 TEST_F(SdchFilterTest, NoDecodeAboutColon) { 524 TEST_F(SdchFilterTest, NoDecodeAboutColon) {
526 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 525 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
527 const std::string kSampleDomain = "sdchtest.com"; 526 const std::string kSampleDomain = "sdchtest.com";
528 std::string dictionary(NewSdchDictionary(kSampleDomain)); 527 std::string dictionary(NewSdchDictionary(kSampleDomain));
529 528
530 std::string url_string = "http://" + kSampleDomain; 529 std::string url_string = "http://" + kSampleDomain;
531 530
532 GURL url(url_string); 531 GURL url(url_string);
533 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 532 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
534 533
535 std::string compressed(NewSdchCompressedData(dictionary)); 534 std::string compressed(NewSdchCompressedData(dictionary));
536 535
537 std::vector<Filter::FilterType> filter_types; 536 std::vector<Filter::FilterType> filter_types;
538 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 537 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
539 538
540 MockFilterContext filter_context; 539 filter_context()->SetURL(GURL("about://" + kSampleDomain));
541 filter_context.SetURL(GURL("about://" + kSampleDomain)); 540 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
542 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
543 541
544 const size_t feed_block_size(100); 542 const size_t feed_block_size(100);
545 const size_t output_block_size(100); 543 const size_t output_block_size(100);
546 std::string output; 544 std::string output;
547 545
548 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 546 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
549 filter.get(), &output)); 547 filter.get(), &output));
550 } 548 }
551 549
552 TEST_F(SdchFilterTest, NoDecodeJavaScript) { 550 TEST_F(SdchFilterTest, NoDecodeJavaScript) {
553 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 551 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
554 const std::string kSampleDomain = "sdchtest.com"; 552 const std::string kSampleDomain = "sdchtest.com";
555 std::string dictionary(NewSdchDictionary(kSampleDomain)); 553 std::string dictionary(NewSdchDictionary(kSampleDomain));
556 554
557 std::string url_string = "http://" + kSampleDomain; 555 std::string url_string = "http://" + kSampleDomain;
558 556
559 GURL url(url_string); 557 GURL url(url_string);
560 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 558 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
561 559
562 std::string compressed(NewSdchCompressedData(dictionary)); 560 std::string compressed(NewSdchCompressedData(dictionary));
563 561
564 std::vector<Filter::FilterType> filter_types; 562 std::vector<Filter::FilterType> filter_types;
565 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 563 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
566 564
567 MockFilterContext filter_context; 565 filter_context()->SetURL(GURL("javascript://" + kSampleDomain));
568 filter_context.SetURL(GURL("javascript://" + kSampleDomain)); 566 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
569 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
570 567
571 const size_t feed_block_size(100); 568 const size_t feed_block_size(100);
572 const size_t output_block_size(100); 569 const size_t output_block_size(100);
573 std::string output; 570 std::string output;
574 571
575 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 572 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
576 filter.get(), &output)); 573 filter.get(), &output));
577 } 574 }
578 575
579 TEST_F(SdchFilterTest, CanStillDecodeHttp) { 576 TEST_F(SdchFilterTest, CanStillDecodeHttp) {
580 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 577 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
581 const std::string kSampleDomain = "sdchtest.com"; 578 const std::string kSampleDomain = "sdchtest.com";
582 std::string dictionary(NewSdchDictionary(kSampleDomain)); 579 std::string dictionary(NewSdchDictionary(kSampleDomain));
583 580
584 std::string url_string = "http://" + kSampleDomain; 581 std::string url_string = "http://" + kSampleDomain;
585 582
586 GURL url(url_string); 583 GURL url(url_string);
587 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 584 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
588 585
589 std::string compressed(NewSdchCompressedData(dictionary)); 586 std::string compressed(NewSdchCompressedData(dictionary));
590 587
591 std::vector<Filter::FilterType> filter_types; 588 std::vector<Filter::FilterType> filter_types;
592 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 589 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
593 590
594 MockFilterContext filter_context; 591 filter_context()->SetURL(GURL("http://" + kSampleDomain));
595 filter_context.SetURL(GURL("http://" + kSampleDomain)); 592 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
596 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
597 593
598 const size_t feed_block_size(100); 594 const size_t feed_block_size(100);
599 const size_t output_block_size(100); 595 const size_t output_block_size(100);
600 std::string output; 596 std::string output;
601 597
602 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size, 598 EXPECT_TRUE(FilterTestData(compressed, feed_block_size, output_block_size,
603 filter.get(), &output)); 599 filter.get(), &output));
604 } 600 }
605 601
606 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) { 602 TEST_F(SdchFilterTest, CrossDomainDictionaryUse) {
607 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 603 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
608 const std::string kSampleDomain = "sdchtest.com"; 604 const std::string kSampleDomain = "sdchtest.com";
609 std::string dictionary(NewSdchDictionary(kSampleDomain)); 605 std::string dictionary(NewSdchDictionary(kSampleDomain));
610 606
611 std::string url_string = "http://" + kSampleDomain; 607 std::string url_string = "http://" + kSampleDomain;
612 608
613 GURL url(url_string); 609 GURL url(url_string);
614 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 610 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
615 611
616 std::string compressed(NewSdchCompressedData(dictionary)); 612 std::string compressed(NewSdchCompressedData(dictionary));
617 613
618 std::vector<Filter::FilterType> filter_types; 614 std::vector<Filter::FilterType> filter_types;
619 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 615 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
620 616
621 // Decode with content arriving from the "wrong" domain. 617 // Decode with content arriving from the "wrong" domain.
622 // This tests SdchManager::CanSet(). 618 // This tests SdchManager::CanSet().
623 MockFilterContext filter_context;
624 GURL wrong_domain_url("http://www.wrongdomain.com"); 619 GURL wrong_domain_url("http://www.wrongdomain.com");
625 filter_context.SetURL(wrong_domain_url); 620 filter_context()->SetURL(wrong_domain_url);
626 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 621 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
627 622
628 size_t feed_block_size = 100; 623 size_t feed_block_size = 100;
629 size_t output_block_size = 100; 624 size_t output_block_size = 100;
630 std::string output; 625 std::string output;
631 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size, 626 EXPECT_FALSE(FilterTestData(compressed, feed_block_size, output_block_size,
632 filter.get(), &output)); 627 filter.get(), &output));
633 EXPECT_EQ(output.size(), 0u); // No output written. 628 EXPECT_EQ(output.size(), 0u); // No output written.
634 629
635 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 630 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
636 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); 631 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(wrong_domain_url));
637 SdchManager::ClearBlacklistings(); 632 sdch_manager_->ClearBlacklistings();
638 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(wrong_domain_url)); 633 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(wrong_domain_url));
639 } 634 }
640 635
641 TEST_F(SdchFilterTest, DictionaryPathValidation) { 636 TEST_F(SdchFilterTest, DictionaryPathValidation) {
642 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 637 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
643 const std::string kSampleDomain = "sdchtest.com"; 638 const std::string kSampleDomain = "sdchtest.com";
644 std::string dictionary(NewSdchDictionary(kSampleDomain)); 639 std::string dictionary(NewSdchDictionary(kSampleDomain));
645 640
646 std::string url_string = "http://" + kSampleDomain; 641 std::string url_string = "http://" + kSampleDomain;
647 642
648 GURL url(url_string); 643 GURL url(url_string);
649 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 644 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
650 645
651 // Create a dictionary with a path restriction, by prefixing dictionary. 646 // Create a dictionary with a path restriction, by prefixing dictionary.
652 const std::string path("/special_path/bin"); 647 const std::string path("/special_path/bin");
653 std::string dictionary_with_path("Path: " + path + "\n"); 648 std::string dictionary_with_path("Path: " + path + "\n");
654 dictionary_with_path.append(dictionary); 649 dictionary_with_path.append(dictionary);
655 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url)); 650 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url));
656 651
657 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path)); 652 std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path));
658 653
659 std::vector<Filter::FilterType> filter_types; 654 std::vector<Filter::FilterType> filter_types;
660 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 655 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
661 656
662 // Test decode the path data, arriving from a valid path. 657 // Test decode the path data, arriving from a valid path.
663 MockFilterContext filter_context; 658 filter_context()->SetURL(GURL(url_string + path));
664 filter_context.SetURL(GURL(url_string + path)); 659 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
665 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
666 660
667 size_t feed_block_size = 100; 661 size_t feed_block_size = 100;
668 size_t output_block_size = 100; 662 size_t output_block_size = 100;
669 std::string output; 663 std::string output;
670 664
671 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size, 665 EXPECT_TRUE(FilterTestData(compressed_for_path, feed_block_size,
672 output_block_size, filter.get(), &output)); 666 output_block_size, filter.get(), &output));
673 EXPECT_EQ(output, expanded_); 667 EXPECT_EQ(output, expanded_);
674 668
675 // Test decode the path data, arriving from a invalid path. 669 // Test decode the path data, arriving from a invalid path.
676 filter_context.SetURL(GURL(url_string)); 670 filter_context()->SetURL(GURL(url_string));
677 filter.reset(Filter::Factory(filter_types, filter_context)); 671 filter.reset(Filter::Factory(filter_types, *filter_context()));
678 672
679 feed_block_size = 100; 673 feed_block_size = 100;
680 output_block_size = 100; 674 output_block_size = 100;
681 output.clear(); 675 output.clear();
682 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size, 676 EXPECT_FALSE(FilterTestData(compressed_for_path, feed_block_size,
683 output_block_size, filter.get(), &output)); 677 output_block_size, filter.get(), &output));
684 EXPECT_EQ(output.size(), 0u); // No output written. 678 EXPECT_EQ(output.size(), 0u); // No output written.
685 679
686 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 680 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
687 SdchManager::ClearBlacklistings(); 681 sdch_manager_->ClearBlacklistings();
688 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 682 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
689 } 683 }
690 684
691 TEST_F(SdchFilterTest, DictionaryPortValidation) { 685 TEST_F(SdchFilterTest, DictionaryPortValidation) {
692 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 686 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
693 const std::string kSampleDomain = "sdchtest.com"; 687 const std::string kSampleDomain = "sdchtest.com";
694 std::string dictionary(NewSdchDictionary(kSampleDomain)); 688 std::string dictionary(NewSdchDictionary(kSampleDomain));
695 689
696 std::string url_string = "http://" + kSampleDomain; 690 std::string url_string = "http://" + kSampleDomain;
697 691
698 GURL url(url_string); 692 GURL url(url_string);
699 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 693 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
700 694
701 695
702 // Create a dictionary with a port restriction, by prefixing old dictionary. 696 // Create a dictionary with a port restriction, by prefixing old dictionary.
703 const std::string port("502"); 697 const std::string port("502");
704 std::string dictionary_with_port("Port: " + port + "\n"); 698 std::string dictionary_with_port("Port: " + port + "\n");
705 dictionary_with_port.append("Port: 80\n"); // Add default port. 699 dictionary_with_port.append("Port: 80\n"); // Add default port.
706 dictionary_with_port.append(dictionary); 700 dictionary_with_port.append(dictionary);
707 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port, 701 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port,
708 GURL(url_string + ":" + port))); 702 GURL(url_string + ":" + port)));
709 703
710 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port)); 704 std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
711 705
712 std::vector<Filter::FilterType> filter_types; 706 std::vector<Filter::FilterType> filter_types;
713 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 707 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
714 708
715 // Test decode the port data, arriving from a valid port. 709 // Test decode the port data, arriving from a valid port.
716 MockFilterContext filter_context; 710 filter_context()->SetURL(GURL(url_string + ":" + port));
717 filter_context.SetURL(GURL(url_string + ":" + port)); 711 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
718 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
719 712
720 size_t feed_block_size = 100; 713 size_t feed_block_size = 100;
721 size_t output_block_size = 100; 714 size_t output_block_size = 100;
722 std::string output; 715 std::string output;
723 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 716 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
724 output_block_size, filter.get(), &output)); 717 output_block_size, filter.get(), &output));
725 EXPECT_EQ(output, expanded_); 718 EXPECT_EQ(output, expanded_);
726 719
727 // Test decode the port data, arriving from a valid (default) port. 720 // Test decode the port data, arriving from a valid (default) port.
728 filter_context.SetURL(GURL(url_string)); // Default port. 721 filter_context()->SetURL(GURL(url_string)); // Default port.
729 filter.reset(Filter::Factory(filter_types, filter_context)); 722 filter.reset(Filter::Factory(filter_types, *filter_context()));
730 723
731 feed_block_size = 100; 724 feed_block_size = 100;
732 output_block_size = 100; 725 output_block_size = 100;
733 output.clear(); 726 output.clear();
734 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size, 727 EXPECT_TRUE(FilterTestData(compressed_for_port, feed_block_size,
735 output_block_size, filter.get(), &output)); 728 output_block_size, filter.get(), &output));
736 EXPECT_EQ(output, expanded_); 729 EXPECT_EQ(output, expanded_);
737 730
738 // Test decode the port data, arriving from a invalid port. 731 // Test decode the port data, arriving from a invalid port.
739 filter_context.SetURL(GURL(url_string + ":" + port + "1")); 732 filter_context()->SetURL(GURL(url_string + ":" + port + "1"));
740 filter.reset(Filter::Factory(filter_types, filter_context)); 733 filter.reset(Filter::Factory(filter_types, *filter_context()));
741 734
742 feed_block_size = 100; 735 feed_block_size = 100;
743 output_block_size = 100; 736 output_block_size = 100;
744 output.clear(); 737 output.clear();
745 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size, 738 EXPECT_FALSE(FilterTestData(compressed_for_port, feed_block_size,
746 output_block_size, filter.get(), &output)); 739 output_block_size, filter.get(), &output));
747 EXPECT_EQ(output.size(), 0u); // No output written. 740 EXPECT_EQ(output.size(), 0u); // No output written.
748 741
749 EXPECT_FALSE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 742 EXPECT_FALSE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
750 SdchManager::ClearBlacklistings(); 743 sdch_manager_->ClearBlacklistings();
751 EXPECT_TRUE(SdchManager::Global()->IsInSupportedDomain(GURL(url_string))); 744 EXPECT_TRUE(sdch_manager_->IsInSupportedDomain(GURL(url_string)));
752 } 745 }
753 746
754 //------------------------------------------------------------------------------ 747 //------------------------------------------------------------------------------
755 // Helper function to perform gzip compression of data. 748 // Helper function to perform gzip compression of data.
756 749
757 static std::string gzip_compress(const std::string &input) { 750 static std::string gzip_compress(const std::string &input) {
758 z_stream zlib_stream; 751 z_stream zlib_stream;
759 memset(&zlib_stream, 0, sizeof(zlib_stream)); 752 memset(&zlib_stream, 0, sizeof(zlib_stream));
760 int code; 753 int code;
761 754
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // Construct a chained filter. 830 // Construct a chained filter.
838 std::vector<Filter::FilterType> filter_types; 831 std::vector<Filter::FilterType> filter_types;
839 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 832 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
840 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 833 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
841 834
842 // First try with a large buffer (larger than test input, or compressed data). 835 // First try with a large buffer (larger than test input, or compressed data).
843 const size_t kLargeInputBufferSize(1000); // Used internally in filters. 836 const size_t kLargeInputBufferSize(1000); // Used internally in filters.
844 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); 837 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size());
845 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); 838 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size());
846 CHECK_GT(kLargeInputBufferSize, expanded_.size()); 839 CHECK_GT(kLargeInputBufferSize, expanded_.size());
847 MockFilterContext filter_context; 840 filter_context()->SetURL(url);
848 filter_context.SetURL(url);
849 scoped_ptr<Filter> filter( 841 scoped_ptr<Filter> filter(
850 SdchFilterChainingTest::Factory(filter_types, filter_context, 842 SdchFilterChainingTest::Factory(filter_types, *filter_context(),
851 kLargeInputBufferSize)); 843 kLargeInputBufferSize));
852 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), 844 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize),
853 filter->stream_buffer_size()); 845 filter->stream_buffer_size());
854 846
855 // Verify that chained filter is waiting for data. 847 // Verify that chained filter is waiting for data.
856 char tiny_output_buffer[10]; 848 char tiny_output_buffer[10];
857 int tiny_output_size = sizeof(tiny_output_buffer); 849 int tiny_output_size = sizeof(tiny_output_buffer);
858 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 850 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
859 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 851 filter->ReadData(tiny_output_buffer, &tiny_output_size));
860 852
861 // Make chain process all data. 853 // Make chain process all data.
862 size_t feed_block_size = kLargeInputBufferSize; 854 size_t feed_block_size = kLargeInputBufferSize;
863 size_t output_block_size = kLargeInputBufferSize; 855 size_t output_block_size = kLargeInputBufferSize;
864 std::string output; 856 std::string output;
865 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 857 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
866 output_block_size, filter.get(), &output)); 858 output_block_size, filter.get(), &output));
867 EXPECT_EQ(output, expanded_); 859 EXPECT_EQ(output, expanded_);
868 860
869 // Next try with a mid-sized internal buffer size. 861 // Next try with a mid-sized internal buffer size.
870 const size_t kMidSizedInputBufferSize(100); 862 const size_t kMidSizedInputBufferSize(100);
871 // Buffer should be big enough to swallow whole gzip content. 863 // Buffer should be big enough to swallow whole gzip content.
872 CHECK_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size()); 864 CHECK_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size());
873 // Buffer should be small enough that entire SDCH content can't fit. 865 // Buffer should be small enough that entire SDCH content can't fit.
874 // We'll go even further, and force the chain to flush the buffer between the 866 // We'll go even further, and force the chain to flush the buffer between the
875 // two filters more than once (that is why we multiply by 2). 867 // two filters more than once (that is why we multiply by 2).
876 CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size()); 868 CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size());
877 filter_context.SetURL(url); 869 filter_context()->SetURL(url);
878 filter.reset( 870 filter.reset(
879 SdchFilterChainingTest::Factory(filter_types, filter_context, 871 SdchFilterChainingTest::Factory(filter_types, *filter_context(),
880 kMidSizedInputBufferSize)); 872 kMidSizedInputBufferSize));
881 EXPECT_EQ(static_cast<int>(kMidSizedInputBufferSize), 873 EXPECT_EQ(static_cast<int>(kMidSizedInputBufferSize),
882 filter->stream_buffer_size()); 874 filter->stream_buffer_size());
883 875
884 feed_block_size = kMidSizedInputBufferSize; 876 feed_block_size = kMidSizedInputBufferSize;
885 output_block_size = kMidSizedInputBufferSize; 877 output_block_size = kMidSizedInputBufferSize;
886 output.clear(); 878 output.clear();
887 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 879 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
888 output_block_size, filter.get(), &output)); 880 output_block_size, filter.get(), &output));
889 EXPECT_EQ(output, expanded_); 881 EXPECT_EQ(output, expanded_);
890 882
891 // Next try with a tiny input and output buffer to cover edge effects. 883 // Next try with a tiny input and output buffer to cover edge effects.
892 filter.reset(SdchFilterChainingTest::Factory(filter_types, filter_context, 884 filter.reset(SdchFilterChainingTest::Factory(filter_types, *filter_context(),
893 kLargeInputBufferSize)); 885 kLargeInputBufferSize));
894 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize), 886 EXPECT_EQ(static_cast<int>(kLargeInputBufferSize),
895 filter->stream_buffer_size()); 887 filter->stream_buffer_size());
896 888
897 feed_block_size = 1; 889 feed_block_size = 1;
898 output_block_size = 1; 890 output_block_size = 1;
899 output.clear(); 891 output.clear();
900 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 892 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
901 output_block_size, filter.get(), &output)); 893 output_block_size, filter.get(), &output));
902 EXPECT_EQ(output, expanded_); 894 EXPECT_EQ(output, expanded_);
(...skipping 12 matching lines...) Expand all
915 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 907 std::string sdch_compressed(NewSdchCompressedData(dictionary));
916 908
917 // Use Gzip to compress the sdch sdch_compressed data. 909 // Use Gzip to compress the sdch sdch_compressed data.
918 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 910 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
919 911
920 // Only claim to have sdch content, but really use the gzipped sdch content. 912 // Only claim to have sdch content, but really use the gzipped sdch content.
921 // System should automatically add the missing (optional) gzip. 913 // System should automatically add the missing (optional) gzip.
922 std::vector<Filter::FilterType> filter_types; 914 std::vector<Filter::FilterType> filter_types;
923 filter_types.push_back(Filter::FILTER_TYPE_SDCH); 915 filter_types.push_back(Filter::FILTER_TYPE_SDCH);
924 916
925 MockFilterContext filter_context; 917 filter_context()->SetMimeType("anything/mime");
926 filter_context.SetMimeType("anything/mime"); 918 filter_context()->SetSdchResponse(true);
927 filter_context.SetSdchResponse(true); 919 Filter::FixupEncodingTypes(*filter_context(), &filter_types);
928 Filter::FixupEncodingTypes(filter_context, &filter_types);
929 ASSERT_EQ(filter_types.size(), 2u); 920 ASSERT_EQ(filter_types.size(), 2u);
930 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); 921 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH);
931 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 922 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
932 923
933 // First try with a large buffer (larger than test input, or compressed data). 924 // First try with a large buffer (larger than test input, or compressed data).
934 filter_context.SetURL(url); 925 filter_context()->SetURL(url);
935 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 926 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
936 927
937 928
938 // Verify that chained filter is waiting for data. 929 // Verify that chained filter is waiting for data.
939 char tiny_output_buffer[10]; 930 char tiny_output_buffer[10];
940 int tiny_output_size = sizeof(tiny_output_buffer); 931 int tiny_output_size = sizeof(tiny_output_buffer);
941 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 932 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
942 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 933 filter->ReadData(tiny_output_buffer, &tiny_output_size));
943 934
944 size_t feed_block_size = 100; 935 size_t feed_block_size = 100;
945 size_t output_block_size = 100; 936 size_t output_block_size = 100;
946 std::string output; 937 std::string output;
947 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 938 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
948 output_block_size, filter.get(), &output)); 939 output_block_size, filter.get(), &output));
949 EXPECT_EQ(output, expanded_); 940 EXPECT_EQ(output, expanded_);
950 941
951 // Next try with a tiny buffer to cover edge effects. 942 // Next try with a tiny buffer to cover edge effects.
952 filter.reset(Filter::Factory(filter_types, filter_context)); 943 filter.reset(Filter::Factory(filter_types, *filter_context()));
953 944
954 feed_block_size = 1; 945 feed_block_size = 1;
955 output_block_size = 1; 946 output_block_size = 1;
956 output.clear(); 947 output.clear();
957 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 948 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
958 output_block_size, filter.get(), &output)); 949 output_block_size, filter.get(), &output));
959 EXPECT_EQ(output, expanded_); 950 EXPECT_EQ(output, expanded_);
960 } 951 }
961 952
962 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) { 953 TEST_F(SdchFilterTest, AcceptGzipSdchIfGzip) {
(...skipping 11 matching lines...) Expand all
974 // Use Gzip to compress the sdch sdch_compressed data. 965 // Use Gzip to compress the sdch sdch_compressed data.
975 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 966 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
976 967
977 // Some proxies strip the content encoding statement down to a mere gzip, but 968 // Some proxies strip the content encoding statement down to a mere gzip, but
978 // pass through the original content (with full sdch,gzip encoding). 969 // pass through the original content (with full sdch,gzip encoding).
979 // Only claim to have gzip content, but really use the gzipped sdch content. 970 // Only claim to have gzip content, but really use the gzipped sdch content.
980 // System should automatically add the missing (optional) sdch. 971 // System should automatically add the missing (optional) sdch.
981 std::vector<Filter::FilterType> filter_types; 972 std::vector<Filter::FilterType> filter_types;
982 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 973 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
983 974
984 MockFilterContext filter_context; 975 filter_context()->SetMimeType("anything/mime");
985 filter_context.SetMimeType("anything/mime"); 976 filter_context()->SetSdchResponse(true);
986 filter_context.SetSdchResponse(true); 977 Filter::FixupEncodingTypes(*filter_context(), &filter_types);
987 Filter::FixupEncodingTypes(filter_context, &filter_types);
988 ASSERT_EQ(filter_types.size(), 3u); 978 ASSERT_EQ(filter_types.size(), 3u);
989 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 979 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
990 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 980 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
991 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); 981 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP);
992 982
993 // First try with a large buffer (larger than test input, or compressed data). 983 // First try with a large buffer (larger than test input, or compressed data).
994 filter_context.SetURL(url); 984 filter_context()->SetURL(url);
995 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 985 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
996 986
997 987
998 // Verify that chained filter is waiting for data. 988 // Verify that chained filter is waiting for data.
999 char tiny_output_buffer[10]; 989 char tiny_output_buffer[10];
1000 int tiny_output_size = sizeof(tiny_output_buffer); 990 int tiny_output_size = sizeof(tiny_output_buffer);
1001 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 991 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
1002 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 992 filter->ReadData(tiny_output_buffer, &tiny_output_size));
1003 993
1004 size_t feed_block_size = 100; 994 size_t feed_block_size = 100;
1005 size_t output_block_size = 100; 995 size_t output_block_size = 100;
1006 std::string output; 996 std::string output;
1007 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 997 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
1008 output_block_size, filter.get(), &output)); 998 output_block_size, filter.get(), &output));
1009 EXPECT_EQ(output, expanded_); 999 EXPECT_EQ(output, expanded_);
1010 1000
1011 // Next try with a tiny buffer to cover edge effects. 1001 // Next try with a tiny buffer to cover edge effects.
1012 filter.reset(Filter::Factory(filter_types, filter_context)); 1002 filter.reset(Filter::Factory(filter_types, *filter_context()));
1013 1003
1014 feed_block_size = 1; 1004 feed_block_size = 1;
1015 output_block_size = 1; 1005 output_block_size = 1;
1016 output.clear(); 1006 output.clear();
1017 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 1007 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
1018 output_block_size, filter.get(), &output)); 1008 output_block_size, filter.get(), &output));
1019 EXPECT_EQ(output, expanded_); 1009 EXPECT_EQ(output, expanded_);
1020 } 1010 }
1021 1011
1022 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) { 1012 TEST_F(SdchFilterTest, DefaultSdchGzipIfEmpty) {
1023 // Construct a valid SDCH dictionary from a VCDIFF dictionary. 1013 // Construct a valid SDCH dictionary from a VCDIFF dictionary.
1024 const std::string kSampleDomain = "sdchtest.com"; 1014 const std::string kSampleDomain = "sdchtest.com";
1025 std::string dictionary(NewSdchDictionary(kSampleDomain)); 1015 std::string dictionary(NewSdchDictionary(kSampleDomain));
1026 1016
1027 std::string url_string = "http://" + kSampleDomain; 1017 std::string url_string = "http://" + kSampleDomain;
1028 1018
1029 GURL url(url_string); 1019 GURL url(url_string);
1030 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); 1020 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
1031 1021
1032 std::string sdch_compressed(NewSdchCompressedData(dictionary)); 1022 std::string sdch_compressed(NewSdchCompressedData(dictionary));
1033 1023
1034 // Use Gzip to compress the sdch sdch_compressed data. 1024 // Use Gzip to compress the sdch sdch_compressed data.
1035 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); 1025 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed);
1036 1026
1037 // Only claim to have non-encoded content, but really use the gzipped sdch 1027 // Only claim to have non-encoded content, but really use the gzipped sdch
1038 // content. 1028 // content.
1039 // System should automatically add the missing (optional) sdch,gzip. 1029 // System should automatically add the missing (optional) sdch,gzip.
1040 std::vector<Filter::FilterType> filter_types; 1030 std::vector<Filter::FilterType> filter_types;
1041 1031
1042 MockFilterContext filter_context; 1032 filter_context()->SetMimeType("anything/mime");
1043 filter_context.SetMimeType("anything/mime"); 1033 filter_context()->SetSdchResponse(true);
1044 filter_context.SetSdchResponse(true); 1034 Filter::FixupEncodingTypes(*filter_context(), &filter_types);
1045 Filter::FixupEncodingTypes(filter_context, &filter_types);
1046 ASSERT_EQ(filter_types.size(), 2u); 1035 ASSERT_EQ(filter_types.size(), 2u);
1047 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 1036 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
1048 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 1037 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
1049 1038
1050 // First try with a large buffer (larger than test input, or compressed data). 1039 // First try with a large buffer (larger than test input, or compressed data).
1051 filter_context.SetURL(url); 1040 filter_context()->SetURL(url);
1052 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 1041 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
1053 1042
1054 1043
1055 // Verify that chained filter is waiting for data. 1044 // Verify that chained filter is waiting for data.
1056 char tiny_output_buffer[10]; 1045 char tiny_output_buffer[10];
1057 int tiny_output_size = sizeof(tiny_output_buffer); 1046 int tiny_output_size = sizeof(tiny_output_buffer);
1058 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 1047 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
1059 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 1048 filter->ReadData(tiny_output_buffer, &tiny_output_size));
1060 1049
1061 size_t feed_block_size = 100; 1050 size_t feed_block_size = 100;
1062 size_t output_block_size = 100; 1051 size_t output_block_size = 100;
1063 std::string output; 1052 std::string output;
1064 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 1053 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
1065 output_block_size, filter.get(), &output)); 1054 output_block_size, filter.get(), &output));
1066 EXPECT_EQ(output, expanded_); 1055 EXPECT_EQ(output, expanded_);
1067 1056
1068 // Next try with a tiny buffer to cover edge effects. 1057 // Next try with a tiny buffer to cover edge effects.
1069 filter.reset(Filter::Factory(filter_types, filter_context)); 1058 filter.reset(Filter::Factory(filter_types, *filter_context()));
1070 1059
1071 feed_block_size = 1; 1060 feed_block_size = 1;
1072 output_block_size = 1; 1061 output_block_size = 1;
1073 output.clear(); 1062 output.clear();
1074 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, 1063 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size,
1075 output_block_size, filter.get(), &output)); 1064 output_block_size, filter.get(), &output));
1076 EXPECT_EQ(output, expanded_); 1065 EXPECT_EQ(output, expanded_);
1077 } 1066 }
1078 1067
1079 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) { 1068 TEST_F(SdchFilterTest, AcceptGzipGzipSdchIfGzip) {
(...skipping 14 matching lines...) Expand all
1094 // Use Gzip to double compress the sdch sdch_compressed data. 1083 // Use Gzip to double compress the sdch sdch_compressed data.
1095 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( 1084 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress(
1096 sdch_compressed)); 1085 sdch_compressed));
1097 1086
1098 // Only claim to have gzip content, but really use the double gzipped sdch 1087 // Only claim to have gzip content, but really use the double gzipped sdch
1099 // content. 1088 // content.
1100 // System should automatically add the missing (optional) sdch, gzip decoders. 1089 // System should automatically add the missing (optional) sdch, gzip decoders.
1101 std::vector<Filter::FilterType> filter_types; 1090 std::vector<Filter::FilterType> filter_types;
1102 filter_types.push_back(Filter::FILTER_TYPE_GZIP); 1091 filter_types.push_back(Filter::FILTER_TYPE_GZIP);
1103 1092
1104 MockFilterContext filter_context; 1093 filter_context()->SetMimeType("anything/mime");
1105 filter_context.SetMimeType("anything/mime"); 1094 filter_context()->SetSdchResponse(true);
1106 filter_context.SetSdchResponse(true); 1095 Filter::FixupEncodingTypes(*filter_context(), &filter_types);
1107 Filter::FixupEncodingTypes(filter_context, &filter_types);
1108 ASSERT_EQ(filter_types.size(), 3u); 1096 ASSERT_EQ(filter_types.size(), 3u);
1109 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); 1097 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE);
1110 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); 1098 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH);
1111 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); 1099 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP);
1112 1100
1113 // First try with a large buffer (larger than test input, or compressed data). 1101 // First try with a large buffer (larger than test input, or compressed data).
1114 filter_context.SetURL(url); 1102 filter_context()->SetURL(url);
1115 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); 1103 scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
1116 1104
1117 // Verify that chained filter is waiting for data. 1105 // Verify that chained filter is waiting for data.
1118 char tiny_output_buffer[10]; 1106 char tiny_output_buffer[10];
1119 int tiny_output_size = sizeof(tiny_output_buffer); 1107 int tiny_output_size = sizeof(tiny_output_buffer);
1120 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, 1108 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA,
1121 filter->ReadData(tiny_output_buffer, &tiny_output_size)); 1109 filter->ReadData(tiny_output_buffer, &tiny_output_size));
1122 1110
1123 size_t feed_block_size = 100; 1111 size_t feed_block_size = 100;
1124 size_t output_block_size = 100; 1112 size_t output_block_size = 100;
1125 std::string output; 1113 std::string output;
1126 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1114 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1127 output_block_size, filter.get(), &output)); 1115 output_block_size, filter.get(), &output));
1128 EXPECT_EQ(output, expanded_); 1116 EXPECT_EQ(output, expanded_);
1129 1117
1130 // Next try with a tiny buffer to cover edge effects. 1118 // Next try with a tiny buffer to cover edge effects.
1131 filter.reset(Filter::Factory(filter_types, filter_context)); 1119 filter.reset(Filter::Factory(filter_types, *filter_context()));
1132 1120
1133 feed_block_size = 1; 1121 feed_block_size = 1;
1134 output_block_size = 1; 1122 output_block_size = 1;
1135 output.clear(); 1123 output.clear();
1136 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size, 1124 EXPECT_TRUE(FilterTestData(double_gzip_compressed_sdch, feed_block_size,
1137 output_block_size, filter.get(), &output)); 1125 output_block_size, filter.get(), &output));
1138 EXPECT_EQ(output, expanded_); 1126 EXPECT_EQ(output, expanded_);
1139 } 1127 }
1140 1128
1141 } // namespace net 1129 } // namespace net
OLDNEW
« no previous file with comments | « net/filter/sdch_filter.cc ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698