Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc

Issue 286013002: Added alternative configuration for the data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(true, true, false, true);
48 drp_params.set_key(kDataReductionProxyKey);
44 DataReductionProxySettings::InitDataReductionAuthentication( 49 DataReductionProxySettings::InitDataReductionAuthentication(
45 &cache, kDataReductionProxyKey); 50 &cache, &drp_params);
46 DataReductionProxySettings::DataReductionProxyList proxies = 51 DataReductionProxyParams::DataReductionProxyList proxies =
47 DataReductionProxySettings::GetDataReductionProxies(); 52 drp_params.GetAllowedProxies();
48 for (DataReductionProxySettings::DataReductionProxyList::iterator it = 53 for (DataReductionProxyParams::DataReductionProxyList::iterator it =
49 proxies.begin(); it != proxies.end(); ++it) { 54 proxies.begin(); it != proxies.end(); ++it) {
50 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it, 55 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it,
51 std::string("/")); 56 std::string("/"));
52 EXPECT_TRUE(entry != NULL); 57 EXPECT_TRUE(entry != NULL);
53 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme()); 58 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme());
54 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9)); 59 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9));
55 } 60 }
56 GURL bad_server = GURL("https://bad.proxy.com/"); 61 GURL bad_server = GURL("https://bad.proxy.com/");
57 net::HttpAuthCache::Entry* entry = 62 net::HttpAuthCache::Entry* entry =
58 cache.LookupByPath(bad_server, std::string()); 63 cache.LookupByPath(bad_server, std::string());
59 EXPECT_TRUE(entry == NULL); 64 EXPECT_TRUE(entry == NULL);
60 } 65 }
61 66
62 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { 67 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) {
63 AddProxyToCommandLine();
64 // SetUp() adds the origin to the command line, which should be returned here. 68 // SetUp() adds the origin to the command line, which should be returned here.
65 std::string result = 69 std::string result =
66 DataReductionProxySettings::GetDataReductionProxyOrigin(); 70 settings_->params()->origin().spec();
67 EXPECT_EQ(kDataReductionProxy, result); 71 EXPECT_EQ(GURL(kDataReductionProxy), GURL(result));
68 } 72 }
69 73
70 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { 74 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) {
71 AddProxyToCommandLine();
72 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 75 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
73 switches::kDataReductionProxyDev, kDataReductionProxyDev); 76 switches::kDataReductionProxyDev, kDataReductionProxyDev);
77 ResetSettings(true, true, false, true);
74 std::string result = 78 std::string result =
75 DataReductionProxySettings::GetDataReductionProxyOrigin(); 79 settings_->params()->origin().spec();
76 EXPECT_EQ(kDataReductionProxyDev, result); 80 EXPECT_EQ(GURL(kDataReductionProxyDev), GURL(result));
77 } 81 }
78 82
83
79 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { 84 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) {
80 DataReductionProxySettings::DataReductionProxyList proxies = 85 DataReductionProxyParams drp_params(true, true, false, true);
81 DataReductionProxySettings::GetDataReductionProxies(); 86 DataReductionProxyParams::DataReductionProxyList proxies =
87 drp_params.GetAllowedProxies();
82 88
83 unsigned int expected_proxy_size = 0u; 89 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()); 90 EXPECT_EQ(expected_proxy_size, proxies.size());
92 91
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 92 // Command line proxies have precedence, so even if there were other values
111 // compiled in, these should be the ones in the list. 93 // compiled in, these should be the ones in the list.
112 EXPECT_EQ("foo.com", proxies[0].host()); 94 EXPECT_EQ("foo.com", proxies[0].host());
113 EXPECT_EQ(443 ,proxies[0].EffectiveIntPort()); 95 EXPECT_EQ(443 ,proxies[0].EffectiveIntPort());
114 EXPECT_EQ("bar.com", proxies[1].host()); 96 EXPECT_EQ("bar.com", proxies[1].host());
115 EXPECT_EQ(80, proxies[1].EffectiveIntPort()); 97 EXPECT_EQ(80, proxies[1].EffectiveIntPort());
116 } 98 }
117 99
118 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { 100 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) {
119 AddProxyToCommandLine();
120 std::string salt = "8675309"; // Jenny's number to test the hash generator. 101 std::string salt = "8675309"; // Jenny's number to test the hash generator.
121 std::string salted_key = salt + kDataReductionProxyKey + salt; 102 std::string salted_key = salt + kDataReductionProxyKey + salt;
122 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key)); 103 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key));
123 EXPECT_EQ(expected_hash, 104 EXPECT_EQ(expected_hash,
124 DataReductionProxySettings::AuthHashForSalt( 105 DataReductionProxySettings::AuthHashForSalt(
125 8675309, kDataReductionProxyKey)); 106 8675309, kDataReductionProxyKey));
126 } 107 }
127 108
128 // Test that the auth key set by preprocessor directive is not used 109 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( 110 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
134 switches::kDataReductionProxy, kDataReductionProxy); 111 switches::kDataReductionProxyAlt, kDataReductionProxyAlt);
135 EXPECT_EQ(base::string16(), 112 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
136 DataReductionProxySettings::AuthHashForSalt( 113 switches::kDataReductionProxyAltFallback, kDataReductionProxyAltFallback);
137 8675309, kDataReductionProxyKey)); 114 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
115 switches::kDataReductionSSLProxy, kDataReductionProxySSL);
116 ResetSettings(true, true, true, true);
117 TestDataReductionProxyConfig* config =
118 static_cast<TestDataReductionProxyConfig*>(
119 settings_->configurator());
120
121 settings_->SetProxyConfigs(true, true, false, false);
122 EXPECT_TRUE(config->enabled_);
123 EXPECT_EQ(kDataReductionProxyAlt, config->origin_);
124 EXPECT_EQ(kDataReductionProxyAltFallback, config->fallback_origin_);
125 EXPECT_EQ(kDataReductionProxySSL, config->ssl_origin_);
126
127 settings_->SetProxyConfigs(true, false, false, false);
128 EXPECT_TRUE(config->enabled_);
129 EXPECT_EQ(kDataReductionProxy, config->origin_);
130 EXPECT_EQ(kDataReductionProxyFallback, config->fallback_origin_);
131 EXPECT_EQ("", config->ssl_origin_);
132
133 settings_->SetProxyConfigs(false, true, false, false);
134 EXPECT_FALSE(config->enabled_);
135 EXPECT_EQ("", config->origin_);
136 EXPECT_EQ("", config->fallback_origin_);
137 EXPECT_EQ("", config->ssl_origin_);
138
139 settings_->SetProxyConfigs(false, false, false, false);
140 EXPECT_FALSE(config->enabled_);
141 EXPECT_EQ("", config->origin_);
142 EXPECT_EQ("", config->fallback_origin_);
143 EXPECT_EQ("", config->ssl_origin_);
138 } 144 }
139 145
140 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { 146 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
141 AddProxyToCommandLine();
142 settings_->InitPrefMembers(); 147 settings_->InitPrefMembers();
143 base::MessageLoopForUI loop; 148 base::MessageLoopForUI loop;
144 // The proxy is disabled initially. 149 // The proxy is disabled initially.
145 settings_->enabled_by_user_ = false; 150 settings_->enabled_by_user_ = false;
146 settings_->SetProxyConfigs(false, false, false); 151 settings_->SetProxyConfigs(false, false, false, false);
147 152
148 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); 153 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled());
149 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); 154 EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
150 155
151 CheckOnPrefChange(true, true, false); 156 CheckOnPrefChange(true, true, false);
152 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); 157 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
153 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); 158 EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
154 159
155 CheckOnPrefChange(true, true, true); 160 CheckOnPrefChange(true, true, true);
156 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); 161 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
157 EXPECT_TRUE(settings_->IsDataReductionProxyManaged()); 162 EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
158 } 163 }
159 164
160 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { 165 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) {
161 AddProxyToCommandLine();
162 typedef struct { 166 typedef struct {
163 std::string host; 167 std::string host;
164 std::string realm; 168 std::string realm;
165 bool expected_to_succeed; 169 bool expected_to_succeed;
166 } challenge_test; 170 } challenge_test;
167 171
168 challenge_test tests[] = { 172 challenge_test tests[] = {
169 {"foo.com:443", "", false}, // 0. No realm. 173 {"foo.com:443", "", false}, // 0. No realm.
170 {"foo.com:443", "xxx", false}, // 1. Wrong realm. 174 {"foo.com:443", "xxx", false}, // 1. Wrong realm.
171 {"foo.com:443", "spdyproxy", false}, // 2. Case matters. 175 {"foo.com:443", "spdyproxy", false}, // 2. Case matters.
172 {"foo.com:443", "SpdyProxy", true}, // 3. OK. 176 {"foo.com:443", "SpdyProxy", true}, // 3. OK.
173 {"foo.com:443", "SpdyProxy1234567", true}, // 4. OK 177 {"foo.com:443", "SpdyProxy1234567", true}, // 4. OK
174 {"bar.com:80", "SpdyProxy1234567", true}, // 5. OK. 178 {"bar.com:80", "SpdyProxy1234567", true}, // 5. OK.
175 {"foo.com:443", "SpdyProxyxxx", true}, // 6. OK 179 {"foo.com:443", "SpdyProxyxxx", true}, // 6. OK
176 {"", "SpdyProxy1234567", false}, // 7. No challenger. 180 {"", "SpdyProxy1234567", false}, // 7. No challenger.
177 {"xxx.net:443", "SpdyProxy1234567", false}, // 8. Wrong host. 181 {"xxx.net:443", "SpdyProxy1234567", false}, // 8. Wrong host.
178 {"foo.com", "SpdyProxy1234567", false}, // 9. No port. 182 {"foo.com", "SpdyProxy1234567", false}, // 9. No port.
179 {"foo.com:80", "SpdyProxy1234567", false}, // 10.Wrong port. 183 {"foo.com:80", "SpdyProxy1234567", false}, // 10.Wrong port.
180 {"bar.com:81", "SpdyProxy1234567", false}, // 11.Wrong port. 184 {"bar.com:81", "SpdyProxy1234567", false}, // 11.Wrong port.
181 }; 185 };
182 186
183 for (int i = 0; i <= 11; ++i) { 187 for (int i = 0; i <= 11; ++i) {
184 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); 188 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
185 auth_info->challenger = net::HostPortPair::FromString(tests[i].host); 189 auth_info->challenger = net::HostPortPair::FromString(tests[i].host);
186 auth_info->realm = tests[i].realm; 190 auth_info->realm = tests[i].realm;
187 EXPECT_EQ(tests[i].expected_to_succeed, 191 EXPECT_EQ(tests[i].expected_to_succeed,
188 DataReductionProxySettings::IsAcceptableAuthChallenge( 192 settings_->IsAcceptableAuthChallenge(auth_info.get()));
189 auth_info.get()));
190 } 193 }
191 } 194 }
192 195
193 TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) { 196 TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) {
194 AddProxyToCommandLine();
195 typedef struct { 197 typedef struct {
196 std::string realm; 198 std::string realm;
197 bool expected_empty_token; 199 bool expected_empty_token;
198 } token_test; 200 } token_test;
199 201
200 token_test tests[] = { 202 token_test tests[] = {
201 {"", true}, // 0. No realm. 203 {"", true}, // 0. No realm.
202 {"xxx", true}, // 1. realm too short. 204 {"xxx", true}, // 1. realm too short.
203 {"spdyproxy", true}, // 2. no salt. 205 {"spdyproxy", true}, // 2. no salt.
204 {"SpdyProxyxxx", true}, // 3. Salt not an int. 206 {"SpdyProxyxxx", true}, // 3. Salt not an int.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 &original_content_length, 276 &original_content_length,
275 &received_content_length, 277 &received_content_length,
276 &last_update_time); 278 &last_update_time);
277 EXPECT_EQ(expected_total_original_content_length, original_content_length); 279 EXPECT_EQ(expected_total_original_content_length, original_content_length);
278 EXPECT_EQ(expected_total_received_content_length, received_content_length); 280 EXPECT_EQ(expected_total_received_content_length, received_content_length);
279 } 281 }
280 282
281 // TODO(marq): Add a test to verify that MaybeActivateDataReductionProxy 283 // TODO(marq): Add a test to verify that MaybeActivateDataReductionProxy
282 // is called when the pref in |settings_| is enabled. 284 // is called when the pref in |settings_| is enabled.
283 TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { 285 TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) {
284 AddProxyToCommandLine();
285
286 // Initialize the pref member in |settings_| without the usual callback 286 // Initialize the pref member in |settings_| without the usual callback
287 // so it won't trigger MaybeActivateDataReductionProxy when the pref value 287 // so it won't trigger MaybeActivateDataReductionProxy when the pref value
288 // is set. 288 // is set.
289 settings_->spdy_proxy_auth_enabled_.Init( 289 settings_->spdy_proxy_auth_enabled_.Init(
290 prefs::kDataReductionProxyEnabled, 290 prefs::kDataReductionProxyEnabled,
291 settings_->GetOriginalProfilePrefs()); 291 settings_->GetOriginalProfilePrefs());
292 settings_->data_reduction_proxy_alternative_enabled_.Init(
293 prefs::kDataReductionProxyAltEnabled,
294 settings_->GetOriginalProfilePrefs());
292 295
293 // TODO(bengr): Test enabling/disabling while a probe is outstanding. 296 // TODO(bengr): Test enabling/disabling while a probe is outstanding.
294 base::MessageLoopForUI loop; 297 base::MessageLoopForUI loop;
295 // The proxy is enabled and unrestructed initially. 298 // The proxy is enabled and unrestructed initially.
296 // Request succeeded but with bad response, expect proxy to be restricted. 299 // Request succeeded but with bad response, expect proxy to be restricted.
297 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false); 300 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false);
298 // Request succeeded with valid response, expect proxy to be unrestricted. 301 // Request succeeded with valid response, expect proxy to be unrestricted.
299 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false); 302 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false);
300 // Request failed, expect proxy to be enabled but restricted. 303 // Request failed, expect proxy to be enabled but restricted.
301 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false); 304 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false);
302 // The proxy is disabled initially. Probes should not be emitted to change 305 // The proxy is disabled initially. Probes should not be emitted to change
303 // state. 306 // state.
304 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false); 307 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false);
305 } 308 }
306 309
307 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { 310 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
308 AddProxyToCommandLine();
309 base::MessageLoopForUI loop; 311 base::MessageLoopForUI loop;
310 // The proxy is enabled initially. 312 // The proxy is enabled initially.
311 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); 313 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true);
312 settings_->spdy_proxy_auth_enabled_.Init( 314 settings_->spdy_proxy_auth_enabled_.Init(
313 prefs::kDataReductionProxyEnabled, 315 prefs::kDataReductionProxyEnabled,
314 settings_->GetOriginalProfilePrefs()); 316 settings_->GetOriginalProfilePrefs());
317 settings_->data_reduction_proxy_alternative_enabled_.Init(
318 prefs::kDataReductionProxyAltEnabled,
319 settings_->GetOriginalProfilePrefs());
315 settings_->enabled_by_user_ = true; 320 settings_->enabled_by_user_ = true;
316 settings_->restricted_by_carrier_ = false; 321 settings_->restricted_by_carrier_ = false;
317 settings_->SetProxyConfigs(true, false, true); 322 settings_->SetProxyConfigs(true, false, false, true);
318 // IP address change triggers a probe that succeeds. Proxy remains 323 // IP address change triggers a probe that succeeds. Proxy remains
319 // unrestricted. 324 // unrestricted.
320 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); 325 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false);
321 // IP address change triggers a probe that fails. Proxy is restricted. 326 // IP address change triggers a probe that fails. Proxy is restricted.
322 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); 327 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false);
323 // IP address change triggers a probe that fails. Proxy remains restricted. 328 // IP address change triggers a probe that fails. Proxy remains restricted.
324 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); 329 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false);
325 // IP address change triggers a probe that succeed. Proxy is unrestricted. 330 // IP address change triggers a probe that succeed. Proxy is unrestricted.
326 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false); 331 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false);
327 } 332 }
328 333
329 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { 334 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) {
330 AddProxyToCommandLine();
331 settings_->InitPrefMembers(); 335 settings_->InitPrefMembers();
332 base::MessageLoopForUI loop; 336 base::MessageLoopForUI loop;
333 // The proxy is enabled initially. 337 // The proxy is enabled initially.
334 settings_->enabled_by_user_ = true; 338 settings_->enabled_by_user_ = true;
335 settings_->SetProxyConfigs(true, false, true); 339 settings_->SetProxyConfigs(true, false, false, true);
336 // The pref is disabled, so correspondingly should be the proxy. 340 // The pref is disabled, so correspondingly should be the proxy.
337 CheckOnPrefChange(false, false, false); 341 CheckOnPrefChange(false, false, false);
338 // The pref is enabled, so correspondingly should be the proxy. 342 // The pref is enabled, so correspondingly should be the proxy.
339 CheckOnPrefChange(true, true, false); 343 CheckOnPrefChange(true, true, false);
340 } 344 }
341 345
342 TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOn) { 346 TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOn) {
343 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); 347 MockSettings* settings = static_cast<MockSettings*>(settings_.get());
344 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED)); 348 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED));
345 349
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 long expected_length = 381 long expected_length =
378 static_cast<long>((kNumDaysInHistory - 1 - i) * 2); 382 static_cast<long>((kNumDaysInHistory - 1 - i) * 2);
379 ASSERT_EQ(expected_length, result[i]); 383 ASSERT_EQ(expected_length, result[i]);
380 } 384 }
381 } 385 }
382 386
383 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { 387 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
384 // No call to |AddProxyToCommandLine()| was made, so the proxy feature 388 // No call to |AddProxyToCommandLine()| was made, so the proxy feature
385 // should be unavailable. 389 // should be unavailable.
386 base::MessageLoopForUI loop; 390 base::MessageLoopForUI loop;
387 DataReductionProxySettings::SetAllowed(false); 391 // Clear the command line. Setting flags can force the proxy to be allowed.
388 EXPECT_FALSE(DataReductionProxySettings::IsDataReductionProxyAllowed()); 392 CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
393 ResetSettings(false, false, false, false);
389 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); 394 MockSettings* settings = static_cast<MockSettings*>(settings_.get());
395 EXPECT_FALSE(settings->params()->allowed());
390 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); 396 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));
391 397
392 scoped_ptr<DataReductionProxyConfigurator> configurator( 398 scoped_ptr<DataReductionProxyConfigurator> configurator(
393 new TestDataReductionProxyConfig()); 399 new TestDataReductionProxyConfig());
394 settings_->SetProxyConfigurator(configurator.Pass()); 400 settings_->SetProxyConfigurator(configurator.Pass());
395 scoped_refptr<net::TestURLRequestContextGetter> request_context = 401 scoped_refptr<net::TestURLRequestContextGetter> request_context =
396 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 402 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
397 settings_->InitDataReductionProxySettings(&pref_service_, 403 settings_->InitDataReductionProxySettings(&pref_service_,
398 &pref_service_, 404 &pref_service_,
399 request_context.get()); 405 request_context.get());
400 406
401 base::MessageLoop::current()->RunUntilIdle(); 407 base::MessageLoop::current()->RunUntilIdle();
402 } 408 }
403 409
404 } // namespace data_reduction_proxy 410 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698