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

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

Issue 338723002: Add probe to warm data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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"
(...skipping 13 matching lines...) Expand all
24 const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; 24 const char kDataReductionProxyDev[] = "http://foo-dev.com:80";
25 const char kDataReductionProxyFallback[] = "http://bar.com:80"; 25 const char kDataReductionProxyFallback[] = "http://bar.com:80";
26 const char kDataReductionProxyKey[] = "12345"; 26 const char kDataReductionProxyKey[] = "12345";
27 const char kDataReductionProxyAlt[] = "https://alt.com:443/"; 27 const char kDataReductionProxyAlt[] = "https://alt.com:443/";
28 const char kDataReductionProxyAltFallback[] = "http://alt2.com:80"; 28 const char kDataReductionProxyAltFallback[] = "http://alt2.com:80";
29 const char kDataReductionProxySSL[] = "http://ssl.com:80"; 29 const char kDataReductionProxySSL[] = "http://ssl.com:80";
30 30
31 const char kProbeURLWithOKResponse[] = "http://ok.org/"; 31 const char kProbeURLWithOKResponse[] = "http://ok.org/";
32 const char kProbeURLWithBadResponse[] = "http://bad.org/"; 32 const char kProbeURLWithBadResponse[] = "http://bad.org/";
33 const char kProbeURLWithNoResponse[] = "http://no.org/"; 33 const char kProbeURLWithNoResponse[] = "http://no.org/";
34 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/";
34 35
35 } // namespace 36 } // namespace
36 37
37 namespace data_reduction_proxy { 38 namespace data_reduction_proxy {
38 39
39 class DataReductionProxySettingsTest 40 class DataReductionProxySettingsTest
40 : public ConcreteDataReductionProxySettingsTest< 41 : public ConcreteDataReductionProxySettingsTest<
41 DataReductionProxySettings> { 42 DataReductionProxySettings> {
42 }; 43 };
43 44
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 151
151 settings_->SetProxyConfigs(false, false, false, false); 152 settings_->SetProxyConfigs(false, false, false, false);
152 EXPECT_FALSE(config->enabled_); 153 EXPECT_FALSE(config->enabled_);
153 EXPECT_EQ("", config->origin_); 154 EXPECT_EQ("", config->origin_);
154 EXPECT_EQ("", config->fallback_origin_); 155 EXPECT_EQ("", config->fallback_origin_);
155 EXPECT_EQ("", config->ssl_origin_); 156 EXPECT_EQ("", config->ssl_origin_);
156 } 157 }
157 158
158 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { 159 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
159 settings_->InitPrefMembers(); 160 settings_->InitPrefMembers();
160 base::MessageLoopForUI loop; 161 base::MessageLoopForUI loop;
161 // The proxy is disabled initially. 162 // The proxy is disabled initially.
162 settings_->enabled_by_user_ = false; 163 settings_->enabled_by_user_ = false;
163 settings_->SetProxyConfigs(false, false, false, false); 164 settings_->SetProxyConfigs(false, false, false, false);
164 165
165 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); 166 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled());
166 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); 167 EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
167 168
168 CheckOnPrefChange(true, true, false); 169 CheckOnPrefChange(true, true, false);
169 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); 170 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
170 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); 171 EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
171 172
172 CheckOnPrefChange(true, true, true); 173 CheckOnPrefChange(true, true, true);
173 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled()); 174 EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
174 EXPECT_TRUE(settings_->IsDataReductionProxyManaged()); 175 EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
176
177 base::MessageLoop::current()->RunUntilIdle();
175 } 178 }
176 179
177 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { 180 TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) {
178 typedef struct { 181 typedef struct {
179 std::string host; 182 std::string host;
180 std::string realm; 183 std::string realm;
181 bool expected_to_succeed; 184 bool expected_to_succeed;
182 } challenge_test; 185 } challenge_test;
183 186
184 challenge_test tests[] = { 187 challenge_test tests[] = {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 prefs::kDataReductionProxyEnabled, 305 prefs::kDataReductionProxyEnabled,
303 settings_->GetOriginalProfilePrefs()); 306 settings_->GetOriginalProfilePrefs());
304 settings_->data_reduction_proxy_alternative_enabled_.Init( 307 settings_->data_reduction_proxy_alternative_enabled_.Init(
305 prefs::kDataReductionProxyAltEnabled, 308 prefs::kDataReductionProxyAltEnabled,
306 settings_->GetOriginalProfilePrefs()); 309 settings_->GetOriginalProfilePrefs());
307 310
308 // TODO(bengr): Test enabling/disabling while a probe is outstanding. 311 // TODO(bengr): Test enabling/disabling while a probe is outstanding.
309 base::MessageLoopForUI loop; 312 base::MessageLoopForUI loop;
310 // The proxy is enabled and unrestructed initially. 313 // The proxy is enabled and unrestructed initially.
311 // Request succeeded but with bad response, expect proxy to be restricted. 314 // Request succeeded but with bad response, expect proxy to be restricted.
312 CheckProbe(true, kProbeURLWithBadResponse, "Bad", true, true, true, false); 315 CheckProbe(true,
316 kProbeURLWithBadResponse,
317 kWarmupURLWithNoContentResponse,
318 "Bad",
319 true,
320 true,
321 true,
322 false);
313 // Request succeeded with valid response, expect proxy to be unrestricted. 323 // Request succeeded with valid response, expect proxy to be unrestricted.
314 CheckProbe(true, kProbeURLWithOKResponse, "OK", true, true, false, false); 324 CheckProbe(true,
325 kProbeURLWithOKResponse,
326 kWarmupURLWithNoContentResponse,
327 "OK",
328 true,
329 true,
330 false,
331 false);
315 // Request failed, expect proxy to be enabled but restricted. 332 // Request failed, expect proxy to be enabled but restricted.
316 CheckProbe(true, kProbeURLWithNoResponse, "", false, true, true, false); 333 CheckProbe(true,
334 kProbeURLWithNoResponse,
335 kWarmupURLWithNoContentResponse,
336 "",
337 false,
338 true,
339 true,
340 false);
317 // The proxy is disabled initially. Probes should not be emitted to change 341 // The proxy is disabled initially. Probes should not be emitted to change
318 // state. 342 // state.
319 CheckProbe(false, kProbeURLWithOKResponse, "OK", true, false, false, false); 343 CheckProbe(false,
344 kProbeURLWithOKResponse,
345 kWarmupURLWithNoContentResponse,
346 "OK",
347 true,
348 false,
349 false,
350 false);
320 } 351 }
321 352
322 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { 353 TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
323 base::MessageLoopForUI loop; 354 base::MessageLoopForUI loop;
324 // The proxy is enabled initially. 355 // The proxy is enabled initially.
325 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); 356 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true);
326 settings_->spdy_proxy_auth_enabled_.Init( 357 settings_->spdy_proxy_auth_enabled_.Init(
327 prefs::kDataReductionProxyEnabled, 358 prefs::kDataReductionProxyEnabled,
328 settings_->GetOriginalProfilePrefs()); 359 settings_->GetOriginalProfilePrefs());
329 settings_->data_reduction_proxy_alternative_enabled_.Init( 360 settings_->data_reduction_proxy_alternative_enabled_.Init(
330 prefs::kDataReductionProxyAltEnabled, 361 prefs::kDataReductionProxyAltEnabled,
331 settings_->GetOriginalProfilePrefs()); 362 settings_->GetOriginalProfilePrefs());
332 settings_->enabled_by_user_ = true; 363 settings_->enabled_by_user_ = true;
333 settings_->restricted_by_carrier_ = false; 364 settings_->restricted_by_carrier_ = false;
334 settings_->SetProxyConfigs(true, false, false, true); 365 settings_->SetProxyConfigs(true, false, false, true);
335 // IP address change triggers a probe that succeeds. Proxy remains 366 // IP address change triggers a probe that succeeds. Proxy remains
336 // unrestricted. 367 // unrestricted.
337 CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); 368 CheckProbeOnIPChange(kProbeURLWithOKResponse,
369 kWarmupURLWithNoContentResponse,
370 "OK",
371 true,
372 false,
373 false);
338 // IP address change triggers a probe that fails. Proxy is restricted. 374 // IP address change triggers a probe that fails. Proxy is restricted.
339 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); 375 CheckProbeOnIPChange(kProbeURLWithBadResponse,
376 kWarmupURLWithNoContentResponse,
377 "Bad",
378 true,
379 true,
380 false);
340 // IP address change triggers a probe that fails. Proxy remains restricted. 381 // IP address change triggers a probe that fails. Proxy remains restricted.
341 CheckProbeOnIPChange(kProbeURLWithBadResponse, "Bad", true, true, false); 382 CheckProbeOnIPChange(kProbeURLWithBadResponse,
383 kWarmupURLWithNoContentResponse,
384 "Bad",
385 true,
386 true,
387 false);
342 // IP address change triggers a probe that succeed. Proxy is unrestricted. 388 // IP address change triggers a probe that succeed. Proxy is unrestricted.
343 CheckProbeOnIPChange(kProbeURLWithBadResponse, "OK", true, false, false); 389 CheckProbeOnIPChange(kProbeURLWithBadResponse,
390 kWarmupURLWithNoContentResponse,
391 "OK",
392 true,
393 false,
394 false);
344 } 395 }
345 396
346 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { 397 TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) {
347 settings_->InitPrefMembers(); 398 settings_->InitPrefMembers();
348 base::MessageLoopForUI loop; 399 base::MessageLoopForUI loop;
349 // The proxy is enabled initially. 400 // The proxy is enabled initially.
350 settings_->enabled_by_user_ = true; 401 settings_->enabled_by_user_ = true;
351 settings_->SetProxyConfigs(true, false, false, true); 402 settings_->SetProxyConfigs(true, false, false, true);
352 // The pref is disabled, so correspondingly should be the proxy. 403 // The pref is disabled, so correspondingly should be the proxy.
353 CheckOnPrefChange(false, false, false); 404 CheckOnPrefChange(false, false, false);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 scoped_refptr<net::TestURLRequestContextGetter> request_context = 465 scoped_refptr<net::TestURLRequestContextGetter> request_context =
415 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 466 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
416 settings_->InitDataReductionProxySettings(&pref_service_, 467 settings_->InitDataReductionProxySettings(&pref_service_,
417 &pref_service_, 468 &pref_service_,
418 request_context.get()); 469 request_context.get());
419 470
420 base::MessageLoop::current()->RunUntilIdle(); 471 base::MessageLoop::current()->RunUntilIdle();
421 } 472 }
422 473
423 } // namespace data_reduction_proxy 474 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698