| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 37 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
| 38 // SetUp() adds the origin to the command line, which should be returned here. | 38 // SetUp() adds the origin to the command line, which should be returned here. |
| 39 std::string result = | 39 std::string result = |
| 40 settings_->params()->origin().spec(); | 40 settings_->params()->origin().spec(); |
| 41 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), GURL(result)); | 41 EXPECT_EQ(GURL(expected_params_->DefaultOrigin()), GURL(result)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { | 44 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { |
| 45 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 45 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 46 switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin()); | 46 switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin()); |
| 47 ResetSettings(true, true, false, true); | 47 ResetSettings(true, true, false, true, false); |
| 48 std::string result = | 48 std::string result = |
| 49 settings_->params()->origin().spec(); | 49 settings_->params()->origin().spec(); |
| 50 EXPECT_EQ(GURL(expected_params_->DefaultDevOrigin()), GURL(result)); | 50 EXPECT_EQ(GURL(expected_params_->DefaultDevOrigin()), GURL(result)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { | 54 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { |
| 55 DataReductionProxyParams::DataReductionProxyList proxies = | 55 DataReductionProxyParams::DataReductionProxyList proxies = |
| 56 expected_params_->GetAllowedProxies(); | 56 expected_params_->GetAllowedProxies(); |
| 57 | 57 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 DataReductionProxyParams::kPromoAllowed, | 76 DataReductionProxyParams::kPromoAllowed, |
| 77 TestDataReductionProxyParams::HAS_EVERYTHING & | 77 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 78 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); | 78 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
| 79 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 79 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 80 switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin()); | 80 switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin()); |
| 81 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 81 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 82 switches::kDataReductionProxyAltFallback, | 82 switches::kDataReductionProxyAltFallback, |
| 83 drp_params.DefaultAltFallbackOrigin()); | 83 drp_params.DefaultAltFallbackOrigin()); |
| 84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 85 switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin()); | 85 switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin()); |
| 86 ResetSettings(true, true, true, true); | 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( |
| 95 net::HostPortPair::FromString(config->origin_))); | 95 net::HostPortPair::FromString(config->origin_))); |
| 96 EXPECT_TRUE(net::HostPortPair::FromString( | 96 EXPECT_TRUE(net::HostPortPair::FromString( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 EXPECT_EQ("", config->fallback_origin_); | 115 EXPECT_EQ("", config->fallback_origin_); |
| 116 EXPECT_EQ("", config->ssl_origin_); | 116 EXPECT_EQ("", config->ssl_origin_); |
| 117 | 117 |
| 118 settings_->SetProxyConfigs(false, false, false, false); | 118 settings_->SetProxyConfigs(false, false, false, false); |
| 119 EXPECT_FALSE(config->enabled_); | 119 EXPECT_FALSE(config->enabled_); |
| 120 EXPECT_EQ("", config->origin_); | 120 EXPECT_EQ("", config->origin_); |
| 121 EXPECT_EQ("", config->fallback_origin_); | 121 EXPECT_EQ("", config->fallback_origin_); |
| 122 EXPECT_EQ("", config->ssl_origin_); | 122 EXPECT_EQ("", config->ssl_origin_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigsHoldback) { |
| 126 ResetSettings(true, true, true, true, true); |
| 127 TestDataReductionProxyConfig* config = |
| 128 static_cast<TestDataReductionProxyConfig*>( |
| 129 settings_->configurator()); |
| 130 |
| 131 // Holdback. |
| 132 ResetSettings(true, true, true, true, true); |
| 133 settings_->SetProxyConfigs(true, true, false, false); |
| 134 EXPECT_TRUE(config->enabled_); |
| 135 EXPECT_EQ("", config->origin_); |
| 136 EXPECT_EQ("", config->fallback_origin_); |
| 137 EXPECT_EQ("", config->ssl_origin_); |
| 138 } |
| 139 |
| 125 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { | 140 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { |
| 126 settings_->InitPrefMembers(); | 141 settings_->InitPrefMembers(); |
| 127 base::MessageLoopForUI loop; | 142 base::MessageLoopForUI loop; |
| 128 // The proxy is disabled initially. | 143 // The proxy is disabled initially. |
| 129 settings_->enabled_by_user_ = false; | 144 settings_->enabled_by_user_ = false; |
| 130 settings_->SetProxyConfigs(false, false, false, false); | 145 settings_->SetProxyConfigs(false, false, false, false); |
| 131 | 146 |
| 132 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); | 147 EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); |
| 133 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); | 148 EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); |
| 134 | 149 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 373 } |
| 359 } | 374 } |
| 360 | 375 |
| 361 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { | 376 TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { |
| 362 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | 377 // No call to |AddProxyToCommandLine()| was made, so the proxy feature |
| 363 // should be unavailable. | 378 // should be unavailable. |
| 364 base::MessageLoopForUI loop; | 379 base::MessageLoopForUI loop; |
| 365 // Clear the command line. Setting flags can force the proxy to be allowed. | 380 // Clear the command line. Setting flags can force the proxy to be allowed. |
| 366 CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); | 381 CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
| 367 | 382 |
| 368 ResetSettings(false, false, false, false); | 383 ResetSettings(false, false, false, false, false); |
| 369 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | 384 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); |
| 370 EXPECT_FALSE(settings->params()->allowed()); | 385 EXPECT_FALSE(settings->params()->allowed()); |
| 371 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | 386 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); |
| 372 | 387 |
| 373 scoped_ptr<DataReductionProxyConfigurator> configurator( | 388 scoped_ptr<DataReductionProxyConfigurator> configurator( |
| 374 new TestDataReductionProxyConfig()); | 389 new TestDataReductionProxyConfig()); |
| 375 settings_->SetProxyConfigurator(configurator.Pass()); | 390 settings_->SetProxyConfigurator(configurator.Pass()); |
| 376 scoped_refptr<net::TestURLRequestContextGetter> request_context = | 391 scoped_refptr<net::TestURLRequestContextGetter> request_context = |
| 377 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 392 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
| 378 settings_->InitDataReductionProxySettings(&pref_service_, | 393 settings_->InitDataReductionProxySettings(&pref_service_, |
| 379 &pref_service_, | 394 &pref_service_, |
| 380 request_context.get()); | 395 request_context.get()); |
| 381 | 396 |
| 382 base::MessageLoop::current()->RunUntilIdle(); | 397 base::MessageLoop::current()->RunUntilIdle(); |
| 383 } | 398 } |
| 384 | 399 |
| 385 } // namespace data_reduction_proxy | 400 } // namespace data_reduction_proxy |
| OLD | NEW |