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

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: Rebase Created 5 years, 8 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/test/base/in_process_browser_test.h"
11 #include "components/policy/core/browser/browser_policy_connector.h"
12 #include "components/policy/core/common/mock_configuration_policy_provider.h"
13 #include "components/policy/core/common/policy_map.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/test/browser_test.h"
16 #include "net/http/http_transaction_factory.h"
17 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h"
19 #include "policy/policy_constants.h"
20
21 namespace {
22
23 void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter,
24 bool quic_enabled_expected,
25 const base::Closure& done_callback) {
26 net::URLRequestContext* context = getter->GetURLRequestContext();
27 bool quic_enabled = context->http_transaction_factory()->GetSession()->
28 params().enable_quic;
29 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.
30
31 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
32 done_callback);
Andrew T Wilson (Slow) 2015/04/14 17:48:47 indent to opening paren
peletskyi 2015/04/27 11:05:50 Done.
33 }
34
35 } // namespace
36
37 namespace policy {
38
39 // 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
40 // guarantees that QUIC protocol is enabled which is the case at the moment
41 // when these are being written.
42 class QuicAllowedPolicyTestBase: public InProcessBrowserTest {
43 public:
44 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){}
45
46 protected:
47 void SetUpInProcessBrowserTestFixture() override {
48 base::CommandLine::ForCurrentProcess()->AppendSwitch("enable-quic");
49 EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
50 .WillRepeatedly(testing::Return(true));
51
52 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
53 PolicyMap values;
54 GetQuicAllowedPolicy(&values);
55 provider_.UpdateChromePolicy(values);
56 }
57
58 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
59
60 private:
61 MockConfigurationPolicyProvider provider_;
62 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
63 };
64
65 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
66 public:
67 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){}
68
69 protected:
70 void GetQuicAllowedPolicy(PolicyMap* values) override {
71 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
72 new base::FundamentalValue(false), NULL);
73 }
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse);
77 };
78
79 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) {
80 base::RunLoop run_loop;
81 content::BrowserThread::PostTask(
82 content::BrowserThread::IO,
83 FROM_HERE,
84 base::Bind(
85 VerifyQuicEnabledStatus,
86 make_scoped_refptr(g_browser_process->system_request_context()),
87 false,
88 run_loop.QuitClosure()));
89 run_loop.Run();
90 }
91
92 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase {
93 public:
94 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){}
95
96 protected:
97 void GetQuicAllowedPolicy(PolicyMap* values) override {
98 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
99 new base::FundamentalValue(true), NULL);
100 }
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue);
104 };
105
106 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) {
107 base::RunLoop run_loop;
108 content::BrowserThread::PostTask(
109 content::BrowserThread::IO,
110 FROM_HERE,
111 base::Bind(
112 VerifyQuicEnabledStatus,
113 make_scoped_refptr(g_browser_process->system_request_context()),
114 true,
115 run_loop.QuitClosure()));
116 run_loop.Run();
117 }
118
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
132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
133 base::RunLoop run_loop;
134 content::BrowserThread::PostTask(
135 content::BrowserThread::IO,
136 FROM_HERE,
137 base::Bind(
138 VerifyQuicEnabledStatus,
139 make_scoped_refptr(g_browser_process->system_request_context()),
140 true,
141 run_loop.QuitClosure()));
142 run_loop.Run();
143 }
144
145 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698