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) |
| 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 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_; |
| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { | 554 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { |
503 command_line_.AppendSwitch(switches::kEnableQuic); | 555 command_line_.AppendSwitch(switches::kEnableQuic); |
504 is_quic_allowed_by_policy_ = false; | 556 is_quic_allowed_by_policy_ = false; |
505 ConfigureQuicGlobals(); | 557 ConfigureQuicGlobals(); |
506 | 558 |
507 net::HttpNetworkSession::Params params; | 559 net::HttpNetworkSession::Params params; |
508 InitializeNetworkSessionParams(¶ms); | 560 InitializeNetworkSessionParams(¶ms); |
509 EXPECT_FALSE(params.enable_quic); | 561 EXPECT_FALSE(params.enable_quic); |
510 } | 562 } |
511 | 563 |
| 564 TEST_F(IOThreadTest, UpdateNegotiateDisableCnameLookup) { |
| 565 IOThreadPeer peer; |
| 566 |
| 567 net::HttpAuthHandlerRegistryFactory* factory = |
| 568 peer.io_thread()->globals()->http_auth_handler_factory.get(); |
| 569 |
| 570 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( |
| 571 factory->GetSchemeFactory("negotiate")); |
| 572 peer.pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, |
| 573 false); |
| 574 EXPECT_FALSE(negotiate_factory->disable_cname_lookup()); |
| 575 peer.pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, |
| 576 true); |
| 577 EXPECT_TRUE(negotiate_factory->disable_cname_lookup()); |
| 578 } |
| 579 |
| 580 TEST_F(IOThreadTest, UpdateEnableAuthNegotiatePort) { |
| 581 IOThreadPeer peer; |
| 582 |
| 583 net::HttpAuthHandlerRegistryFactory* factory = |
| 584 peer.io_thread()->globals()->http_auth_handler_factory.get(); |
| 585 |
| 586 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( |
| 587 factory->GetSchemeFactory("negotiate")); |
| 588 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, false); |
| 589 EXPECT_FALSE(negotiate_factory->use_port()); |
| 590 peer.pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, true); |
| 591 EXPECT_TRUE(negotiate_factory->use_port()); |
| 592 } |
| 593 |
| 594 TEST_F(IOThreadTest, UpdateServerWhitelist) { |
| 595 IOThreadPeer peer; |
| 596 |
| 597 GURL url("http://test.example.com"); |
| 598 |
| 599 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, ""); |
| 600 net::URLSecurityManager* security_manager = |
| 601 peer.io_thread()->globals()->url_security_manager.get(); |
| 602 EXPECT_FALSE(security_manager->CanUseDefaultCredentials(url)); |
| 603 |
| 604 peer.pref_service()->SetString(prefs::kAuthServerWhitelist, "*"); |
| 605 security_manager = peer.io_thread()->globals()->url_security_manager.get(); |
| 606 EXPECT_TRUE(security_manager->CanUseDefaultCredentials(url)); |
| 607 } |
| 608 |
| 609 TEST_F(IOThreadTest, UpdateDelegateWhitelist) { |
| 610 IOThreadPeer peer; |
| 611 |
| 612 GURL url("http://test.example.com"); |
| 613 |
| 614 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, ""); |
| 615 net::URLSecurityManager* security_manager = |
| 616 peer.io_thread()->globals()->url_security_manager.get(); |
| 617 EXPECT_FALSE(security_manager->CanDelegate(url)); |
| 618 |
| 619 peer.pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, "*"); |
| 620 security_manager = peer.io_thread()->globals()->url_security_manager.get(); |
| 621 EXPECT_TRUE(security_manager->CanDelegate(url)); |
| 622 } |
| 623 |
| 624 #if defined(OS_ANDROID) |
| 625 // AuthAndroidNegotiateAccountType is only used on Android. |
| 626 TEST_F(IOThreadTest, UpdateAuthAndroidNegotiateAccountType) { |
| 627 IOThreadPeer peer; |
| 628 |
| 629 net::HttpAuthHandlerRegistryFactory* factory = |
| 630 peer.io_thread()->globals()->http_auth_handler_factory.get(); |
| 631 |
| 632 auto negotiate_factory = static_cast<net::HttpAuthHandlerNegotiate::Factory*>( |
| 633 factory->GetSchemeFactory("negotiate")); |
| 634 peer.pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, |
| 635 "acc1"); |
| 636 EXPECT_EQ("acc1", *(negotiate_factory->get_library())); |
| 637 peer.pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, |
| 638 "acc2"); |
| 639 EXPECT_EQ("acc2", *(negotiate_factory->get_library())); |
| 640 } |
| 641 #endif |
| 642 |
512 } // namespace test | 643 } // namespace test |
OLD | NEW |