| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te
st_utils.h" |
| 9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace { | |
| 13 // Test values to replacethe values specified in preprocessor defines. | |
| 14 static const char kDefaultKey[] = "test-key"; | |
| 15 static const char kDefaultDevOrigin[] = "https://dev.net:443/"; | |
| 16 static const char kDefaultOrigin[] = "https://origin.net:443/"; | |
| 17 static const char kDefaultFallbackOrigin[] = "http://fallback.net:80/"; | |
| 18 static const char kDefaultSSLOrigin[] = "http://ssl.net:1080/"; | |
| 19 static const char kDefaultAltOrigin[] = "https://alt.net:443/"; | |
| 20 static const char kDefaultAltFallbackOrigin[] = "http://altfallback.net:80/"; | |
| 21 static const char kDefaultProbeURL[] = "http://probe.net/"; | |
| 22 | |
| 23 static const char kFlagKey[] = "test-flag-key"; | |
| 24 static const char kFlagOrigin[] = "https://origin.org:443/"; | |
| 25 static const char kFlagFallbackOrigin[] = "http://fallback.org:80/"; | |
| 26 static const char kFlagSSLOrigin[] = "http://ssl.org:1080/"; | |
| 27 static const char kFlagAltOrigin[] = "https://alt.org:443/"; | |
| 28 static const char kFlagAltFallbackOrigin[] = "http://altfallback.org:80/"; | |
| 29 static const char kFlagProbeURL[] = "http://probe.org/"; | |
| 30 | |
| 31 // Used to emulate having constants defined by the preprocessor. | |
| 32 static const unsigned int HAS_NOTHING = 0x0; | |
| 33 static const unsigned int HAS_KEY = 0x1; | |
| 34 static const unsigned int HAS_DEV_ORIGIN = 0x2; | |
| 35 static const unsigned int HAS_ORIGIN = 0x4; | |
| 36 static const unsigned int HAS_FALLBACK_ORIGIN = 0x8; | |
| 37 static const unsigned int HAS_SSL_ORIGIN = 0x10; | |
| 38 static const unsigned int HAS_ALT_ORIGIN = 0x20; | |
| 39 static const unsigned int HAS_ALT_FALLBACK_ORIGIN = 0x40; | |
| 40 static const unsigned int HAS_PROBE_URL = 0x80; | |
| 41 static const unsigned int HAS_EVERYTHING = 0xff; | |
| 42 } // namespace | |
| 43 | |
| 44 namespace data_reduction_proxy { | 13 namespace data_reduction_proxy { |
| 45 namespace { | |
| 46 class TestDataReductionProxyParams : public DataReductionProxyParams { | |
| 47 public: | |
| 48 | |
| 49 TestDataReductionProxyParams(int flags, | |
| 50 unsigned int has_definitions) | |
| 51 : DataReductionProxyParams(flags, | |
| 52 false), | |
| 53 has_definitions_(has_definitions) { | |
| 54 init_result_ = Init(flags & DataReductionProxyParams::kAllowed, | |
| 55 flags & DataReductionProxyParams::kFallbackAllowed, | |
| 56 flags & DataReductionProxyParams::kAlternativeAllowed); | |
| 57 } | |
| 58 | |
| 59 bool init_result() const { | |
| 60 return init_result_; | |
| 61 } | |
| 62 | |
| 63 protected: | |
| 64 virtual std::string GetDefaultKey() const OVERRIDE { | |
| 65 return GetDefinition(HAS_KEY, kDefaultKey); | |
| 66 } | |
| 67 | |
| 68 virtual std::string GetDefaultDevOrigin() const OVERRIDE { | |
| 69 return GetDefinition(HAS_DEV_ORIGIN, kDefaultDevOrigin); | |
| 70 } | |
| 71 | |
| 72 virtual std::string GetDefaultOrigin() const OVERRIDE { | |
| 73 return GetDefinition(HAS_ORIGIN, kDefaultOrigin); | |
| 74 } | |
| 75 | |
| 76 virtual std::string GetDefaultFallbackOrigin() const OVERRIDE { | |
| 77 return GetDefinition(HAS_FALLBACK_ORIGIN, kDefaultFallbackOrigin); | |
| 78 } | |
| 79 | |
| 80 virtual std::string GetDefaultSSLOrigin() const OVERRIDE { | |
| 81 return GetDefinition(HAS_SSL_ORIGIN, kDefaultSSLOrigin); | |
| 82 } | |
| 83 | |
| 84 virtual std::string GetDefaultAltOrigin() const OVERRIDE { | |
| 85 return GetDefinition(HAS_ALT_ORIGIN, kDefaultAltOrigin); | |
| 86 } | |
| 87 | |
| 88 virtual std::string GetDefaultAltFallbackOrigin() const OVERRIDE { | |
| 89 return GetDefinition(HAS_ALT_FALLBACK_ORIGIN, kDefaultAltFallbackOrigin); | |
| 90 } | |
| 91 | |
| 92 virtual std::string GetDefaultProbeURL() const OVERRIDE { | |
| 93 return GetDefinition(HAS_PROBE_URL, kDefaultProbeURL); | |
| 94 } | |
| 95 | |
| 96 private: | |
| 97 std::string GetDefinition(unsigned int has_def, | |
| 98 const std::string& definition) const { | |
| 99 return ((has_definitions_ & has_def) ? definition : std::string()); | |
| 100 } | |
| 101 | |
| 102 unsigned int has_definitions_; | |
| 103 bool init_result_; | |
| 104 }; | |
| 105 } // namespace | |
| 106 | |
| 107 class DataReductionProxyParamsTest : public testing::Test { | 14 class DataReductionProxyParamsTest : public testing::Test { |
| 108 public: | 15 public: |
| 109 void CheckParams(const TestDataReductionProxyParams& params, | 16 void CheckParams(const TestDataReductionProxyParams& params, |
| 110 bool expected_init_result, | 17 bool expected_init_result, |
| 111 bool expected_allowed, | 18 bool expected_allowed, |
| 112 bool expected_fallback_allowed, | 19 bool expected_fallback_allowed, |
| 113 bool expected_alternative_allowed, | 20 bool expected_alternative_allowed, |
| 114 bool expected_promo_allowed) { | 21 bool expected_promo_allowed) { |
| 115 EXPECT_EQ(expected_init_result, params.init_result()); | 22 EXPECT_EQ(expected_init_result, params.init_result()); |
| 116 EXPECT_EQ(expected_allowed, params.allowed()); | 23 EXPECT_EQ(expected_allowed, params.allowed()); |
| 117 EXPECT_EQ(expected_fallback_allowed, params.fallback_allowed()); | 24 EXPECT_EQ(expected_fallback_allowed, params.fallback_allowed()); |
| 118 EXPECT_EQ(expected_alternative_allowed, params.alternative_allowed()); | 25 EXPECT_EQ(expected_alternative_allowed, params.alternative_allowed()); |
| 119 EXPECT_EQ(expected_promo_allowed, params.promo_allowed()); | 26 EXPECT_EQ(expected_promo_allowed, params.promo_allowed()); |
| 120 } | 27 } |
| 121 void CheckValues(const TestDataReductionProxyParams& params, | 28 void CheckValues(const TestDataReductionProxyParams& params, |
| 122 const std::string expected_key, | |
| 123 const std::string& expected_origin, | 29 const std::string& expected_origin, |
| 124 const std::string& expected_fallback_origin, | 30 const std::string& expected_fallback_origin, |
| 125 const std::string& expected_ssl_origin, | 31 const std::string& expected_ssl_origin, |
| 126 const std::string& expected_alt_origin, | 32 const std::string& expected_alt_origin, |
| 127 const std::string& expected_alt_fallback_origin, | 33 const std::string& expected_alt_fallback_origin, |
| 128 const std::string& expected_probe_url) { | 34 const std::string& expected_probe_url) { |
| 129 EXPECT_EQ(expected_key, params.key()); | |
| 130 EXPECT_EQ(GURL(expected_origin), params.origin()); | 35 EXPECT_EQ(GURL(expected_origin), params.origin()); |
| 131 EXPECT_EQ(GURL(expected_fallback_origin), params.fallback_origin()); | 36 EXPECT_EQ(GURL(expected_fallback_origin), params.fallback_origin()); |
| 132 EXPECT_EQ(GURL(expected_ssl_origin), params.ssl_origin()); | 37 EXPECT_EQ(GURL(expected_ssl_origin), params.ssl_origin()); |
| 133 EXPECT_EQ(GURL(expected_alt_origin), params.alt_origin()); | 38 EXPECT_EQ(GURL(expected_alt_origin), params.alt_origin()); |
| 134 EXPECT_EQ(GURL(expected_alt_fallback_origin), params.alt_fallback_origin()); | 39 EXPECT_EQ(GURL(expected_alt_fallback_origin), params.alt_fallback_origin()); |
| 135 EXPECT_EQ(GURL(expected_probe_url), params.probe_url()); | 40 EXPECT_EQ(GURL(expected_probe_url), params.probe_url()); |
| 136 } | 41 } |
| 137 }; | 42 }; |
| 138 | 43 |
| 139 TEST_F(DataReductionProxyParamsTest, EverythingDefined) { | 44 TEST_F(DataReductionProxyParamsTest, EverythingDefined) { |
| 140 TestDataReductionProxyParams params( | 45 TestDataReductionProxyParams params( |
| 141 DataReductionProxyParams::kAllowed | | 46 DataReductionProxyParams::kAllowed | |
| 142 DataReductionProxyParams::kFallbackAllowed | | 47 DataReductionProxyParams::kFallbackAllowed | |
| 143 DataReductionProxyParams::kPromoAllowed, HAS_EVERYTHING); | 48 DataReductionProxyParams::kPromoAllowed, |
| 49 TestDataReductionProxyParams::HAS_EVERYTHING); |
| 144 CheckParams(params, true, true, true, false, true); | 50 CheckParams(params, true, true, true, false, true); |
| 145 CheckValues(params, | 51 CheckValues(params, |
| 146 kDefaultKey, | 52 TestDataReductionProxyParams::DefaultDevOrigin(), |
| 147 kDefaultDevOrigin, | 53 TestDataReductionProxyParams::DefaultFallbackOrigin(), |
| 148 kDefaultFallbackOrigin, | 54 TestDataReductionProxyParams::DefaultSSLOrigin(), |
| 149 kDefaultSSLOrigin, | 55 TestDataReductionProxyParams::DefaultAltOrigin(), |
| 150 kDefaultAltOrigin, | 56 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), |
| 151 kDefaultAltFallbackOrigin, | 57 TestDataReductionProxyParams::DefaultProbeURL()); |
| 152 kDefaultProbeURL); | |
| 153 } | 58 } |
| 154 | 59 |
| 155 TEST_F(DataReductionProxyParamsTest, NoDevOrigin) { | 60 TEST_F(DataReductionProxyParamsTest, NoDevOrigin) { |
| 156 TestDataReductionProxyParams params( | 61 TestDataReductionProxyParams params( |
| 157 DataReductionProxyParams::kAllowed | | 62 DataReductionProxyParams::kAllowed | |
| 158 DataReductionProxyParams::kFallbackAllowed | | 63 DataReductionProxyParams::kFallbackAllowed | |
| 159 DataReductionProxyParams::kPromoAllowed, | 64 DataReductionProxyParams::kPromoAllowed, |
| 160 HAS_EVERYTHING & ~HAS_DEV_ORIGIN); | 65 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 66 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
| 161 CheckParams(params, true, true, true, false, true); | 67 CheckParams(params, true, true, true, false, true); |
| 162 CheckValues(params, | 68 CheckValues(params, |
| 163 kDefaultKey, | 69 TestDataReductionProxyParams::DefaultOrigin(), |
| 164 kDefaultOrigin, | 70 TestDataReductionProxyParams::DefaultFallbackOrigin(), |
| 165 kDefaultFallbackOrigin, | 71 TestDataReductionProxyParams::DefaultSSLOrigin(), |
| 166 kDefaultSSLOrigin, | 72 TestDataReductionProxyParams::DefaultAltOrigin(), |
| 167 kDefaultAltOrigin, | 73 TestDataReductionProxyParams::DefaultAltFallbackOrigin(), |
| 168 kDefaultAltFallbackOrigin, | 74 TestDataReductionProxyParams::DefaultProbeURL()); |
| 169 kDefaultProbeURL); | |
| 170 } | 75 } |
| 171 | 76 |
| 172 TEST_F(DataReductionProxyParamsTest, Flags) { | 77 TEST_F(DataReductionProxyParamsTest, Flags) { |
| 173 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 78 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 174 switches::kDataReductionProxyKey, kFlagKey); | 79 switches::kDataReductionProxy, |
| 80 TestDataReductionProxyParams::FlagOrigin()); |
| 175 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 81 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 176 switches::kDataReductionProxy, kFlagOrigin); | 82 switches::kDataReductionProxyFallback, |
| 83 TestDataReductionProxyParams::FlagFallbackOrigin()); |
| 177 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 178 switches::kDataReductionProxyFallback, kFlagFallbackOrigin); | 85 switches::kDataReductionSSLProxy, |
| 86 TestDataReductionProxyParams::FlagSSLOrigin()); |
| 179 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 87 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 180 switches::kDataReductionSSLProxy, kFlagSSLOrigin); | 88 switches::kDataReductionProxyAlt, |
| 89 TestDataReductionProxyParams::FlagAltOrigin()); |
| 181 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 90 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 182 switches::kDataReductionProxyAlt, kFlagAltOrigin); | 91 switches::kDataReductionProxyAltFallback, |
| 92 TestDataReductionProxyParams::FlagAltFallbackOrigin()); |
| 183 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 93 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 184 switches::kDataReductionProxyAltFallback, kFlagAltFallbackOrigin); | 94 switches::kDataReductionProxyProbeURL, |
| 185 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 95 TestDataReductionProxyParams::FlagProbeURL()); |
| 186 switches::kDataReductionProxyProbeURL, kFlagProbeURL); | |
| 187 TestDataReductionProxyParams params( | 96 TestDataReductionProxyParams params( |
| 188 DataReductionProxyParams::kAllowed | | 97 DataReductionProxyParams::kAllowed | |
| 189 DataReductionProxyParams::kFallbackAllowed | | 98 DataReductionProxyParams::kFallbackAllowed | |
| 190 DataReductionProxyParams::kAlternativeAllowed | | 99 DataReductionProxyParams::kAlternativeAllowed | |
| 191 DataReductionProxyParams::kPromoAllowed, HAS_EVERYTHING); | 100 DataReductionProxyParams::kPromoAllowed, |
| 101 TestDataReductionProxyParams::HAS_EVERYTHING); |
| 192 CheckParams(params, true, true, true, true, true); | 102 CheckParams(params, true, true, true, true, true); |
| 193 CheckValues(params, | 103 CheckValues(params, |
| 194 kFlagKey, | 104 TestDataReductionProxyParams::FlagOrigin(), |
| 195 kFlagOrigin, | 105 TestDataReductionProxyParams::FlagFallbackOrigin(), |
| 196 kFlagFallbackOrigin, | 106 TestDataReductionProxyParams::FlagSSLOrigin(), |
| 197 kFlagSSLOrigin, | 107 TestDataReductionProxyParams::FlagAltOrigin(), |
| 198 kFlagAltOrigin, | 108 TestDataReductionProxyParams::FlagAltFallbackOrigin(), |
| 199 kFlagAltFallbackOrigin, | 109 TestDataReductionProxyParams::FlagProbeURL()); |
| 200 kFlagProbeURL); | |
| 201 } | 110 } |
| 202 | 111 |
| 203 TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) { | 112 TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) { |
| 204 const struct { | 113 const struct { |
| 205 bool allowed; | 114 bool allowed; |
| 206 bool fallback_allowed; | 115 bool fallback_allowed; |
| 207 bool alternative_allowed; | 116 bool alternative_allowed; |
| 208 bool promo_allowed; | 117 bool promo_allowed; |
| 209 unsigned int missing_definitions; | 118 unsigned int missing_definitions; |
| 210 bool expected_result; | 119 bool expected_result; |
| 211 } tests[] = { | 120 } tests[] = { |
| 212 { true, true, true, true, HAS_NOTHING, true }, | 121 { |
| 213 { true, true, true, true, HAS_KEY, true }, | 122 true, |
| 214 { true, true, true, true, HAS_DEV_ORIGIN, true }, | 123 true, |
| 215 { true, true, true, true, HAS_ORIGIN, true }, | 124 true, |
| 216 { true, true, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, | 125 true, |
| 217 { true, true, true, true, HAS_FALLBACK_ORIGIN, false }, | 126 TestDataReductionProxyParams::HAS_NOTHING, |
| 218 { true, true, true, true, HAS_SSL_ORIGIN, false }, | 127 true |
| 219 { true, true, true, true, HAS_ALT_ORIGIN, false }, | 128 }, |
| 220 { true, true, true, true, HAS_ALT_FALLBACK_ORIGIN, false }, | 129 { |
| 221 { true, true, true, true, HAS_PROBE_URL, false }, | 130 true, |
| 131 true, |
| 132 true, |
| 133 true, |
| 134 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 135 true |
| 136 }, |
| 137 { |
| 138 true, |
| 139 true, |
| 140 true, |
| 141 true, |
| 142 TestDataReductionProxyParams::HAS_ORIGIN, |
| 143 true |
| 144 }, |
| 145 { |
| 146 true, |
| 147 true, |
| 148 true, |
| 149 true, |
| 150 TestDataReductionProxyParams::HAS_ORIGIN | |
| 151 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 152 false |
| 153 }, |
| 154 { true, |
| 155 true, |
| 156 true, |
| 157 true, |
| 158 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
| 159 false |
| 160 }, |
| 161 { true, |
| 162 true, |
| 163 true, |
| 164 true, |
| 165 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
| 166 false |
| 167 }, |
| 168 { true, |
| 169 true, |
| 170 true, |
| 171 true, |
| 172 TestDataReductionProxyParams::HAS_ALT_ORIGIN, |
| 173 false |
| 174 }, |
| 175 { true, |
| 176 true, |
| 177 true, |
| 178 true, |
| 179 TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN, |
| 180 false |
| 181 }, |
| 182 { true, |
| 183 true, |
| 184 true, |
| 185 true, |
| 186 TestDataReductionProxyParams::HAS_PROBE_URL, |
| 187 false |
| 188 }, |
| 189 { |
| 190 true, |
| 191 false, |
| 192 true, |
| 193 true, |
| 194 TestDataReductionProxyParams::HAS_NOTHING, |
| 195 true |
| 196 }, |
| 197 { |
| 198 true, |
| 199 false, |
| 200 true, |
| 201 true, |
| 202 TestDataReductionProxyParams::HAS_ORIGIN | |
| 203 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 204 false |
| 205 }, |
| 206 { |
| 207 true, |
| 208 false, |
| 209 true, |
| 210 true, |
| 211 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
| 212 true |
| 213 }, |
| 214 { |
| 215 true, |
| 216 false, |
| 217 true, |
| 218 true, |
| 219 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
| 220 false |
| 221 }, |
| 222 { |
| 223 true, |
| 224 false, |
| 225 true, |
| 226 true, |
| 227 TestDataReductionProxyParams::HAS_ALT_ORIGIN, |
| 228 false |
| 229 }, |
| 230 { |
| 231 true, |
| 232 false, |
| 233 true, |
| 234 true, |
| 235 TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN, |
| 236 true |
| 237 }, |
| 238 { |
| 239 true, |
| 240 false, |
| 241 true, |
| 242 true, |
| 243 TestDataReductionProxyParams::HAS_PROBE_URL, |
| 244 false |
| 245 }, |
| 222 | 246 |
| 223 { true, false, true, true, HAS_NOTHING, true }, | 247 { |
| 224 { true, false, true, true, HAS_KEY, true }, | 248 true, |
| 225 { true, false, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, | 249 true, |
| 226 { true, false, true, true, HAS_FALLBACK_ORIGIN, true }, | 250 false, |
| 227 { true, false, true, true, HAS_SSL_ORIGIN, false }, | 251 true, |
| 228 { true, false, true, true, HAS_ALT_ORIGIN, false }, | 252 TestDataReductionProxyParams::HAS_NOTHING, |
| 229 { true, false, true, true, HAS_ALT_FALLBACK_ORIGIN, true }, | 253 true |
| 230 { true, false, true, true, HAS_PROBE_URL, false }, | 254 }, |
| 231 | 255 { |
| 232 { true, true, false, true, HAS_NOTHING, true }, | 256 true, |
| 233 { true, true, false, true, HAS_KEY, true }, | 257 true, |
| 234 { true, true, false, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, | 258 false, |
| 235 { true, true, false, true, HAS_FALLBACK_ORIGIN, false }, | 259 true, |
| 236 { true, true, false, true, HAS_SSL_ORIGIN, true }, | 260 TestDataReductionProxyParams::HAS_ORIGIN | |
| 237 { true, true, false, true, HAS_ALT_ORIGIN, true }, | 261 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 238 { true, true, false, true, HAS_ALT_FALLBACK_ORIGIN, true }, | 262 false |
| 239 { true, true, false, true, HAS_PROBE_URL, false }, | 263 }, |
| 240 | 264 { |
| 241 { true, false, false, true, HAS_KEY, true }, | 265 true, |
| 242 { true, false, false, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, | 266 true, |
| 243 { true, false, false, true, HAS_FALLBACK_ORIGIN, true }, | 267 false, |
| 244 { true, false, false, true, HAS_SSL_ORIGIN, true }, | 268 true, |
| 245 { true, false, false, true, HAS_ALT_ORIGIN, true }, | 269 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
| 246 { true, false, false, true, HAS_ALT_FALLBACK_ORIGIN, true }, | 270 false |
| 247 { true, false, false, true, HAS_PROBE_URL, false }, | 271 }, |
| 248 | 272 { |
| 249 { false, true, true, true, HAS_NOTHING, false }, | 273 true, |
| 250 { false, true, true, true, HAS_KEY, false }, | 274 true, |
| 251 { false, true, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, | 275 false, |
| 252 { false, true, true, true, HAS_FALLBACK_ORIGIN, false }, | 276 true, |
| 253 { false, true, true, true, HAS_SSL_ORIGIN, false }, | 277 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
| 254 { false, true, true, true, HAS_ALT_ORIGIN, false }, | 278 true |
| 255 { false, true, true, true, HAS_ALT_FALLBACK_ORIGIN, false }, | 279 }, |
| 256 { false, true, true, true, HAS_PROBE_URL, false }, | 280 { |
| 281 true, |
| 282 true, |
| 283 false, |
| 284 true, |
| 285 TestDataReductionProxyParams::HAS_ALT_ORIGIN, |
| 286 true |
| 287 }, |
| 288 { |
| 289 true, |
| 290 true, |
| 291 false, |
| 292 true, |
| 293 TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN, |
| 294 true |
| 295 }, |
| 296 { |
| 297 true, |
| 298 true, |
| 299 false, |
| 300 true, |
| 301 TestDataReductionProxyParams::HAS_PROBE_URL, |
| 302 false |
| 303 }, |
| 304 { |
| 305 true, |
| 306 false, |
| 307 false, |
| 308 true, |
| 309 TestDataReductionProxyParams::HAS_ORIGIN | |
| 310 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 311 false |
| 312 }, |
| 313 { |
| 314 true, |
| 315 false, |
| 316 false, |
| 317 true, |
| 318 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
| 319 true |
| 320 }, |
| 321 { |
| 322 true, |
| 323 false, |
| 324 false, |
| 325 true, |
| 326 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
| 327 true |
| 328 }, |
| 329 { |
| 330 true, |
| 331 false, |
| 332 false, |
| 333 true, |
| 334 TestDataReductionProxyParams::HAS_ALT_ORIGIN, |
| 335 true |
| 336 }, |
| 337 { |
| 338 true, |
| 339 false, |
| 340 false, |
| 341 true, |
| 342 TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN, |
| 343 true |
| 344 }, |
| 345 { |
| 346 true, |
| 347 false, |
| 348 false, |
| 349 true, |
| 350 TestDataReductionProxyParams::HAS_PROBE_URL, |
| 351 false |
| 352 }, |
| 353 { |
| 354 false, |
| 355 true, |
| 356 true, |
| 357 true, |
| 358 TestDataReductionProxyParams::HAS_NOTHING, |
| 359 false |
| 360 }, |
| 361 { |
| 362 false, |
| 363 true, |
| 364 true, |
| 365 true, |
| 366 TestDataReductionProxyParams::HAS_ORIGIN | |
| 367 TestDataReductionProxyParams::HAS_DEV_ORIGIN, |
| 368 false |
| 369 }, |
| 370 { |
| 371 false, |
| 372 true, |
| 373 true, |
| 374 true, |
| 375 TestDataReductionProxyParams::HAS_FALLBACK_ORIGIN, |
| 376 false |
| 377 }, |
| 378 { |
| 379 false, |
| 380 true, |
| 381 true, |
| 382 true, |
| 383 TestDataReductionProxyParams::HAS_SSL_ORIGIN, |
| 384 false |
| 385 }, |
| 386 { |
| 387 false, |
| 388 true, |
| 389 true, |
| 390 true, |
| 391 TestDataReductionProxyParams::HAS_ALT_ORIGIN, |
| 392 false |
| 393 }, |
| 394 { |
| 395 false, |
| 396 true, |
| 397 true, |
| 398 true, |
| 399 TestDataReductionProxyParams::HAS_ALT_FALLBACK_ORIGIN, |
| 400 false |
| 401 }, |
| 402 { |
| 403 false, |
| 404 true, |
| 405 true, |
| 406 true, |
| 407 TestDataReductionProxyParams::HAS_PROBE_URL, |
| 408 false |
| 409 }, |
| 257 }; | 410 }; |
| 258 | 411 |
| 259 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 412 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 260 int flags = 0; | 413 int flags = 0; |
| 261 if (tests[i].allowed) | 414 if (tests[i].allowed) |
| 262 flags |= DataReductionProxyParams::kAllowed; | 415 flags |= DataReductionProxyParams::kAllowed; |
| 263 if (tests[i].fallback_allowed) | 416 if (tests[i].fallback_allowed) |
| 264 flags |= DataReductionProxyParams::kFallbackAllowed; | 417 flags |= DataReductionProxyParams::kFallbackAllowed; |
| 265 if (tests[i].alternative_allowed) | 418 if (tests[i].alternative_allowed) |
| 266 flags |= DataReductionProxyParams::kAlternativeAllowed; | 419 flags |= DataReductionProxyParams::kAlternativeAllowed; |
| 267 if (tests[i].promo_allowed) | 420 if (tests[i].promo_allowed) |
| 268 flags |= DataReductionProxyParams::kPromoAllowed; | 421 flags |= DataReductionProxyParams::kPromoAllowed; |
| 269 TestDataReductionProxyParams params( | 422 TestDataReductionProxyParams params( |
| 270 flags, | 423 flags, |
| 271 HAS_EVERYTHING & ~(tests[i].missing_definitions)); | 424 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 425 ~(tests[i].missing_definitions)); |
| 272 EXPECT_EQ(tests[i].expected_result, params.init_result()); | 426 EXPECT_EQ(tests[i].expected_result, params.init_result()); |
| 273 } | 427 } |
| 274 } | 428 } |
| 275 | 429 |
| 276 TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { | 430 TEST_F(DataReductionProxyParamsTest, IsDataReductionProxy) { |
| 277 const struct { | 431 const struct { |
| 278 net::HostPortPair host_port_pair; | 432 net::HostPortPair host_port_pair; |
| 279 bool fallback_allowed; | 433 bool fallback_allowed; |
| 280 bool expected_result; | 434 bool expected_result; |
| 281 net::HostPortPair expected_first; | 435 net::HostPortPair expected_first; |
| 282 net::HostPortPair expected_second; | 436 net::HostPortPair expected_second; |
| 283 } tests[] = { | 437 } tests[] = { |
| 284 { net::HostPortPair::FromURL(GURL(kDefaultOrigin)), | 438 { net::HostPortPair::FromURL(GURL( |
| 439 TestDataReductionProxyParams::DefaultOrigin())), |
| 285 true, | 440 true, |
| 286 true, | 441 true, |
| 287 net::HostPortPair::FromURL(GURL(kDefaultOrigin)), | 442 net::HostPortPair::FromURL(GURL( |
| 288 net::HostPortPair::FromURL(GURL(kDefaultFallbackOrigin)) | 443 TestDataReductionProxyParams::DefaultOrigin())), |
| 444 net::HostPortPair::FromURL(GURL( |
| 445 TestDataReductionProxyParams::DefaultFallbackOrigin())) |
| 289 }, | 446 }, |
| 290 { net::HostPortPair::FromURL(GURL(kDefaultOrigin)), | 447 { net::HostPortPair::FromURL(GURL( |
| 448 TestDataReductionProxyParams::DefaultOrigin())), |
| 291 false, | 449 false, |
| 292 true, | 450 true, |
| 293 net::HostPortPair::FromURL(GURL(kDefaultOrigin)), | 451 net::HostPortPair::FromURL(GURL( |
| 452 TestDataReductionProxyParams::DefaultOrigin())), |
| 294 net::HostPortPair::FromURL(GURL()) | 453 net::HostPortPair::FromURL(GURL()) |
| 295 }, | 454 }, |
| 296 { net::HostPortPair::FromURL(GURL(kDefaultFallbackOrigin)), | 455 { net::HostPortPair::FromURL(GURL( |
| 456 TestDataReductionProxyParams::DefaultFallbackOrigin())), |
| 297 true, | 457 true, |
| 298 true, | 458 true, |
| 299 net::HostPortPair::FromURL(GURL(kDefaultFallbackOrigin)), | 459 net::HostPortPair::FromURL(GURL( |
| 460 TestDataReductionProxyParams::DefaultFallbackOrigin())), |
| 300 net::HostPortPair::FromURL(GURL()) | 461 net::HostPortPair::FromURL(GURL()) |
| 301 }, | 462 }, |
| 302 { net::HostPortPair::FromURL(GURL(kDefaultFallbackOrigin)), | 463 { net::HostPortPair::FromURL(GURL( |
| 464 TestDataReductionProxyParams::DefaultFallbackOrigin())), |
| 303 false, | 465 false, |
| 304 false, | 466 false, |
| 305 net::HostPortPair::FromURL(GURL()), | 467 net::HostPortPair::FromURL(GURL()), |
| 306 net::HostPortPair::FromURL(GURL()) | 468 net::HostPortPair::FromURL(GURL()) |
| 307 }, | 469 }, |
| 308 { net::HostPortPair::FromURL(GURL(kDefaultAltOrigin)), | 470 { net::HostPortPair::FromURL(GURL( |
| 471 TestDataReductionProxyParams::DefaultAltOrigin())), |
| 309 true, | 472 true, |
| 310 true, | 473 true, |
| 311 net::HostPortPair::FromURL(GURL(kDefaultAltOrigin)), | 474 net::HostPortPair::FromURL(GURL( |
| 312 net::HostPortPair::FromURL(GURL(kDefaultAltFallbackOrigin)) | 475 TestDataReductionProxyParams::DefaultAltOrigin())), |
| 476 net::HostPortPair::FromURL(GURL( |
| 477 TestDataReductionProxyParams::DefaultAltFallbackOrigin())) |
| 313 }, | 478 }, |
| 314 { net::HostPortPair::FromURL(GURL(kDefaultAltOrigin)), | 479 { net::HostPortPair::FromURL(GURL( |
| 480 TestDataReductionProxyParams::DefaultAltOrigin())), |
| 315 false, | 481 false, |
| 316 true, | 482 true, |
| 317 net::HostPortPair::FromURL(GURL(kDefaultAltOrigin)), | 483 net::HostPortPair::FromURL(GURL( |
| 484 TestDataReductionProxyParams::DefaultAltOrigin())), |
| 318 net::HostPortPair::FromURL(GURL()) | 485 net::HostPortPair::FromURL(GURL()) |
| 319 }, | 486 }, |
| 320 { net::HostPortPair::FromURL(GURL(kDefaultAltFallbackOrigin)), | 487 { net::HostPortPair::FromURL( |
| 488 GURL(TestDataReductionProxyParams::DefaultAltFallbackOrigin())), |
| 321 true, | 489 true, |
| 322 true, | 490 true, |
| 323 net::HostPortPair::FromURL(GURL(kDefaultAltFallbackOrigin)), | 491 net::HostPortPair::FromURL(GURL( |
| 492 TestDataReductionProxyParams::DefaultAltFallbackOrigin())), |
| 324 net::HostPortPair::FromURL(GURL()) | 493 net::HostPortPair::FromURL(GURL()) |
| 325 }, | 494 }, |
| 326 { net::HostPortPair::FromURL(GURL(kDefaultAltFallbackOrigin)), | 495 { net::HostPortPair::FromURL(GURL( |
| 496 TestDataReductionProxyParams::DefaultAltFallbackOrigin())), |
| 327 false, | 497 false, |
| 328 false, | 498 false, |
| 329 net::HostPortPair::FromURL(GURL()), | 499 net::HostPortPair::FromURL(GURL()), |
| 330 net::HostPortPair::FromURL(GURL()) | 500 net::HostPortPair::FromURL(GURL()) |
| 331 }, | 501 }, |
| 332 { net::HostPortPair::FromURL(GURL(kDefaultSSLOrigin)), | 502 { net::HostPortPair::FromURL(GURL( |
| 503 TestDataReductionProxyParams::DefaultSSLOrigin())), |
| 333 true, | 504 true, |
| 334 true, | 505 true, |
| 335 net::HostPortPair::FromURL(GURL(kDefaultSSLOrigin)), | 506 net::HostPortPair::FromURL(GURL( |
| 507 TestDataReductionProxyParams::DefaultSSLOrigin())), |
| 336 net::HostPortPair::FromURL(GURL()) | 508 net::HostPortPair::FromURL(GURL()) |
| 337 }, | 509 }, |
| 338 }; | 510 }; |
| 339 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 511 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 340 int flags = DataReductionProxyParams::kAllowed | | 512 int flags = DataReductionProxyParams::kAllowed | |
| 341 DataReductionProxyParams::kAlternativeAllowed; | 513 DataReductionProxyParams::kAlternativeAllowed; |
| 342 if (tests[i].fallback_allowed) | 514 if (tests[i].fallback_allowed) |
| 343 flags |= DataReductionProxyParams::kFallbackAllowed; | 515 flags |= DataReductionProxyParams::kFallbackAllowed; |
| 344 TestDataReductionProxyParams params(flags, | 516 TestDataReductionProxyParams params( |
| 345 HAS_EVERYTHING & ~HAS_DEV_ORIGIN); | 517 flags, |
| 518 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 519 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
| 346 std::pair<GURL, GURL> proxy_servers; | 520 std::pair<GURL, GURL> proxy_servers; |
| 347 EXPECT_EQ(tests[i].expected_result, | 521 EXPECT_EQ(tests[i].expected_result, |
| 348 params.IsDataReductionProxy( | 522 params.IsDataReductionProxy( |
| 349 tests[i].host_port_pair, &proxy_servers)); | 523 tests[i].host_port_pair, &proxy_servers)); |
| 350 EXPECT_TRUE(tests[i].expected_first.Equals( | 524 EXPECT_TRUE(tests[i].expected_first.Equals( |
| 351 net::HostPortPair::FromURL(proxy_servers.first))); | 525 net::HostPortPair::FromURL(proxy_servers.first))); |
| 352 EXPECT_TRUE(tests[i].expected_second.Equals( | 526 EXPECT_TRUE(tests[i].expected_second.Equals( |
| 353 net::HostPortPair::FromURL(proxy_servers.second))); | 527 net::HostPortPair::FromURL(proxy_servers.second))); |
| 354 } | 528 } |
| 355 } | 529 } |
| 356 | |
| 357 } // namespace data_reduction_proxy | 530 } // namespace data_reduction_proxy |
| OLD | NEW |