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

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

Issue 2546533003: Respect QuicAllowed policy for new streams (Closed)
Patch Set: IOS io_thread also initializes DynamicSharedParams Created 3 years, 12 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
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/http/http_transaction_factory.h" 21 #include "net/http/http_transaction_factory.h"
22 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
24 24
25 namespace { 25 namespace {
26 26
27 void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter, 27 void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter,
28 bool quic_enabled_expected, 28 bool quic_enabled_expected,
29 const base::Closure& done_callback) { 29 const base::Closure& done_callback) {
30 net::URLRequestContext* context = getter->GetURLRequestContext(); 30 net::URLRequestContext* context = getter->GetURLRequestContext();
31 bool quic_enabled = context->http_transaction_factory()->GetSession()-> 31 bool quic_enabled =
32 params().enable_quic; 32 context->http_transaction_factory()->GetSession()->params().enable_quic();
33 EXPECT_EQ(quic_enabled_expected, quic_enabled); 33 EXPECT_EQ(quic_enabled_expected, quic_enabled);
34 34
35 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 35 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
36 done_callback); 36 done_callback);
37 } 37 }
38 38
39 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) { 39 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) {
40 base::RunLoop run_loop; 40 base::RunLoop run_loop;
41 content::BrowserThread::PostTask( 41 content::BrowserThread::PostTask(
42 content::BrowserThread::IO, FROM_HERE, 42 content::BrowserThread::IO, FROM_HERE,
43 base::Bind(VerifyQuicEnabledStatus, 43 base::Bind(VerifyQuicEnabledStatus,
44 base::RetainedRef(g_browser_process->system_request_context()), 44 base::RetainedRef(g_browser_process->system_request_context()),
45 quic_enabled_expected, run_loop.QuitClosure())); 45 quic_enabled_expected, run_loop.QuitClosure()));
46 run_loop.Run(); 46 run_loop.Run();
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 namespace policy { 51 namespace policy {
52 52
53 // The tests are based on the assumption that command line flag kEnableQuic 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 54 // guarantees that QUIC protocol is enabled which is the case at the moment
55 // when these are being written. 55 // when these are being written.
56 class QuicAllowedPolicyTestBase: public InProcessBrowserTest { 56 class QuicAllowedPolicyTestBase: public InProcessBrowserTest {
57 public: 57 public:
58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} 58 QuicAllowedPolicyTestBase() : InProcessBrowserTest() {}
59 59
60 protected: 60 protected:
61 void SetUpInProcessBrowserTestFixture() override { 61 void SetUpInProcessBrowserTestFixture() override {
62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); 62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic);
63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) 63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
64 .WillRepeatedly(testing::Return(true)); 64 .WillRepeatedly(testing::Return(true));
65 65
66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
67 PolicyMap values; 67 PolicyMap values;
68 GetQuicAllowedPolicy(&values); 68 GetQuicAllowedPolicy(&values);
69 provider_.UpdateChromePolicy(values); 69 provider_.UpdateChromePolicy(values);
70 } 70 }
71 71
72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; 72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0;
73 73
74 MockConfigurationPolicyProvider provider_;
74 private: 75 private:
75 MockConfigurationPolicyProvider provider_;
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); 76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
77 }; 77 };
78 78
79 // Policy QuicAllowed set to false. 79 // Policy QuicAllowed set to false.
80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { 80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
81 public: 81 public:
82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} 82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase() {}
83 83
84 protected: 84 protected:
85 void GetQuicAllowedPolicy(PolicyMap* values) override { 85 void GetQuicAllowedPolicy(PolicyMap* values) override {
86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
87 POLICY_SOURCE_CLOUD, 87 POLICY_SOURCE_CLOUD,
88 base::MakeUnique<base::FundamentalValue>(false), nullptr); 88 base::MakeUnique<base::FundamentalValue>(false), nullptr);
89 } 89 }
90 90
91 private: 91 private:
92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); 92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse);
93 }; 93 };
94 94
95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { 95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) {
96 VerifyQuicEnabledStatusInIOThread(false); 96 VerifyQuicEnabledStatusInIOThread(false);
97 } 97 }
98 98
99 // Policy QuicAllowed set to true. 99 // Policy QuicAllowed set to true.
100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { 100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase {
101 public: 101 public:
102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} 102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase() {}
103 103
104 protected: 104 protected:
105 void GetQuicAllowedPolicy(PolicyMap* values) override { 105 void GetQuicAllowedPolicy(PolicyMap* values) override {
106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
107 POLICY_SOURCE_CLOUD, 107 POLICY_SOURCE_CLOUD,
108 base::MakeUnique<base::FundamentalValue>(true), nullptr); 108 base::MakeUnique<base::FundamentalValue>(true), nullptr);
109 } 109 }
110 110
111 private: 111 private:
112 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); 112 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue);
113 }; 113 };
114 114
115 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { 115 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) {
116 VerifyQuicEnabledStatusInIOThread(true); 116 VerifyQuicEnabledStatusInIOThread(true);
117 } 117 }
118 118
119 // Policy QuicAllowed is not set. 119 // Policy QuicAllowed is not set.
120 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { 120 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase {
121 public: 121 public:
122 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} 122 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase() {}
123 123
124 protected: 124 protected:
125 void GetQuicAllowedPolicy(PolicyMap* values) override { 125 void GetQuicAllowedPolicy(PolicyMap* values) override {
126 } 126 }
127 127
128 private: 128 private:
129 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); 129 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet);
130 }; 130 };
131 131
132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { 132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
133 VerifyQuicEnabledStatusInIOThread(true); 133 VerifyQuicEnabledStatusInIOThread(true);
134 } 134 }
135 135
136 // Policy QuicAllowed is set after IOThread initialization.
137 class QuicAllowedPolicyIsSetToFalseAfterInit
138 : public QuicAllowedPolicyTestBase {
139 public:
140 QuicAllowedPolicyIsSetToFalseAfterInit() : QuicAllowedPolicyTestBase() {}
141
142 protected:
143 void GetQuicAllowedPolicy(PolicyMap* values) override {}
144
145 void SetUpOnMainThread() override {
146 PolicyMap values;
147 values.Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
148 POLICY_SOURCE_CLOUD,
149 base::MakeUnique<base::FundamentalValue>(false), nullptr);
150 provider_.UpdateChromePolicy(values);
151 base::RunLoop().RunUntilIdle();
152 }
153
154 private:
155 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsSetToFalseAfterInit);
156 };
157
158 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsSetToFalseAfterInit, QuicDisallowed) {
159 VerifyQuicEnabledStatusInIOThread(false);
160 }
136 } // namespace policy 161 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698