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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/field_trial.h" | |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator_test_utils.h" | 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf igurator_test_utils.h" |
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h" | 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings_test_utils.h" |
14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" | 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" |
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" |
17 #include "net/http/http_auth.h" | 18 #include "net/http/http_auth.h" |
18 #include "net/http/http_auth_cache.h" | 19 #include "net/http/http_auth_cache.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kProbeURLWithOKResponse[] = "http://ok.org/"; | 25 const char kProbeURLWithOKResponse[] = "http://ok.org/"; |
25 const char kProbeURLWithBadResponse[] = "http://bad.org/"; | 26 const char kProbeURLWithBadResponse[] = "http://bad.org/"; |
26 const char kProbeURLWithNoResponse[] = "http://no.org/"; | 27 const char kProbeURLWithNoResponse[] = "http://no.org/"; |
27 | 28 |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 namespace data_reduction_proxy { | 31 namespace data_reduction_proxy { |
31 | 32 |
32 class DataReductionProxyStatisticsPrefs; | 33 class DataReductionProxyStatisticsPrefs; |
33 | 34 |
35 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | |
36 public: | |
37 ~BadEntropyProvider() override {} | |
38 | |
39 double GetEntropyForTrial(const std::string& trial_name, | |
40 uint32 randomization_seed) const override { | |
41 return 0.5; | |
42 } | |
43 }; | |
44 | |
34 class DataReductionProxySettingsTest | 45 class DataReductionProxySettingsTest |
35 : public ConcreteDataReductionProxySettingsTest< | 46 : public ConcreteDataReductionProxySettingsTest< |
36 DataReductionProxySettings> { | 47 DataReductionProxySettings> { |
37 }; | 48 }; |
38 | 49 |
39 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 50 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
40 // SetUp() adds the origin to the command line, which should be returned here. | 51 // SetUp() adds the origin to the command line, which should be returned here. |
41 std::string result = | 52 std::string result = |
42 settings_->params()->origin().ToURI(); | 53 settings_->params()->origin().ToURI(); |
43 EXPECT_EQ(expected_params_->DefaultOrigin(), result); | 54 EXPECT_EQ(expected_params_->DefaultOrigin(), result); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 &net_log_, | 441 &net_log_, |
431 event_store_.get()); | 442 event_store_.get()); |
432 settings_->SetOnDataReductionEnabledCallback( | 443 settings_->SetOnDataReductionEnabledCallback( |
433 base::Bind(&DataReductionProxySettingsTestBase:: | 444 base::Bind(&DataReductionProxySettingsTestBase:: |
434 RegisterSyntheticFieldTrialCallback, | 445 RegisterSyntheticFieldTrialCallback, |
435 base::Unretained(this))); | 446 base::Unretained(this))); |
436 | 447 |
437 base::MessageLoop::current()->RunUntilIdle(); | 448 base::MessageLoop::current()->RunUntilIdle(); |
438 } | 449 } |
439 | 450 |
451 TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) { | |
452 const struct { | |
453 bool enable_quic; | |
454 } tests[] = { | |
455 { | |
456 false, | |
457 }, | |
458 { | |
459 true, | |
460 }, | |
461 }; | |
462 | |
463 for (size_t i = 0; i < arraysize(tests); ++i) { | |
Ryan Hamilton
2015/02/14 00:09:23
nit: Your call but consider writing this as:
for
tbansal1
2015/02/14 01:06:11
Good suggestion, done.
| |
464 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | |
465 // should be unavailable. | |
466 base::MessageLoopForUI loop; | |
467 // Clear the command line. Setting flags can force the proxy to be allowed. | |
468 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); | |
469 | |
470 ResetSettings(false, false, false, false, false); | |
471 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | |
472 EXPECT_FALSE(settings->params()->allowed()); | |
473 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | |
474 | |
475 scoped_ptr<DataReductionProxyConfigurator> configurator( | |
476 new TestDataReductionProxyConfigurator( | |
477 scoped_refptr<base::TestSimpleTaskRunner>( | |
478 new base::TestSimpleTaskRunner()), | |
479 &net_log_, event_store_.get())); | |
480 settings_->SetProxyConfigurator(configurator.get()); | |
481 scoped_refptr<net::TestURLRequestContextGetter> request_context = | |
482 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | |
483 | |
484 settings_->InitDataReductionProxySettings( | |
485 &pref_service_, | |
486 scoped_ptr<DataReductionProxyStatisticsPrefs>(), | |
487 request_context.get(), | |
488 &net_log_, | |
489 event_store_.get()); | |
490 | |
491 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | |
492 if (tests[i].enable_quic){ | |
493 base::FieldTrialList::CreateFieldTrial( | |
494 DataReductionProxyParams::GetQuicFieldTrialName(), | |
495 "Enabled"); | |
496 } else { | |
497 base::FieldTrialList::CreateFieldTrial( | |
498 DataReductionProxyParams::GetQuicFieldTrialName(), | |
499 "Disabled"); | |
500 } | |
501 settings_->params()->EnableQuic(tests[i].enable_quic); | |
502 | |
503 settings_->SetOnDataReductionEnabledCallback( | |
504 base::Bind(&DataReductionProxySettingsTestBase:: | |
505 RegisterSyntheticFieldTrialCallback, | |
506 base::Unretained(this))); | |
507 | |
508 EXPECT_EQ(tests[i].enable_quic, | |
509 settings->params()->origin().is_quic()) << i; | |
510 } | |
511 } | |
512 | |
440 } // namespace data_reduction_proxy | 513 } // namespace data_reduction_proxy |
OLD | NEW |