OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 <stddef.h> | 5 #include "components/network_session_configurator/network_session_configurator.h " |
Ryan Hamilton
2016/04/21 21:15:25
Ditto. I wonder if we could shrink the name in som
| |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include <map> |
8 #include "base/command_line.h" | 8 #include <memory> |
9 #include "base/macros.h" | 9 |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/run_loop.h" | |
12 #include "base/test/mock_entropy_provider.h" | 11 #include "base/test/mock_entropy_provider.h" |
13 #include "build/build_config.h" | 12 #include "components/network_session_configurator/switches.h" |
14 #include "chrome/browser/io_thread.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
18 #include "components/policy/core/common/mock_policy_service.h" | |
19 #include "components/prefs/pref_registry_simple.h" | |
20 #include "components/prefs/pref_service.h" | |
21 #include "components/prefs/testing_pref_service.h" | |
22 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
23 #include "components/proxy_config/proxy_config_pref_names.h" | |
24 #include "components/variations/variations_associated_data.h" | 13 #include "components/variations/variations_associated_data.h" |
25 #include "content/public/browser/browser_thread.h" | 14 #include "net/http/http_stream_factory.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | |
27 #include "net/cert_net/nss_ocsp.h" | |
28 #include "net/http/http_auth_preferences.h" | |
29 #include "net/http/http_auth_scheme.h" | |
30 #include "net/http/http_network_session.h" | |
31 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
32 #include "net/quic/quic_stream_factory.h" | |
33 #include "testing/gmock/include/gmock/gmock.h" | |
34 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
35 | 17 |
36 #if defined(ENABLE_EXTENSIONS) | |
37 #include "chrome/browser/extensions/event_router_forwarder.h" | |
38 #endif | |
39 | |
40 #if defined(OS_CHROMEOS) | |
41 #include "chromeos/dbus/dbus_thread_manager.h" | |
42 #include "chromeos/network/network_handler.h" | |
43 #endif | |
44 | |
45 namespace test { | 18 namespace test { |
46 | 19 |
47 using ::testing::ReturnRef; | |
48 | |
49 // Class used for accessing IOThread methods (friend of IOThread). | |
50 class IOThreadPeer { | |
51 public: | |
52 static net::HttpAuthPreferences* GetAuthPreferences(IOThread* io_thread) { | |
53 return io_thread->globals()->http_auth_preferences.get(); | |
54 } | |
55 }; | |
56 | |
57 class NetworkSessionConfiguratorTest : public testing::Test { | 20 class NetworkSessionConfiguratorTest : public testing::Test { |
58 public: | 21 public: |
59 NetworkSessionConfiguratorTest() | 22 NetworkSessionConfiguratorTest() |
60 : is_spdy_allowed_by_policy_(true), is_quic_allowed_by_policy_(true) { | 23 : is_spdy_allowed_by_policy_(true), |
24 is_quic_allowed_by_policy_(true), | |
25 quic_user_agent_id_("Chrome/52.0.2709.0 Linux x86_64") { | |
61 field_trial_list_.reset( | 26 field_trial_list_.reset( |
62 new base::FieldTrialList(new base::MockEntropyProvider())); | 27 new base::FieldTrialList(new base::MockEntropyProvider())); |
63 variations::testing::ClearAllVariationParams(); | 28 variations::testing::ClearAllVariationParams(); |
64 } | 29 } |
65 | 30 |
66 void ParseFieldTrials() { | 31 void ParseFieldTrials() { |
67 network_session_configurator_.ParseFieldTrials( | 32 network_session_configurator::ParseFieldTrials( |
68 is_spdy_allowed_by_policy_, is_quic_allowed_by_policy_, ¶ms_); | 33 is_spdy_allowed_by_policy_, is_quic_allowed_by_policy_, |
34 quic_user_agent_id_, ¶ms_); | |
69 } | 35 } |
70 | 36 |
71 void ParseFieldTrialsAndCommandLine() { | 37 void ParseFieldTrialsAndCommandLine() { |
72 network_session_configurator_.ParseFieldTrialsAndCommandLine( | 38 network_session_configurator::ParseFieldTrialsAndCommandLine( |
73 is_spdy_allowed_by_policy_, is_quic_allowed_by_policy_, ¶ms_); | 39 is_spdy_allowed_by_policy_, is_quic_allowed_by_policy_, |
40 quic_user_agent_id_, ¶ms_); | |
41 } | |
42 | |
43 bool ShouldEnableQuicForDataReductionProxy() { | |
44 const base::CommandLine& command_line = | |
45 *base::CommandLine::ForCurrentProcess(); | |
46 return network_session_configurator::ShouldEnableQuicForDataReductionProxy( | |
47 command_line); | |
74 } | 48 } |
75 | 49 |
76 bool is_spdy_allowed_by_policy_; | 50 bool is_spdy_allowed_by_policy_; |
77 bool is_quic_allowed_by_policy_; | 51 bool is_quic_allowed_by_policy_; |
52 std::string quic_user_agent_id_; | |
78 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 53 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
79 net::HttpNetworkSession::Params params_; | 54 net::HttpNetworkSession::Params params_; |
80 | |
81 private: | |
82 IOThread::NetworkSessionConfigurator network_session_configurator_; | |
83 }; | 55 }; |
84 | 56 |
85 TEST_F(NetworkSessionConfiguratorTest, Defaults) { | 57 TEST_F(NetworkSessionConfiguratorTest, Defaults) { |
86 ParseFieldTrialsAndCommandLine(); | 58 ParseFieldTrialsAndCommandLine(); |
87 | 59 |
88 EXPECT_FALSE(params_.ignore_certificate_errors); | 60 EXPECT_FALSE(params_.ignore_certificate_errors); |
61 EXPECT_EQ("Chrome/52.0.2709.0 Linux x86_64", params_.quic_user_agent_id); | |
89 EXPECT_EQ(0u, params_.testing_fixed_http_port); | 62 EXPECT_EQ(0u, params_.testing_fixed_http_port); |
90 EXPECT_EQ(0u, params_.testing_fixed_https_port); | 63 EXPECT_EQ(0u, params_.testing_fixed_https_port); |
91 EXPECT_FALSE(params_.enable_spdy31); | 64 EXPECT_FALSE(params_.enable_spdy31); |
92 EXPECT_TRUE(params_.enable_http2); | 65 EXPECT_TRUE(params_.enable_http2); |
93 EXPECT_FALSE(params_.enable_tcp_fast_open_for_ssl); | 66 EXPECT_FALSE(params_.enable_tcp_fast_open_for_ssl); |
94 EXPECT_FALSE(params_.parse_alternative_services); | 67 EXPECT_FALSE(params_.parse_alternative_services); |
95 EXPECT_FALSE(params_.enable_alternative_service_with_different_host); | 68 EXPECT_FALSE(params_.enable_alternative_service_with_different_host); |
96 EXPECT_FALSE(params_.enable_npn); | 69 EXPECT_FALSE(params_.enable_npn); |
97 EXPECT_TRUE(params_.enable_priority_dependencies); | 70 EXPECT_TRUE(params_.enable_priority_dependencies); |
98 EXPECT_FALSE(params_.enable_quic); | 71 EXPECT_FALSE(params_.enable_quic); |
99 EXPECT_FALSE(params_.enable_quic_for_proxies); | 72 EXPECT_FALSE(params_.enable_quic_for_proxies); |
100 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy()); | 73 EXPECT_FALSE(ShouldEnableQuicForDataReductionProxy()); |
101 } | 74 } |
102 | 75 |
103 TEST_F(NetworkSessionConfiguratorTest, IgnoreCertificateErrors) { | 76 TEST_F(NetworkSessionConfiguratorTest, IgnoreCertificateErrors) { |
104 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 77 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
105 "ignore-certificate-errors"); | 78 "ignore-certificate-errors"); |
106 | 79 |
107 ParseFieldTrialsAndCommandLine(); | 80 ParseFieldTrialsAndCommandLine(); |
108 | 81 |
109 EXPECT_TRUE(params_.ignore_certificate_errors); | 82 EXPECT_TRUE(params_.ignore_certificate_errors); |
110 } | 83 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 EXPECT_FALSE(params_.enable_alternative_service_with_different_host); | 228 EXPECT_FALSE(params_.enable_alternative_service_with_different_host); |
256 EXPECT_EQ(0, params_.quic_max_number_of_lossy_connections); | 229 EXPECT_EQ(0, params_.quic_max_number_of_lossy_connections); |
257 EXPECT_EQ(1.0f, params_.quic_packet_loss_threshold); | 230 EXPECT_EQ(1.0f, params_.quic_packet_loss_threshold); |
258 EXPECT_FALSE(params_.quic_delay_tcp_race); | 231 EXPECT_FALSE(params_.quic_delay_tcp_race); |
259 EXPECT_FALSE(params_.quic_close_sessions_on_ip_change); | 232 EXPECT_FALSE(params_.quic_close_sessions_on_ip_change); |
260 EXPECT_EQ(net::kIdleConnectionTimeoutSeconds, | 233 EXPECT_EQ(net::kIdleConnectionTimeoutSeconds, |
261 params_.quic_idle_connection_timeout_seconds); | 234 params_.quic_idle_connection_timeout_seconds); |
262 EXPECT_FALSE(params_.quic_disable_preconnect_if_0rtt); | 235 EXPECT_FALSE(params_.quic_disable_preconnect_if_0rtt); |
263 EXPECT_FALSE(params_.quic_migrate_sessions_on_network_change); | 236 EXPECT_FALSE(params_.quic_migrate_sessions_on_network_change); |
264 EXPECT_FALSE(params_.quic_migrate_sessions_early); | 237 EXPECT_FALSE(params_.quic_migrate_sessions_early); |
265 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy()); | 238 EXPECT_FALSE(ShouldEnableQuicForDataReductionProxy()); |
266 EXPECT_TRUE(params_.quic_host_whitelist.empty()); | 239 EXPECT_TRUE(params_.quic_host_whitelist.empty()); |
267 | 240 |
268 net::HttpNetworkSession::Params default_params; | 241 net::HttpNetworkSession::Params default_params; |
269 EXPECT_EQ(default_params.quic_supported_versions, | 242 EXPECT_EQ(default_params.quic_supported_versions, |
270 params_.quic_supported_versions); | 243 params_.quic_supported_versions); |
271 } | 244 } |
272 | 245 |
246 TEST_F(NetworkSessionConfiguratorTest, DisableQuicFromCommandLine) { | |
247 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); | |
248 base::CommandLine::ForCurrentProcess()->AppendSwitch("disable-quic"); | |
249 | |
250 ParseFieldTrialsAndCommandLine(); | |
251 | |
252 EXPECT_FALSE(params_.enable_quic); | |
253 } | |
254 | |
255 TEST_F(NetworkSessionConfiguratorTest, EnableQuicForDataReductionProxy) { | |
256 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); | |
257 base::FieldTrialList::CreateFieldTrial("DataReductionProxyUseQuic", | |
258 "Enabled"); | |
259 | |
260 ParseFieldTrialsAndCommandLine(); | |
261 | |
262 EXPECT_TRUE(params_.enable_quic); | |
263 EXPECT_TRUE(ShouldEnableQuicForDataReductionProxy()); | |
264 } | |
265 | |
273 TEST_F(NetworkSessionConfiguratorTest, | 266 TEST_F(NetworkSessionConfiguratorTest, |
274 DisableQuicWhenConnectionTimesOutWithOpenStreamsFromFieldTrialParams) { | 267 DisableQuicWhenConnectionTimesOutWithOpenStreamsFromFieldTrialParams) { |
275 std::map<std::string, std::string> field_trial_params; | 268 std::map<std::string, std::string> field_trial_params; |
276 field_trial_params["disable_quic_on_timeout_with_open_streams"] = "true"; | 269 field_trial_params["disable_quic_on_timeout_with_open_streams"] = "true"; |
277 variations::AssociateVariationParams("QUIC", "Enabled", field_trial_params); | 270 variations::AssociateVariationParams("QUIC", "Enabled", field_trial_params); |
278 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); | 271 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); |
279 | 272 |
280 ParseFieldTrials(); | 273 ParseFieldTrials(); |
281 | 274 |
282 EXPECT_TRUE(params_.disable_quic_on_timeout_with_open_streams); | 275 EXPECT_TRUE(params_.disable_quic_on_timeout_with_open_streams); |
(...skipping 20 matching lines...) Expand all Loading... | |
303 "EnabledControl", true, | 296 "EnabledControl", true, |
304 }, | 297 }, |
305 { | 298 { |
306 "Enabled", true, | 299 "Enabled", true, |
307 }, | 300 }, |
308 }; | 301 }; |
309 | 302 |
310 field_trial_list_.reset(); | 303 field_trial_list_.reset(); |
311 for (size_t i = 0; i < arraysize(tests); ++i) { | 304 for (size_t i = 0; i < arraysize(tests); ++i) { |
312 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | 305 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
313 base::FieldTrialList::CreateFieldTrial( | 306 base::FieldTrialList::CreateFieldTrial("DataReductionProxyUseQuic", |
314 data_reduction_proxy::params::GetQuicFieldTrialName(), | 307 tests[i].field_trial_group_name); |
315 tests[i].field_trial_group_name); | |
316 | 308 |
317 ParseFieldTrials(); | 309 ParseFieldTrials(); |
318 | 310 |
319 EXPECT_FALSE(params_.enable_quic) << i; | 311 EXPECT_FALSE(params_.enable_quic) << i; |
320 EXPECT_EQ(tests[i].expect_enable_quic, params_.enable_quic_for_proxies) | 312 EXPECT_EQ(tests[i].expect_enable_quic, params_.enable_quic_for_proxies) |
321 << i; | 313 << i; |
322 EXPECT_EQ(tests[i].expect_enable_quic, | 314 EXPECT_EQ(tests[i].expect_enable_quic, |
323 IOThread::ShouldEnableQuicForDataReductionProxy()) | 315 ShouldEnableQuicForDataReductionProxy()) |
324 << i; | 316 << i; |
325 } | 317 } |
326 } | 318 } |
327 | 319 |
328 TEST_F(NetworkSessionConfiguratorTest, EnableQuicFromCommandLine) { | 320 TEST_F(NetworkSessionConfiguratorTest, EnableQuicFromCommandLine) { |
329 base::CommandLine::ForCurrentProcess()->AppendSwitch("enable-quic"); | 321 base::CommandLine::ForCurrentProcess()->AppendSwitch("enable-quic"); |
330 | 322 |
331 ParseFieldTrialsAndCommandLine(); | 323 ParseFieldTrialsAndCommandLine(); |
332 | 324 |
333 EXPECT_TRUE(params_.enable_quic); | 325 EXPECT_TRUE(params_.enable_quic); |
334 EXPECT_TRUE(params_.enable_quic_for_proxies); | 326 EXPECT_TRUE(params_.enable_quic_for_proxies); |
335 EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy()); | 327 EXPECT_FALSE(ShouldEnableQuicForDataReductionProxy()); |
336 } | 328 } |
337 | 329 |
338 TEST_F(NetworkSessionConfiguratorTest, | 330 TEST_F(NetworkSessionConfiguratorTest, |
339 EnableAlternativeServicesFromCommandLineWithQuicDisabled) { | 331 EnableAlternativeServicesFromCommandLineWithQuicDisabled) { |
340 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 332 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
341 "enable-alternative-services"); | 333 "enable-alternative-services"); |
342 | 334 |
343 ParseFieldTrialsAndCommandLine(); | 335 ParseFieldTrialsAndCommandLine(); |
344 | 336 |
345 EXPECT_FALSE(params_.enable_quic); | 337 EXPECT_FALSE(params_.enable_quic); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); | 666 base::FieldTrialList::CreateFieldTrial("QUIC", "Enabled"); |
675 | 667 |
676 ParseFieldTrials(); | 668 ParseFieldTrials(); |
677 | 669 |
678 EXPECT_EQ(2u, params_.quic_host_whitelist.size()); | 670 EXPECT_EQ(2u, params_.quic_host_whitelist.size()); |
679 EXPECT_TRUE(ContainsKey(params_.quic_host_whitelist, "www.example.org")); | 671 EXPECT_TRUE(ContainsKey(params_.quic_host_whitelist, "www.example.org")); |
680 EXPECT_TRUE(ContainsKey(params_.quic_host_whitelist, "www.example.com")); | 672 EXPECT_TRUE(ContainsKey(params_.quic_host_whitelist, "www.example.com")); |
681 } | 673 } |
682 | 674 |
683 TEST_F(NetworkSessionConfiguratorTest, QuicDisallowedByPolicy) { | 675 TEST_F(NetworkSessionConfiguratorTest, QuicDisallowedByPolicy) { |
684 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); | 676 base::CommandLine::ForCurrentProcess()->AppendSwitch("enable-quic"); |
685 is_quic_allowed_by_policy_ = false; | 677 is_quic_allowed_by_policy_ = false; |
686 | 678 |
687 ParseFieldTrialsAndCommandLine(); | 679 ParseFieldTrialsAndCommandLine(); |
688 | 680 |
689 EXPECT_FALSE(params_.enable_quic); | 681 EXPECT_FALSE(params_.enable_quic); |
690 } | 682 } |
691 | 683 |
692 TEST_F(NetworkSessionConfiguratorTest, TCPFastOpenHttpsEnabled) { | 684 TEST_F(NetworkSessionConfiguratorTest, TCPFastOpenHttpsEnabled) { |
693 base::FieldTrialList::CreateFieldTrial("TCPFastOpen", "HttpsEnabled"); | 685 base::FieldTrialList::CreateFieldTrial("TCPFastOpen", "HttpsEnabled"); |
694 | 686 |
695 ParseFieldTrials(); | 687 ParseFieldTrials(); |
696 | 688 |
697 EXPECT_TRUE(params_.enable_tcp_fast_open_for_ssl); | 689 EXPECT_TRUE(params_.enable_tcp_fast_open_for_ssl); |
698 } | 690 } |
699 | 691 |
700 class IOThreadTestWithIOThreadObject : public testing::Test { | |
701 public: | |
702 // These functions need to be public, since it is difficult to bind to | |
703 // protected functions in a test (the code would need to explicitly contain | |
704 // the name of the actual test class). | |
705 void CheckCnameLookup(bool expected) { | |
706 auto http_auth_preferences = | |
707 IOThreadPeer::GetAuthPreferences(io_thread_.get()); | |
708 ASSERT_NE(nullptr, http_auth_preferences); | |
709 EXPECT_EQ(expected, http_auth_preferences->NegotiateDisableCnameLookup()); | |
710 } | |
711 | |
712 void CheckNegotiateEnablePort(bool expected) { | |
713 auto http_auth_preferences = | |
714 IOThreadPeer::GetAuthPreferences(io_thread_.get()); | |
715 ASSERT_NE(nullptr, http_auth_preferences); | |
716 EXPECT_EQ(expected, http_auth_preferences->NegotiateEnablePort()); | |
717 } | |
718 | |
719 #if defined(OS_ANDROID) | |
720 void CheckAuthAndroidNegoitateAccountType(std::string expected) { | |
721 auto http_auth_preferences = | |
722 IOThreadPeer::GetAuthPreferences(io_thread_.get()); | |
723 ASSERT_NE(nullptr, http_auth_preferences); | |
724 EXPECT_EQ(expected, | |
725 http_auth_preferences->AuthAndroidNegotiateAccountType()); | |
726 } | |
727 #endif | |
728 | |
729 void CheckCanUseDefaultCredentials(bool expected, const GURL& url) { | |
730 auto http_auth_preferences = | |
731 IOThreadPeer::GetAuthPreferences(io_thread_.get()); | |
732 EXPECT_EQ(expected, http_auth_preferences->CanUseDefaultCredentials(url)); | |
733 } | |
734 | |
735 void CheckCanDelegate(bool expected, const GURL& url) { | |
736 auto http_auth_preferences = | |
737 IOThreadPeer::GetAuthPreferences(io_thread_.get()); | |
738 EXPECT_EQ(expected, http_auth_preferences->CanDelegate(url)); | |
739 } | |
740 | |
741 protected: | |
742 IOThreadTestWithIOThreadObject() | |
743 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD | | |
744 content::TestBrowserThreadBundle::DONT_START_THREADS) { | |
745 #if defined(ENABLE_EXTENSIONS) | |
746 event_router_forwarder_ = new extensions::EventRouterForwarder; | |
747 #endif | |
748 PrefRegistrySimple* pref_registry = pref_service_.registry(); | |
749 IOThread::RegisterPrefs(pref_registry); | |
750 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry); | |
751 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry); | |
752 | |
753 // Set up default function behaviour. | |
754 EXPECT_CALL(policy_service_, | |
755 GetPolicies(policy::PolicyNamespace( | |
756 policy::POLICY_DOMAIN_CHROME, std::string()))) | |
757 .WillRepeatedly(ReturnRef(policy_map_)); | |
758 | |
759 #if defined(OS_CHROMEOS) | |
760 // Needed by IOThread constructor. | |
761 chromeos::DBusThreadManager::Initialize(); | |
762 chromeos::NetworkHandler::Initialize(); | |
763 #endif | |
764 // The IOThread constructor registers the IOThread object with as the | |
765 // BrowserThreadDelegate for the io thread. | |
766 io_thread_.reset(new IOThread(&pref_service_, &policy_service_, nullptr, | |
767 #if defined(ENABLE_EXTENSIONS) | |
768 event_router_forwarder_.get() | |
769 #else | |
770 nullptr | |
771 #endif | |
772 )); | |
773 // Now that IOThread object is registered starting the threads will | |
774 // call the IOThread::Init(). This sets up the environment needed for | |
775 // these tests. | |
776 thread_bundle_.Start(); | |
777 } | |
778 | |
779 ~IOThreadTestWithIOThreadObject() override { | |
780 #if defined(USE_NSS_CERTS) | |
781 // Reset OCSPIOLoop thread checks, so that the test runner can run | |
782 // futher tests in the same process. | |
783 RunOnIOThreadBlocking(base::Bind(&net::ResetNSSHttpIOForTesting)); | |
784 #endif | |
785 #if defined(OS_CHROMEOS) | |
786 chromeos::NetworkHandler::Shutdown(); | |
787 chromeos::DBusThreadManager::Shutdown(); | |
788 #endif | |
789 } | |
790 TestingPrefServiceSimple* pref_service() { return &pref_service_; } | |
791 | |
792 void RunOnIOThreadBlocking(const base::Closure& task) { | |
793 base::RunLoop run_loop; | |
794 content::BrowserThread::PostTaskAndReply( | |
795 content::BrowserThread::IO, FROM_HERE, task, run_loop.QuitClosure()); | |
796 run_loop.Run(); | |
797 } | |
798 | |
799 private: | |
800 base::ShadowingAtExitManager at_exit_manager_; | |
801 TestingPrefServiceSimple pref_service_; | |
802 #if defined(ENABLE_EXTENSIONS) | |
803 scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_; | |
804 #endif | |
805 policy::PolicyMap policy_map_; | |
806 policy::MockPolicyService policy_service_; | |
807 // The ordering of the declarations of |io_thread_object_| and | |
808 // |thread_bundle_| matters. An IOThread cannot be deleted until all of | |
809 // the globals have been reset to their initial state via CleanUp. As | |
810 // TestBrowserThreadBundle's destructor is responsible for calling | |
811 // CleanUp(), the IOThread must be declared before the bundle, so that | |
812 // the bundle is deleted first. | |
813 std::unique_ptr<IOThread> io_thread_; | |
814 content::TestBrowserThreadBundle thread_bundle_; | |
815 }; | |
816 | |
817 TEST_F(IOThreadTestWithIOThreadObject, UpdateNegotiateDisableCnameLookup) { | |
818 // This test uses the kDisableAuthNegotiateCnameLookup to check that | |
819 // the HttpAuthPreferences are correctly initialized and running on the | |
820 // IO thread. The other preferences are tested by the HttpAuthPreferences | |
821 // unit tests. | |
822 pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, false); | |
823 RunOnIOThreadBlocking( | |
824 base::Bind(&IOThreadTestWithIOThreadObject::CheckCnameLookup, | |
825 base::Unretained(this), false)); | |
826 pref_service()->SetBoolean(prefs::kDisableAuthNegotiateCnameLookup, true); | |
827 RunOnIOThreadBlocking( | |
828 base::Bind(&IOThreadTestWithIOThreadObject::CheckCnameLookup, | |
829 base::Unretained(this), true)); | |
830 } | |
831 | |
832 TEST_F(IOThreadTestWithIOThreadObject, UpdateEnableAuthNegotiatePort) { | |
833 pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, false); | |
834 RunOnIOThreadBlocking( | |
835 base::Bind(&IOThreadTestWithIOThreadObject::CheckNegotiateEnablePort, | |
836 base::Unretained(this), false)); | |
837 pref_service()->SetBoolean(prefs::kEnableAuthNegotiatePort, true); | |
838 RunOnIOThreadBlocking( | |
839 base::Bind(&IOThreadTestWithIOThreadObject::CheckNegotiateEnablePort, | |
840 base::Unretained(this), true)); | |
841 } | |
842 | |
843 TEST_F(IOThreadTestWithIOThreadObject, UpdateServerWhitelist) { | |
844 GURL url("http://test.example.com"); | |
845 | |
846 pref_service()->SetString(prefs::kAuthServerWhitelist, "xxx"); | |
847 RunOnIOThreadBlocking( | |
848 base::Bind(&IOThreadTestWithIOThreadObject::CheckCanUseDefaultCredentials, | |
849 base::Unretained(this), false, url)); | |
850 | |
851 pref_service()->SetString(prefs::kAuthServerWhitelist, "*"); | |
852 RunOnIOThreadBlocking( | |
853 base::Bind(&IOThreadTestWithIOThreadObject::CheckCanUseDefaultCredentials, | |
854 base::Unretained(this), true, url)); | |
855 } | |
856 | |
857 TEST_F(IOThreadTestWithIOThreadObject, UpdateDelegateWhitelist) { | |
858 GURL url("http://test.example.com"); | |
859 | |
860 pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, ""); | |
861 RunOnIOThreadBlocking( | |
862 base::Bind(&IOThreadTestWithIOThreadObject::CheckCanDelegate, | |
863 base::Unretained(this), false, url)); | |
864 | |
865 pref_service()->SetString(prefs::kAuthNegotiateDelegateWhitelist, "*"); | |
866 RunOnIOThreadBlocking( | |
867 base::Bind(&IOThreadTestWithIOThreadObject::CheckCanDelegate, | |
868 base::Unretained(this), true, url)); | |
869 } | |
870 | |
871 #if defined(OS_ANDROID) | |
872 // AuthAndroidNegotiateAccountType is only used on Android. | |
873 TEST_F(IOThreadTestWithIOThreadObject, UpdateAuthAndroidNegotiateAccountType) { | |
874 pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, "acc1"); | |
875 RunOnIOThreadBlocking(base::Bind( | |
876 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType, | |
877 base::Unretained(this), "acc1")); | |
878 pref_service()->SetString(prefs::kAuthAndroidNegotiateAccountType, "acc2"); | |
879 RunOnIOThreadBlocking(base::Bind( | |
880 &IOThreadTestWithIOThreadObject::CheckAuthAndroidNegoitateAccountType, | |
881 base::Unretained(this), "acc2")); | |
882 } | |
883 #endif | |
884 | |
885 } // namespace test | 692 } // namespace test |
OLD | NEW |