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 |
33 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | |
34 public: | |
35 ~BadEntropyProvider() override {} | |
bengr
2015/02/11 23:57:28
Move close curly to new line.
tbansal1
2015/02/12 02:27:22
I don't understand the comment.
bengr
2015/02/12 17:14:46
I mean, style afaik is to do:
~BadEntopyProvider()
tbansal1
2015/02/13 17:10:39
Not sure, see: https://code.google.com/p/chromium/
| |
36 | |
37 double GetEntropyForTrial(const std::string& trial_name, | |
38 uint32 randomization_seed) const override { | |
39 return 0.5; | |
40 } | |
41 }; | |
42 | |
43 | |
32 class DataReductionProxySettingsTest | 44 class DataReductionProxySettingsTest |
33 : public ConcreteDataReductionProxySettingsTest< | 45 : public ConcreteDataReductionProxySettingsTest< |
34 DataReductionProxySettings> { | 46 DataReductionProxySettings> { |
35 }; | 47 }; |
36 | 48 |
37 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { | 49 TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { |
38 // SetUp() adds the origin to the command line, which should be returned here. | 50 // SetUp() adds the origin to the command line, which should be returned here. |
39 std::string result = | 51 std::string result = |
40 settings_->params()->origin().ToURI(); | 52 settings_->params()->origin().ToURI(); |
41 EXPECT_EQ(expected_params_->DefaultOrigin(), result); | 53 EXPECT_EQ(expected_params_->DefaultOrigin(), result); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 &net_log_, | 439 &net_log_, |
428 event_store_.get()); | 440 event_store_.get()); |
429 settings_->SetOnDataReductionEnabledCallback( | 441 settings_->SetOnDataReductionEnabledCallback( |
430 base::Bind(&DataReductionProxySettingsTestBase:: | 442 base::Bind(&DataReductionProxySettingsTestBase:: |
431 RegisterSyntheticFieldTrialCallback, | 443 RegisterSyntheticFieldTrialCallback, |
432 base::Unretained(this))); | 444 base::Unretained(this))); |
433 | 445 |
434 base::MessageLoop::current()->RunUntilIdle(); | 446 base::MessageLoop::current()->RunUntilIdle(); |
435 } | 447 } |
436 | 448 |
449 TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) { | |
450 const struct { | |
451 bool enable_quic; | |
452 bool enable_quic_field_trial; | |
453 } tests[] = { | |
454 { | |
455 false, | |
bengr
2015/02/11 23:57:28
Indentation is off. See other examples in our tes
tbansal1
2015/02/12 02:27:22
Done.
| |
456 false, | |
457 }, | |
458 { | |
459 false, | |
460 true, | |
461 }, | |
462 { | |
463 true, | |
464 false, | |
465 }, | |
466 { | |
467 true, | |
468 true, | |
469 }, | |
470 }; | |
471 | |
472 for (size_t i = 0; i < arraysize(tests); ++i) { | |
473 // No call to |AddProxyToCommandLine()| was made, so the proxy feature | |
474 // should be unavailable. | |
475 base::MessageLoopForUI loop; | |
476 // Clear the command line. Setting flags can force the proxy to be allowed. | |
477 base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); | |
478 | |
479 ResetSettings(false, false, false, false, false); | |
480 MockSettings* settings = static_cast<MockSettings*>(settings_.get()); | |
481 EXPECT_FALSE(settings->params()->allowed()); | |
482 EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); | |
483 | |
484 scoped_ptr<DataReductionProxyConfigurator> configurator( | |
485 new TestDataReductionProxyConfigurator( | |
486 scoped_refptr<base::TestSimpleTaskRunner>( | |
487 new base::TestSimpleTaskRunner()), | |
488 &net_log_, event_store_.get())); | |
489 settings_->SetProxyConfigurator(configurator.get()); | |
490 scoped_refptr<net::TestURLRequestContextGetter> request_context = | |
491 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | |
492 | |
493 settings_->InitDataReductionProxySettings( | |
494 &pref_service_, | |
495 request_context.get(), | |
496 &net_log_, | |
497 event_store_.get()); | |
498 | |
499 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | |
500 if (tests[i].enable_quic_field_trial){ | |
501 base::FieldTrialList::CreateFieldTrial("DataReductionProxyUseQuic", | |
502 "Enabled"); | |
503 } else { | |
504 base::FieldTrialList::CreateFieldTrial("DataReductionProxyUseQuic", | |
505 "Disabled"); | |
506 } | |
507 settings_->EnableQUIC(tests[i].enable_quic); | |
508 | |
509 settings_->SetOnDataReductionEnabledCallback( | |
510 base::Bind(&DataReductionProxySettingsTestBase:: | |
511 RegisterSyntheticFieldTrialCallback, | |
512 base::Unretained(this))); | |
513 | |
514 EXPECT_EQ(tests[i].enable_quic_field_trial, | |
515 settings->params()->IsIncludedInUseQUICFieldTrial()) << i; | |
516 EXPECT_EQ(tests[i].enable_quic && tests[i].enable_quic_field_trial, | |
517 settings->params()->origin().is_quic()) << i; | |
518 | |
519 base::MessageLoop::current()->RunUntilIdle(); | |
bengr
2015/02/11 23:57:28
This can be part of the test harness.
tbansal1
2015/02/12 02:27:22
removed since it was not useful for this test.
| |
520 } | |
521 } | |
522 | |
437 } // namespace data_reduction_proxy | 523 } // namespace data_reduction_proxy |
OLD | NEW |