OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "base/bind.h" |
| 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" |
| 21 |
| 22 namespace { |
| 23 |
| 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()-> |
| 29 params().enable_quic; |
| 30 EXPECT_EQ(quic_enabled_expected, quic_enabled); |
| 31 |
| 32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 33 done_callback); |
| 34 } |
| 35 |
| 36 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) { |
| 37 base::RunLoop run_loop; |
| 38 content::BrowserThread::PostTask( |
| 39 content::BrowserThread::IO, |
| 40 FROM_HERE, |
| 41 base::Bind( |
| 42 VerifyQuicEnabledStatus, |
| 43 make_scoped_refptr(g_browser_process->system_request_context()), |
| 44 quic_enabled_expected, |
| 45 run_loop.QuitClosure())); |
| 46 run_loop.Run(); |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 namespace policy { |
| 52 |
| 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 { |
| 57 public: |
| 58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} |
| 59 |
| 60 protected: |
| 61 void SetUpInProcessBrowserTestFixture() override { |
| 62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); |
| 63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) |
| 64 .WillRepeatedly(testing::Return(true)); |
| 65 |
| 66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 67 PolicyMap values; |
| 68 GetQuicAllowedPolicy(&values); |
| 69 provider_.UpdateChromePolicy(values); |
| 70 } |
| 71 |
| 72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; |
| 73 |
| 74 private: |
| 75 MockConfigurationPolicyProvider provider_; |
| 76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); |
| 77 }; |
| 78 |
| 79 // Policy QuicAllowed set to false. |
| 80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { |
| 81 public: |
| 82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} |
| 83 |
| 84 protected: |
| 85 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 87 new base::FundamentalValue(false), NULL); |
| 88 } |
| 89 |
| 90 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); |
| 92 }; |
| 93 |
| 94 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { |
| 95 VerifyQuicEnabledStatusInIOThread(false); |
| 96 } |
| 97 |
| 98 // Policy QuicAllowed set to true. |
| 99 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { |
| 100 public: |
| 101 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} |
| 102 |
| 103 protected: |
| 104 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 105 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 106 new base::FundamentalValue(true), NULL); |
| 107 } |
| 108 |
| 109 private: |
| 110 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); |
| 111 }; |
| 112 |
| 113 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { |
| 114 VerifyQuicEnabledStatusInIOThread(true); |
| 115 } |
| 116 |
| 117 // Policy QuicAllowed is not set. |
| 118 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { |
| 119 public: |
| 120 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} |
| 121 |
| 122 protected: |
| 123 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 124 } |
| 125 |
| 126 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); |
| 128 }; |
| 129 |
| 130 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { |
| 131 VerifyQuicEnabledStatusInIOThread(true); |
| 132 } |
| 133 |
| 134 } // namespace policy |
OLD | NEW |