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

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

Issue 792803007: Make Data Reduction Proxy a best effort proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated tests Created 5 years, 11 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator. h"
6
7 #include <string>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/prefs/testing_pref_service.h"
13 #include "base/test/test_simple_task_runner.h"
14 #include "base/values.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event _store.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
18 #include "net/base/capturing_net_log.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 class DataReductionProxyConfigTest : public testing::Test {
23 public:
24 void SetUp() override {
25 PrefRegistrySimple* registry = pref_service_.registry();
26 registry->RegisterDictionaryPref(prefs::kProxy);
27 net_log_.reset(new net::CapturingNetLog());
28 data_reduction_proxy_event_store_.reset(
29 new data_reduction_proxy::DataReductionProxyEventStore(
30 new base::TestSimpleTaskRunner()));
31 config_.reset(new DataReductionProxyChromeConfigurator(
32 &pref_service_,
33 new base::TestSimpleTaskRunner(),
34 net_log_.get(),
35 data_reduction_proxy_event_store_.get()));
36 }
37
38 void CheckProxyConfig(
39 const std::string& expected_mode,
40 const std::string& expected_server,
41 const std::string& expected_bypass_list) {
42
43 const base::DictionaryValue* dict =
44 pref_service_.GetDictionary(prefs::kProxy);
45 std::string mode;
46 std::string server;
47 std::string bypass_list;
48 dict->GetString("mode", &mode);
49 ASSERT_EQ(expected_mode, mode);
50 dict->GetString("server", &server);
51 ASSERT_EQ(expected_server, server);
52 dict->GetString("bypass_list", &bypass_list);
53 ASSERT_EQ(expected_bypass_list, bypass_list);
54 }
55
56 scoped_ptr<DataReductionProxyChromeConfigurator> config_;
57 TestingPrefServiceSimple pref_service_;
58 scoped_ptr<net::NetLog> net_log_;
59 scoped_ptr<data_reduction_proxy::DataReductionProxyEventStore>
60 data_reduction_proxy_event_store_;
61 };
62
63 TEST_F(DataReductionProxyConfigTest, TestUnrestricted) {
64 config_->Enable(false,
65 false,
66 "https://www.foo.com:443/",
67 "http://www.bar.com:80/",
68 "");
69 CheckProxyConfig(
70 "fixed_servers",
71 "http=https://www.foo.com:443,http://www.bar.com:80,direct://;",
72 "");
73 }
74
75 TEST_F(DataReductionProxyConfigTest, TestUnrestrictedSSL) {
76 config_->Enable(false,
77 false,
78 "https://www.foo.com:443/",
79 "http://www.bar.com:80/",
80 "http://www.ssl.com:80/");
81 CheckProxyConfig(
82 "fixed_servers",
83 "http=https://www.foo.com:443,http://www.bar.com:80,direct://;"
84 "https=http://www.ssl.com:80,direct://;",
85 "");
86 }
87
88 TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) {
89 config_->AddHostPatternToBypass("<local>");
90 config_->AddHostPatternToBypass("*.goo.com");
91 config_->Enable(false,
92 false,
93 "https://www.foo.com:443/",
94 "http://www.bar.com:80/",
95 "");
96 CheckProxyConfig(
97 "fixed_servers",
98 "http=https://www.foo.com:443,http://www.bar.com:80,direct://;",
99 "<local>, *.goo.com");
100 }
101
102 TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithoutFallback) {
103 config_->Enable(false, false, "https://www.foo.com:443/", "", "");
104 CheckProxyConfig("fixed_servers",
105 "http=https://www.foo.com:443,direct://;",
106 "");
107 }
108
109 TEST_F(DataReductionProxyConfigTest, TestRestricted) {
110 config_->Enable(true,
111 false,
112 "https://www.foo.com:443/",
113 "http://www.bar.com:80/",
114 "");
115 CheckProxyConfig("fixed_servers",
116 "http=http://www.bar.com:80,direct://;",
117 "");
118 }
119
120 TEST_F(DataReductionProxyConfigTest, TestFallbackRestricted) {
121 config_->Enable(false,
122 true,
123 "https://www.foo.com:443/",
124 "http://www.bar.com:80/",
125 "");
126 CheckProxyConfig("fixed_servers",
127 "http=https://www.foo.com:443,direct://;",
128 "");
129 }
130
131 TEST_F(DataReductionProxyConfigTest, TestBothRestricted) {
132 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy);
133 base::DictionaryValue* dict = update.Get();
134 dict->SetString("mode", "system");
135
136 config_->Enable(true,
137 true,
138 "https://www.foo.com:443/",
139 "http://www.bar.com:80/",
140 "");
141 CheckProxyConfig("system", "", "");
142 }
143
144 TEST_F(DataReductionProxyConfigTest, TestDisable) {
145 data_reduction_proxy::DataReductionProxyParams params(
146 data_reduction_proxy::DataReductionProxyParams::
147 kAllowAllProxyConfigurations);
148 config_->Enable(false,
149 false,
150 params.origin().spec(),
151 params.fallback_origin().spec(),
152 "");
153 config_->Disable();
154 CheckProxyConfig("system", "", "");
155 }
156
157 TEST_F(DataReductionProxyConfigTest, TestDisableWithUserOverride) {
158 data_reduction_proxy::DataReductionProxyParams params(
159 data_reduction_proxy::DataReductionProxyParams::
160 kAllowAllProxyConfigurations);
161 config_->Enable(false,
162 false,
163 params.origin().spec(),
164 params.fallback_origin().spec(),
165 "");
166
167 // Override the data reduction proxy.
168 DictionaryPrefUpdate update(&pref_service_, prefs::kProxy);
169 base::DictionaryValue* dict = update.Get();
170 dict->SetString("server", "https://www.baz.com:22/");
171
172 // This should have no effect since proxy server was overridden.
173 config_->Disable();
174
175 CheckProxyConfig("fixed_servers", "https://www.baz.com:22/", "");
176 }
177
178 TEST_F(DataReductionProxyConfigTest, TestBypassList) {
179 config_->AddHostPatternToBypass("http://www.google.com");
180 config_->AddHostPatternToBypass("fefe:13::abc/33");
181 config_->AddURLPatternToBypass("foo.org/images/*");
182 config_->AddURLPatternToBypass("http://foo.com/*");
183 config_->AddURLPatternToBypass("http://baz.com:22/bar/*");
184 config_->AddURLPatternToBypass("http://*bat.com/bar/*");
185
186 std::string expected[] = {
187 "http://www.google.com",
188 "fefe:13::abc/33",
189 "foo.org",
190 "http://foo.com",
191 "http://baz.com:22",
192 "http://*bat.com"
193 };
194
195 ASSERT_EQ(config_->bypass_rules_.size(), 6u);
196 int i = 0;
197 for (std::vector<std::string>::iterator it = config_->bypass_rules_.begin();
198 it != config_->bypass_rules_.end(); ++it) {
199 EXPECT_EQ(expected[i++], *it);
200 }
201 }
202
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698