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

Side by Side Diff: chrome/browser/policy/policy_network_browsertest.cc

Issue 998383002: Created policy QuicAllowed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made browser tests codebase better Created 5 years, 7 months 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
(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(
63 switches:: kEnableQuic);
64 EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
65 .WillRepeatedly(testing::Return(true));
66
67 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
68 PolicyMap values;
69 GetQuicAllowedPolicy(&values);
70 provider_.UpdateChromePolicy(values);
71 }
72
73 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0;
74
75 private:
76 MockConfigurationPolicyProvider provider_;
77 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
78 };
79
80 // Policy QuicAllowed set to false.
81 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
82 public:
83 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){}
84
85 protected:
86 void GetQuicAllowedPolicy(PolicyMap* values) override {
87 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
88 new base::FundamentalValue(false), NULL);
89 }
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse);
93 };
94
95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) {
96 VerifyQuicEnabledStatusInIOThread(false);
97 }
98
99 // Policy QuicAllowed set to true.
100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase {
101 public:
102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){}
103
104 protected:
105 void GetQuicAllowedPolicy(PolicyMap* values) override {
106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
107 new base::FundamentalValue(true), NULL);
108 }
109
110 private:
111 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue);
112 };
113
114 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) {
115 VerifyQuicEnabledStatusInIOThread(true);
116 }
117
118 // Policy QuicAllowed is not set.
119 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase {
120 public:
121 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){}
122
123 protected:
124 void GetQuicAllowedPolicy(PolicyMap* values) override {
125 }
126
127 private:
128 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet);
129 };
130
131 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
132 VerifyQuicEnabledStatusInIOThread(true);
133 }
134
135 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698