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
3// found in the LICENSE file.
4
5#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
6
7#include <map>
8
9#include "base/command_line.h"
10#include "base/logging.h"
11#include "components/data_reduction_proxy/browser/data_reduction_proxy_params_test_utils.h"
12#include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h"
13#include "net/proxy/proxy_retry_info.h"
14#include "net/proxy/proxy_server.h"
15#include "testing/gtest/include/gtest/gtest.h"
16
17namespace data_reduction_proxy {
18class DataReductionProxyParamsTest : public testing::Test {
19 public:
20  void CheckParams(const TestDataReductionProxyParams& params,
21                   bool expected_init_result,
22                   bool expected_allowed,
23                   bool expected_fallback_allowed,
24                   bool expected_alternative_allowed,
25                   bool expected_promo_allowed) {
26    EXPECT_EQ(expected_init_result, params.init_result());
27    EXPECT_EQ(expected_allowed, params.allowed());
28    EXPECT_EQ(expected_fallback_allowed, params.fallback_allowed());
29    EXPECT_EQ(expected_alternative_allowed, params.alternative_allowed());
30    EXPECT_EQ(expected_promo_allowed, params.promo_allowed());
31  }
32  void CheckValues(const TestDataReductionProxyParams& params,
33                   const std::string& expected_origin,
34                   const std::string& expected_fallback_origin,
35                   const std::string& expected_ssl_origin,
36                   const std::string& expected_alt_origin,
37                   const std::string& expected_alt_fallback_origin,
38                   const std::string& expected_probe_url) {
39    EXPECT_EQ(GURL(expected_origin), params.origin());
40    EXPECT_EQ(GURL(expected_fallback_origin), params.fallback_origin());
41    EXPECT_EQ(GURL(expected_ssl_origin), params.ssl_origin());
42    EXPECT_EQ(GURL(expected_alt_origin), params.alt_origin());
43    EXPECT_EQ(GURL(expected_alt_fallback_origin), params.alt_fallback_origin());
44    EXPECT_EQ(GURL(expected_probe_url), params.probe_url());
45  }
46};
47
48TEST_F(DataReductionProxyParamsTest, EverythingDefined) {
49  TestDataReductionProxyParams params(
50      DataReductionProxyParams::kAllowed |
51      DataReductionProxyParams::kFallbackAllowed |
52      DataReductionProxyParams::kPromoAllowed,
53      TestDataReductionProxyParams::HAS_EVERYTHING);
54  CheckParams(params, true, true, true, false, true);
55  CheckValues(params,
56              TestDataReductionProxyParams::DefaultDevOrigin(),
57              TestDataReductionProxyParams::DefaultDevFallbackOrigin(),
58              TestDataReductionProxyParams::DefaultSSLOrigin(),
59              TestDataReductionProxyParams::DefaultAltOrigin(),
60              TestDataReductionProxyParams::DefaultAltFallbackOrigin(),
61              TestDataReductionProxyParams::DefaultProbeURL());
62}
63
64TEST_F(DataReductionProxyParamsTest, NoDevOrigin) {
65  TestDataReductionProxyParams params(
66      DataReductionProxyParams::kAllowed |
67      DataReductionProxyParams::kFallbackAllowed |
68      DataReductionProxyParams::kPromoAllowed,
69      TestDataReductionProxyParams::HAS_EVERYTHING &
70      ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
71      ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN);
72  CheckParams(params, true, true, true, false, true);
73  CheckValues(params,
74              TestDataReductionProxyParams::DefaultOrigin(),
75              TestDataReductionProxyParams::DefaultFallbackOrigin(),
76              TestDataReductionProxyParams::DefaultSSLOrigin(),
77              TestDataReductionProxyParams::DefaultAltOrigin(),
78              TestDataReductionProxyParams::DefaultAltFallbackOrigin(),
79              TestDataReductionProxyParams::DefaultProbeURL());
80}
81
82TEST_F(DataReductionProxyParamsTest, Flags) {
83  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
84      switches::kDataReductionProxy,
85      TestDataReductionProxyParams::FlagOrigin());
86  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
87      switches::kDataReductionProxyFallback,
88      TestDataReductionProxyParams::FlagFallbackOrigin());
89  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
90      switches::kDataReductionSSLProxy,
91      TestDataReductionProxyParams::FlagSSLOrigin());
92  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
93      switches::kDataReductionProxyAlt,
94      TestDataReductionProxyParams::FlagAltOrigin());
95  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
96      switches::kDataReductionProxyAltFallback,
97      TestDataReductionProxyParams::FlagAltFallbackOrigin());
98  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
99      switches::kDataReductionProxyProbeURL,
100      TestDataReductionProxyParams::FlagProbeURL());
101  TestDataReductionProxyParams params(
102      DataReductionProxyParams::kAllowed |
103      DataReductionProxyParams::kFallbackAllowed |
104      DataReductionProxyParams::kAlternativeAllowed |
105      DataReductionProxyParams::kPromoAllowed,
106      TestDataReductionProxyParams::HAS_EVERYTHING);
107  CheckParams(params, true, true, true, true, true);
108  CheckValues(params,
109              TestDataReductionProxyParams::FlagOrigin(),
110              TestDataReductionProxyParams::FlagFallbackOrigin(),
111              TestDataReductionProxyParams::FlagSSLOrigin(),
112              TestDataReductionProxyParams::FlagAltOrigin(),
113              TestDataReductionProxyParams::FlagAltFallbackOrigin(),
114              TestDataReductionProxyParams::FlagProbeURL());
115}
116
117TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) {
118  const struct {
119    bool allowed;
120    bool fallback_allowed;
121    bool alternative_allowed;
122    bool alternative_fallback_allowed;
123    bool promo_allowed;
124    unsigned int missing_definitions;
125    bool expected_result;
126  } tests[]  = {
127    {
128      true,
129      true,
130      true,
131      false,
132      true,
133      TestDataReductionProxyParams::HAS_NOTHING,
134      true
135    },
136    {
137      true,
138      true,
139      true,
140      false,
141      true,
142      TestDataReductionProxyParams::HAS_DEV_ORIGIN |
143          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
144      true
145    },
146    {
147      true,
148      true,
149      true,
150      false,
151      true,
152      TestDataReductionProxyParams::HAS_ORIGIN,
153      true
154    },
155    {
156      true,
157      true,
158      true,
159      false,
160      true,
161      TestDataReductionProxyParams::HAS_ORIGIN |
162          TestDataReductionProxyParams::HAS_DEV_ORIGIN |
163          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
164      false
165    },
166    {
167      true,
168      true,
169      true,
170      false,
171      true,
172      TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN |
173          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
174      false
175    },
176    {
177      true,
178      true,
179      true,
180      false,
181      true,
182      TestDataReductionProxyParams::HAS_SSL_ORIGIN,
183      false
184    },
185    {
186      true,
187      true,
188      true,
189      false,
190      true,
191      TestDataReductionProxyParams::HAS_ALT_ORIGIN,
192      false
193    },
194    {
195      true,
196      true,
197      true,
198      false,
199      true,
200      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
201      true
202    },
203    {
204      true,
205      true,
206      true,
207      true,
208      true,
209      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
210      false
211    },
212    {
213      true,
214      true,
215      true,
216      false,
217      true,
218      TestDataReductionProxyParams::HAS_PROBE_URL,
219      false
220    },
221    {
222      true,
223      false,
224      true,
225      false,
226      true,
227      TestDataReductionProxyParams::HAS_NOTHING,
228      true
229    },
230    {
231      true,
232      false,
233      true,
234      false,
235      true,
236      TestDataReductionProxyParams::HAS_ORIGIN |
237          TestDataReductionProxyParams::HAS_DEV_ORIGIN |
238          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
239      false
240    },
241    {
242      true,
243      false,
244      true,
245      false,
246      true,
247      TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN,
248      true
249    },
250    {
251      true,
252      false,
253      true,
254      false,
255      true,
256      TestDataReductionProxyParams::HAS_SSL_ORIGIN,
257      false
258    },
259    {
260      true,
261      false,
262      true,
263      false,
264      true,
265      TestDataReductionProxyParams::HAS_ALT_ORIGIN,
266      false
267    },
268    {
269      true,
270      false,
271      true,
272      false,
273      true,
274      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
275      true
276    },
277    {
278      true,
279      false,
280      true,
281      true,
282      true,
283      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
284      false
285    },
286    {
287      true,
288      false,
289      true,
290      false,
291      true,
292      TestDataReductionProxyParams::HAS_PROBE_URL,
293      false
294    },
295    {
296      true,
297      true,
298      false,
299      false,
300      true,
301      TestDataReductionProxyParams::HAS_NOTHING,
302      true
303    },
304    {
305      true,
306      true,
307      false,
308      false,
309      true,
310      TestDataReductionProxyParams::HAS_ORIGIN |
311          TestDataReductionProxyParams::HAS_DEV_ORIGIN |
312          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
313      false
314    },
315    {
316      true,
317      true,
318      false,
319      false,
320      true,
321      TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN |
322          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
323      false
324    },
325    {
326      true,
327      true,
328      false,
329      false,
330      true,
331      TestDataReductionProxyParams::HAS_SSL_ORIGIN,
332      true
333    },
334    {
335      true,
336      true,
337      false,
338      false,
339      true,
340      TestDataReductionProxyParams::HAS_ALT_ORIGIN,
341      true
342    },
343    {
344      true,
345      true,
346      false,
347      false,
348      true,
349      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
350      true
351    },
352    {
353      true,
354      true,
355      false,
356      true,
357      true,
358      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
359      false
360    },
361    {
362      true,
363      true,
364      false,
365      false,
366      true,
367      TestDataReductionProxyParams::HAS_PROBE_URL,
368      false
369    },
370    {
371      true,
372      false,
373      false,
374      false,
375      true,
376      TestDataReductionProxyParams::HAS_ORIGIN |
377          TestDataReductionProxyParams::HAS_DEV_ORIGIN |
378          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
379      false
380    },
381    {
382      true,
383      false,
384      false,
385      false,
386      true,
387      TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN,
388      true
389    },
390    {
391      true,
392      false,
393      false,
394      false,
395      true,
396      TestDataReductionProxyParams::HAS_SSL_ORIGIN,
397      true
398    },
399    {
400      true,
401      false,
402      false,
403      false,
404      true,
405      TestDataReductionProxyParams::HAS_ALT_ORIGIN,
406      true
407    },
408    {
409      true,
410      false,
411      false,
412      false,
413      true,
414      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
415      true
416    },
417    {
418      true,
419      false,
420      false,
421      true,
422      true,
423      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
424      false
425    },
426    {
427      true,
428      false,
429      false,
430      false,
431      true,
432      TestDataReductionProxyParams::HAS_PROBE_URL,
433      false
434    },
435    {
436      false,
437      true,
438      true,
439      false,
440      true,
441      TestDataReductionProxyParams::HAS_NOTHING,
442      false
443    },
444    {
445      false,
446      true,
447      true,
448      false,
449      true,
450      TestDataReductionProxyParams::HAS_ORIGIN |
451          TestDataReductionProxyParams::HAS_DEV_ORIGIN |
452          TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
453      false
454    },
455    {
456      false,
457      true,
458      true,
459      false,
460      true,
461      TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN,
462      false
463    },
464    {
465      false,
466      true,
467      true,
468      false,
469      true,
470      TestDataReductionProxyParams::HAS_SSL_ORIGIN,
471      false
472    },
473    {
474      false,
475      true,
476      true,
477      false,
478      true,
479      TestDataReductionProxyParams::HAS_ALT_ORIGIN,
480      false
481    },
482    {
483      false,
484      true,
485      true,
486      false,
487      true,
488      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
489      false
490    },
491    {
492      false,
493      true,
494      true,
495      true,
496      true,
497      TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN,
498      false
499    },
500    {
501      false,
502      true,
503      true,
504      false,
505      true,
506      TestDataReductionProxyParams::HAS_PROBE_URL,
507      false
508    },
509  };
510
511  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
512    int flags = 0;
513    if (tests[i].allowed)
514      flags |= DataReductionProxyParams::kAllowed;
515    if (tests[i].fallback_allowed)
516      flags |= DataReductionProxyParams::kFallbackAllowed;
517    if (tests[i].alternative_allowed)
518      flags |= DataReductionProxyParams::kAlternativeAllowed;
519    if (tests[i].alternative_fallback_allowed)
520      flags |= DataReductionProxyParams::kAlternativeFallbackAllowed;
521    if (tests[i].promo_allowed)
522      flags |= DataReductionProxyParams::kPromoAllowed;
523    TestDataReductionProxyParams params(
524        flags,
525        TestDataReductionProxyParams::HAS_EVERYTHING &
526            ~(tests[i].missing_definitions));
527    EXPECT_EQ(tests[i].expected_result, params.init_result()) << i;
528  }
529}
530
531TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) {
532  const struct {
533    net::HostPortPair host_port_pair;
534    bool fallback_allowed;
535    bool alt_fallback_allowed;
536    bool set_dev_origin;
537    bool expected_result;
538    net::HostPortPair expected_first;
539    net::HostPortPair expected_second;
540    bool expected_is_fallback;
541    bool expected_is_alternative;
542    bool expected_is_ssl;
543  } tests[]  = {
544      {
545        net::HostPortPair::FromURL(GURL(
546            TestDataReductionProxyParams::DefaultOrigin())),
547        true,
548        true,
549        false,
550        true,
551        net::HostPortPair::FromURL(GURL(
552            TestDataReductionProxyParams::DefaultOrigin())),
553        net::HostPortPair::FromURL(GURL(
554            TestDataReductionProxyParams::DefaultFallbackOrigin())),
555        false,
556        false,
557        false
558      },
559      {
560        net::HostPortPair::FromURL(GURL(
561            TestDataReductionProxyParams::DefaultOrigin())),
562        false,
563        false,
564        false,
565        true,
566        net::HostPortPair::FromURL(GURL(
567            TestDataReductionProxyParams::DefaultOrigin())),
568        net::HostPortPair::FromURL(GURL()),
569        false,
570        false,
571        false
572      },
573      {
574        net::HostPortPair::FromURL(GURL(
575            TestDataReductionProxyParams::DefaultFallbackOrigin())),
576        true,
577        true,
578        false,
579        true,
580        net::HostPortPair::FromURL(GURL(
581            TestDataReductionProxyParams::DefaultFallbackOrigin())),
582        net::HostPortPair::FromURL(GURL()),
583        true,
584        false,
585        false
586      },
587      {
588        net::HostPortPair::FromURL(GURL(
589            TestDataReductionProxyParams::DefaultFallbackOrigin())),
590        false,
591        false,
592        false,
593        false,
594        net::HostPortPair::FromURL(GURL()),
595        net::HostPortPair::FromURL(GURL()),
596        false,
597        false,
598        false
599      },
600      {
601        net::HostPortPair::FromURL(GURL(
602            TestDataReductionProxyParams::DefaultAltOrigin())),
603        true,
604        true,
605        false,
606        true,
607        net::HostPortPair::FromURL(GURL(
608            TestDataReductionProxyParams::DefaultAltOrigin())),
609        net::HostPortPair::FromURL(GURL(
610            TestDataReductionProxyParams::DefaultAltFallbackOrigin())),
611        false,
612        true,
613        false
614      },
615      {
616        net::HostPortPair::FromURL(GURL(
617            TestDataReductionProxyParams::DefaultAltOrigin())),
618        false,
619        false,
620        false,
621        true,
622        net::HostPortPair::FromURL(GURL(
623            TestDataReductionProxyParams::DefaultAltOrigin())),
624        net::HostPortPair::FromURL(GURL()),
625        false,
626        true,
627        false
628      },
629      {
630        net::HostPortPair::FromURL(
631            GURL(TestDataReductionProxyParams::DefaultAltFallbackOrigin())),
632        true,
633        true,
634        false,
635        true,
636        net::HostPortPair::FromURL(GURL(
637            TestDataReductionProxyParams::DefaultAltFallbackOrigin())),
638        net::HostPortPair::FromURL(GURL()),
639        true,
640        true,
641        false
642      },
643      {
644        net::HostPortPair::FromURL(GURL(
645            TestDataReductionProxyParams::DefaultAltFallbackOrigin())),
646        false,
647        false,
648        false,
649        false,
650        net::HostPortPair::FromURL(GURL()),
651        net::HostPortPair::FromURL(GURL()),
652        false,
653        false,
654        false
655      },
656      {
657        net::HostPortPair::FromURL(GURL(
658            TestDataReductionProxyParams::DefaultSSLOrigin())),
659        true,
660        true,
661        false,
662        true,
663        net::HostPortPair::FromURL(GURL(
664            TestDataReductionProxyParams::DefaultSSLOrigin())),
665        net::HostPortPair::FromURL(GURL()),
666        false,
667        false,
668        true
669      },
670      {
671        net::HostPortPair::FromURL(GURL(
672            TestDataReductionProxyParams::DefaultDevOrigin())),
673        true,
674        true,
675        true,
676        true,
677        net::HostPortPair::FromURL(GURL(
678            TestDataReductionProxyParams::DefaultDevOrigin())),
679        net::HostPortPair::FromURL(GURL(
680            TestDataReductionProxyParams::DefaultDevFallbackOrigin())),
681        false,
682        false,
683        false
684      },
685      {
686        net::HostPortPair::FromURL(GURL(
687            TestDataReductionProxyParams::DefaultOrigin())),
688        true,
689        true,
690        true,
691        false,
692        net::HostPortPair::FromURL(GURL()),
693        net::HostPortPair::FromURL(GURL()),
694        false,
695        false,
696        false
697      },
698  };
699  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
700    int flags = DataReductionProxyParams::kAllowed |
701                DataReductionProxyParams::kAlternativeAllowed;
702    if (tests[i].fallback_allowed)
703      flags |= DataReductionProxyParams::kFallbackAllowed;
704    if (tests[i].alt_fallback_allowed)
705      flags |= DataReductionProxyParams::kAlternativeFallbackAllowed;
706    unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING;
707    if (!tests[i].set_dev_origin) {
708      has_definitions &= ~TestDataReductionProxyParams::HAS_DEV_ORIGIN;
709      has_definitions &= ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN;
710    }
711    TestDataReductionProxyParams params(flags, has_definitions);
712    DataReductionProxyTypeInfo proxy_type_info;
713    EXPECT_EQ(tests[i].expected_result,
714              params.IsDataReductionProxy(
715                  tests[i].host_port_pair, &proxy_type_info)) << i;
716    EXPECT_TRUE(tests[i].expected_first.Equals(
717        net::HostPortPair::FromURL(proxy_type_info.proxy_servers.first))) << i;
718    EXPECT_TRUE(tests[i].expected_second.Equals(
719        net::HostPortPair::FromURL(proxy_type_info.proxy_servers.second))) << i;
720    EXPECT_EQ(tests[i].expected_is_fallback, proxy_type_info.is_fallback) << i;
721    EXPECT_EQ(tests[i].expected_is_alternative, proxy_type_info.is_alternative)
722        << i;
723    EXPECT_EQ(tests[i].expected_is_ssl, proxy_type_info.is_ssl) << i;
724  }
725}
726
727std::string GetRetryMapKeyFromOrigin(std::string origin) {
728  // The retry map has the scheme prefix for https but not for http
729  return net::ProxyServer(GURL(origin).SchemeIs(url::kHttpsScheme) ?
730      net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP,
731      net::HostPortPair::FromURL(GURL(origin))).ToURI();
732}
733
734TEST_F(DataReductionProxyParamsTest, AreProxiesBypassed) {
735  const struct {
736    // proxy flags
737    bool allowed;
738    bool fallback_allowed;
739    bool alt_allowed;
740    // is https request
741    bool is_https;
742    // proxies in retry map
743    bool origin;
744    bool fallback_origin;
745    bool alt_origin;
746    bool alt_fallback_origin;
747    bool ssl_origin;
748
749    bool expected_result;
750  } tests[]  = {
751      { // proxy flags
752        false,
753        false,
754        false,
755        // is https request
756        false,
757        // proxies in retry map
758        false,
759        false,
760        false,
761        false,
762        false,
763        // expected result
764        false,
765      },
766      { // proxy flags
767        true,
768        false,
769        false,
770        // is https request
771        false,
772        // proxies in retry map
773        false,
774        false,
775        false,
776        false,
777        false,
778        // expected result
779        false,
780      },
781      { // proxy flags
782        true,
783        true,
784        false,
785        // is https request
786        false,
787        // proxies in retry map
788        false,
789        false,
790        false,
791        false,
792        false,
793        // expected result
794        false,
795      },
796      { // proxy flags
797        true,
798        true,
799        true,
800        // is https request
801        false,
802        // proxies in retry map
803        false,
804        false,
805        false,
806        false,
807        false,
808        // expected result
809        false,
810      },
811      { // proxy flags
812        true,
813        true,
814        true,
815        // is https request
816        true,
817        // proxies in retry map
818        false,
819        false,
820        false,
821        false,
822        false,
823        // expected result
824        false,
825      },
826      { // proxy flags
827        false,
828        false,
829        true,
830        // is https request
831        true,
832        // proxies in retry map
833        false,
834        false,
835        false,
836        false,
837        true,
838        // expected result
839        true,
840      },
841      { // proxy flags
842        true,
843        true,
844        true,
845        // is https request
846        true,
847        // proxies in retry map
848        false,
849        false,
850        false,
851        false,
852        true,
853        // expected result
854        true,
855      },
856      { // proxy flags
857        true,
858        false,
859        false,
860        // is https request
861        false,
862        // proxies in retry map
863        true,
864        false,
865        false,
866        false,
867        false,
868        // expected result
869        true,
870      },
871      { // proxy flags
872        true,
873        true,
874        false,
875        // is https request
876        false,
877        // proxies in retry map
878        false,
879        true,
880        false,
881        false,
882        false,
883        // expected result
884        true,
885      },
886      { // proxy flags
887        false,
888        true,
889        true,
890        // is https request
891        false,
892        // proxies in retry map
893        false,
894        false,
895        false,
896        true,
897        false,
898        // expected result
899        true,
900      },
901      { // proxy flags
902        true,
903        true,
904        false,
905        // is https request
906        false,
907        // proxies in retry map
908        true,
909        false,
910        false,
911        false,
912        false,
913        // expected result
914        false,
915      },
916      { // proxy flags
917        true,
918        true,
919        false,
920        // is https request
921        false,
922        // proxies in retry map
923        true,
924        true,
925        false,
926        false,
927        false,
928        // expected result
929        true,
930      },
931      { // proxy flags
932        true,
933        true,
934        true,
935        // is https request
936        false,
937        // proxies in retry map
938        true,
939        true,
940        false,
941        false,
942        false,
943        // expected result
944        true,
945      },
946      { // proxy flags
947        true,
948        true,
949        true,
950        // is https request
951        false,
952        // proxies in retry map
953        true,
954        false,
955        true,
956        false,
957        false,
958        // expected result
959        false,
960      },
961      { // proxy flags
962        true,
963        true,
964        true,
965        // is https request
966        false,
967        // proxies in retry map
968        false,
969        false,
970        true,
971        true,
972        false,
973        // expected result
974        true,
975      },
976      { // proxy flags
977        false,
978        true,
979        true,
980        // is https request
981        false,
982        // proxies in retry map
983        false,
984        false,
985        true,
986        true,
987        false,
988        // expected result
989        true,
990      },
991      { // proxy flags
992        false,
993        true,
994        false,
995        // is https request
996        false,
997        // proxies in retry map
998        false,
999        false,
1000        true,
1001        false,
1002        false,
1003        // expected result
1004        false,
1005      },
1006      { // proxy flags
1007        true,
1008        true,
1009        true,
1010        // is https request
1011        false,
1012        // proxies in retry map
1013        true,
1014        false,
1015        true,
1016        true,
1017        false,
1018        // expected result
1019        true,
1020      },
1021      { // proxy flags
1022        true,
1023        true,
1024        true,
1025        // is https request
1026        false,
1027        // proxies in retry map
1028        true,
1029        true,
1030        true,
1031        true,
1032        true,
1033        // expected result
1034        true,
1035      },
1036      { // proxy flags
1037        true,
1038        true,
1039        true,
1040        // is https request
1041        true,
1042        // proxies in retry map
1043        true,
1044        true,
1045        true,
1046        true,
1047        true,
1048        // expected result
1049        true,
1050      },
1051      { // proxy flags
1052        true,
1053        true,
1054        true,
1055        // is https request
1056        true,
1057        // proxies in retry map
1058        true,
1059        true,
1060        true,
1061        true,
1062        false,
1063        // expected result
1064        false,
1065      },
1066  };
1067
1068  // The retry map has the scheme prefix for https but not for http.
1069  std::string origin = GetRetryMapKeyFromOrigin(
1070      TestDataReductionProxyParams::DefaultOrigin());
1071  std::string fallback_origin =GetRetryMapKeyFromOrigin(
1072      TestDataReductionProxyParams::DefaultFallbackOrigin());
1073  std::string alt_origin = GetRetryMapKeyFromOrigin(
1074      TestDataReductionProxyParams::DefaultAltOrigin());
1075  std::string alt_fallback_origin = GetRetryMapKeyFromOrigin(
1076      TestDataReductionProxyParams::DefaultAltFallbackOrigin());
1077  std::string ssl_origin = GetRetryMapKeyFromOrigin(
1078      TestDataReductionProxyParams::DefaultSSLOrigin());
1079
1080  for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1081    int flags = 0;
1082    if (tests[i].allowed)
1083      flags |= DataReductionProxyParams::kAllowed;
1084    if (tests[i].alt_allowed)
1085      flags |= DataReductionProxyParams::kAlternativeAllowed;
1086    if (tests[i].fallback_allowed)
1087      flags |= DataReductionProxyParams::kFallbackAllowed;
1088    unsigned int has_definitions =
1089        TestDataReductionProxyParams::HAS_EVERYTHING &
1090        ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
1091        ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN;
1092    TestDataReductionProxyParams params(flags, has_definitions);
1093
1094    net::ProxyRetryInfoMap retry_map;
1095    net::ProxyRetryInfo retry_info;
1096
1097    if (tests[i].origin)
1098      retry_map[origin] = retry_info;
1099    if (tests[i].fallback_origin)
1100      retry_map[fallback_origin] = retry_info;
1101    if (tests[i].alt_origin)
1102      retry_map[alt_origin] = retry_info;
1103    if (tests[i].alt_fallback_origin)
1104      retry_map[alt_fallback_origin] = retry_info;
1105    if (tests[i].ssl_origin)
1106      retry_map[ssl_origin] = retry_info;
1107
1108    bool was_bypassed = params.AreProxiesBypassed(retry_map,
1109                                                  tests[i].is_https,
1110                                                  NULL);
1111
1112    EXPECT_EQ(tests[i].expected_result, was_bypassed);
1113  }
1114}
1115}  // namespace data_reduction_proxy
1116