Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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); | |
| 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 Loading... | |
| 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_); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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_); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 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 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 void ResetInputBuffer(Filter* filter, int size) { | |
| 820 filter->ResetInputBufferForTest(size); | |
| 821 } | |
| 822 }; | |
| 823 | |
| 839 // Test that filters can be cascaded (chained) so that the output of one filter | 824 // 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 | 825 // 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 | 826 // 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. | 827 // do the gzip decoding first, and then decode the SDCH content. |
| 843 TEST_F(SdchFilterTest, FilterChaining) { | 828 TEST_F(SdchFilterTest, FilterChaining) { |
| 844 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 829 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 845 const std::string kSampleDomain = "sdchtest.com"; | 830 const std::string kSampleDomain = "sdchtest.com"; |
| 846 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 831 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 847 | 832 |
| 848 std::string url_string = "http://" + kSampleDomain; | 833 std::string url_string = "http://" + kSampleDomain; |
| 849 | 834 |
| 850 GURL url(url_string); | 835 GURL url(url_string); |
| 851 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 836 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 852 | 837 |
| 853 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 838 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
| 854 | 839 |
| 855 // Use Gzip to compress the sdch sdch_compressed data. | 840 // Use Gzip to compress the sdch sdch_compressed data. |
| 856 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 841 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 857 | 842 |
| 858 // Construct a chained filter. | 843 // Construct a chained filter. |
| 859 std::vector<Filter::FilterType> filter_types; | 844 std::vector<Filter::FilterType> filter_types; |
| 860 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 845 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 861 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 846 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 862 | 847 |
| 863 // First try with a large buffer (larger than test input, or compressed data). | 848 MockFilterContext filter_context; |
| 864 const size_t kLargeInputBufferSize(1000); // Used internally in filters. | |
| 865 CHECK_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); | |
| 866 CHECK_GT(kLargeInputBufferSize, sdch_compressed.size()); | |
| 867 CHECK_GT(kLargeInputBufferSize, expanded_.size()); | |
| 868 MockFilterContext filter_context(kLargeInputBufferSize); | |
| 869 filter_context.SetURL(url); | 849 filter_context.SetURL(url); |
| 870 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 850 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| 871 | 851 |
| 852 const size_t kLargeInputBufferSize(1000); | |
| 853 ASSERT_LE(static_cast<int>(kLargeInputBufferSize), | |
| 854 filter->stream_buffer_size()); | |
| 855 ASSERT_GT(kLargeInputBufferSize, gzip_compressed_sdch.size()); | |
| 856 ASSERT_GT(kLargeInputBufferSize, sdch_compressed.size()); | |
| 857 ASSERT_GT(kLargeInputBufferSize, expanded_.size()); | |
|
jar (doing other things)
2011/02/26 01:36:52
It is OK to use asserts, but it was not clear why
| |
| 858 | |
| 872 // Verify that chained filter is waiting for data. | 859 // Verify that chained filter is waiting for data. |
| 873 char tiny_output_buffer[10]; | 860 char tiny_output_buffer[10]; |
| 874 int tiny_output_size = sizeof(tiny_output_buffer); | 861 int tiny_output_size = sizeof(tiny_output_buffer); |
| 875 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, | 862 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, |
| 876 filter->ReadData(tiny_output_buffer, &tiny_output_size)); | 863 filter->ReadData(tiny_output_buffer, &tiny_output_size)); |
| 877 | 864 |
| 878 // Make chain process all data. | 865 // Make chain process all data. |
| 879 size_t feed_block_size = kLargeInputBufferSize; | 866 size_t feed_block_size = kLargeInputBufferSize; |
| 880 size_t output_block_size = kLargeInputBufferSize; | 867 size_t output_block_size = kLargeInputBufferSize; |
| 881 std::string output; | 868 std::string output; |
| 882 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, | 869 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, |
| 883 output_block_size, filter.get(), &output)); | 870 output_block_size, filter.get(), &output)); |
| 884 EXPECT_EQ(output, expanded_); | 871 EXPECT_EQ(output, expanded_); |
| 885 | 872 |
| 886 // Next try with a mid-sized internal buffer size. | 873 // Next try with a mid-sized internal buffer size. |
| 887 const size_t kMidSizedInputBufferSize(100); | 874 const size_t kMidSizedInputBufferSize(100); |
| 888 // Buffer should be big enough to swallow whole gzip content. | 875 // Buffer should be big enough to swallow whole gzip content. |
| 889 CHECK_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size()); | 876 ASSERT_GT(kMidSizedInputBufferSize, gzip_compressed_sdch.size()); |
| 890 // Buffer should be small enough that entire SDCH content can't fit. | 877 // 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 | 878 // 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). | 879 // two filters more than once (that is why we multiply by 2). |
| 893 CHECK_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size()); | 880 ASSERT_LT(kMidSizedInputBufferSize * 2, sdch_compressed.size()); |
| 894 filter_context.SetBufferSize(kMidSizedInputBufferSize); | |
| 895 filter_context.SetURL(url); | 881 filter_context.SetURL(url); |
| 896 filter.reset(Filter::Factory(filter_types, filter_context)); | 882 filter.reset(Filter::Factory(filter_types, filter_context)); |
| 883 SdchFilterChainingTest::ResetInputBuffer(filter.get(), | |
| 884 kMidSizedInputBufferSize); | |
| 897 | 885 |
| 898 feed_block_size = kMidSizedInputBufferSize; | 886 feed_block_size = kMidSizedInputBufferSize; |
| 899 output_block_size = kMidSizedInputBufferSize; | 887 output_block_size = kMidSizedInputBufferSize; |
| 900 output.clear(); | 888 output.clear(); |
| 901 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, | 889 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, |
| 902 output_block_size, filter.get(), &output)); | 890 output_block_size, filter.get(), &output)); |
| 903 EXPECT_EQ(output, expanded_); | 891 EXPECT_EQ(output, expanded_); |
| 904 | 892 |
| 905 // Next try with a tiny input and output buffer to cover edge effects. | 893 // Next try with a tiny input and output buffer to cover edge effects. |
| 906 filter_context.SetBufferSize(kLargeInputBufferSize); | |
| 907 filter.reset(Filter::Factory(filter_types, filter_context)); | 894 filter.reset(Filter::Factory(filter_types, filter_context)); |
| 895 SdchFilterChainingTest::ResetInputBuffer(filter.get(), kLargeInputBufferSize); | |
|
jar (doing other things)
2011/02/26 01:36:52
You could probably put this into the teardown of y
| |
| 908 | 896 |
| 909 feed_block_size = 1; | 897 feed_block_size = 1; |
| 910 output_block_size = 1; | 898 output_block_size = 1; |
| 911 output.clear(); | 899 output.clear(); |
| 912 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, | 900 EXPECT_TRUE(FilterTestData(gzip_compressed_sdch, feed_block_size, |
| 913 output_block_size, filter.get(), &output)); | 901 output_block_size, filter.get(), &output)); |
| 914 EXPECT_EQ(output, expanded_); | 902 EXPECT_EQ(output, expanded_); |
| 915 } | 903 } |
| 916 | 904 |
| 917 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { | 905 TEST_F(SdchFilterTest, DefaultGzipIfSdch) { |
| 918 // Construct a valid SDCH dictionary from a VCDIFF dictionary. | 906 // Construct a valid SDCH dictionary from a VCDIFF dictionary. |
| 919 const std::string kSampleDomain = "sdchtest.com"; | 907 const std::string kSampleDomain = "sdchtest.com"; |
| 920 std::string dictionary(NewSdchDictionary(kSampleDomain)); | 908 std::string dictionary(NewSdchDictionary(kSampleDomain)); |
| 921 | 909 |
| 922 std::string url_string = "http://" + kSampleDomain; | 910 std::string url_string = "http://" + kSampleDomain; |
| 923 | 911 |
| 924 GURL url(url_string); | 912 GURL url(url_string); |
| 925 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); | 913 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url)); |
| 926 | 914 |
| 927 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 915 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
| 928 | 916 |
| 929 // Use Gzip to compress the sdch sdch_compressed data. | 917 // Use Gzip to compress the sdch sdch_compressed data. |
| 930 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 918 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 931 | 919 |
| 932 // Only claim to have sdch content, but really use the gzipped sdch content. | 920 // Only claim to have sdch content, but really use the gzipped sdch content. |
| 933 // System should automatically add the missing (optional) gzip. | 921 // System should automatically add the missing (optional) gzip. |
| 934 std::vector<Filter::FilterType> filter_types; | 922 std::vector<Filter::FilterType> filter_types; |
| 935 filter_types.push_back(Filter::FILTER_TYPE_SDCH); | 923 filter_types.push_back(Filter::FILTER_TYPE_SDCH); |
| 936 | 924 |
| 937 const int kInputBufferSize(100); | 925 MockFilterContext filter_context; |
| 938 MockFilterContext filter_context(kInputBufferSize); | |
| 939 filter_context.SetMimeType("anything/mime"); | 926 filter_context.SetMimeType("anything/mime"); |
| 940 filter_context.SetSdchResponse(true); | 927 filter_context.SetSdchResponse(true); |
| 941 Filter::FixupEncodingTypes(filter_context, &filter_types); | 928 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 942 ASSERT_EQ(filter_types.size(), 2u); | 929 ASSERT_EQ(filter_types.size(), 2u); |
| 943 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); | 930 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH); |
| 944 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 931 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 945 | 932 |
| 946 // First try with a large buffer (larger than test input, or compressed data). | 933 // First try with a large buffer (larger than test input, or compressed data). |
| 947 filter_context.SetURL(url); | 934 filter_context.SetURL(url); |
| 948 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 935 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 // Use Gzip to compress the sdch sdch_compressed data. | 974 // Use Gzip to compress the sdch sdch_compressed data. |
| 988 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 975 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 989 | 976 |
| 990 // Some proxies strip the content encoding statement down to a mere gzip, but | 977 // Some proxies strip the content encoding statement down to a mere gzip, but |
| 991 // pass through the original content (with full sdch,gzip encoding). | 978 // pass through the original content (with full sdch,gzip encoding). |
| 992 // Only claim to have gzip content, but really use the gzipped sdch content. | 979 // Only claim to have gzip content, but really use the gzipped sdch content. |
| 993 // System should automatically add the missing (optional) sdch. | 980 // System should automatically add the missing (optional) sdch. |
| 994 std::vector<Filter::FilterType> filter_types; | 981 std::vector<Filter::FilterType> filter_types; |
| 995 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 982 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 996 | 983 |
| 997 const int kInputBufferSize(100); | 984 MockFilterContext filter_context; |
| 998 MockFilterContext filter_context(kInputBufferSize); | |
| 999 filter_context.SetMimeType("anything/mime"); | 985 filter_context.SetMimeType("anything/mime"); |
| 1000 filter_context.SetSdchResponse(true); | 986 filter_context.SetSdchResponse(true); |
| 1001 Filter::FixupEncodingTypes(filter_context, &filter_types); | 987 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1002 ASSERT_EQ(filter_types.size(), 3u); | 988 ASSERT_EQ(filter_types.size(), 3u); |
| 1003 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 989 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1004 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 990 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1005 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 991 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1006 | 992 |
| 1007 // First try with a large buffer (larger than test input, or compressed data). | 993 // First try with a large buffer (larger than test input, or compressed data). |
| 1008 filter_context.SetURL(url); | 994 filter_context.SetURL(url); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 std::string sdch_compressed(NewSdchCompressedData(dictionary)); | 1032 std::string sdch_compressed(NewSdchCompressedData(dictionary)); |
| 1047 | 1033 |
| 1048 // Use Gzip to compress the sdch sdch_compressed data. | 1034 // Use Gzip to compress the sdch sdch_compressed data. |
| 1049 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); | 1035 std::string gzip_compressed_sdch = gzip_compress(sdch_compressed); |
| 1050 | 1036 |
| 1051 // Only claim to have non-encoded content, but really use the gzipped sdch | 1037 // Only claim to have non-encoded content, but really use the gzipped sdch |
| 1052 // content. | 1038 // content. |
| 1053 // System should automatically add the missing (optional) sdch,gzip. | 1039 // System should automatically add the missing (optional) sdch,gzip. |
| 1054 std::vector<Filter::FilterType> filter_types; | 1040 std::vector<Filter::FilterType> filter_types; |
| 1055 | 1041 |
| 1056 const int kInputBufferSize(100); | 1042 MockFilterContext filter_context; |
| 1057 MockFilterContext filter_context(kInputBufferSize); | |
| 1058 filter_context.SetMimeType("anything/mime"); | 1043 filter_context.SetMimeType("anything/mime"); |
| 1059 filter_context.SetSdchResponse(true); | 1044 filter_context.SetSdchResponse(true); |
| 1060 Filter::FixupEncodingTypes(filter_context, &filter_types); | 1045 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1061 ASSERT_EQ(filter_types.size(), 2u); | 1046 ASSERT_EQ(filter_types.size(), 2u); |
| 1062 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1047 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1063 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1048 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1064 | 1049 |
| 1065 // First try with a large buffer (larger than test input, or compressed data). | 1050 // First try with a large buffer (larger than test input, or compressed data). |
| 1066 filter_context.SetURL(url); | 1051 filter_context.SetURL(url); |
| 1067 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); | 1052 scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 // Use Gzip to double compress the sdch sdch_compressed data. | 1094 // Use Gzip to double compress the sdch sdch_compressed data. |
| 1110 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( | 1095 std::string double_gzip_compressed_sdch = gzip_compress(gzip_compress( |
| 1111 sdch_compressed)); | 1096 sdch_compressed)); |
| 1112 | 1097 |
| 1113 // Only claim to have gzip content, but really use the double gzipped sdch | 1098 // Only claim to have gzip content, but really use the double gzipped sdch |
| 1114 // content. | 1099 // content. |
| 1115 // System should automatically add the missing (optional) sdch, gzip decoders. | 1100 // System should automatically add the missing (optional) sdch, gzip decoders. |
| 1116 std::vector<Filter::FilterType> filter_types; | 1101 std::vector<Filter::FilterType> filter_types; |
| 1117 filter_types.push_back(Filter::FILTER_TYPE_GZIP); | 1102 filter_types.push_back(Filter::FILTER_TYPE_GZIP); |
| 1118 | 1103 |
| 1119 const int kInputBufferSize(100); | 1104 MockFilterContext filter_context; |
| 1120 MockFilterContext filter_context(kInputBufferSize); | |
| 1121 filter_context.SetMimeType("anything/mime"); | 1105 filter_context.SetMimeType("anything/mime"); |
| 1122 filter_context.SetSdchResponse(true); | 1106 filter_context.SetSdchResponse(true); |
| 1123 Filter::FixupEncodingTypes(filter_context, &filter_types); | 1107 Filter::FixupEncodingTypes(filter_context, &filter_types); |
| 1124 ASSERT_EQ(filter_types.size(), 3u); | 1108 ASSERT_EQ(filter_types.size(), 3u); |
| 1125 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); | 1109 EXPECT_EQ(filter_types[0], Filter::FILTER_TYPE_SDCH_POSSIBLE); |
| 1126 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); | 1110 EXPECT_EQ(filter_types[1], Filter::FILTER_TYPE_GZIP_HELPING_SDCH); |
| 1127 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); | 1111 EXPECT_EQ(filter_types[2], Filter::FILTER_TYPE_GZIP); |
| 1128 | 1112 |
| 1129 // First try with a large buffer (larger than test input, or compressed data). | 1113 // First try with a large buffer (larger than test input, or compressed data). |
| 1130 filter_context.SetURL(url); | 1114 filter_context.SetURL(url); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1401 sdch_manager_->SetAllowLatencyExperiment(url, false); | 1385 sdch_manager_->SetAllowLatencyExperiment(url, false); |
| 1402 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1386 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 1403 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); | 1387 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 1404 | 1388 |
| 1405 sdch_manager_->SetAllowLatencyExperiment(url2, false); | 1389 sdch_manager_->SetAllowLatencyExperiment(url2, false); |
| 1406 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1390 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
| 1407 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); | 1391 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); |
| 1408 } | 1392 } |
| 1409 | 1393 |
| 1410 } // namespace net | 1394 } // namespace net |
| OLD | NEW |