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/browser/data_reduction_proxy_params.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 TEST_F(DataReductionProxyParamsTest, EverythingDefined) { | 48 TEST_F(DataReductionProxyParamsTest, EverythingDefined) { |
49 TestDataReductionProxyParams params( | 49 TestDataReductionProxyParams params( |
50 DataReductionProxyParams::kAllowed | | 50 DataReductionProxyParams::kAllowed | |
51 DataReductionProxyParams::kFallbackAllowed | | 51 DataReductionProxyParams::kFallbackAllowed | |
52 DataReductionProxyParams::kPromoAllowed, | 52 DataReductionProxyParams::kPromoAllowed, |
53 TestDataReductionProxyParams::HAS_EVERYTHING); | 53 TestDataReductionProxyParams::HAS_EVERYTHING); |
54 CheckParams(params, true, true, true, false, true); | 54 CheckParams(params, true, true, true, false, true); |
55 CheckValues(params, | 55 CheckValues(params, |
56 TestDataReductionProxyParams::DefaultDevOrigin(), | 56 TestDataReductionProxyParams::DefaultDevOrigin(), |
57 TestDataReductionProxyParams::DefaultFallbackOrigin(), | 57 TestDataReductionProxyParams::DefaultDevFallbackOrigin(), |
58 TestDataReductionProxyParams::DefaultSSLOrigin(), | 58 TestDataReductionProxyParams::DefaultSSLOrigin(), |
59 TestDataReductionProxyParams::DefaultAltOrigin(), | 59 TestDataReductionProxyParams::DefaultAltOrigin(), |
60 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), | 60 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), |
61 TestDataReductionProxyParams::DefaultProbeURL()); | 61 TestDataReductionProxyParams::DefaultProbeURL()); |
62 } | 62 } |
63 | 63 |
64 TEST_F(DataReductionProxyParamsTest, NoDevOrigin) { | 64 TEST_F(DataReductionProxyParamsTest, NoDevOrigin) { |
65 TestDataReductionProxyParams params( | 65 TestDataReductionProxyParams params( |
66 DataReductionProxyParams::kAllowed | | 66 DataReductionProxyParams::kAllowed | |
67 DataReductionProxyParams::kFallbackAllowed | | 67 DataReductionProxyParams::kFallbackAllowed | |
68 DataReductionProxyParams::kPromoAllowed, | 68 DataReductionProxyParams::kPromoAllowed, |
69 TestDataReductionProxyParams::HAS_EVERYTHING & | 69 TestDataReductionProxyParams::HAS_EVERYTHING & |
70 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); | 70 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & |
| 71 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN); |
71 CheckParams(params, true, true, true, false, true); | 72 CheckParams(params, true, true, true, false, true); |
72 CheckValues(params, | 73 CheckValues(params, |
73 TestDataReductionProxyParams::DefaultOrigin(), | 74 TestDataReductionProxyParams::DefaultOrigin(), |
74 TestDataReductionProxyParams::DefaultFallbackOrigin(), | 75 TestDataReductionProxyParams::DefaultFallbackOrigin(), |
75 TestDataReductionProxyParams::DefaultSSLOrigin(), | 76 TestDataReductionProxyParams::DefaultSSLOrigin(), |
76 TestDataReductionProxyParams::DefaultAltOrigin(), | 77 TestDataReductionProxyParams::DefaultAltOrigin(), |
77 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), | 78 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), |
78 TestDataReductionProxyParams::DefaultProbeURL()); | 79 TestDataReductionProxyParams::DefaultProbeURL()); |
79 } | 80 } |
80 | 81 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 true, | 129 true, |
129 true, | 130 true, |
130 TestDataReductionProxyParams::HAS_NOTHING, | 131 TestDataReductionProxyParams::HAS_NOTHING, |
131 true | 132 true |
132 }, | 133 }, |
133 { | 134 { |
134 true, | 135 true, |
135 true, | 136 true, |
136 true, | 137 true, |
137 true, | 138 true, |
138 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 139 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 140 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
139 true | 141 true |
140 }, | 142 }, |
141 { | 143 { |
142 true, | 144 true, |
143 true, | 145 true, |
144 true, | 146 true, |
145 true, | 147 true, |
146 TestDataReductionProxyParams::HAS_ORIGIN, | 148 TestDataReductionProxyParams::HAS_ORIGIN, |
147 true | 149 true |
148 }, | 150 }, |
149 { | 151 { |
150 true, | 152 true, |
151 true, | 153 true, |
152 true, | 154 true, |
153 true, | 155 true, |
154 TestDataReductionProxyParams::HAS_ORIGIN | | 156 TestDataReductionProxyParams::HAS_ORIGIN | |
155 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 157 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 158 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
156 false | 159 false |
157 }, | 160 }, |
158 { true, | 161 { true, |
159 true, | 162 true, |
160 true, | 163 true, |
161 true, | 164 true, |
162 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, | 165 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN | |
| 166 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
163 false | 167 false |
164 }, | 168 }, |
165 { true, | 169 { true, |
166 true, | 170 true, |
167 true, | 171 true, |
168 true, | 172 true, |
169 TestDataReductionProxyParams::HAS_SSL_ORIGIN, | 173 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
170 false | 174 false |
171 }, | 175 }, |
172 { true, | 176 { true, |
(...skipping 24 matching lines...) Expand all Loading... |
197 true, | 201 true, |
198 TestDataReductionProxyParams::HAS_NOTHING, | 202 TestDataReductionProxyParams::HAS_NOTHING, |
199 true | 203 true |
200 }, | 204 }, |
201 { | 205 { |
202 true, | 206 true, |
203 false, | 207 false, |
204 true, | 208 true, |
205 true, | 209 true, |
206 TestDataReductionProxyParams::HAS_ORIGIN | | 210 TestDataReductionProxyParams::HAS_ORIGIN | |
207 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 211 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 212 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
208 false | 213 false |
209 }, | 214 }, |
210 { | 215 { |
211 true, | 216 true, |
212 false, | 217 false, |
213 true, | 218 true, |
214 true, | 219 true, |
215 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, | 220 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
216 true | 221 true |
217 }, | 222 }, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 true, | 260 true, |
256 TestDataReductionProxyParams::HAS_NOTHING, | 261 TestDataReductionProxyParams::HAS_NOTHING, |
257 true | 262 true |
258 }, | 263 }, |
259 { | 264 { |
260 true, | 265 true, |
261 true, | 266 true, |
262 false, | 267 false, |
263 true, | 268 true, |
264 TestDataReductionProxyParams::HAS_ORIGIN | | 269 TestDataReductionProxyParams::HAS_ORIGIN | |
265 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 270 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 271 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
266 false | 272 false |
267 }, | 273 }, |
268 { | 274 { |
269 true, | 275 true, |
270 true, | 276 true, |
271 false, | 277 false, |
272 true, | 278 true, |
273 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, | 279 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN | |
| 280 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
274 false | 281 false |
275 }, | 282 }, |
276 { | 283 { |
277 true, | 284 true, |
278 true, | 285 true, |
279 false, | 286 false, |
280 true, | 287 true, |
281 TestDataReductionProxyParams::HAS_SSL_ORIGIN, | 288 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
282 true | 289 true |
283 }, | 290 }, |
(...skipping 20 matching lines...) Expand all Loading... |
304 true, | 311 true, |
305 TestDataReductionProxyParams::HAS_PROBE_URL, | 312 TestDataReductionProxyParams::HAS_PROBE_URL, |
306 false | 313 false |
307 }, | 314 }, |
308 { | 315 { |
309 true, | 316 true, |
310 false, | 317 false, |
311 false, | 318 false, |
312 true, | 319 true, |
313 TestDataReductionProxyParams::HAS_ORIGIN | | 320 TestDataReductionProxyParams::HAS_ORIGIN | |
314 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 321 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 322 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
315 false | 323 false |
316 }, | 324 }, |
317 { | 325 { |
318 true, | 326 true, |
319 false, | 327 false, |
320 false, | 328 false, |
321 true, | 329 true, |
322 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, | 330 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
323 true | 331 true |
324 }, | 332 }, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 true, | 369 true, |
362 TestDataReductionProxyParams::HAS_NOTHING, | 370 TestDataReductionProxyParams::HAS_NOTHING, |
363 false | 371 false |
364 }, | 372 }, |
365 { | 373 { |
366 false, | 374 false, |
367 true, | 375 true, |
368 true, | 376 true, |
369 true, | 377 true, |
370 TestDataReductionProxyParams::HAS_ORIGIN | | 378 TestDataReductionProxyParams::HAS_ORIGIN | |
371 TestDataReductionProxyParams::HAS_DEV_ORIGIN, | 379 TestDataReductionProxyParams::HAS_DEV_ORIGIN | |
| 380 TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN, |
372 false | 381 false |
373 }, | 382 }, |
374 { | 383 { |
375 false, | 384 false, |
376 true, | 385 true, |
377 true, | 386 true, |
378 true, | 387 true, |
379 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, | 388 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
380 false | 389 false |
381 }, | 390 }, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 if (tests[i].fallback_allowed) | 429 if (tests[i].fallback_allowed) |
421 flags |= DataReductionProxyParams::kFallbackAllowed; | 430 flags |= DataReductionProxyParams::kFallbackAllowed; |
422 if (tests[i].alternative_allowed) | 431 if (tests[i].alternative_allowed) |
423 flags |= DataReductionProxyParams::kAlternativeAllowed; | 432 flags |= DataReductionProxyParams::kAlternativeAllowed; |
424 if (tests[i].promo_allowed) | 433 if (tests[i].promo_allowed) |
425 flags |= DataReductionProxyParams::kPromoAllowed; | 434 flags |= DataReductionProxyParams::kPromoAllowed; |
426 TestDataReductionProxyParams params( | 435 TestDataReductionProxyParams params( |
427 flags, | 436 flags, |
428 TestDataReductionProxyParams::HAS_EVERYTHING & | 437 TestDataReductionProxyParams::HAS_EVERYTHING & |
429 ~(tests[i].missing_definitions)); | 438 ~(tests[i].missing_definitions)); |
430 EXPECT_EQ(tests[i].expected_result, params.init_result()); | 439 EXPECT_EQ(tests[i].expected_result, params.init_result()) << i; |
431 } | 440 } |
432 } | 441 } |
433 | 442 |
434 TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { | 443 TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { |
435 const struct { | 444 const struct { |
436 net::HostPortPair host_port_pair; | 445 net::HostPortPair host_port_pair; |
437 bool fallback_allowed; | 446 bool fallback_allowed; |
438 bool set_dev_origin; | 447 bool set_dev_origin; |
439 bool expected_result; | 448 bool expected_result; |
440 net::HostPortPair expected_first; | 449 net::HostPortPair expected_first; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 true | 561 true |
553 }, | 562 }, |
554 { net::HostPortPair::FromURL(GURL( | 563 { net::HostPortPair::FromURL(GURL( |
555 TestDataReductionProxyParams::DefaultDevOrigin())), | 564 TestDataReductionProxyParams::DefaultDevOrigin())), |
556 true, | 565 true, |
557 true, | 566 true, |
558 true, | 567 true, |
559 net::HostPortPair::FromURL(GURL( | 568 net::HostPortPair::FromURL(GURL( |
560 TestDataReductionProxyParams::DefaultDevOrigin())), | 569 TestDataReductionProxyParams::DefaultDevOrigin())), |
561 net::HostPortPair::FromURL(GURL( | 570 net::HostPortPair::FromURL(GURL( |
562 TestDataReductionProxyParams::DefaultFallbackOrigin())), | 571 TestDataReductionProxyParams::DefaultDevFallbackOrigin())), |
563 false, | 572 false, |
564 false, | 573 false, |
565 false | 574 false |
566 }, | 575 }, |
567 { net::HostPortPair::FromURL(GURL( | 576 { net::HostPortPair::FromURL(GURL( |
568 TestDataReductionProxyParams::DefaultOrigin())), | 577 TestDataReductionProxyParams::DefaultOrigin())), |
569 true, | 578 true, |
570 true, | 579 true, |
571 true, | 580 true, |
572 net::HostPortPair::FromURL(GURL( | 581 net::HostPortPair::FromURL(GURL( |
573 TestDataReductionProxyParams::DefaultOrigin())), | 582 TestDataReductionProxyParams::DefaultOrigin())), |
574 net::HostPortPair::FromURL(GURL( | 583 net::HostPortPair::FromURL(GURL( |
575 TestDataReductionProxyParams::DefaultFallbackOrigin())), | 584 TestDataReductionProxyParams::DefaultDevFallbackOrigin())), |
576 false, | 585 false, |
577 false, | 586 false, |
578 false | 587 false |
579 }, | 588 }, |
580 }; | 589 }; |
581 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 590 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
582 int flags = DataReductionProxyParams::kAllowed | | 591 int flags = DataReductionProxyParams::kAllowed | |
583 DataReductionProxyParams::kAlternativeAllowed; | 592 DataReductionProxyParams::kAlternativeAllowed; |
584 if (tests[i].fallback_allowed) | 593 if (tests[i].fallback_allowed) |
585 flags |= DataReductionProxyParams::kFallbackAllowed; | 594 flags |= DataReductionProxyParams::kFallbackAllowed; |
586 unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING; | 595 unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING; |
587 if (!tests[i].set_dev_origin) { | 596 if (!tests[i].set_dev_origin) { |
588 has_definitions &= ~TestDataReductionProxyParams::HAS_DEV_ORIGIN; | 597 has_definitions &= ~TestDataReductionProxyParams::HAS_DEV_ORIGIN; |
| 598 has_definitions &= ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN; |
589 } | 599 } |
590 TestDataReductionProxyParams params(flags, has_definitions); | 600 TestDataReductionProxyParams params(flags, has_definitions); |
591 DataReductionProxyTypeInfo proxy_type_info; | 601 DataReductionProxyTypeInfo proxy_type_info; |
592 EXPECT_EQ(tests[i].expected_result, | 602 EXPECT_EQ(tests[i].expected_result, |
593 params.IsDataReductionProxy( | 603 params.IsDataReductionProxy( |
594 tests[i].host_port_pair, &proxy_type_info)); | 604 tests[i].host_port_pair, &proxy_type_info)) << i; |
595 EXPECT_TRUE(tests[i].expected_first.Equals( | 605 EXPECT_TRUE(tests[i].expected_first.Equals( |
596 net::HostPortPair::FromURL(proxy_type_info.proxy_servers.first))); | 606 net::HostPortPair::FromURL(proxy_type_info.proxy_servers.first))) << i; |
597 EXPECT_TRUE(tests[i].expected_second.Equals( | 607 EXPECT_TRUE(tests[i].expected_second.Equals( |
598 net::HostPortPair::FromURL(proxy_type_info.proxy_servers.second))); | 608 net::HostPortPair::FromURL(proxy_type_info.proxy_servers.second))) << i; |
599 EXPECT_EQ(tests[i].expected_is_fallback, proxy_type_info.is_fallback); | 609 EXPECT_EQ(tests[i].expected_is_fallback, proxy_type_info.is_fallback) << i; |
600 EXPECT_EQ(tests[i].expected_is_alternative, proxy_type_info.is_alternative); | 610 EXPECT_EQ(tests[i].expected_is_alternative, proxy_type_info.is_alternative) |
601 EXPECT_EQ(tests[i].expected_is_ssl, proxy_type_info.is_ssl); | 611 << i; |
| 612 EXPECT_EQ(tests[i].expected_is_ssl, proxy_type_info.is_ssl) << i; |
602 } | 613 } |
603 } | 614 } |
604 | 615 |
605 std::string GetRetryMapKeyFromOrigin(std::string origin) { | 616 std::string GetRetryMapKeyFromOrigin(std::string origin) { |
606 // The retry map has the scheme prefix for https but not for http | 617 // The retry map has the scheme prefix for https but not for http |
607 return net::ProxyServer(GURL(origin).SchemeIs(url::kHttpsScheme) ? | 618 return net::ProxyServer(GURL(origin).SchemeIs(url::kHttpsScheme) ? |
608 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 619 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, |
609 net::HostPortPair::FromURL(GURL(origin))).ToURI(); | 620 net::HostPortPair::FromURL(GURL(origin))).ToURI(); |
610 } | 621 } |
611 | 622 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 969 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
959 int flags = 0; | 970 int flags = 0; |
960 if (tests[i].allowed) | 971 if (tests[i].allowed) |
961 flags |= DataReductionProxyParams::kAllowed; | 972 flags |= DataReductionProxyParams::kAllowed; |
962 if (tests[i].alt_allowed) | 973 if (tests[i].alt_allowed) |
963 flags |= DataReductionProxyParams::kAlternativeAllowed; | 974 flags |= DataReductionProxyParams::kAlternativeAllowed; |
964 if (tests[i].fallback_allowed) | 975 if (tests[i].fallback_allowed) |
965 flags |= DataReductionProxyParams::kFallbackAllowed; | 976 flags |= DataReductionProxyParams::kFallbackAllowed; |
966 unsigned int has_definitions = | 977 unsigned int has_definitions = |
967 TestDataReductionProxyParams::HAS_EVERYTHING & | 978 TestDataReductionProxyParams::HAS_EVERYTHING & |
968 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN; | 979 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & |
| 980 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN; |
969 TestDataReductionProxyParams params(flags, has_definitions); | 981 TestDataReductionProxyParams params(flags, has_definitions); |
970 | 982 |
971 net::ProxyRetryInfoMap retry_map; | 983 net::ProxyRetryInfoMap retry_map; |
972 net::ProxyRetryInfo retry_info; | 984 net::ProxyRetryInfo retry_info; |
973 | 985 |
974 if (tests[i].origin) | 986 if (tests[i].origin) |
975 retry_map[origin] = retry_info; | 987 retry_map[origin] = retry_info; |
976 if (tests[i].fallback_origin) | 988 if (tests[i].fallback_origin) |
977 retry_map[fallback_origin] = retry_info; | 989 retry_map[fallback_origin] = retry_info; |
978 if (tests[i].alt_origin) | 990 if (tests[i].alt_origin) |
979 retry_map[alt_origin] = retry_info; | 991 retry_map[alt_origin] = retry_info; |
980 if (tests[i].alt_fallback_origin) | 992 if (tests[i].alt_fallback_origin) |
981 retry_map[alt_fallback_origin] = retry_info; | 993 retry_map[alt_fallback_origin] = retry_info; |
982 if (tests[i].ssl_origin) | 994 if (tests[i].ssl_origin) |
983 retry_map[ssl_origin] = retry_info; | 995 retry_map[ssl_origin] = retry_info; |
984 | 996 |
985 bool was_bypassed = params.AreProxiesBypassed(retry_map, | 997 bool was_bypassed = params.AreProxiesBypassed(retry_map, |
986 tests[i].is_https, | 998 tests[i].is_https, |
987 NULL); | 999 NULL); |
988 | 1000 |
989 EXPECT_EQ(tests[i].expected_result, was_bypassed); | 1001 EXPECT_EQ(tests[i].expected_result, was_bypassed); |
990 } | 1002 } |
991 } | 1003 } |
992 } // namespace data_reduction_proxy | 1004 } // namespace data_reduction_proxy |
OLD | NEW |