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_settings.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_
test_utils.h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_
test_utils.h" |
12 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
14 #include "net/http/http_auth.h" | 15 #include "net/http/http_auth.h" |
15 #include "net/http/http_auth_cache.h" | 16 #include "net/http/http_auth_cache.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char kDataReductionProxy[] = "https://foo.com:443/"; | 23 const char kDataReductionProxy[] = "https://foo.com:443/"; |
23 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; | 24 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; |
24 const char kDataReductionProxyFallback[] = "http://bar.com:80"; | 25 const char kDataReductionProxyFallback[] = "http://bar.com:80"; |
25 const char kDataReductionProxyKey[] = "12345"; | 26 const char kDataReductionProxyKey[] = "12345"; |
| 27 const char kDataReductionProxyAlt[] = "https://alt.com:443/"; |
| 28 const char kDataReductionProxyAltFallback[] = "http://alt2.com:80"; |
| 29 const char kDataReductionProxySSL[] = "http://ssl.com:80"; |
26 | 30 |
27 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 31 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
28 const char kProbeURLWithBadResponse[] = "http://bad.org/"; | 32 const char kProbeURLWithBadResponse[] = "http://bad.org/"; |
29 const char kProbeURLWithNoResponse[] = "http://no.org/"; | 33 const char kProbeURLWithNoResponse[] = "http://no.org/"; |
30 | 34 |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 namespace data_reduction_proxy { | 37 namespace data_reduction_proxy { |
34 | 38 |
35 class DataReductionProxySettingsTest | 39 class DataReductionProxySettingsTest |
36 : public ConcreteDataReductionProxySettingsTest< | 40 : public ConcreteDataReductionProxySettingsTest< |
37 DataReductionProxySettings> { | 41 DataReductionProxySettings> { |
38 }; | 42 }; |
39 | 43 |
40 | 44 |
41 TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) { | 45 TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) { |
42 AddProxyToCommandLine(); | |
43 net::HttpAuthCache cache; | 46 net::HttpAuthCache cache; |
| 47 DataReductionProxyParams drp_params( |
| 48 DataReductionProxyParams::kAllowed | |
| 49 DataReductionProxyParams::kFallbackAllowed | |
| 50 DataReductionProxyParams::kPromoAllowed); |
| 51 drp_params.set_key(kDataReductionProxyKey); |
44 DataReductionProxySettings::InitDataReductionAuthentication( | 52 DataReductionProxySettings::InitDataReductionAuthentication( |
45 &cache, kDataReductionProxyKey); | 53 &cache, &drp_params); |
46 DataReductionProxySettings::DataReductionProxyList proxies = | 54 DataReductionProxyParams::DataReductionProxyList proxies = |
47 DataReductionProxySettings::GetDataReductionProxies(); | 55 drp_params.GetAllowedProxies(); |
48 for (DataReductionProxySettings::DataReductionProxyList::iterator it = | 56 for (DataReductionProxyParams::DataReductionProxyList::iterator it = |
49 proxies.begin(); it != proxies.end(); ++it) { | 57 proxies.begin(); it != proxies.end(); ++it) { |
50 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it, | 58 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it, |
51 std::string("/")); | 59 std::string("/")); |
52 EXPECT_TRUE(entry != NULL); | 60 EXPECT_TRUE(entry != NULL); |
53 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme()); | 61 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme()); |
54 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9)); | 62 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9)); |
55 } | 63 } |
56 GURL bad_server = GURL("https://bad.proxy.com/"); | 64 GURL bad_server = GURL("https://bad.proxy.com/"); |
57 net::HttpAuthCache::Entry* entry = | 65 net::HttpAuthCache::Entry* entry = |
58 cache.LookupByPath(bad_server, std::string()); | 66 cache.LookupByPath(bad_server, std::string()); |
59 EXPECT_TRUE(entry == NULL); | 67 EXPECT_TRUE(entry == NULL); |
60 } | 68 } |
61 | 69 |
62 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 70 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
63 AddProxyToCommandLine(); | |
64 // SetUp() adds the origin to the command line, which should be returned here. | 71 // SetUp() adds the origin to the command line, which should be returned here. |
65 std::string result = | 72 std::string result = |
66 DataReductionProxySettings::GetDataReductionProxyOrigin(); | 73 settings_->params()->origin().spec(); |
67 EXPECT_EQ(kDataReductionProxy, result); | 74 EXPECT_EQ(GURL(kDataReductionProxy), GURL(result)); |
68 } | 75 } |
69 | 76 |
70 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { | 77 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { |
71 AddProxyToCommandLine(); | |
72 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 78 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
73 switches::kDataReductionProxyDev, kDataReductionProxyDev); | 79 switches::kDataReductionProxyDev, kDataReductionProxyDev); |
| 80 ResetSettings(true, true, false, true); |
74 std::string result = | 81 std::string result = |
75 DataReductionProxySettings::GetDataReductionProxyOrigin(); | 82 settings_->params()->origin().spec(); |
76 EXPECT_EQ(kDataReductionProxyDev, result); | 83 EXPECT_EQ(GURL(kDataReductionProxyDev), GURL(result)); |
77 } | 84 } |
78 | 85 |
| 86 |
79 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { | 87 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { |
80 DataReductionProxySettings::DataReductionProxyList proxies = | 88 DataReductionProxyParams drp_params( |
81 DataReductionProxySettings::GetDataReductionProxies(); | 89 DataReductionProxyParams::kAllowed | |
| 90 DataReductionProxyParams::kFallbackAllowed | |
| 91 DataReductionProxyParams::kPromoAllowed); |
| 92 DataReductionProxyParams::DataReductionProxyList proxies = |
| 93 drp_params.GetAllowedProxies(); |
82 | 94 |
83 unsigned int expected_proxy_size = 0u; | 95 unsigned int expected_proxy_size = 2u; |
84 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
85 ++expected_proxy_size; | |
86 #endif | |
87 #if defined(DATA_REDUCTION_FALLBACK_HOST) | |
88 ++expected_proxy_size; | |
89 #endif | |
90 | |
91 EXPECT_EQ(expected_proxy_size, proxies.size()); | 96 EXPECT_EQ(expected_proxy_size, proxies.size()); |
92 | 97 |
93 // Adding just the fallback on the command line shouldn't add a proxy unless | |
94 // there was already one compiled in. | |
95 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
96 switches::kDataReductionProxyFallback, kDataReductionProxyFallback); | |
97 proxies = DataReductionProxySettings::GetDataReductionProxies(); | |
98 | |
99 // So: if there weren't any proxies before, there still won't be. | |
100 // If there were one or two, there will be two now. | |
101 expected_proxy_size = expected_proxy_size == 0u ? 0u : 2u; | |
102 | |
103 EXPECT_EQ(expected_proxy_size, proxies.size()); | |
104 | |
105 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
106 switches::kDataReductionProxy, kDataReductionProxy); | |
107 proxies = DataReductionProxySettings::GetDataReductionProxies(); | |
108 EXPECT_EQ(2u, proxies.size()); | |
109 | |
110 // Command line proxies have precedence, so even if there were other values | 98 // Command line proxies have precedence, so even if there were other values |
111 // compiled in, these should be the ones in the list. | 99 // compiled in, these should be the ones in the list. |
112 EXPECT_EQ("foo.com", proxies[0].host()); | 100 EXPECT_EQ("foo.com", proxies[0].host()); |
113 EXPECT_EQ(443 ,proxies[0].EffectiveIntPort()); | 101 EXPECT_EQ(443 ,proxies[0].EffectiveIntPort()); |
114 EXPECT_EQ("bar.com", proxies[1].host()); | 102 EXPECT_EQ("bar.com", proxies[1].host()); |
115 EXPECT_EQ(80, proxies[1].EffectiveIntPort()); | 103 EXPECT_EQ(80, proxies[1].EffectiveIntPort()); |
116 } | 104 } |
117 | 105 |
118 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { | 106 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { |
119 AddProxyToCommandLine(); | |
120 std::string salt = "8675309"; // Jenny's number to test the hash generator. | 107 std::string salt = "8675309"; // Jenny's number to test the hash generator. |
121 std::string salted_key = salt + kDataReductionProxyKey + salt; | 108 std::string salted_key = salt + kDataReductionProxyKey + salt; |
122 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key)); | 109 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key)); |
123 EXPECT_EQ(expected_hash, | 110 EXPECT_EQ(expected_hash, |
124 DataReductionProxySettings::AuthHashForSalt( | 111 DataReductionProxySettings::AuthHashForSalt( |
125 8675309, kDataReductionProxyKey)); | 112 8675309, kDataReductionProxyKey)); |
126 } | 113 } |
127 | 114 |
128 // Test that the auth key set by preprocessor directive is not used | 115 TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) { |
129 // when an origin is set via a switch. This test only does anything useful in | |
130 // Chrome builds. | |
131 TEST_F(DataReductionProxySettingsTest, | |
132 TestAuthHashGenerationWithOriginSetViaSwitch) { | |
133 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 116 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
134 switches::kDataReductionProxy, kDataReductionProxy); | 117 switches::kDataReductionProxyAlt, kDataReductionProxyAlt); |
135 EXPECT_EQ(base::string16(), | 118 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
136 DataReductionProxySettings::AuthHashForSalt( | 119 switches::kDataReductionProxyAltFallback, kDataReductionProxyAltFallback); |
137 8675309, kDataReductionProxyKey)); | 120 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 121 switches::kDataReductionSSLProxy, kDataReductionProxySSL); |
| 122 ResetSettings(true, true, true, true); |
| 123 TestDataReductionProxyConfig* config = |
| 124 static_cast<TestDataReductionProxyConfig*>( |
| 125 settings_->configurator()); |
| 126 |
| 127 settings_->SetProxyConfigs(true, true, false, false); |
| 128 EXPECT_TRUE(config->enabled_); |
| 129 EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxyAlt).Equals( |
| 130 net::HostPortPair::FromString(config->origin_))); |
| 131 EXPECT_TRUE( |
| 132 net::HostPortPair::FromString(kDataReductionProxyAltFallback).Equals( |
| 133 net::HostPortPair::FromString(config->fallback_origin_))); |
| 134 EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxySSL).Equals( |
| 135 net::HostPortPair::FromString(config->ssl_origin_))); |
| 136 |
| 137 settings_->SetProxyConfigs(true, false, false, false); |
| 138 EXPECT_TRUE(config->enabled_); |
| 139 EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxy).Equals( |
| 140 net::HostPortPair::FromString(config->origin_))); |
| 141 EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxyFallback).Equals( |
| 142 net::HostPortPair::FromString(config->fallback_origin_))); |
| 143 EXPECT_EQ("", config->ssl_origin_); |
| 144 |
| 145 settings_->SetProxyConfigs(false, true, false, false); |
| 146 EXPECT_FALSE(config->enabled_); |
| 147 EXPECT_EQ("", config->origin_); |
| 148 EXPECT_EQ("", config->fallback_origin_); |
| 149 EXPECT_EQ("", config->ssl_origin_); |
| 150 |
| 151 settings_->SetProxyConfigs(false, false, false, false); |
| 152 EXPECT_FALSE(config->enabled_); |
| 153 EXPECT_EQ("", config->origin_); |
| 154 EXPECT_EQ("", config->fallback_origin_); |
| 155 EXPECT_EQ("", config->ssl_origin_); |
138 } | 156 } |
139 | 157 |
140 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { | 158 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { |
141 AddProxyToCommandLine(); | |
142 settings_->InitPrefMembers(); | 159 settings_->InitPrefMembers(); |
143 base::MessageLoopForUI loop; | 160 base::MessageLoopForUI loop; |
144 // The proxy is disabled initially. | 161 // The proxy is disabled initially. |
145 settings_->enabled_by_user_ = false; | 162 settings_->enabled_by_user_ = false; |
146 settings_->SetProxyConfigs(false, false, false); | 163 settings_->SetProxyConfigs(false, false, false, false); |
147 | 164 |
148 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); | 165 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); |
149 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); | 166 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); |
150 | 167 |
151 CheckOnPrefChange(true, true, false); | 168 CheckOnPrefChange(true, true, false); |
152 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); | 169 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); |
153 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); | 170 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); |
154 | 171 |
155 CheckOnPrefChange(true, true, true); | 172 CheckOnPrefChange(true, true, true); |
156 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); | 173 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); |
157 EXPECT_TRUE(settings_->IsDataReductionProxyManaged()); | 174 EXPECT_TRUE(settings_->IsDataReductionProxyManaged()); |
158 } | 175 } |
159 | 176 |
160 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { | 177 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { |
161 AddProxyToCommandLine(); | |
162 typedef struct { | 178 typedef struct { |
163 std::string host; | 179 std::string host; |
164 std::string realm; | 180 std::string realm; |
165 bool expected_to_succeed; | 181 bool expected_to_succeed; |
166 } challenge_test; | 182 } challenge_test; |
167 | 183 |
168 challenge_test tests[] = { | 184 challenge_test tests[] = { |
169 {"foo.com:443", "", false}, // 0. No realm. | 185 {"foo.com:443", "", false}, // 0. No realm. |
170 {"foo.com:443", "xxx", false}, // 1. Wrong realm. | 186 {"foo.com:443", "xxx", false}, // 1. Wrong realm. |
171 {"foo.com:443", "spdyproxy", false}, // 2. Case matters. | 187 {"foo.com:443", "spdyproxy", false}, // 2. Case matters. |
172 {"foo.com:443", "SpdyProxy", true}, // 3. OK. | 188 {"foo.com:443", "SpdyProxy", true}, // 3. OK. |
173 {"foo.com:443", "SpdyProxy1234567", true}, // 4. OK | 189 {"foo.com:443", "SpdyProxy1234567", true}, // 4. OK |
174 {"bar.com:80", "SpdyProxy1234567", true}, // 5. OK. | 190 {"bar.com:80", "SpdyProxy1234567", true}, // 5. OK. |
175 {"foo.com:443", "SpdyProxyxxx", true}, // 6. OK | 191 {"foo.com:443", "SpdyProxyxxx", true}, // 6. OK |
176 {"", "SpdyProxy1234567", false}, // 7. No challenger. | 192 {"", "SpdyProxy1234567", false}, // 7. No challenger. |
177 {"xxx.net:443", "SpdyProxy1234567", false}, // 8. Wrong host. | 193 {"xxx.net:443", "SpdyProxy1234567", false}, // 8. Wrong host. |
178 {"foo.com", "SpdyProxy1234567", false}, // 9. No port. | 194 {"foo.com", "SpdyProxy1234567", false}, // 9. No port. |
179 {"foo.com:80", "SpdyProxy1234567", false}, // 10.Wrong port. | 195 {"foo.com:80", "SpdyProxy1234567", false}, // 10.Wrong port. |
180 {"bar.com:81", "SpdyProxy1234567", false}, // 11.Wrong port. | 196 {"bar.com:81", "SpdyProxy1234567", false}, // 11.Wrong port. |
181 }; | 197 }; |
182 | 198 |
183 for (int i = 0; i <= 11; ++i) { | 199 for (int i = 0; i <= 11; ++i) { |
184 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); | 200 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); |
185 auth_info->challenger = net::HostPortPair::FromString(tests[i].host); | 201 auth_info->challenger = net::HostPortPair::FromString(tests[i].host); |
186 auth_info->realm = tests[i].realm; | 202 auth_info->realm = tests[i].realm; |
187 EXPECT_EQ(tests[i].expected_to_succeed, | 203 EXPECT_EQ(tests[i].expected_to_succeed, |
188 DataReductionProxySettings::IsAcceptableAuthChallenge( | 204 settings_->IsAcceptableAuthChallenge(auth_info.get())); |
189 auth_info.get())); | |
190 } | 205 } |
191 } | 206 } |
192 | 207 |
193 TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) { | 208 TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) { |
194 AddProxyToCommandLine(); | |
195 typedef struct { | 209 typedef struct { |
196 std::string realm; | 210 std::string realm; |
197 bool expected_empty_token; | 211 bool expected_empty_token; |
198 } token_test; | 212 } token_test; |
199 | 213 |
200 token_test tests[] = { | 214 token_test tests[] = { |
201 {"", true}, // 0. No realm. | 215 {"", true}, // 0. No realm. |
202 {"xxx", true}, // 1. realm too short. | 216 {"xxx", true}, // 1. realm too short. |
203 {"spdyproxy", true}, // 2. no salt. | 217 {"spdyproxy", true}, // 2. no salt. |
204 {"SpdyProxyxxx", true}, // 3. Salt not an int. | 218 {"SpdyProxyxxx", true}, // 3. Salt not an int. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 &original_content_length, | 288 &original_content_length, |
275 &received_content_length, | 289 &received_content_length, |
276 &last_update_time); | 290 &last_update_time); |
277 EXPECT_EQ(expected_total_original_content_length, original_content_length); | 291 EXPECT_EQ(expected_total_original_content_length, original_content_length); |
278 EXPECT_EQ(expected_total_received_content_length, received_content_length); | 292 EXPECT_EQ(expected_total_received_content_length, received_content_length); |
279 } | 293 } |
280 | 294 |
281 // TODO(marq): Add a test to verify that MaybeActivateDataReductionProxy | 295 // TODO(marq): Add a test to verify that MaybeActivateDataReductionProxy |
282 // is called when the pref in |settings_| is enabled. | 296 // is called when the pref in |settings_| is enabled. |
283 TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { | 297 TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { |
284 AddProxyToCommandLine(); | |
285 | |
286 // Initialize the pref member in |settings_| without the usual callback | 298 // Initialize the pref member in |settings_| without the usual callback |
287 // so it won't trigger MaybeActivateDataReductionProxy when the pref value | 299 // so it won't trigger MaybeActivateDataReductionProxy when the pref value |
288 // is set. | 300 // is set. |
289 settings_->spdy_proxy_auth_enabled_.Init( | 301 settings_->spdy_proxy_auth_enabled_.Init( |
290 prefs::kDataReductionProxyEnabled, | 302 prefs::kDataReductionProxyEnabled, |
291 settings_->GetOriginalProfilePrefs()); | 303 settings_->GetOriginalProfilePrefs()); |
| 304 settings_->data_reduction_proxy_alternative_enabled_.Init( |
| 305 prefs::kDataReductionProxyAltEnabled, |
| 306 settings_->GetOriginalProfilePrefs()); |
292 | 307 |
293 // TODO(bengr): Test enabling/disabling while a probe is outstanding. | 308 // TODO(bengr): Test enabling/disabling while a probe is outstanding. |
294 base::MessageLoopForUI loop; | 309 base::MessageLoopForUI loop; |
295 // The proxy is enabled and unrestructed initially. | 310 // The proxy is enabled and unrestructed initially. |
296 // Request succeeded but with bad response, expect proxy to be restricted. | 311 // Request succeeded but with bad response, expect proxy to be restricted. |
297 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false); | 312 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false); |
298 // Request succeeded with valid response, expect proxy to be unrestricted. | 313 // Request succeeded with valid response, expect proxy to be unrestricted. |
299 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false); | 314 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false); |
300 // Request failed, expect proxy to be enabled but restricted. | 315 // Request failed, expect proxy to be enabled but restricted. |
301 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false); | 316 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false); |
302 // The proxy is disabled initially. Probes should not be emitted to change | 317 // The proxy is disabled initially. Probes should not be emitted to change |
303 // state. | 318 // state. |
304 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false); | 319 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false); |
305 } | 320 } |
306 | 321 |
307 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { | 322 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { |
308 AddProxyToCommandLine(); | |
309 base::MessageLoopForUI loop; | 323 base::MessageLoopForUI loop; |
310 // The proxy is enabled initially. | 324 // The proxy is enabled initially. |
311 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); | 325 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); |
312 settings_->spdy_proxy_auth_enabled_.Init( | 326 settings_->spdy_proxy_auth_enabled_.Init( |
313 prefs::kDataReductionProxyEnabled, | 327 prefs::kDataReductionProxyEnabled, |
314 settings_->GetOriginalProfilePrefs()); | 328 settings_->GetOriginalProfilePrefs()); |
| 329 settings_->data_reduction_proxy_alternative_enabled_.Init( |
| 330 prefs::kDataReductionProxyAltEnabled, |
| 331 settings_->GetOriginalProfilePrefs()); |
315 settings_->enabled_by_user_ = true; | 332 settings_->enabled_by_user_ = true; |
316 settings_->restricted_by_carrier_ = false; | 333 settings_->restricted_by_carrier_ = false; |
317 settings_->SetProxyConfigs(true, false, true); | 334 settings_->SetProxyConfigs(true, false, false, true); |
318 // IP address change triggers a probe that succeeds. Proxy remains | 335 // IP address change triggers a probe that succeeds. Proxy remains |
319 // unrestricted. | 336 // unrestricted. |
320 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); | 337 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); |
321 // IP address change triggers a probe that fails. Proxy is restricted. | 338 // IP address change triggers a probe that fails. Proxy is restricted. |
322 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); | 339 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); |
323 // IP address change triggers a probe that fails. Proxy remains restricted. | 340 // IP address change triggers a probe that fails. Proxy remains restricted. |
324 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); | 341 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); |
325 // IP address change triggers a probe that succeed. Proxy is unrestricted. | 342 // IP address change triggers a probe that succeed. Proxy is unrestricted. |
326 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false); | 343 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false); |
327 } | 344 } |
328 | 345 |
329 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { | 346 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { |
330 AddProxyToCommandLine(); | |
331 settings_->InitPrefMembers(); | 347 settings_->InitPrefMembers(); |
332 base::MessageLoopForUI loop; | 348 base::MessageLoopForUI loop; |
333 // The proxy is enabled initially. | 349 // The proxy is enabled initially. |
334 settings_->enabled_by_user_ = true; | 350 settings_->enabled_by_user_ = true; |
335 settings_->SetProxyConfigs(true, false, true); | 351 settings_->SetProxyConfigs(true, false, false, true); |
336 // The pref is disabled, so correspondingly should be the proxy. | 352 // The pref is disabled, so correspondingly should be the proxy. |
337 CheckOnPrefChange(false, false, false); | 353 CheckOnPrefChange(false, false, false); |
338 // The pref is enabled, so correspondingly should be the proxy. | 354 // The pref is enabled, so correspondingly should be the proxy. |
339 CheckOnPrefChange(true, true, false); | 355 CheckOnPrefChange(true, true, false); |
340 } | 356 } |
341 | 357 |
342 TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOn) { | 358 TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOn) { |
343 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 359 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
344 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED)); | 360 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED)); |
345 | 361 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 long expected_length = | 393 long expected_length = |
378 static_cast<long>((kNumDaysInHistory - 1 - i) * 2); | 394 static_cast<long>((kNumDaysInHistory - 1 - i) * 2); |
379 ASSERT_EQ(expected_length, result[i]); | 395 ASSERT_EQ(expected_length, result[i]); |
380 } | 396 } |
381 } | 397 } |
382 | 398 |
383 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { | 399 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { |
384 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | 400 // No call to |AddProxyToCommandLine()| was made, so the proxy feature |
385 // should be unavailable. | 401 // should be unavailable. |
386 base::MessageLoopForUI loop; | 402 base::MessageLoopForUI loop; |
387 DataReductionProxySettings::SetAllowed(false); | 403 // Clear the command line. Setting flags can force the proxy to be allowed. |
388 EXPECT_FALSE(DataReductionProxySettings::IsDataReductionProxyAllowed()); | 404 CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 405 |
| 406 ResetSettings(false, false, false, false); |
389 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 407 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
| 408 EXPECT_FALSE(settings->params()->allowed()); |
390 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | 409 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); |
391 | 410 |
392 scoped_ptr<DataReductionProxyConfigurator> configurator( | 411 scoped_ptr<DataReductionProxyConfigurator> configurator( |
393 new TestDataReductionProxyConfig()); | 412 new TestDataReductionProxyConfig()); |
394 settings_->SetProxyConfigurator(configurator.Pass()); | 413 settings_->SetProxyConfigurator(configurator.Pass()); |
395 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 414 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
396 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 415 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
397 settings_->InitDataReductionProxySettings(&pref_service_, | 416 settings_->InitDataReductionProxySettings(&pref_service_, |
398 &pref_service_, | 417 &pref_service_, |
399 request_context.get()); | 418 request_context.get()); |
400 | 419 |
401 base::MessageLoop::current()->RunUntilIdle(); | 420 base::MessageLoop::current()->RunUntilIdle(); |
402 } | 421 } |
403 | 422 |
404 } // namespace data_reduction_proxy | 423 } // namespace data_reduction_proxy |
OLD | NEW |