| 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/core/browser/data_reduction_proxy_sett
ings.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.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 23 matching lines...) Expand all Loading... |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 36 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
| 37 // SetUp() adds the origin to the command line, which should be returned here. | 37 // SetUp() adds the origin to the command line, which should be returned here. |
| 38 std::string result = | 38 std::string result = |
| 39 settings_->params()->origin().spec(); | 39 settings_->params()->origin().spec(); |
| 40 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), GURL(result)); | 40 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), GURL(result)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { | 43 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { |
| 44 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 44 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 45 switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin()); | 45 switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin()); |
| 46 ResetSettings(true, true, false, true, false); | 46 ResetSettings(true, true, false, true, false); |
| 47 std::string result = | 47 std::string result = |
| 48 settings_->params()->origin().spec(); | 48 settings_->params()->origin().spec(); |
| 49 EXPECT_EQ(GURL(expected_params_->DefaultDevOrigin()), GURL(result)); | 49 EXPECT_EQ(GURL(expected_params_->DefaultDevOrigin()), GURL(result)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { | 53 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { |
| 54 DataReductionProxyParams::DataReductionProxyList proxies = | 54 DataReductionProxyParams::DataReductionProxyList proxies = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) { | 71 TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) { |
| 72 TestDataReductionProxyParams drp_params( | 72 TestDataReductionProxyParams drp_params( |
| 73 DataReductionProxyParams::kAllowed | | 73 DataReductionProxyParams::kAllowed | |
| 74 DataReductionProxyParams::kFallbackAllowed | | 74 DataReductionProxyParams::kFallbackAllowed | |
| 75 DataReductionProxyParams::kPromoAllowed, | 75 DataReductionProxyParams::kPromoAllowed, |
| 76 TestDataReductionProxyParams::HAS_EVERYTHING & | 76 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 77 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & | 77 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN & |
| 78 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN); | 78 ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN); |
| 79 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 79 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 80 switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin()); | 80 switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin()); |
| 81 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 82 switches::kDataReductionProxyAltFallback, | 82 switches::kDataReductionProxyAltFallback, |
| 83 drp_params.DefaultAltFallbackOrigin()); | 83 drp_params.DefaultAltFallbackOrigin()); |
| 84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 84 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 85 switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin()); | 85 switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin()); |
| 86 ResetSettings(true, true, true, true, false); | 86 ResetSettings(true, true, true, true, false); |
| 87 TestDataReductionProxyConfig* config = | 87 TestDataReductionProxyConfig* config = |
| 88 static_cast<TestDataReductionProxyConfig*>( | 88 static_cast<TestDataReductionProxyConfig*>( |
| 89 settings_->configurator()); | 89 settings_->configurator()); |
| 90 | 90 |
| 91 settings_->SetProxyConfigs(true, true, false, false); | 91 settings_->SetProxyConfigs(true, true, false, false); |
| 92 EXPECT_TRUE(config->enabled_); | 92 EXPECT_TRUE(config->enabled_); |
| 93 EXPECT_TRUE(net::HostPortPair::FromString( | 93 EXPECT_TRUE(net::HostPortPair::FromString( |
| 94 expected_params_->DefaultAltOrigin()).Equals( | 94 expected_params_->DefaultAltOrigin()).Equals( |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 EXPECT_CALL(*settings, RecordStartupState(PROXY_DISABLED)); | 370 EXPECT_CALL(*settings, RecordStartupState(PROXY_DISABLED)); |
| 371 | 371 |
| 372 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, false); | 372 pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, false); |
| 373 CheckInitDataReductionProxy(false); | 373 CheckInitDataReductionProxy(false); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST_F(DataReductionProxySettingsTest, TestEnableProxyFromCommandLine) { | 376 TEST_F(DataReductionProxySettingsTest, TestEnableProxyFromCommandLine) { |
| 377 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 377 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
| 378 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED)); | 378 EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED)); |
| 379 | 379 |
| 380 CommandLine::ForCurrentProcess()->AppendSwitch( | 380 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 381 switches::kEnableDataReductionProxy); | 381 switches::kEnableDataReductionProxy); |
| 382 CheckInitDataReductionProxy(true); | 382 CheckInitDataReductionProxy(true); |
| 383 } | 383 } |
| 384 | 384 |
| 385 TEST_F(DataReductionProxySettingsTest, TestGetDailyContentLengths) { | 385 TEST_F(DataReductionProxySettingsTest, TestGetDailyContentLengths) { |
| 386 DataReductionProxySettings::ContentLengthList result = | 386 DataReductionProxySettings::ContentLengthList result = |
| 387 settings_->GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); | 387 settings_->GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength); |
| 388 | 388 |
| 389 ASSERT_FALSE(result.empty()); | 389 ASSERT_FALSE(result.empty()); |
| 390 ASSERT_EQ(kNumDaysInHistory, result.size()); | 390 ASSERT_EQ(kNumDaysInHistory, result.size()); |
| 391 | 391 |
| 392 for (size_t i = 0; i < kNumDaysInHistory; ++i) { | 392 for (size_t i = 0; i < kNumDaysInHistory; ++i) { |
| 393 long expected_length = | 393 long expected_length = |
| 394 static_cast<long>((kNumDaysInHistory - 1 - i) * 2); | 394 static_cast<long>((kNumDaysInHistory - 1 - i) * 2); |
| 395 ASSERT_EQ(expected_length, result[i]); | 395 ASSERT_EQ(expected_length, result[i]); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { | 399 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { |
| 400 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | 400 // No call to |AddProxyToCommandLine()| was made, so the proxy feature |
| 401 // should be unavailable. | 401 // should be unavailable. |
| 402 base::MessageLoopForUI loop; | 402 base::MessageLoopForUI loop; |
| 403 // Clear the command line. Setting flags can force the proxy to be allowed. | 403 // Clear the command line. Setting flags can force the proxy to be allowed. |
| 404 CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); | 404 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 405 | 405 |
| 406 ResetSettings(false, false, false, false, false); | 406 ResetSettings(false, false, false, false, false); |
| 407 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 407 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
| 408 EXPECT_FALSE(settings->params()->allowed()); | 408 EXPECT_FALSE(settings->params()->allowed()); |
| 409 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | 409 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); |
| 410 | 410 |
| 411 scoped_ptr<DataReductionProxyConfigurator> configurator( | 411 scoped_ptr<DataReductionProxyConfigurator> configurator( |
| 412 new TestDataReductionProxyConfig()); | 412 new TestDataReductionProxyConfig()); |
| 413 settings_->SetProxyConfigurator(configurator.get()); | 413 settings_->SetProxyConfigurator(configurator.get()); |
| 414 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 414 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
| 415 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 415 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
| 416 settings_->InitDataReductionProxySettings( | 416 settings_->InitDataReductionProxySettings( |
| 417 &pref_service_, | 417 &pref_service_, |
| 418 request_context.get(), | 418 request_context.get(), |
| 419 &net_log_, | 419 &net_log_, |
| 420 event_store_.get()); | 420 event_store_.get()); |
| 421 settings_->SetOnDataReductionEnabledCallback( | 421 settings_->SetOnDataReductionEnabledCallback( |
| 422 base::Bind(&DataReductionProxySettingsTestBase:: | 422 base::Bind(&DataReductionProxySettingsTestBase:: |
| 423 RegisterSyntheticFieldTrialCallback, | 423 RegisterSyntheticFieldTrialCallback, |
| 424 base::Unretained(this))); | 424 base::Unretained(this))); |
| 425 | 425 |
| 426 base::MessageLoop::current()->RunUntilIdle(); | 426 base::MessageLoop::current()->RunUntilIdle(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace data_reduction_proxy | 429 } // namespace data_reduction_proxy |
| OLD | NEW |