| 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 "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.
h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_para
ms.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 class DataReductionProxyConfigTest : public testing::Test { | 20 class DataReductionProxyConfigTest : public testing::Test { |
| 19 public: | 21 public: |
| 20 virtual void SetUp() { | 22 virtual void SetUp() { |
| 21 PrefRegistrySimple* registry = pref_service_.registry(); | 23 PrefRegistrySimple* registry = pref_service_.registry(); |
| 22 registry->RegisterDictionaryPref(prefs::kProxy); | 24 registry->RegisterDictionaryPref(prefs::kProxy); |
| 23 config_.reset(new DataReductionProxyChromeConfigurator( | 25 config_.reset(new DataReductionProxyChromeConfigurator( |
| 24 &pref_service_, | 26 &pref_service_, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 dict->GetString("mode", &mode); | 40 dict->GetString("mode", &mode); |
| 39 ASSERT_EQ(expected_mode, mode); | 41 ASSERT_EQ(expected_mode, mode); |
| 40 dict->GetString("server", &server); | 42 dict->GetString("server", &server); |
| 41 ASSERT_EQ(expected_server, server); | 43 ASSERT_EQ(expected_server, server); |
| 42 dict->GetString("bypass_list", &bypass_list); | 44 dict->GetString("bypass_list", &bypass_list); |
| 43 ASSERT_EQ(expected_bypass_list, bypass_list); | 45 ASSERT_EQ(expected_bypass_list, bypass_list); |
| 44 } | 46 } |
| 45 | 47 |
| 46 scoped_ptr<DataReductionProxyChromeConfigurator> config_; | 48 scoped_ptr<DataReductionProxyChromeConfigurator> config_; |
| 47 TestingPrefServiceSimple pref_service_; | 49 TestingPrefServiceSimple pref_service_; |
| 50 const int drp_flag = |
| 51 data_reduction_proxy::DataReductionProxyParams::kAllowed | |
| 52 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed | |
| 53 data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed | |
| 54 data_reduction_proxy::DataReductionProxyParams:: |
| 55 kAlternativeFallbackAllowed; |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 TEST_F(DataReductionProxyConfigTest, TestUnrestricted) { | 58 TEST_F(DataReductionProxyConfigTest, TestUnrestricted) { |
| 51 config_->Enable(false, | 59 config_->Enable(false, |
| 52 false, | 60 false, |
| 53 "https://www.foo.com:443/", | 61 "https://www.foo.com:443/", |
| 54 "http://www.bar.com:80/", | 62 "http://www.bar.com:80/", |
| 55 ""); | 63 ""); |
| 56 CheckProxyConfig( | 64 CheckProxyConfig( |
| 57 "fixed_servers", | 65 "fixed_servers", |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 true, | 117 true, |
| 110 "https://www.foo.com:443/", | 118 "https://www.foo.com:443/", |
| 111 "http://www.bar.com:80/", | 119 "http://www.bar.com:80/", |
| 112 ""); | 120 ""); |
| 113 CheckProxyConfig("fixed_servers", | 121 CheckProxyConfig("fixed_servers", |
| 114 "http=https://www.foo.com:443,direct://;", | 122 "http=https://www.foo.com:443,direct://;", |
| 115 ""); | 123 ""); |
| 116 } | 124 } |
| 117 | 125 |
| 118 TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { | 126 TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { |
| 127 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy); |
| 128 base::DictionaryValue* dict = update.Get(); |
| 129 dict->SetString("mode", "system"); |
| 130 |
| 119 config_->Enable(true, | 131 config_->Enable(true, |
| 120 true, | 132 true, |
| 121 "https://www.foo.com:443/", | 133 "https://www.foo.com:443/", |
| 122 "http://www.bar.com:80/", | 134 "http://www.bar.com:80/", |
| 123 ""); | 135 ""); |
| 124 CheckProxyConfig("system", "", ""); | 136 CheckProxyConfig("system", "", ""); |
| 125 } | 137 } |
| 126 | 138 |
| 127 TEST_F(DataReductionProxyConfigTest, TestDisable) { | 139 TEST_F(DataReductionProxyConfigTest, TestDisable) { |
| 140 data_reduction_proxy::DataReductionProxyParams params(drp_flag); |
| 141 config_->Enable(false, |
| 142 false, |
| 143 params.origin().spec(), |
| 144 params.fallback_origin().spec(), |
| 145 ""); |
| 128 config_->Disable(); | 146 config_->Disable(); |
| 129 CheckProxyConfig("system", "", ""); | 147 CheckProxyConfig("system", "", ""); |
| 130 } | 148 } |
| 131 | 149 |
| 150 TEST_F(DataReductionProxyConfigTest, TestDisableWithUserOverride) { |
| 151 data_reduction_proxy::DataReductionProxyParams params(drp_flag); |
| 152 config_->Enable(false, |
| 153 false, |
| 154 params.origin().spec(), |
| 155 params.fallback_origin().spec(), |
| 156 ""); |
| 157 |
| 158 // Override the data reduction proxy. |
| 159 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy); |
| 160 base::DictionaryValue* dict = update.Get(); |
| 161 dict->SetString("server", "https://www.baz.com:22/"); |
| 162 |
| 163 // This should have no effect since proxy server was overridden. |
| 164 config_->Disable(); |
| 165 |
| 166 CheckProxyConfig("fixed_servers", "https://www.baz.com:22/", ""); |
| 167 } |
| 132 | 168 |
| 133 TEST_F(DataReductionProxyConfigTest, TestBypassList) { | 169 TEST_F(DataReductionProxyConfigTest, TestBypassList) { |
| 134 config_->AddHostPatternToBypass("http://www.google.com"); | 170 config_->AddHostPatternToBypass("http://www.google.com"); |
| 135 config_->AddHostPatternToBypass("fefe:13::abc/33"); | 171 config_->AddHostPatternToBypass("fefe:13::abc/33"); |
| 136 config_->AddURLPatternToBypass("foo.org/images/*"); | 172 config_->AddURLPatternToBypass("foo.org/images/*"); |
| 137 config_->AddURLPatternToBypass("http://foo.com/*"); | 173 config_->AddURLPatternToBypass("http://foo.com/*"); |
| 138 config_->AddURLPatternToBypass("http://baz.com:22/bar/*"); | 174 config_->AddURLPatternToBypass("http://baz.com:22/bar/*"); |
| 139 config_->AddURLPatternToBypass("http://*bat.com/bar/*"); | 175 config_->AddURLPatternToBypass("http://*bat.com/bar/*"); |
| 140 | 176 |
| 141 std::string expected[] = { | 177 std::string expected[] = { |
| 142 "http://www.google.com", | 178 "http://www.google.com", |
| 143 "fefe:13::abc/33", | 179 "fefe:13::abc/33", |
| 144 "foo.org", | 180 "foo.org", |
| 145 "http://foo.com", | 181 "http://foo.com", |
| 146 "http://baz.com:22", | 182 "http://baz.com:22", |
| 147 "http://*bat.com" | 183 "http://*bat.com" |
| 148 }; | 184 }; |
| 149 | 185 |
| 150 ASSERT_EQ(config_->bypass_rules_.size(), 6u); | 186 ASSERT_EQ(config_->bypass_rules_.size(), 6u); |
| 151 int i = 0; | 187 int i = 0; |
| 152 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin(); | 188 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin(); |
| 153 it != config_->bypass_rules_.end(); ++it) { | 189 it != config_->bypass_rules_.end(); ++it) { |
| 154 EXPECT_EQ(expected[i++], *it); | 190 EXPECT_EQ(expected[i++], *it); |
| 155 } | 191 } |
| 156 } | 192 } |
| 157 | 193 |
| OLD | NEW |