Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/io_thread_unittest.cc

Issue 1414313002: Allow dynamic updating of authentication policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move //base/prefs references out of net - part 1. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "base/run_loop.h"
7 #include "base/test/mock_entropy_provider.h" 11 #include "base/test/mock_entropy_provider.h"
12 #include "chrome/browser/extensions/event_router_forwarder.h"
8 #include "chrome/browser/io_thread.h" 13 #include "chrome/browser/io_thread.h"
9 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h"
10 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
17 #include "components/policy/core/common/mock_policy_service.h"
18 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
19 #include "components/proxy_config/proxy_config_pref_names.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "net/base/net_pref_names.h"
23 #include "net/http/http_auth_preferences.h"
24 #include "net/http/http_auth_scheme.h"
11 #include "net/http/http_network_session.h" 25 #include "net/http/http_network_session.h"
12 #include "net/http/http_server_properties_impl.h" 26 #include "net/http/http_server_properties_impl.h"
13 #include "net/quic/quic_protocol.h" 27 #include "net/quic/quic_protocol.h"
14 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
16 30
31 #if defined(OS_CHROMEOS)
32 #include "chromeos/dbus/dbus_thread_manager.h"
33 #include "chromeos/network/network_handler.h"
34 #endif
35
17 namespace test { 36 namespace test {
18 37
19 using ::testing::ElementsAre; 38 using ::testing::ElementsAre;
39 using ::testing::ReturnRef;
20 40
41 // Class used for accessing IOThread methods (friend of IOThread).
21 class IOThreadPeer { 42 class IOThreadPeer {
22 public: 43 public:
23 static void ConfigureQuicGlobals( 44 static void ConfigureQuicGlobals(
24 const base::CommandLine& command_line, 45 const base::CommandLine& command_line,
25 base::StringPiece quic_trial_group, 46 base::StringPiece quic_trial_group,
26 const std::map<std::string, std::string>& quic_trial_params, 47 const std::map<std::string, std::string>& quic_trial_params,
27 bool is_quic_allowed_by_policy, 48 bool is_quic_allowed_by_policy,
28 IOThread::Globals* globals) { 49 IOThread::Globals* globals) {
29 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group, 50 IOThread::ConfigureQuicGlobals(command_line, quic_trial_group,
30 quic_trial_params, is_quic_allowed_by_policy, 51 quic_trial_params, is_quic_allowed_by_policy,
(...skipping 12 matching lines...) Expand all
43 static void ConfigureNPNGlobals(base::StringPiece npn_trial_group, 64 static void ConfigureNPNGlobals(base::StringPiece npn_trial_group,
44 IOThread::Globals* globals) { 65 IOThread::Globals* globals) {
45 IOThread::ConfigureNPNGlobals(npn_trial_group, globals); 66 IOThread::ConfigureNPNGlobals(npn_trial_group, globals);
46 } 67 }
47 68
48 static void InitializeNetworkSessionParamsFromGlobals( 69 static void InitializeNetworkSessionParamsFromGlobals(
49 const IOThread::Globals& globals, 70 const IOThread::Globals& globals,
50 net::HttpNetworkSession::Params* params) { 71 net::HttpNetworkSession::Params* params) {
51 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params); 72 IOThread::InitializeNetworkSessionParamsFromGlobals(globals, params);
52 } 73 }
74
75 static void InitIOThread(IOThread* io_thread) { io_thread->Init(); }
76
77 static void CleanUpIOThread(IOThread* io_thread) { io_thread->CleanUp(); }
78
79 static net::HttpAuthPreferences* GetAuthPreferences(IOThread* io_thread) {
80 return &(io_thread->http_auth_preferences_);
81 }
53 }; 82 };
54 83
55 class IOThreadTest : public testing::Test { 84 class IOThreadTest : public testing::Test {
56 public: 85 public:
57 IOThreadTest() 86 IOThreadTest()
58 : command_line_(base::CommandLine::NO_PROGRAM), 87 : command_line_(base::CommandLine::NO_PROGRAM),
59 is_quic_allowed_by_policy_(true) { 88 is_quic_allowed_by_policy_(true) {
60 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl()); 89 globals_.http_server_properties.reset(new net::HttpServerPropertiesImpl());
61 } 90 }
62 91
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 TEST_F(IOThreadTest, QuicDisallowedByPolicy) { 545 TEST_F(IOThreadTest, QuicDisallowedByPolicy) {
517 command_line_.AppendSwitch(switches::kEnableQuic); 546 command_line_.AppendSwitch(switches::kEnableQuic);
518 is_quic_allowed_by_policy_ = false; 547 is_quic_allowed_by_policy_ = false;
519 ConfigureQuicGlobals(); 548 ConfigureQuicGlobals();
520 549
521 net::HttpNetworkSession::Params params; 550 net::HttpNetworkSession::Params params;
522 InitializeNetworkSessionParams(&params); 551 InitializeNetworkSessionParams(&params);
523 EXPECT_FALSE(params.enable_quic); 552 EXPECT_FALSE(params.enable_quic);
524 } 553 }
525 554
555 class IOThreadTestWithIOThreadObject : public testing::Test {
556 public:
557 // These functions need to be public, since it is difficult to bind to
558 // protected functions in a test (the code would need to explicitly contain
559 // the name of the actual test class).
560 void CheckCnameLookup(bool expected) {
561 auto http_auth_preferences =
562 IOThreadPeer::GetAuthPreferences(io_thread_.get());
563 ASSERT_NE(nullptr, http_auth_preferences);
564 EXPECT_EQ(expected,
565 http_auth_preferences->negotiate_disable_cname_lookup());
566 }
567
568 protected:
569 IOThreadTestWithIOThreadObject()
570 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {
571 #if defined(ENABLE_EXTENSIONS)
572 event_router_forwarder_ = new extensions::EventRouterForwarder;
573 #endif
574 PrefRegistrySimple* pref_registry = pref_service_.registry();
575 IOThread::RegisterPrefs(pref_registry);
576 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry);
577 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry);
578
579 // Set up default function behaviour.
580 EXPECT_CALL(policy_service_,
581 GetPolicies(policy::PolicyNamespace(
582 policy::POLICY_DOMAIN_CHROME, std::string())))
583 .WillRepeatedly(ReturnRef(policy_map_));
584
585 #if defined(OS_CHROMEOS)
586 // Needed by IOThread constructor.
587 chromeos::DBusThreadManager::Initialize();
588 chromeos::NetworkHandler::Initialize();
589 #endif
590 io_thread_.reset(new IOThread(&pref_service_, &policy_service_, nullptr,
591 event_router_forwarder_.get()));
592 // Init must be run on the IO thread.
593 RunOnIOThreadBlocking(
594 base::Bind(&IOThreadPeer::InitIOThread, io_thread_.get()));
595 }
596
597 ~IOThreadTestWithIOThreadObject() override {
598 RunOnIOThreadBlocking(
599 base::Bind(&IOThreadPeer::CleanUpIOThread, io_thread_.get()));
600 #if defined(OS_CHROMEOS)
601 chromeos::NetworkHandler::Shutdown();
602 chromeos::DBusThreadManager::Shutdown();
603 #endif
604 }
605 TestingPrefServiceSimple* pref_service() { return &pref_service_; }
606
607 IOThread* io_thread() { return io_thread_.get(); }
608
609 void RunOnIOThreadBlocking(base::Closure task) {
610 base::RunLoop run_loop;
611 content::BrowserThread::PostTaskAndReply(
612 content::BrowserThread::IO, FROM_HERE, task, run_loop.QuitClosure());
613 run_loop.Run();
614 }
615
616 private:
617 content::TestBrowserThreadBundle thread_bundle_;
618 TestingPrefServiceSimple pref_service_;
619 scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_;
620 policy::PolicyMap policy_map_;
621 policy::MockPolicyService policy_service_;
622 scoped_ptr<IOThread> io_thread_;
623 IOThread::Globals globals_;
624 };
625
626 TEST_F(IOThreadTestWithIOThreadObject, HttpAuthPreferences) {
627 // This test uses the kDisableAuthNegotiateCnameLookup to check that
628 // the HttpAuthPreferences are correctly initialized and running on the
629 // IO thread. The other preferences are tested by the HttpAuthPreferences
630 // unit tests.
631 pref_service()->SetBoolean(net::prefs::kDisableAuthNegotiateCnameLookup,
632 false);
633 RunOnIOThreadBlocking(
634 base::Bind(&IOThreadTestWithIOThreadObject::CheckCnameLookup,
635 base::Unretained(this), false));
636 pref_service()->SetBoolean(net::prefs::kDisableAuthNegotiateCnameLookup,
637 true);
638 RunOnIOThreadBlocking(
639 base::Bind(&IOThreadTestWithIOThreadObject::CheckCnameLookup,
640 base::Unretained(this), true));
641 }
642
526 } // namespace test 643 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698