Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / policy / policy_network_browsertest.cc
blobe5c42af2e3fcabbbd7e668305eaf3f895f5a4a2e
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.
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"
22 namespace {
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);
32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
33 done_callback);
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();
49 } // namespace
51 namespace policy {
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(){}
60 protected:
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_);
67 PolicyMap values;
68 GetQuicAllowedPolicy(&values);
69 provider_.UpdateChromePolicy(values);
72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0;
74 private:
75 MockConfigurationPolicyProvider provider_;
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
79 // Policy QuicAllowed set to false.
80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
81 public:
82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){}
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);
90 private:
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 {
100 public:
101 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){}
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);
109 private:
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 {
119 public:
120 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){}
122 protected:
123 void GetQuicAllowedPolicy(PolicyMap* values) override {
126 private:
127 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet);
130 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
131 VerifyQuicEnabledStatusInIOThread(true);
134 } // namespace policy