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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc

Issue 2922663002: Data Reduction Proxy: Remove duplicate functions (Closed)
Patch Set: megjablon comments Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/core/browser/data_reduction_proxy_conf ig.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cstdlib> 10 #include <cstdlib>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void SetUp() override { 116 void SetUp() override {
117 net::NetworkChangeNotifier::SetTestNotificationsOnly(true); 117 net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
118 base::RunLoop().RunUntilIdle(); 118 base::RunLoop().RunUntilIdle();
119 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 119 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
120 120
121 test_context_ = DataReductionProxyTestContext::Builder() 121 test_context_ = DataReductionProxyTestContext::Builder()
122 .WithMockConfig() 122 .WithMockConfig()
123 .WithMockDataReductionProxyService() 123 .WithMockDataReductionProxyService()
124 .Build(); 124 .Build();
125 125
126 ResetSettings(true, false); 126 ResetSettings();
127 127
128 expected_params_.reset(new TestDataReductionProxyParams( 128 expected_params_.reset(new TestDataReductionProxyParams());
129 DataReductionProxyParams::kPromoAllowed,
130 TestDataReductionProxyParams::HAS_EVERYTHING));
131 } 129 }
132 130
133 void ResetSettings(bool promo_allowed, bool holdback) { 131 void ResetSettings() { config()->ResetParamFlagsForTest(); }
134 int flags = 0;
135 if (promo_allowed)
136 flags |= DataReductionProxyParams::kPromoAllowed;
137 if (holdback)
138 flags |= DataReductionProxyParams::kHoldback;
139 config()->ResetParamFlagsForTest(flags);
140 }
141 132
142 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() { 133 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() {
143 return message_loop_.task_runner(); 134 return message_loop_.task_runner();
144 } 135 }
145 136
146 class TestResponder { 137 class TestResponder {
147 public: 138 public:
148 void ExecuteCallback(FetcherResponseCallback callback) { 139 void ExecuteCallback(FetcherResponseCallback callback) {
149 callback.Run(response, status, http_response_code); 140 callback.Run(response, status, http_response_code);
150 } 141 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 219
229 private: 220 private:
230 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; 221 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
231 222
232 base::MessageLoopForIO message_loop_; 223 base::MessageLoopForIO message_loop_;
233 std::unique_ptr<DataReductionProxyTestContext> test_context_; 224 std::unique_ptr<DataReductionProxyTestContext> test_context_;
234 std::unique_ptr<TestDataReductionProxyParams> expected_params_; 225 std::unique_ptr<TestDataReductionProxyParams> expected_params_;
235 }; 226 };
236 227
237 TEST_F(DataReductionProxyConfigTest, TestReloadConfigHoldback) { 228 TEST_F(DataReductionProxyConfigTest, TestReloadConfigHoldback) {
229 base::FieldTrialList field_trial_list(nullptr);
230 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
231 "DataCompressionProxyHoldback", "Enabled"));
232
238 const net::ProxyServer kHttpsProxy = net::ProxyServer::FromURI( 233 const net::ProxyServer kHttpsProxy = net::ProxyServer::FromURI(
239 "https://secure_origin.net:443", net::ProxyServer::SCHEME_HTTP); 234 "https://secure_origin.net:443", net::ProxyServer::SCHEME_HTTP);
240 const net::ProxyServer kHttpProxy = net::ProxyServer::FromURI( 235 const net::ProxyServer kHttpProxy = net::ProxyServer::FromURI(
241 "insecure_origin.net:80", net::ProxyServer::SCHEME_HTTP); 236 "insecure_origin.net:80", net::ProxyServer::SCHEME_HTTP);
242 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy}); 237 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy});
243 238
244 ResetSettings(true, true); 239 ResetSettings();
245 240
246 config()->UpdateConfigForTesting(true, false); 241 config()->UpdateConfigForTesting(true, false);
247 config()->ReloadConfig(); 242 config()->ReloadConfig();
248 EXPECT_EQ(std::vector<net::ProxyServer>(), GetConfiguredProxiesForHttp()); 243 EXPECT_EQ(std::vector<net::ProxyServer>(), GetConfiguredProxiesForHttp());
249 } 244 }
250 245
251 TEST_F(DataReductionProxyConfigTest, TestOnIPAddressChanged) { 246 TEST_F(DataReductionProxyConfigTest, TestOnIPAddressChanged) {
252 const net::URLRequestStatus kSuccess(net::URLRequestStatus::SUCCESS, net::OK); 247 const net::URLRequestStatus kSuccess(net::URLRequestStatus::SUCCESS, net::OK);
253 const net::ProxyServer kHttpsProxy = net::ProxyServer::FromURI( 248 const net::ProxyServer kHttpsProxy = net::ProxyServer::FromURI(
254 "https://secure_origin.net:443", net::ProxyServer::SCHEME_HTTP); 249 "https://secure_origin.net:443", net::ProxyServer::SCHEME_HTTP);
255 const net::ProxyServer kHttpProxy = net::ProxyServer::FromURI( 250 const net::ProxyServer kHttpProxy = net::ProxyServer::FromURI(
256 "insecure_origin.net:80", net::ProxyServer::SCHEME_HTTP); 251 "insecure_origin.net:80", net::ProxyServer::SCHEME_HTTP);
257 252
258 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy}); 253 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy});
259 ResetSettings(true, false); 254 ResetSettings();
260 255
261 // The proxy is enabled initially. 256 // The proxy is enabled initially.
262 config()->UpdateConfigForTesting(true, true); 257 config()->UpdateConfigForTesting(true, true);
263 config()->ReloadConfig(); 258 config()->ReloadConfig();
264 259
265 // IP address change triggers a secure proxy check that succeeds. Proxy 260 // IP address change triggers a secure proxy check that succeeds. Proxy
266 // remains unrestricted. 261 // remains unrestricted.
267 CheckSecureProxyCheckOnIPChange("OK", false, net::HTTP_OK, kSuccess, 262 CheckSecureProxyCheckOnIPChange("OK", false, net::HTTP_OK, kSuccess,
268 SUCCEEDED_PROXY_ALREADY_ENABLED, 263 SUCCEEDED_PROXY_ALREADY_ENABLED,
269 {kHttpsProxy, kHttpProxy}); 264 {kHttpsProxy, kHttpProxy});
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 true, false, 355 true, false,
361 }, 356 },
362 { 357 {
363 true, true, 358 true, true,
364 }, 359 },
365 }; 360 };
366 for (const auto& test : tests) { 361 for (const auto& test : tests) {
367 base::HistogramTester histogram_tester; 362 base::HistogramTester histogram_tester;
368 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy}); 363 SetProxiesForHttpOnCommandLine({kHttpsProxy, kHttpProxy});
369 364
370 ResetSettings(true, false); 365 ResetSettings();
371 366
372 variations::testing::ClearAllVariationParams(); 367 variations::testing::ClearAllVariationParams();
373 std::map<std::string, std::string> variation_params; 368 std::map<std::string, std::string> variation_params;
374 variation_params["enable_warmup"] = 369 variation_params["enable_warmup"] =
375 test.enabled_via_field_trial ? "true" : "false"; 370 test.enabled_via_field_trial ? "true" : "false";
376 variation_params["warmup_url"] = warmup_url.spec(); 371 variation_params["warmup_url"] = warmup_url.spec();
377 372
378 ASSERT_TRUE(variations::AssociateVariationParams( 373 ASSERT_TRUE(variations::AssociateVariationParams(
379 params::GetQuicFieldTrialName(), "Enabled", variation_params)); 374 params::GetQuicFieldTrialName(), "Enabled", variation_params));
380 375
381 base::FieldTrialList field_trial_list(nullptr); 376 base::FieldTrialList field_trial_list(nullptr);
382 base::FieldTrialList::CreateFieldTrial(params::GetQuicFieldTrialName(), 377 base::FieldTrialList::CreateFieldTrial(params::GetQuicFieldTrialName(),
383 "Enabled"); 378 "Enabled");
384 379
385 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); 380 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
386 TestDataReductionProxyConfig config( 381 TestDataReductionProxyConfig config(task_runner(), nullptr, configurator(),
387 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr, 382 event_creator());
388 configurator(), event_creator());
389 383
390 scoped_refptr<net::URLRequestContextGetter> request_context_getter_ = 384 scoped_refptr<net::URLRequestContextGetter> request_context_getter_ =
391 new net::TestURLRequestContextGetter(task_runner()); 385 new net::TestURLRequestContextGetter(task_runner());
392 config.InitializeOnIOThread(request_context_getter_.get(), 386 config.InitializeOnIOThread(request_context_getter_.get(),
393 request_context_getter_.get()); 387 request_context_getter_.get());
394 388
395 // Set the connection type to WiFi so that warm up URL is fetched even if 389 // Set the connection type to WiFi so that warm up URL is fetched even if
396 // the test device does not have connectivity. 390 // the test device does not have connectivity.
397 config.connection_type_ = net::NetworkChangeNotifier::CONNECTION_WIFI; 391 config.connection_type_ = net::NetworkChangeNotifier::CONNECTION_WIFI;
398 config.SetProxyConfig(test.data_reduction_proxy_enabled, true); 392 config.SetProxyConfig(test.data_reduction_proxy_enabled, true);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (tests[i].allowed) 580 if (tests[i].allowed)
587 proxies.push_back(origin); 581 proxies.push_back(origin);
588 if (tests[i].allowed && tests[i].fallback_allowed) 582 if (tests[i].allowed && tests[i].fallback_allowed)
589 proxies.push_back(fallback_origin); 583 proxies.push_back(fallback_origin);
590 584
591 std::string proxy_rules = "http=" + base::JoinString(proxies, ",") + 585 std::string proxy_rules = "http=" + base::JoinString(proxies, ",") +
592 ",direct://;"; 586 ",direct://;";
593 587
594 rules.ParseFromString(proxy_rules); 588 rules.ParseFromString(proxy_rules);
595 589
596 int flags = 0;
597 unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING;
598 std::unique_ptr<TestDataReductionProxyParams> params( 590 std::unique_ptr<TestDataReductionProxyParams> params(
599 new TestDataReductionProxyParams(flags, has_definitions)); 591 new TestDataReductionProxyParams());
600 std::unique_ptr<DataReductionProxyConfig> config = 592 std::unique_ptr<DataReductionProxyConfig> config =
601 BuildConfig(std::move(params)); 593 BuildConfig(std::move(params));
602 594
603 net::ProxyRetryInfoMap retry_map; 595 net::ProxyRetryInfoMap retry_map;
604 net::ProxyRetryInfo retry_info; 596 net::ProxyRetryInfo retry_info;
605 retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max(); 597 retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max();
606 598
607 if (tests[i].origin) 599 if (tests[i].origin)
608 retry_map[origin] = retry_info; 600 retry_map[origin] = retry_info;
609 if (tests[i].fallback_origin) 601 if (tests[i].fallback_origin)
(...skipping 18 matching lines...) Expand all
628 std::vector<std::string> proxies; 620 std::vector<std::string> proxies;
629 621
630 proxies.push_back(origin); 622 proxies.push_back(origin);
631 proxies.push_back(fallback_origin); 623 proxies.push_back(fallback_origin);
632 624
633 std::string proxy_rules = 625 std::string proxy_rules =
634 "http=" + base::JoinString(proxies, ",") + ",direct://;"; 626 "http=" + base::JoinString(proxies, ",") + ",direct://;";
635 627
636 rules.ParseFromString(proxy_rules); 628 rules.ParseFromString(proxy_rules);
637 629
638 int flags = 0;
639 unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING;
640 std::unique_ptr<TestDataReductionProxyParams> params( 630 std::unique_ptr<TestDataReductionProxyParams> params(
641 new TestDataReductionProxyParams(flags, has_definitions)); 631 new TestDataReductionProxyParams());
642 std::unique_ptr<DataReductionProxyConfig> config = 632 std::unique_ptr<DataReductionProxyConfig> config =
643 BuildConfig(std::move(params)); 633 BuildConfig(std::move(params));
644 634
645 net::ProxyRetryInfoMap retry_map; 635 net::ProxyRetryInfoMap retry_map;
646 net::ProxyRetryInfo retry_info; 636 net::ProxyRetryInfo retry_info;
647 637
648 retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max(); 638 retry_info.bad_until = base::TimeTicks() + base::TimeDelta::Max();
649 retry_map[origin] = retry_info; 639 retry_map[origin] = retry_info;
650 640
651 retry_info.bad_until = base::TimeTicks(); 641 retry_info.bad_until = base::TimeTicks();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 false}, 686 false},
697 {net::ProxyServer::FromURI( 687 {net::ProxyServer::FromURI(
698 TestDataReductionProxyParams::DefaultFallbackOrigin(), 688 TestDataReductionProxyParams::DefaultFallbackOrigin(),
699 net::ProxyServer::SCHEME_HTTP), 689 net::ProxyServer::SCHEME_HTTP),
700 true, net::ProxyServer::FromURI( 690 true, net::ProxyServer::FromURI(
701 TestDataReductionProxyParams::DefaultFallbackOrigin(), 691 TestDataReductionProxyParams::DefaultFallbackOrigin(),
702 net::ProxyServer::SCHEME_HTTP), 692 net::ProxyServer::SCHEME_HTTP),
703 net::ProxyServer(), true}, 693 net::ProxyServer(), true},
704 }; 694 };
705 for (size_t i = 0; i < arraysize(tests); ++i) { 695 for (size_t i = 0; i < arraysize(tests); ++i) {
706 int flags = 0;
707 unsigned int has_definitions = TestDataReductionProxyParams::HAS_EVERYTHING;
708 std::unique_ptr<TestDataReductionProxyParams> params( 696 std::unique_ptr<TestDataReductionProxyParams> params(
709 new TestDataReductionProxyParams(flags, has_definitions)); 697 new TestDataReductionProxyParams());
710 DataReductionProxyTypeInfo proxy_type_info; 698 DataReductionProxyTypeInfo proxy_type_info;
711 std::unique_ptr<DataReductionProxyConfig> config( 699 std::unique_ptr<DataReductionProxyConfig> config(
712 new DataReductionProxyConfig(task_runner(), net_log(), 700 new DataReductionProxyConfig(task_runner(), net_log(),
713 std::move(params), configurator(), 701 std::move(params), configurator(),
714 event_creator())); 702 event_creator()));
715 EXPECT_EQ( 703 EXPECT_EQ(
716 tests[i].expected_result, 704 tests[i].expected_result,
717 config->IsDataReductionProxy(tests[i].proxy_server, &proxy_type_info)) 705 config->IsDataReductionProxy(tests[i].proxy_server, &proxy_type_info))
718 << i; 706 << i;
719 EXPECT_EQ(tests[i].expected_first.is_valid(), 707 EXPECT_EQ(tests[i].expected_first.is_valid(),
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 } 1254 }
1267 1255
1268 // Tests if metrics for Lo-Fi accuracy are recorded properly. 1256 // Tests if metrics for Lo-Fi accuracy are recorded properly.
1269 TEST_F(DataReductionProxyConfigTest, LoFiAccuracy) { 1257 TEST_F(DataReductionProxyConfigTest, LoFiAccuracy) {
1270 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1258 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1271 new base::SimpleTestTickClock()); 1259 new base::SimpleTestTickClock());
1272 1260
1273 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals; 1261 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
1274 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(0)); 1262 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(0));
1275 1263
1276 TestDataReductionProxyConfig config( 1264 TestDataReductionProxyConfig config(task_runner(), nullptr, configurator(),
1277 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr, 1265 event_creator());
1278 configurator(), event_creator());
1279 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals); 1266 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
1280 config.SetTickClock(tick_clock.get()); 1267 config.SetTickClock(tick_clock.get());
1281 1268
1282 variations::testing::ClearAllVariationParams(); 1269 variations::testing::ClearAllVariationParams();
1283 std::map<std::string, std::string> variation_params; 1270 std::map<std::string, std::string> variation_params;
1284 1271
1285 int expected_hysteresis_sec = 360; 1272 int expected_hysteresis_sec = 360;
1286 1273
1287 variation_params["effective_connection_type"] = "Slow2G"; 1274 variation_params["effective_connection_type"] = "Slow2G";
1288 variation_params["hysteresis_period_seconds"] = 1275 variation_params["hysteresis_period_seconds"] =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 1341
1355 // Tests if metrics for Lo-Fi accuracy are recorded properly at the specified 1342 // Tests if metrics for Lo-Fi accuracy are recorded properly at the specified
1356 // interval. 1343 // interval.
1357 TEST_F(DataReductionProxyConfigTest, LoFiAccuracyNonZeroDelay) { 1344 TEST_F(DataReductionProxyConfigTest, LoFiAccuracyNonZeroDelay) {
1358 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1345 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1359 new base::SimpleTestTickClock()); 1346 new base::SimpleTestTickClock());
1360 1347
1361 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals; 1348 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals;
1362 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(1)); 1349 lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(1));
1363 1350
1364 TestDataReductionProxyConfig config( 1351 TestDataReductionProxyConfig config(task_runner(), nullptr, configurator(),
1365 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr, 1352 event_creator());
1366 configurator(), event_creator());
1367 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals); 1353 config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals);
1368 config.SetTickClock(tick_clock.get()); 1354 config.SetTickClock(tick_clock.get());
1369 1355
1370 variations::testing::ClearAllVariationParams(); 1356 variations::testing::ClearAllVariationParams();
1371 std::map<std::string, std::string> variation_params; 1357 std::map<std::string, std::string> variation_params;
1372 1358
1373 variation_params["effective_connection_type"] = "Slow2G"; 1359 variation_params["effective_connection_type"] = "Slow2G";
1374 1360
1375 ASSERT_TRUE(variations::AssociateVariationParams( 1361 ASSERT_TRUE(variations::AssociateVariationParams(
1376 params::GetLoFiFieldTrialName(), "Enabled", variation_params)); 1362 params::GetLoFiFieldTrialName(), "Enabled", variation_params));
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 "DataReductionProxyPreviewsBlackListTransition", "Enabled"); 1723 "DataReductionProxyPreviewsBlackListTransition", "Enabled");
1738 EXPECT_FALSE(config()->ShouldAcceptLitePages(*request.get(), 1724 EXPECT_FALSE(config()->ShouldAcceptLitePages(*request.get(),
1739 *previews_decider.get())); 1725 *previews_decider.get()));
1740 previews_decider = base::MakeUnique<TestPreviewsDecider>(true); 1726 previews_decider = base::MakeUnique<TestPreviewsDecider>(true);
1741 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(), 1727 EXPECT_TRUE(config()->ShouldAcceptLitePages(*request.get(),
1742 *previews_decider.get())); 1728 *previews_decider.get()));
1743 } 1729 }
1744 } 1730 }
1745 1731
1746 } // namespace data_reduction_proxy 1732 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698