Chromium Code Reviews| Index: chrome/browser/policy/policy_network_browsertest.cc |
| diff --git a/chrome/browser/policy/policy_network_browsertest.cc b/chrome/browser/policy/policy_network_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..74503ee973f4543bdcf82dbaf73d781702e51f22 |
| --- /dev/null |
| +++ b/chrome/browser/policy/policy_network_browsertest.cc |
| @@ -0,0 +1,145 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/command_line.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/run_loop.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "components/policy/core/browser/browser_policy_connector.h" |
| +#include "components/policy/core/common/mock_configuration_policy_provider.h" |
| +#include "components/policy/core/common/policy_map.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/test/browser_test.h" |
| +#include "net/http/http_transaction_factory.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| +#include "policy/policy_constants.h" |
| + |
| +namespace { |
| + |
| +void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter, |
| + bool quic_enabled_expected, |
| + const base::Closure& done_callback) { |
| + net::URLRequestContext* context = getter->GetURLRequestContext(); |
| + bool quic_enabled = context->http_transaction_factory()->GetSession()-> |
| + params().enable_quic; |
| + EXPECT_EQ(quic_enabled, quic_enabled_expected); |
|
Andrew T Wilson (Slow)
2015/04/14 17:48:47
nit: this is the wrong order, order should be:
EX
peletskyi
2015/04/27 11:05:50
Done.
|
| + |
| + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| + done_callback); |
|
Andrew T Wilson (Slow)
2015/04/14 17:48:47
indent to opening paren
peletskyi
2015/04/27 11:05:50
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +namespace policy { |
| + |
| +// The tests are based on the assumption that command line flag "enable-quic" |
|
Andrew T Wilson (Slow)
2015/04/14 17:48:47
Maybe move this comment down to where you are appe
peletskyi
2015/04/27 11:05:50
Insert kEnableQuic - done.
Move the comment: i thi
|
| +// guarantees that QUIC protocol is enabled which is the case at the moment |
| +// when these are being written. |
| +class QuicAllowedPolicyTestBase: public InProcessBrowserTest { |
| + public: |
| + QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} |
| + |
| + protected: |
| + void SetUpInProcessBrowserTestFixture() override { |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch("enable-quic"); |
| + EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) |
| + .WillRepeatedly(testing::Return(true)); |
| + |
| + BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| + PolicyMap values; |
| + GetQuicAllowedPolicy(&values); |
| + provider_.UpdateChromePolicy(values); |
| + } |
| + |
| + virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; |
|
Andrew T Wilson (Slow)
2015/04/14 17:48:47
Why is this necessary? You can change the policy o
peletskyi
2015/04/27 11:05:50
Unfortunately the policy value should be set on st
|
| + |
| + private: |
| + MockConfigurationPolicyProvider provider_; |
| + DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); |
| +}; |
| + |
| +class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { |
| + public: |
| + QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} |
| + |
| + protected: |
| + void GetQuicAllowedPolicy(PolicyMap* values) override { |
| + values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| + new base::FundamentalValue(false), NULL); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { |
| + base::RunLoop run_loop; |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind( |
| + VerifyQuicEnabledStatus, |
| + make_scoped_refptr(g_browser_process->system_request_context()), |
| + false, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| +} |
| + |
| +class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { |
| + public: |
| + QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} |
| + |
| + protected: |
| + void GetQuicAllowedPolicy(PolicyMap* values) override { |
| + values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| + new base::FundamentalValue(true), NULL); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { |
| + base::RunLoop run_loop; |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind( |
| + VerifyQuicEnabledStatus, |
| + make_scoped_refptr(g_browser_process->system_request_context()), |
| + true, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| +} |
| + |
| +class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { |
| + public: |
| + QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} |
| + |
| + protected: |
| + void GetQuicAllowedPolicy(PolicyMap* values) override { |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); |
| +}; |
| + |
| + |
| +IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { |
| + base::RunLoop run_loop; |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind( |
| + VerifyQuicEnabledStatus, |
| + make_scoped_refptr(g_browser_process->system_request_context()), |
| + true, |
| + run_loop.QuitClosure())); |
| + run_loop.Run(); |
| +} |
| + |
| +} // namespace policy |