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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
7 #include "base/prefs/pref_registry_simple.h" | |
8 #include "base/prefs/pref_service.h" | |
9 #include "base/prefs/testing_pref_service.h" | |
7 #include "base/test/mock_entropy_provider.h" | 10 #include "base/test/mock_entropy_provider.h" |
11 #include "chrome/browser/extensions/event_router_forwarder.h" | |
8 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
9 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | |
10 #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" |
16 #include "components/policy/core/common/mock_policy_service.h" | |
17 #include "components/proxy_config/proxy_config_pref_names.h" | |
18 #include "content/public/test/test_browser_thread_bundle.h" | |
19 #include "net/http/http_auth_handler_negotiate.h" | |
11 #include "net/http/http_network_session.h" | 20 #include "net/http/http_network_session.h" |
12 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
13 #include "net/quic/quic_protocol.h" | 22 #include "net/quic/quic_protocol.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
16 | 25 |
17 namespace test { | 26 namespace test { |
18 | 27 |
19 using ::testing::ElementsAre; | 28 using ::testing::ElementsAre; |
29 using ::testing::ReturnRef; | |
20 | 30 |
31 // Class used for accessing IOThread methods (friend of IOThread). Creating | |
32 // an IOThreadPeer creates and initializes an IOThread instance set up for | |
33 // testing, deleting it cleanly closes down and deletes the IOThread instance. | |
21 class IOThreadPeer { | 34 class IOThreadPeer { |
22 public: | 35 public: |
36 IOThreadPeer() | |
37 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | |
38 pref_service_(new TestingPrefServiceSimple()), | |
39 event_router_forwarder_(new extensions::EventRouterForwarder) { | |
40 PrefRegistrySimple* pref_registry = pref_service_->registry(); | |
41 IOThread::RegisterPrefs(pref_registry); | |
42 pref_registry->RegisterDictionaryPref(proxy_config::prefs::kProxy); | |
Bernhard Bauer
2015/10/23 08:15:41
Call PrefProxyConfigTrackerImpl::RegisterPrefs()?
aberent
2015/10/23 15:40:33
Done. Thanks, I was looking for something of the s
| |
43 SSLConfigServiceManager::RegisterPrefs(pref_registry); | |
44 | |
45 // Set up default function behaviour. | |
46 EXPECT_CALL(policy_service_, | |
47 GetPolicies(policy::PolicyNamespace( | |
48 policy::POLICY_DOMAIN_CHROME, std::string()))) | |
49 .WillRepeatedly(ReturnRef(policy_map_)); | |
50 io_thread_.reset(new IOThread(pref_service_.get(), &policy_service_, | |
51 nullptr, event_router_forwarder_.get())); | |
52 io_thread_->Init(); | |
53 } | |
54 | |
55 ~IOThreadPeer() { io_thread_->CleanUp(); } | |
Bernhard Bauer
2015/10/23 08:15:41
Is this clang-formatted? If not, I would move this
aberent
2015/10/23 15:40:33
Yes, this is clang formatted; would not have been
Bernhard Bauer
2015/10/23 15:57:58
Hm. Could we out-of-line this so clang-format will
| |
56 | |
23 static void ConfigureQuicGlobals( | 57 static void ConfigureQuicGlobals( |
24 const base::CommandLine& command_line, | 58 const base::CommandLine& command_line, |
25 base::StringPiece quic_trial_group, | 59 base::StringPiece quic_trial_group, |
26 const std::map<std::string, std::string>& quic_trial_params, | 60 const std::map<std::string, std::string>& quic_trial_params, |
27 bool is_quic_allowed_by_policy, | 61 bool is_quic_allowed_by_policy, |
28 IOThread::Globals* globals) { | 62 IOThread::Globals* globals) { |
29 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, | 63 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, |
30 quic_trial_params, is_quic_allowed_by_policy, | 64 quic_trial_params, is_quic_allowed_by_policy, |
31 globals); | 65 globals); |
32 } | 66 } |
33 | 67 |
34 static void ConfigureSpdyGlobals( | 68 static void ConfigureSpdyGlobals( |
35 const base::CommandLine& command_line, | 69 const base::CommandLine& command_line, |
36 base::StringPiece spdy_trial_group, | 70 base::StringPiece spdy_trial_group, |
37 const std::map<std::string, std::string>& spdy_trial_params, | 71 const std::map<std::string, std::string>& spdy_trial_params, |
38 IOThread::Globals* globals) { | 72 IOThread::Globals* globals) { |
39 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, | 73 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, |
40 spdy_trial_params, globals); | 74 spdy_trial_params, globals); |
41 } | 75 } |
42 | 76 |
43 static void InitializeNetworkSessionParamsFromGlobals( | 77 static void InitializeNetworkSessionParamsFromGlobals( |
44 const IOThread::Globals& globals, | 78 const IOThread::Globals& globals, |
45 net::HttpNetworkSession::Params* params) { | 79 net::HttpNetworkSession::Params* params) { |
46 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); | 80 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); |
47 } | 81 } |
82 | |
83 IOThread* io_thread() const { return io_thread_.get(); } | |
84 | |
85 TestingPrefServiceSimple* pref_service() const { return pref_service_.get(); } | |
86 | |
87 private: | |
88 content::TestBrowserThreadBundle thread_bundle_; | |
89 scoped_ptr<TestingPrefServiceSimple> pref_service_; | |
Bernhard Bauer
2015/10/23 08:15:41
You could probably make this a direct member, so y
aberent
2015/10/23 15:40:33
Done.
| |
90 scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_; | |
91 policy::PolicyMap policy_map_; | |
92 policy::MockPolicyService policy_service_; | |
93 scoped_ptr<IOThread> io_thread_; | |
Bernhard Bauer
2015/10/23 08:15:41
DISALLOW_COPY_AND_ASSIGN
aberent
2015/10/23 15:40:33
Done.
| |
48 }; | 94 }; |
49 | 95 |
50 class IOThreadTest : public testing::Test { | 96 class IOThreadTest : public testing::Test { |
51 public: | 97 public: |
52 IOThreadTest() | 98 IOThreadTest() |
53 : command_line_(base::CommandLine::NO_PROGRAM), | 99 : command_line_(base::CommandLine::NO_PROGRAM), |
54 is_quic_allowed_by_policy_(true) { | 100 is_quic_allowed_by_policy_(true) { |
55 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); | 101 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
56 } | 102 } |
57 | 103 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { | 548 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { |
503 command_line_.AppendSwitch(switches::kEnableQuic); | 549 command_line_.AppendSwitch(switches::kEnableQuic); |
504 is_quic_allowed_by_policy_ = false; | 550 is_quic_allowed_by_policy_ = false; |
505 ConfigureQuicGlobals(); | 551 ConfigureQuicGlobals(); |
506 | 552 |
507 net::HttpNetworkSession::Params params; | 553 net::HttpNetworkSession::Params params; |
508 InitializeNetworkSessionParams(¶ms); | 554 InitializeNetworkSessionParams(¶ms); |
509 EXPECT_FALSE(params.enable_quic); | 555 EXPECT_FALSE(params.enable_quic); |
510 } | 556 } |
511 | 557 |
558 TEST_F(IOThreadTest, UpdateNegotiateDisableCnameLookup) { | |
559 IOThreadPeer peer; | |
560 | |
561 net::HttpAuthHandlerRegistryFactory* factory = | |
562 peer.io_thread()->globals()->http_auth_handler_factory.get(); | |
563 | |
564 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( | |
565 factory->GetSchemeFactory("negotiate")); | |
566 peer.pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, | |
567 false); | |
568 EXPECT_FALSE(negotiate_factory->disable_cname_lookup()); | |
569 peer.pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, | |
570 true); | |
571 EXPECT_TRUE(negotiate_factory->disable_cname_lookup()); | |
572 } | |
573 | |
574 TEST_F(IOThreadTest, UpdateEnableAuthNegotiatePort) { | |
575 IOThreadPeer peer; | |
576 | |
577 net::HttpAuthHandlerRegistryFactory* factory = | |
578 peer.io_thread()->globals()->http_auth_handler_factory.get(); | |
579 | |
580 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( | |
581 factory->GetSchemeFactory("negotiate")); | |
582 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, false); | |
583 EXPECT_FALSE(negotiate_factory->use_port()); | |
584 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, true); | |
585 EXPECT_TRUE(negotiate_factory->use_port()); | |
586 } | |
587 | |
588 TEST_F(IOThreadTest, UpdateServerWhitelist) { | |
589 IOThreadPeer peer; | |
590 | |
591 GURL url("http://test.example.com"); | |
592 | |
593 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, ""); | |
Bernhard Bauer
2015/10/23 08:15:41
Use an empty std::string() constructor to save a c
aberent
2015/10/23 15:40:33
Instruction level performance is hardly and issue
| |
594 net::URLSecurityManager* security_manager = | |
595 peer.io_thread()->globals()->url_security_manager.get(); | |
596 EXPECT_FALSE(security_manager->CanUseDefaultCredentials(url)); | |
597 | |
598 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, "*"); | |
599 security_manager = peer.io_thread()->globals()->url_security_manager.get(); | |
600 EXPECT_TRUE(security_manager->CanUseDefaultCredentials(url)); | |
601 } | |
602 | |
603 TEST_F(IOThreadTest, UpdateDelegateWhitelist) { | |
604 IOThreadPeer peer; | |
605 | |
606 GURL url("http://test.example.com"); | |
607 | |
608 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, ""); | |
609 net::URLSecurityManager* security_manager = | |
610 peer.io_thread()->globals()->url_security_manager.get(); | |
611 EXPECT_FALSE(security_manager->CanDelegate(url)); | |
612 | |
613 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, "*"); | |
614 security_manager = peer.io_thread()->globals()->url_security_manager.get(); | |
615 EXPECT_TRUE(security_manager->CanDelegate(url)); | |
616 } | |
617 | |
512 } // namespace test | 618 } // namespace test |
OLD | NEW |