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/pref_proxy_config_tracker_impl.h" | |
18 #include "components/proxy_config/proxy_config_pref_names.h" | |
19 #include "content/public/test/test_browser_thread_bundle.h" | |
20 #include "net/http/http_auth_handler_negotiate.h" | |
11 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
12 #include "net/http/http_server_properties_impl.h" | 22 #include "net/http/http_server_properties_impl.h" |
13 #include "net/quic/quic_protocol.h" | 23 #include "net/quic/quic_protocol.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
16 | 26 |
17 namespace test { | 27 namespace test { |
18 | 28 |
19 using ::testing::ElementsAre; | 29 using ::testing::ElementsAre; |
30 using ::testing::ReturnRef; | |
20 | 31 |
32 // Class used for accessing IOThread methods (friend of IOThread). Creating | |
33 // an IOThreadPeer creates and initializes an IOThread instance set up for | |
34 // testing, deleting it cleanly closes down and deletes the IOThread instance. | |
21 class IOThreadPeer { | 35 class IOThreadPeer { |
22 public: | 36 public: |
37 IOThreadPeer() | |
38 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) | |
39 #if defined(ENABLE_EXTENSIONS) | |
asanka
2015/10/28 03:27:43
Not an owner here, but this looks bad enough that
aberent
2015/11/02 18:52:50
Done.
| |
40 , | |
41 event_router_forwarder_(new extensions::EventRouterForwarder) | |
42 #endif | |
43 { | |
44 PrefRegistrySimple* pref_registry = pref_service_.registry(); | |
45 IOThread::RegisterPrefs(pref_registry); | |
46 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry); | |
47 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry); | |
48 | |
49 // Set up default function behaviour. | |
50 EXPECT_CALL(policy_service_, | |
51 GetPolicies(policy::PolicyNamespace( | |
52 policy::POLICY_DOMAIN_CHROME, std::string()))) | |
53 .WillRepeatedly(ReturnRef(policy_map_)); | |
54 io_thread_.reset(new IOThread(&pref_service_, &policy_service_, nullptr, | |
55 event_router_forwarder_.get())); | |
56 io_thread_->Init(); | |
57 } | |
58 | |
59 ~IOThreadPeer() { io_thread_->CleanUp(); } | |
60 | |
23 static void ConfigureQuicGlobals( | 61 static void ConfigureQuicGlobals( |
24 const base::CommandLine& command_line, | 62 const base::CommandLine& command_line, |
25 base::StringPiece quic_trial_group, | 63 base::StringPiece quic_trial_group, |
26 const std::map<std::string, std::string>& quic_trial_params, | 64 const std::map<std::string, std::string>& quic_trial_params, |
27 bool is_quic_allowed_by_policy, | 65 bool is_quic_allowed_by_policy, |
28 IOThread::Globals* globals) { | 66 IOThread::Globals* globals) { |
29 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, | 67 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, |
30 quic_trial_params, is_quic_allowed_by_policy, | 68 quic_trial_params, is_quic_allowed_by_policy, |
31 globals); | 69 globals); |
32 } | 70 } |
33 | 71 |
34 static void ConfigureSpdyGlobals( | 72 static void ConfigureSpdyGlobals( |
35 const base::CommandLine& command_line, | 73 const base::CommandLine& command_line, |
36 base::StringPiece spdy_trial_group, | 74 base::StringPiece spdy_trial_group, |
37 const std::map<std::string, std::string>& spdy_trial_params, | 75 const std::map<std::string, std::string>& spdy_trial_params, |
38 IOThread::Globals* globals) { | 76 IOThread::Globals* globals) { |
39 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, | 77 IOThread::ConfigureSpdyGlobals(command_line, spdy_trial_group, |
40 spdy_trial_params, globals); | 78 spdy_trial_params, globals); |
41 } | 79 } |
42 | 80 |
43 static void InitializeNetworkSessionParamsFromGlobals( | 81 static void InitializeNetworkSessionParamsFromGlobals( |
44 const IOThread::Globals& globals, | 82 const IOThread::Globals& globals, |
45 net::HttpNetworkSession::Params* params) { | 83 net::HttpNetworkSession::Params* params) { |
46 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); | 84 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); |
47 } | 85 } |
86 | |
87 IOThread* io_thread() { return io_thread_.get(); } | |
88 | |
89 TestingPrefServiceSimple* pref_service() { return &pref_service_; } | |
90 | |
91 private: | |
92 content::TestBrowserThreadBundle thread_bundle_; | |
93 TestingPrefServiceSimple pref_service_; | |
94 scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_; | |
asanka
2015/10/28 03:27:43
Guard with #if defined(ENABLE_EXTENSIONS)
aberent
2015/11/02 18:52:50
Doing so means that one needs #ifs in the IOThread
| |
95 policy::PolicyMap policy_map_; | |
96 policy::MockPolicyService policy_service_; | |
97 scoped_ptr<IOThread> io_thread_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(IOThreadPeer); | |
48 }; | 100 }; |
49 | 101 |
50 class IOThreadTest : public testing::Test { | 102 class IOThreadTest : public testing::Test { |
51 public: | 103 public: |
52 IOThreadTest() | 104 IOThreadTest() |
53 : command_line_(base::CommandLine::NO_PROGRAM), | 105 : command_line_(base::CommandLine::NO_PROGRAM), |
54 is_quic_allowed_by_policy_(true) { | 106 is_quic_allowed_by_policy_(true) { |
55 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); | 107 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
56 } | 108 } |
57 | 109 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { | 543 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { |
492 command_line_.AppendSwitch(switches::kEnableQuic); | 544 command_line_.AppendSwitch(switches::kEnableQuic); |
493 is_quic_allowed_by_policy_ = false; | 545 is_quic_allowed_by_policy_ = false; |
494 ConfigureQuicGlobals(); | 546 ConfigureQuicGlobals(); |
495 | 547 |
496 net::HttpNetworkSession::Params params; | 548 net::HttpNetworkSession::Params params; |
497 InitializeNetworkSessionParams(¶ms); | 549 InitializeNetworkSessionParams(¶ms); |
498 EXPECT_FALSE(params.enable_quic); | 550 EXPECT_FALSE(params.enable_quic); |
499 } | 551 } |
500 | 552 |
553 TEST_F(IOThreadTest, UpdateNegotiateDisableCnameLookup) { | |
554 IOThreadPeer peer; | |
555 | |
556 net::HttpAuthHandlerRegistryFactory* factory = | |
557 peer.io_thread()->globals()->http_auth_handler_factory.get(); | |
558 | |
559 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( | |
560 factory->GetSchemeFactory("negotiate")); | |
561 // If we don't have a negotiate factory (net wasn't built with Kerberos) the | |
562 // policy does nothing so we can't test anything. | |
563 if (!negotiate_factory) | |
564 return; | |
565 | |
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 // If we don't have a negotiate factory (net wasn't built with Kerberos) the | |
583 // policy does nothing so we can't test anything. | |
584 if (!negotiate_factory) | |
585 return; | |
586 | |
587 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, false); | |
588 EXPECT_FALSE(negotiate_factory->use_port()); | |
589 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, true); | |
590 EXPECT_TRUE(negotiate_factory->use_port()); | |
591 } | |
592 | |
593 TEST_F(IOThreadTest, UpdateServerWhitelist) { | |
594 IOThreadPeer peer; | |
595 | |
596 GURL url("http://test.example.com"); | |
597 | |
598 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, ""); | |
599 net::URLSecurityManager* security_manager = | |
600 peer.io_thread()->globals()->url_security_manager.get(); | |
601 EXPECT_FALSE(security_manager->CanUseDefaultCredentials(url)); | |
602 | |
603 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, "*"); | |
604 security_manager = peer.io_thread()->globals()->url_security_manager.get(); | |
605 EXPECT_TRUE(security_manager->CanUseDefaultCredentials(url)); | |
606 } | |
607 | |
608 TEST_F(IOThreadTest, UpdateDelegateWhitelist) { | |
609 IOThreadPeer peer; | |
610 | |
611 GURL url("http://test.example.com"); | |
612 | |
613 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, ""); | |
614 net::URLSecurityManager* security_manager = | |
615 peer.io_thread()->globals()->url_security_manager.get(); | |
616 EXPECT_FALSE(security_manager->CanDelegate(url)); | |
617 | |
618 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, "*"); | |
619 security_manager = peer.io_thread()->globals()->url_security_manager.get(); | |
620 EXPECT_TRUE(security_manager->CanDelegate(url)); | |
621 } | |
622 | |
623 #if defined(OS_ANDROID) | |
624 // AuthAndroidNegotiateAccountType is only used on Android. | |
625 TEST_F(IOThreadTest, UpdateAuthAndroidNegotiateAccountType) { | |
626 IOThreadPeer peer; | |
627 | |
628 net::HttpAuthHandlerRegistryFactory* factory = | |
629 peer.io_thread()->globals()->http_auth_handler_factory.get(); | |
630 | |
631 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( | |
632 factory->GetSchemeFactory("negotiate")); | |
633 // If we don't have a negotiate factory (net wasn't built with Kerberos) the | |
634 // policy does nothing so we can't test anything. | |
635 if (!negotiate_factory) | |
636 return; | |
637 | |
638 peer.pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, | |
639 "acc1"); | |
640 EXPECT_EQ("acc1", *(negotiate_factory->library())); | |
641 peer.pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, | |
642 "acc2"); | |
643 EXPECT_EQ("acc2", *(negotiate_factory->library())); | |
644 } | |
645 #endif | |
646 | |
501 } // namespace test | 647 } // namespace test |
OLD | NEW |