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

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc

Issue 669163003: Handle disabling data reduction proxy for all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to head Created 6 years, 1 month 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 "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/common/data_reduction_proxy_param s.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 void SetUp() override { 22 void SetUp() override {
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
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(
135 data_reduction_proxy::DataReductionProxyParams::
136 kAllowAllProxyConfigurations);
137 config_->Enable(false,
138 false,
139 params.origin().spec(),
140 params.fallback_origin().spec(),
141 "");
128 config_->Disable(); 142 config_->Disable();
129 CheckProxyConfig("system", "", ""); 143 CheckProxyConfig("system", "", "");
130 } 144 }
131 145
146 TEST_F(DataReductionProxyConfigTest, TestDisableWithUserOverride) {
147 data_reduction_proxy::DataReductionProxyParams params(
148 data_reduction_proxy::DataReductionProxyParams::
149 kAllowAllProxyConfigurations);
150 config_->Enable(false,
151 false,
152 params.origin().spec(),
153 params.fallback_origin().spec(),
154 "");
155
156 // Override the data reduction proxy.
157 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy);
158 base::DictionaryValue* dict = update.Get();
159 dict->SetString("server", "https://www.baz.com:22/");
160
161 // This should have no effect since proxy server was overridden.
162 config_->Disable();
163
164 CheckProxyConfig("fixed_servers", "https://www.baz.com:22/", "");
165 }
132 166
133 TEST_F(DataReductionProxyConfigTest, TestBypassList) { 167 TEST_F(DataReductionProxyConfigTest, TestBypassList) {
134 config_->AddHostPatternToBypass("http://www.google.com"); 168 config_->AddHostPatternToBypass("http://www.google.com");
135 config_->AddHostPatternToBypass("fefe:13::abc/33"); 169 config_->AddHostPatternToBypass("fefe:13::abc/33");
136 config_->AddURLPatternToBypass("foo.org/images/*"); 170 config_->AddURLPatternToBypass("foo.org/images/*");
137 config_->AddURLPatternToBypass("http://foo.com/*"); 171 config_->AddURLPatternToBypass("http://foo.com/*");
138 config_->AddURLPatternToBypass("http://baz.com:22/bar/*"); 172 config_->AddURLPatternToBypass("http://baz.com:22/bar/*");
139 config_->AddURLPatternToBypass("http://*bat.com/bar/*"); 173 config_->AddURLPatternToBypass("http://*bat.com/bar/*");
140 174
141 std::string expected[] = { 175 std::string expected[] = {
142 "http://www.google.com", 176 "http://www.google.com",
143 "fefe:13::abc/33", 177 "fefe:13::abc/33",
144 "foo.org", 178 "foo.org",
145 "http://foo.com", 179 "http://foo.com",
146 "http://baz.com:22", 180 "http://baz.com:22",
147 "http://*bat.com" 181 "http://*bat.com"
148 }; 182 };
149 183
150 ASSERT_EQ(config_->bypass_rules_.size(), 6u); 184 ASSERT_EQ(config_->bypass_rules_.size(), 6u);
151 int i = 0; 185 int i = 0;
152 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin(); 186 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin();
153 it != config_->bypass_rules_.end(); ++it) { 187 it != config_->bypass_rules_.end(); ++it) {
154 EXPECT_EQ(expected[i++], *it); 188 EXPECT_EQ(expected[i++], *it);
155 } 189 }
156 } 190 }
157 191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698