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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc

Issue 412143009: Moved data reduction proxy initialization logic to ProfileImplIOData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 6 years, 4 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
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_config_se rvice.h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se rvice.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using testing::Mock; 16 using testing::Mock;
16 17
17 namespace { 18 namespace {
18 19
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 config_service_->RemoveObserver(&observer); 192 config_service_->RemoveObserver(&observer);
192 } 193 }
193 194
194 TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) { 195 TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) {
195 MockObserver observer; 196 MockObserver observer;
196 //base::MessageLoopForUI loop; 197 //base::MessageLoopForUI loop;
197 config_service_->AddObserver(&observer); 198 config_service_->AddObserver(&observer);
198 scoped_refptr<base::TestSimpleTaskRunner> task_runner_( 199 scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
199 new base::TestSimpleTaskRunner()); 200 new base::TestSimpleTaskRunner());
200 DataReductionProxyConfigTracker tracker(config_service_.get(), 201 DataReductionProxyConfigTracker tracker(
201 task_runner_.get()); 202 base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
203 UpdateProxyConfig,
204 base::Unretained(config_service_.get())),
205 task_runner_.get());
202 net::ProxyConfig expected_config; 206 net::ProxyConfig expected_config;
203 expected_config.proxy_rules().ParseFromString(kDataReductionProxyRules); 207 expected_config.proxy_rules().ParseFromString(kDataReductionProxyRules);
204 EXPECT_CALL(observer, OnProxyConfigChanged( 208 EXPECT_CALL(observer, OnProxyConfigChanged(
205 ProxyConfigMatches(expected_config), 209 ProxyConfigMatches(expected_config),
206 net::ProxyConfigService::CONFIG_VALID)).Times(1); 210 net::ProxyConfigService::CONFIG_VALID)).Times(1);
207 tracker.Enable(false, 211 tracker.Enable(false,
208 false, 212 false,
209 "https://foo.com:443", 213 "https://foo.com:443",
210 "http://bar.com:80", 214 "http://bar.com:80",
211 ""); 215 "");
212 task_runner_->RunUntilIdle(); 216 task_runner_->RunUntilIdle();
213 Mock::VerifyAndClearExpectations(&observer); 217 Mock::VerifyAndClearExpectations(&observer);
214 218
215 config_service_->RemoveObserver(&observer); 219 config_service_->RemoveObserver(&observer);
216 } 220 }
217 221
218 TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) { 222 TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) {
219 MockObserver observer; 223 MockObserver observer;
220 //base::MessageLoopForUI loop; 224 //base::MessageLoopForUI loop;
221 config_service_->AddObserver(&observer); 225 config_service_->AddObserver(&observer);
222 scoped_refptr<base::TestSimpleTaskRunner> task_runner_( 226 scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
223 new base::TestSimpleTaskRunner()); 227 new base::TestSimpleTaskRunner());
224 DataReductionProxyConfigTracker tracker(config_service_.get(), 228 DataReductionProxyConfigTracker tracker(
225 task_runner_.get()); 229 base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
230 UpdateProxyConfig,
231 base::Unretained(config_service_.get())),
232 task_runner_.get());
226 net::ProxyConfig expected_config; 233 net::ProxyConfig expected_config;
227 expected_config.proxy_rules().ParseFromString( 234 expected_config.proxy_rules().ParseFromString(
228 kDataReductionProxyRestrictedRules); 235 kDataReductionProxyRestrictedRules);
229 EXPECT_CALL(observer, OnProxyConfigChanged( 236 EXPECT_CALL(observer, OnProxyConfigChanged(
230 ProxyConfigMatches(expected_config), 237 ProxyConfigMatches(expected_config),
231 net::ProxyConfigService::CONFIG_VALID)).Times(1); 238 net::ProxyConfigService::CONFIG_VALID)).Times(1);
232 tracker.Enable(true, 239 tracker.Enable(true,
233 false, 240 false,
234 "https://foo.com:443", 241 "https://foo.com:443",
235 "http://bar.com:80", 242 "http://bar.com:80",
236 ""); 243 "");
237 task_runner_->RunUntilIdle(); 244 task_runner_->RunUntilIdle();
238 Mock::VerifyAndClearExpectations(&observer); 245 Mock::VerifyAndClearExpectations(&observer);
239 246
240 config_service_->RemoveObserver(&observer); 247 config_service_->RemoveObserver(&observer);
241 } 248 }
242 249
243 TEST_F(DataReductionProxyConfigServiceTest, TrackerDisable) { 250 TEST_F(DataReductionProxyConfigServiceTest, TrackerDisable) {
244 MockObserver observer; 251 MockObserver observer;
245 //base::MessageLoopForUI loop; 252 //base::MessageLoopForUI loop;
246 config_service_->AddObserver(&observer); 253 config_service_->AddObserver(&observer);
247 scoped_refptr<base::TestSimpleTaskRunner> task_runner_( 254 scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
248 new base::TestSimpleTaskRunner()); 255 new base::TestSimpleTaskRunner());
249 DataReductionProxyConfigTracker tracker(config_service_.get(), 256 DataReductionProxyConfigTracker tracker(
250 task_runner_.get()); 257 base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
258 UpdateProxyConfig,
259 base::Unretained(config_service_.get())),
260 task_runner_.get());
251 net::ProxyConfig expected_config; 261 net::ProxyConfig expected_config;
252 expected_config.proxy_rules().ParseFromString(kSystemProxyRules); 262 expected_config.proxy_rules().ParseFromString(kSystemProxyRules);
253 EXPECT_CALL(observer, OnProxyConfigChanged( 263 EXPECT_CALL(observer, OnProxyConfigChanged(
254 ProxyConfigMatches(expected_config), 264 ProxyConfigMatches(expected_config),
255 net::ProxyConfigService::CONFIG_VALID)).Times(1); 265 net::ProxyConfigService::CONFIG_VALID)).Times(1);
256 tracker.Disable(); 266 tracker.Disable();
257 task_runner_->RunUntilIdle(); 267 task_runner_->RunUntilIdle();
258 //loop.RunUntilIdle(); 268 //loop.RunUntilIdle();
259 Mock::VerifyAndClearExpectations(&observer); 269 Mock::VerifyAndClearExpectations(&observer);
260 270
261 config_service_->RemoveObserver(&observer); 271 config_service_->RemoveObserver(&observer);
262 } 272 }
263 273
264 274
265 TEST_F(DataReductionProxyConfigServiceTest, TrackerBypassList) { 275 TEST_F(DataReductionProxyConfigServiceTest, TrackerBypassList) {
266 base::MessageLoopForUI loop; 276 base::MessageLoopForUI loop;
267 scoped_refptr<base::TestSimpleTaskRunner> task_runner_( 277 scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
268 new base::TestSimpleTaskRunner()); 278 new base::TestSimpleTaskRunner());
269 DataReductionProxyConfigTracker tracker(config_service_.get(), 279 DataReductionProxyConfigTracker tracker(
270 task_runner_.get()); 280 base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
281 UpdateProxyConfig,
282 base::Unretained(config_service_.get())),
283 task_runner_.get());
271 tracker.AddHostPatternToBypass("http://www.google.com"); 284 tracker.AddHostPatternToBypass("http://www.google.com");
272 tracker.AddHostPatternToBypass("fefe:13::abc/33"); 285 tracker.AddHostPatternToBypass("fefe:13::abc/33");
273 tracker.AddURLPatternToBypass("foo.org/images/*"); 286 tracker.AddURLPatternToBypass("foo.org/images/*");
274 tracker.AddURLPatternToBypass("http://foo.com/*"); 287 tracker.AddURLPatternToBypass("http://foo.com/*");
275 tracker.AddURLPatternToBypass("http://baz.com:22/bar/*"); 288 tracker.AddURLPatternToBypass("http://baz.com:22/bar/*");
276 tracker.AddURLPatternToBypass("http://*bat.com/bar/*"); 289 tracker.AddURLPatternToBypass("http://*bat.com/bar/*");
277 290
278 std::string expected[] = { 291 std::string expected[] = {
279 "http://www.google.com", 292 "http://www.google.com",
280 "fefe:13::abc/33", 293 "fefe:13::abc/33",
281 "foo.org", 294 "foo.org",
282 "http://foo.com", 295 "http://foo.com",
283 "http://baz.com:22", 296 "http://baz.com:22",
284 "http://*bat.com" 297 "http://*bat.com"
285 }; 298 };
286 299
287 ASSERT_EQ(tracker.bypass_rules_.size(), 6u); 300 ASSERT_EQ(tracker.bypass_rules_.size(), 6u);
288 int i = 0; 301 int i = 0;
289 for (std::vector<std::string>::iterator it = tracker.bypass_rules_.begin(); 302 for (std::vector<std::string>::iterator it = tracker.bypass_rules_.begin();
290 it != tracker.bypass_rules_.end(); ++it) { 303 it != tracker.bypass_rules_.end(); ++it) {
291 EXPECT_EQ(expected[i++], *it); 304 EXPECT_EQ(expected[i++], *it);
292 } 305 }
293 } 306 }
294 307
295 } // namespace data_reduction_proxy 308 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698