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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 true, | 111 true, |
110 "https://www.foo.com:443/", | 112 "https://www.foo.com:443/", |
111 "http://www.bar.com:80/", | 113 "http://www.bar.com:80/", |
112 ""); | 114 ""); |
113 CheckProxyConfig("fixed_servers", | 115 CheckProxyConfig("fixed_servers", |
114 "http=https://www.foo.com:443,direct://;", | 116 "http=https://www.foo.com:443,direct://;", |
115 ""); | 117 ""); |
116 } | 118 } |
117 | 119 |
118 TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { | 120 TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { |
| 121 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy); |
| 122 base::DictionaryValue* dict = update.Get(); |
| 123 dict->SetString("mode", "system"); |
| 124 |
119 config_->Enable(true, | 125 config_->Enable(true, |
120 true, | 126 true, |
121 "https://www.foo.com:443/", | 127 "https://www.foo.com:443/", |
122 "http://www.bar.com:80/", | 128 "http://www.bar.com:80/", |
123 ""); | 129 ""); |
124 CheckProxyConfig("system", "", ""); | 130 CheckProxyConfig("system", "", ""); |
125 } | 131 } |
126 | 132 |
127 TEST_F(DataReductionProxyConfigTest, TestDisable) { | 133 TEST_F(DataReductionProxyConfigTest, TestDisable) { |
| 134 data_reduction_proxy::DataReductionProxyParams params(0); |
| 135 config_->Enable(false, |
| 136 false, |
| 137 params.origin().spec(), |
| 138 params.fallback_origin().spec(), |
| 139 ""); |
128 config_->Disable(); | 140 config_->Disable(); |
129 CheckProxyConfig("system", "", ""); | 141 CheckProxyConfig("system", "", ""); |
130 } | 142 } |
131 | 143 |
| 144 TEST_F(DataReductionProxyConfigTest, TestDisableWithUserOverride) { |
| 145 data_reduction_proxy::DataReductionProxyParams params(0); |
| 146 config_->Enable(false, |
| 147 false, |
| 148 params.origin().spec(), |
| 149 params.fallback_origin().spec(), |
| 150 ""); |
| 151 |
| 152 // Override the data reduction proxy. |
| 153 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy); |
| 154 base::DictionaryValue* dict = update.Get(); |
| 155 dict->SetString("server", "https://www.baz.com:22/"); |
| 156 |
| 157 // This should have no effect since proxy server was overridden. |
| 158 config_->Disable(); |
| 159 |
| 160 CheckProxyConfig("fixed_servers", "https://www.baz.com:22/", ""); |
| 161 } |
132 | 162 |
133 TEST_F(DataReductionProxyConfigTest, TestBypassList) { | 163 TEST_F(DataReductionProxyConfigTest, TestBypassList) { |
134 config_->AddHostPatternToBypass("http://www.google.com"); | 164 config_->AddHostPatternToBypass("http://www.google.com"); |
135 config_->AddHostPatternToBypass("fefe:13::abc/33"); | 165 config_->AddHostPatternToBypass("fefe:13::abc/33"); |
136 config_->AddURLPatternToBypass("foo.org/images/*"); | 166 config_->AddURLPatternToBypass("foo.org/images/*"); |
137 config_->AddURLPatternToBypass("http://foo.com/*"); | 167 config_->AddURLPatternToBypass("http://foo.com/*"); |
138 config_->AddURLPatternToBypass("http://baz.com:22/bar/*"); | 168 config_->AddURLPatternToBypass("http://baz.com:22/bar/*"); |
139 config_->AddURLPatternToBypass("http://*bat.com/bar/*"); | 169 config_->AddURLPatternToBypass("http://*bat.com/bar/*"); |
140 | 170 |
141 std::string expected[] = { | 171 std::string expected[] = { |
142 "http://www.google.com", | 172 "http://www.google.com", |
143 "fefe:13::abc/33", | 173 "fefe:13::abc/33", |
144 "foo.org", | 174 "foo.org", |
145 "http://foo.com", | 175 "http://foo.com", |
146 "http://baz.com:22", | 176 "http://baz.com:22", |
147 "http://*bat.com" | 177 "http://*bat.com" |
148 }; | 178 }; |
149 | 179 |
150 ASSERT_EQ(config_->bypass_rules_.size(), 6u); | 180 ASSERT_EQ(config_->bypass_rules_.size(), 6u); |
151 int i = 0; | 181 int i = 0; |
152 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin(); | 182 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin(); |
153 it != config_->bypass_rules_.end(); ++it) { | 183 it != config_->bypass_rules_.end(); ++it) { |
154 EXPECT_EQ(expected[i++], *it); | 184 EXPECT_EQ(expected[i++], *it); |
155 } | 185 } |
156 } | 186 } |
157 | 187 |
OLD | NEW |