1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/command_line.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "components/policy/core/browser/browser_policy_connector.h"
13 #include "components/policy/core/common/mock_configuration_policy_provider.h"
14 #include "components/policy/core/common/policy_map.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/test/browser_test.h"
17 #include "net/http/http_transaction_factory.h"
18 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h"
20 #include "policy/policy_constants.h"
24 void VerifyQuicEnabledStatus(net::URLRequestContextGetter
* getter
,
25 bool quic_enabled_expected
,
26 const base::Closure
& done_callback
) {
27 net::URLRequestContext
* context
= getter
->GetURLRequestContext();
28 bool quic_enabled
= context
->http_transaction_factory()->GetSession()->
30 EXPECT_EQ(quic_enabled_expected
, quic_enabled
);
32 content::BrowserThread::PostTask(content::BrowserThread::UI
, FROM_HERE
,
36 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected
) {
37 base::RunLoop run_loop
;
38 content::BrowserThread::PostTask(
39 content::BrowserThread::IO
,
42 VerifyQuicEnabledStatus
,
43 make_scoped_refptr(g_browser_process
->system_request_context()),
44 quic_enabled_expected
,
45 run_loop
.QuitClosure()));
53 // The tests are based on the assumption that command line flag kEnableQuic
54 // guarantees that QUIC protocol is enabled which is the case at the moment
55 // when these are being written.
56 class QuicAllowedPolicyTestBase
: public InProcessBrowserTest
{
58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){}
61 void SetUpInProcessBrowserTestFixture() override
{
62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic
);
63 EXPECT_CALL(provider_
, IsInitializationComplete(testing::_
))
64 .WillRepeatedly(testing::Return(true));
66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_
);
68 GetQuicAllowedPolicy(&values
);
69 provider_
.UpdateChromePolicy(values
);
72 virtual void GetQuicAllowedPolicy(PolicyMap
* values
) = 0;
75 MockConfigurationPolicyProvider provider_
;
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase
);
79 // Policy QuicAllowed set to false.
80 class QuicAllowedPolicyIsFalse
: public QuicAllowedPolicyTestBase
{
82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){}
85 void GetQuicAllowedPolicy(PolicyMap
* values
) override
{
86 values
->Set(key::kQuicAllowed
, POLICY_LEVEL_MANDATORY
, POLICY_SCOPE_MACHINE
,
87 new base::FundamentalValue(false), NULL
);
91 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse
);
94 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse
, QuicDisallowed
) {
95 VerifyQuicEnabledStatusInIOThread(false);
98 // Policy QuicAllowed set to true.
99 class QuicAllowedPolicyIsTrue
: public QuicAllowedPolicyTestBase
{
101 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){}
104 void GetQuicAllowedPolicy(PolicyMap
* values
) override
{
105 values
->Set(key::kQuicAllowed
, POLICY_LEVEL_MANDATORY
, POLICY_SCOPE_MACHINE
,
106 new base::FundamentalValue(true), NULL
);
110 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue
);
113 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue
, QuicAllowed
) {
114 VerifyQuicEnabledStatusInIOThread(true);
117 // Policy QuicAllowed is not set.
118 class QuicAllowedPolicyIsNotSet
: public QuicAllowedPolicyTestBase
{
120 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){}
123 void GetQuicAllowedPolicy(PolicyMap
* values
) override
{
127 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet
);
130 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet
, NoQuicRegulations
) {
131 VerifyQuicEnabledStatusInIOThread(true);
134 } // namespace policy