OLD | NEW |
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 "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
8 #include "net/proxy/proxy_service.h" | 10 #include "net/proxy/proxy_service.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 // Transform "normal"-looking headers (\n-separated) to the appropriate | 15 // Transform "normal"-looking headers (\n-separated) to the appropriate |
14 // input format for ParseRawHeaders (\0-separated). | 16 // input format for ParseRawHeaders (\0-separated). |
15 void HeadersToRaw(std::string* headers) { | 17 void HeadersToRaw(std::string* headers) { |
16 std::replace(headers->begin(), headers->end(), '\n', '\0'); | 18 std::replace(headers->begin(), headers->end(), '\n', '\0'); |
17 if (!headers->empty()) | 19 if (!headers->empty()) |
18 *headers += '\0'; | 20 *headers += '\0'; |
19 } | 21 } |
20 | 22 |
21 } // namespace | 23 } // namespace |
22 | 24 |
23 namespace data_reduction_proxy { | 25 namespace data_reduction_proxy { |
24 | 26 |
25 class DataReductionProxyHeadersTest : public testing::Test {}; | 27 class DataReductionProxyHeadersTest : public testing::Test {}; |
26 | 28 |
| 29 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) { |
| 30 const struct { |
| 31 const char* headers; |
| 32 std::string action_key; |
| 33 bool expected_result; |
| 34 std::string expected_action_value; |
| 35 } tests[] = { |
| 36 { "HTTP/1.1 200 OK\n" |
| 37 "Content-Length: 999\n", |
| 38 "a", |
| 39 false, |
| 40 "", |
| 41 }, |
| 42 { "HTTP/1.1 200 OK\n" |
| 43 "connection: keep-alive\n" |
| 44 "Content-Length: 999\n", |
| 45 "a", |
| 46 false, |
| 47 "", |
| 48 }, |
| 49 { "HTTP/1.1 200 OK\n" |
| 50 "connection: keep-alive\n" |
| 51 "Chrome-Proxy: bypass=86400\n" |
| 52 "Content-Length: 999\n", |
| 53 "bypass", |
| 54 true, |
| 55 "86400", |
| 56 }, |
| 57 { "HTTP/1.1 200 OK\n" |
| 58 "connection: keep-alive\n" |
| 59 "Chrome-Proxy: bypass86400\n" |
| 60 "Content-Length: 999\n", |
| 61 "bypass", |
| 62 false, |
| 63 "", |
| 64 }, |
| 65 { "HTTP/1.1 200 OK\n" |
| 66 "connection: keep-alive\n" |
| 67 "Chrome-Proxy: bypass=0\n" |
| 68 "Content-Length: 999\n", |
| 69 "bypass", |
| 70 true, |
| 71 "0", |
| 72 }, |
| 73 { "HTTP/1.1 200 OK\n" |
| 74 "connection: keep-alive\n" |
| 75 "Chrome-Proxy: bypass=1500\n" |
| 76 "Chrome-Proxy: bypass=86400\n" |
| 77 "Content-Length: 999\n", |
| 78 "bypass", |
| 79 true, |
| 80 "1500", |
| 81 }, |
| 82 { "HTTP/1.1 200 OK\n" |
| 83 "connection: keep-alive\n" |
| 84 "Chrome-Proxy: block=1500, block=3600\n" |
| 85 "Content-Length: 999\n", |
| 86 "block", |
| 87 true, |
| 88 "1500", |
| 89 }, |
| 90 { "HTTP/1.1 200 OK\n" |
| 91 "connection: proxy-bypass\n" |
| 92 "Chrome-Proxy: key=123 \n" |
| 93 "Content-Length: 999\n", |
| 94 "key", |
| 95 true, |
| 96 "123", |
| 97 }, |
| 98 }; |
| 99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 100 std::string headers(tests[i].headers); |
| 101 HeadersToRaw(&headers); |
| 102 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 103 new net::HttpResponseHeaders(headers)); |
| 104 |
| 105 std::string action_value; |
| 106 bool has_action_key = GetDataReductionProxyActionValue( |
| 107 parsed, tests[i].action_key, &action_value); |
| 108 EXPECT_EQ(tests[i].expected_result, has_action_key); |
| 109 if (has_action_key) { |
| 110 EXPECT_EQ(tests[i].expected_action_value, action_value); |
| 111 } |
| 112 } |
| 113 } |
| 114 |
27 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { | 115 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { |
28 const struct { | 116 const struct { |
29 const char* headers; | 117 const char* headers; |
30 bool expected_result; | 118 bool expected_result; |
31 int64 expected_retry_delay; | 119 int64 expected_retry_delay; |
32 bool expected_bypass_all; | 120 bool expected_bypass_all; |
33 } tests[] = { | 121 } tests[] = { |
34 { "HTTP/1.1 200 OK\n" | 122 { "HTTP/1.1 200 OK\n" |
35 "Content-Length: 999\n", | 123 "Content-Length: 999\n", |
36 false, | 124 false, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 283 |
196 DataReductionProxyInfo data_reduction_proxy_info; | 284 DataReductionProxyInfo data_reduction_proxy_info; |
197 EXPECT_TRUE(ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); | 285 EXPECT_TRUE(ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); |
198 EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); | 286 EXPECT_LE(60, data_reduction_proxy_info.bypass_duration.InSeconds()); |
199 EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); | 287 EXPECT_GE(5 * 60, data_reduction_proxy_info.bypass_duration.InSeconds()); |
200 EXPECT_FALSE(data_reduction_proxy_info.bypass_all); | 288 EXPECT_FALSE(data_reduction_proxy_info.bypass_all); |
201 } | 289 } |
202 | 290 |
203 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { | 291 TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) { |
204 const struct { | 292 const struct { |
205 const char* headers; | 293 const char* headers; |
206 bool expected_result; | 294 bool expected_result; |
| 295 bool expected_has_intermediary; |
| 296 bool ignore_intermediary; |
207 } tests[] = { | 297 } tests[] = { |
208 { "HTTP/1.1 200 OK\n" | 298 { "HTTP/1.1 200 OK\n" |
209 "Via: 1.1 Chrome-Proxy\n", | 299 "Via: 1.1 Chrome-Proxy\n", |
210 false, | 300 false, |
| 301 false, |
| 302 false, |
211 }, | 303 }, |
212 { "HTTP/1.1 200 OK\n" | 304 { "HTTP/1.1 200 OK\n" |
213 "Via: 1\n", | 305 "Via: 1\n", |
214 false, | 306 false, |
| 307 false, |
| 308 false, |
215 }, | 309 }, |
216 { "HTTP/1.1 200 OK\n" | 310 { "HTTP/1.1 200 OK\n" |
217 "Via: 1.1 Chrome-Compression-Proxy\n", | 311 "Via: 1.1 Chrome-Compression-Proxy\n", |
218 true, | 312 true, |
| 313 true, |
| 314 false, |
219 }, | 315 }, |
220 { "HTTP/1.1 200 OK\n" | 316 { "HTTP/1.1 200 OK\n" |
221 "Via: 1.0 Chrome-Compression-Proxy\n", | 317 "Via: 1.0 Chrome-Compression-Proxy\n", |
222 true, | 318 true, |
| 319 true, |
| 320 false, |
223 }, | 321 }, |
224 { "HTTP/1.1 200 OK\n" | 322 { "HTTP/1.1 200 OK\n" |
225 "Via: 1.1 Foo-Bar, 1.1 Chrome-Compression-Proxy\n", | 323 "Via: 1.1 Foo-Bar, 1.1 Chrome-Compression-Proxy\n", |
226 true, | 324 true, |
| 325 true, |
| 326 false, |
227 }, | 327 }, |
228 { "HTTP/1.1 200 OK\n" | 328 { "HTTP/1.1 200 OK\n" |
229 "Via: 1.1 Chrome-Compression-Proxy, 1.1 Bar-Foo\n", | 329 "Via: 1.1 Chrome-Compression-Proxy, 1.1 Bar-Foo\n", |
230 true, | 330 true, |
| 331 false, |
| 332 false, |
231 }, | 333 }, |
232 { "HTTP/1.1 200 OK\n" | 334 { "HTTP/1.1 200 OK\n" |
233 "Via: 1.1 chrome-compression-proxy\n", | 335 "Via: 1.1 chrome-compression-proxy\n", |
234 false, | 336 false, |
| 337 false, |
| 338 false, |
235 }, | 339 }, |
236 { "HTTP/1.1 200 OK\n" | 340 { "HTTP/1.1 200 OK\n" |
237 "Via: 1.1 Foo-Bar\n" | 341 "Via: 1.1 Foo-Bar\n" |
238 "Via: 1.1 Chrome-Compression-Proxy\n", | 342 "Via: 1.1 Chrome-Compression-Proxy\n", |
239 true, | 343 true, |
| 344 true, |
| 345 false, |
| 346 }, |
| 347 { "HTTP/1.1 200 OK\n" |
| 348 "Via: 1.1 Chrome-Compression-Proxy\n" |
| 349 "Via: 1.1 Foo-Bar\n", |
| 350 true, |
| 351 false, |
| 352 false, |
240 }, | 353 }, |
241 { "HTTP/1.1 200 OK\n" | 354 { "HTTP/1.1 200 OK\n" |
242 "Via: 1.1 Chrome-Proxy\n", | 355 "Via: 1.1 Chrome-Proxy\n", |
243 false, | 356 false, |
| 357 false, |
| 358 false, |
244 }, | 359 }, |
245 { "HTTP/1.1 200 OK\n" | 360 { "HTTP/1.1 200 OK\n" |
246 "Via: 1.1 Chrome Compression Proxy\n", | 361 "Via: 1.1 Chrome Compression Proxy\n", |
247 true, | 362 true, |
| 363 true, |
| 364 false, |
248 }, | 365 }, |
249 { "HTTP/1.1 200 OK\n" | 366 { "HTTP/1.1 200 OK\n" |
250 "Via: 1.1 Foo-Bar, 1.1 Chrome Compression Proxy\n", | 367 "Via: 1.1 Foo-Bar, 1.1 Chrome Compression Proxy\n", |
251 true, | 368 true, |
| 369 true, |
| 370 false, |
252 }, | 371 }, |
253 { "HTTP/1.1 200 OK\n" | 372 { "HTTP/1.1 200 OK\n" |
254 "Via: 1.1 Chrome Compression Proxy, 1.1 Bar-Foo\n", | 373 "Via: 1.1 Chrome Compression Proxy, 1.1 Bar-Foo\n", |
255 true, | 374 true, |
| 375 false, |
| 376 false, |
256 }, | 377 }, |
257 { "HTTP/1.1 200 OK\n" | 378 { "HTTP/1.1 200 OK\n" |
258 "Via: 1.1 chrome compression proxy\n", | 379 "Via: 1.1 chrome compression proxy\n", |
259 false, | 380 false, |
| 381 false, |
| 382 false, |
260 }, | 383 }, |
261 { "HTTP/1.1 200 OK\n" | 384 { "HTTP/1.1 200 OK\n" |
262 "Via: 1.1 Foo-Bar\n" | 385 "Via: 1.1 Foo-Bar\n" |
263 "Via: 1.1 Chrome Compression Proxy\n", | 386 "Via: 1.1 Chrome Compression Proxy\n", |
264 true, | 387 true, |
| 388 true, |
| 389 false, |
| 390 }, |
| 391 { "HTTP/1.1 200 OK\n" |
| 392 "Via: 1.1 Chrome Compression Proxy\n" |
| 393 "Via: 1.1 Foo-Bar\n", |
| 394 true, |
| 395 false, |
| 396 false, |
| 397 }, |
| 398 { "HTTP/1.1 200 OK\n" |
| 399 "Via: 1.1 Chrome Compression Proxy\n" |
| 400 "Via: 1.1 Foo-Bar\n", |
| 401 true, |
| 402 false, |
| 403 true, |
265 }, | 404 }, |
266 }; | 405 }; |
267 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 406 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
268 std::string headers(tests[i].headers); | 407 std::string headers(tests[i].headers); |
269 HeadersToRaw(&headers); | 408 HeadersToRaw(&headers); |
270 scoped_refptr<net::HttpResponseHeaders> parsed( | 409 scoped_refptr<net::HttpResponseHeaders> parsed( |
271 new net::HttpResponseHeaders(headers)); | 410 new net::HttpResponseHeaders(headers)); |
272 | 411 |
273 EXPECT_EQ(tests[i].expected_result, | 412 bool has_chrome_proxy_via_header, has_intermediary; |
274 HasDataReductionProxyViaHeader(parsed)); | 413 if (tests[i].ignore_intermediary) { |
| 414 has_chrome_proxy_via_header = |
| 415 HasDataReductionProxyViaHeader(parsed, NULL); |
| 416 } |
| 417 else { |
| 418 has_chrome_proxy_via_header = |
| 419 HasDataReductionProxyViaHeader(parsed, &has_intermediary); |
| 420 } |
| 421 EXPECT_EQ(tests[i].expected_result, has_chrome_proxy_via_header); |
| 422 if (has_chrome_proxy_via_header && !tests[i].ignore_intermediary) { |
| 423 EXPECT_EQ(tests[i].expected_has_intermediary, has_intermediary); |
| 424 } |
275 } | 425 } |
276 } | 426 } |
277 | 427 |
278 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { | 428 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) { |
279 const struct { | 429 const struct { |
280 const char* headers; | 430 const char* headers; |
281 net::ProxyService::DataReductionProxyBypassType expected_result; | 431 net::ProxyService::DataReductionProxyBypassType expected_result; |
282 } tests[] = { | 432 } tests[] = { |
283 { "HTTP/1.1 200 OK\n" | 433 { "HTTP/1.1 200 OK\n" |
284 "Chrome-Proxy: bypass=0\n" | 434 "Chrome-Proxy: bypass=0\n" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 524 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
375 std::string headers(tests[i].headers); | 525 std::string headers(tests[i].headers); |
376 HeadersToRaw(&headers); | 526 HeadersToRaw(&headers); |
377 scoped_refptr<net::HttpResponseHeaders> parsed( | 527 scoped_refptr<net::HttpResponseHeaders> parsed( |
378 new net::HttpResponseHeaders(headers)); | 528 new net::HttpResponseHeaders(headers)); |
379 DataReductionProxyInfo chrome_proxy_info; | 529 DataReductionProxyInfo chrome_proxy_info; |
380 EXPECT_EQ(tests[i].expected_result, | 530 EXPECT_EQ(tests[i].expected_result, |
381 GetDataReductionProxyBypassType(parsed, &chrome_proxy_info)); | 531 GetDataReductionProxyBypassType(parsed, &chrome_proxy_info)); |
382 } | 532 } |
383 } | 533 } |
| 534 |
| 535 TEST_F(DataReductionProxyHeadersTest, |
| 536 GetDataReductionProxyActionFingerprintChromeProxy) { |
| 537 const struct { |
| 538 std::string label; |
| 539 const char* headers; |
| 540 bool expected_fingerprint_exist; |
| 541 std::string expected_fingerprint; |
| 542 } tests[] = { |
| 543 { "fingerprint doesn't exist", |
| 544 "HTTP/1.1 200 OK\n" |
| 545 "Chrome-Proxy: bypass=0\n", |
| 546 false, |
| 547 "", |
| 548 }, |
| 549 { "fingerprint occurs once", |
| 550 "HTTP/1.1 200 OK\n" |
| 551 "Chrome-Proxy: bypass=1, fcp=fp\n", |
| 552 true, |
| 553 "fp", |
| 554 }, |
| 555 { "fingerprint occurs twice", |
| 556 "HTTP/1.1 200 OK\n" |
| 557 "Chrome-Proxy: bypass=2, fcp=fp1, fcp=fp2\n", |
| 558 true, |
| 559 "fp1", |
| 560 }, |
| 561 }; |
| 562 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 563 std::string headers(tests[i].headers); |
| 564 HeadersToRaw(&headers); |
| 565 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 566 new net::HttpResponseHeaders(headers)); |
| 567 |
| 568 std::string fingerprint; |
| 569 bool fingerprint_exist = GetDataReductionProxyActionFingerprintChromeProxy( |
| 570 parsed, &fingerprint); |
| 571 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) |
| 572 << tests[i].label; |
| 573 |
| 574 if (fingerprint_exist) |
| 575 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; |
| 576 } |
| 577 } |
| 578 |
| 579 TEST_F(DataReductionProxyHeadersTest, |
| 580 GetDataReductionProxyActionFingerprintVia) { |
| 581 const struct { |
| 582 std::string label; |
| 583 const char* headers; |
| 584 bool expected_fingerprint_exist; |
| 585 std::string expected_fingerprint; |
| 586 } tests[] = { |
| 587 { "fingerprint doesn't exist", |
| 588 "HTTP/1.1 200 OK\n" |
| 589 "Chrome-Proxy: bypass=0\n", |
| 590 false, |
| 591 "", |
| 592 }, |
| 593 { "fingerprint occurs once", |
| 594 "HTTP/1.1 200 OK\n" |
| 595 "Chrome-Proxy: bypass=1, fvia=fvia\n", |
| 596 true, |
| 597 "fvia", |
| 598 }, |
| 599 { "fingerprint occurs twice", |
| 600 "HTTP/1.1 200 OK\n" |
| 601 "Chrome-Proxy: bypass=2, fvia=fvia1, fvia=fvia2\n", |
| 602 true, |
| 603 "fvia1", |
| 604 }, |
| 605 }; |
| 606 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 607 std::string headers(tests[i].headers); |
| 608 HeadersToRaw(&headers); |
| 609 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 610 new net::HttpResponseHeaders(headers)); |
| 611 |
| 612 std::string fingerprint; |
| 613 bool fingerprint_exist = |
| 614 GetDataReductionProxyActionFingerprintVia(parsed, &fingerprint); |
| 615 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) |
| 616 << tests[i].label; |
| 617 |
| 618 if (fingerprint_exist) |
| 619 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; |
| 620 } |
| 621 } |
| 622 |
| 623 TEST_F(DataReductionProxyHeadersTest, |
| 624 GetDataReductionProxyActionFingerprintOtherHeaders) { |
| 625 const struct { |
| 626 std::string label; |
| 627 const char* headers; |
| 628 bool expected_fingerprint_exist; |
| 629 std::string expected_fingerprint; |
| 630 } tests[] = { |
| 631 { "fingerprint doesn't exist", |
| 632 "HTTP/1.1 200 OK\n" |
| 633 "Chrome-Proxy: bypass=0\n", |
| 634 false, |
| 635 "", |
| 636 }, |
| 637 { "fingerprint occurs once", |
| 638 "HTTP/1.1 200 OK\n" |
| 639 "Chrome-Proxy: bypass=1, foh=foh\n", |
| 640 true, |
| 641 "foh", |
| 642 }, |
| 643 { "fingerprint occurs twice", |
| 644 "HTTP/1.1 200 OK\n" |
| 645 "Chrome-Proxy: bypass=2, foh=foh1, foh=foh2\n", |
| 646 true, |
| 647 "foh1", |
| 648 }, |
| 649 }; |
| 650 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 651 std::string headers(tests[i].headers); |
| 652 HeadersToRaw(&headers); |
| 653 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 654 new net::HttpResponseHeaders(headers)); |
| 655 |
| 656 std::string fingerprint; |
| 657 bool fingerprint_exist = |
| 658 GetDataReductionProxyActionFingerprintOtherHeaders( |
| 659 parsed, &fingerprint); |
| 660 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) |
| 661 << tests[i].label; |
| 662 |
| 663 if (fingerprint_exist) |
| 664 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; |
| 665 } |
| 666 } |
| 667 |
| 668 TEST_F(DataReductionProxyHeadersTest, |
| 669 GetDataReductionProxyActionFingerprintContentLength) { |
| 670 const struct { |
| 671 std::string label; |
| 672 const char* headers; |
| 673 bool expected_fingerprint_exist; |
| 674 std::string expected_fingerprint; |
| 675 } tests[] = { |
| 676 { "fingerprint doesn't exist", |
| 677 "HTTP/1.1 200 OK\n" |
| 678 "Chrome-Proxy: bypass=0\n", |
| 679 false, |
| 680 "", |
| 681 }, |
| 682 { "fingerprint occurs once", |
| 683 "HTTP/1.1 200 OK\n" |
| 684 "Chrome-Proxy: bypass=1, fcl=fcl\n", |
| 685 true, |
| 686 "fcl", |
| 687 }, |
| 688 { "fingerprint occurs twice", |
| 689 "HTTP/1.1 200 OK\n" |
| 690 "Chrome-Proxy: bypass=2, fcl=fcl1, fcl=fcl2\n", |
| 691 true, |
| 692 "fcl1", |
| 693 }, |
| 694 }; |
| 695 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 696 std::string headers(tests[i].headers); |
| 697 HeadersToRaw(&headers); |
| 698 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 699 new net::HttpResponseHeaders(headers)); |
| 700 |
| 701 std::string fingerprint; |
| 702 bool fingerprint_exist = |
| 703 GetDataReductionProxyActionFingerprintContentLength( |
| 704 parsed, &fingerprint); |
| 705 EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist) |
| 706 << tests[i].label; |
| 707 |
| 708 if (fingerprint_exist) |
| 709 EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label; |
| 710 } |
| 711 } |
| 712 |
| 713 TEST_F(DataReductionProxyHeadersTest, |
| 714 GetDataReductionProxyHeaderWithFingerprintRemoved) { |
| 715 const struct { |
| 716 std::string label; |
| 717 const char* headers; |
| 718 std::string expected_output_values_string; |
| 719 } test[] = { |
| 720 { |
| 721 "Checks the case that there is no Chrome-Proxy header's fingerprint.", |
| 722 "HTTP/1.1 200 OK\n" |
| 723 "Chrome-Proxy: 1,2,3,5\n", |
| 724 "1,2,3,5,", |
| 725 }, |
| 726 { |
| 727 "Checks the case that there is Chrome-Proxy header's fingerprint.", |
| 728 "HTTP/1.1 200 OK\n" |
| 729 "Chrome-Proxy: 1,2,3,fcp=4,5\n", |
| 730 "1,2,3,5,", |
| 731 }, |
| 732 { |
| 733 "Checks the case that there is Chrome-Proxy header's fingerprint, and it" |
| 734 "occurs at the end.", |
| 735 "HTTP/1.1 200 OK\n" |
| 736 "Chrome-Proxy: 1,2,3,fcp=4,", |
| 737 "1,2,3,", |
| 738 }, |
| 739 { |
| 740 "Checks the case that there is Chrome-Proxy header's fingerprint, and it" |
| 741 "occurs at the beginning.", |
| 742 "HTTP/1.1 200 OK\n" |
| 743 "Chrome-Proxy: fcp=1,2,3,", |
| 744 "2,3,", |
| 745 }, |
| 746 { |
| 747 "Checks the case that value is longer than prefix.", |
| 748 "HTTP/1.1 200 OK\n" |
| 749 "Chrome-Proxy: fcp=1,fcp!=1,fcp!=2,fcpfcp=3", |
| 750 "fcp!=1,fcp!=2,fcpfcp=3,", |
| 751 }, |
| 752 { |
| 753 "Checks the case that value is shorter than prefix but similar.", |
| 754 "HTTP/1.1 200 OK\n" |
| 755 "Chrome-Proxy: fcp=1,fcp,fcp=", |
| 756 "fcp,fcp=,", |
| 757 }, |
| 758 }; |
| 759 |
| 760 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) { |
| 761 std::string headers(test[i].headers); |
| 762 HeadersToRaw(&headers); |
| 763 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 764 new net::HttpResponseHeaders(headers)); |
| 765 |
| 766 std::vector<std::string> output_values; |
| 767 GetDataReductionProxyHeaderWithFingerprintRemoved(parsed, &output_values); |
| 768 |
| 769 std::string output_values_string; |
| 770 for (size_t j = 0; j < output_values.size(); ++j) |
| 771 output_values_string += output_values[j] + ","; |
| 772 |
| 773 EXPECT_EQ(test[i].expected_output_values_string, output_values_string) |
| 774 << test[i].label; |
| 775 } |
| 776 } |
| 777 |
384 } // namespace data_reduction_proxy | 778 } // namespace data_reduction_proxy |
OLD | NEW |