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

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

Issue 2546533003: Respect QuicAllowed policy for new streams (Closed)
Patch Set: Introduced IOThread::UpdateNetworkSessionParams 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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/ui/browser.h"
12 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
14 #include "components/policy/core/browser/browser_policy_connector.h" 17 #include "components/policy/core/browser/browser_policy_connector.h"
15 #include "components/policy/core/common/mock_configuration_policy_provider.h" 18 #include "components/policy/core/common/mock_configuration_policy_provider.h"
16 #include "components/policy/core/common/policy_map.h" 19 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_types.h" 20 #include "components/policy/core/common/policy_types.h"
18 #include "components/policy/policy_constants.h" 21 #include "components/policy/policy_constants.h"
19 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
20 #include "content/public/test/browser_test.h" 23 #include "content/public/test/browser_test.h"
21 #include "net/http/http_transaction_factory.h" 24 #include "net/http/http_transaction_factory.h"
22 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_context_getter.h" 26 #include "net/url_request/url_request_context_getter.h"
24 27
25 namespace { 28 namespace {
26 29
27 void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter, 30 bool IsQuicEnabled(net::URLRequestContextGetter* context) {
28 bool quic_enabled_expected, 31 return context->GetURLRequestContext()
29 const base::Closure& done_callback) { 32 ->http_transaction_factory()
30 net::URLRequestContext* context = getter->GetURLRequestContext(); 33 ->GetSession()
31 bool quic_enabled = context->http_transaction_factory()->GetSession()-> 34 ->IsQuicEnabled();
32 params().enable_quic; 35 }
33 EXPECT_EQ(quic_enabled_expected, quic_enabled); 36
37 void VerifyQuicEnabledStatus(
38 net::URLRequestContextGetter* system_context,
39 net::URLRequestContextGetter* safe_browsing_context,
40 net::URLRequestContextGetter* profile_context,
41 bool quic_enabled_expected,
42 const base::Closure& done_callback) {
43 bool quic_enabled_system = IsQuicEnabled(system_context);
44 EXPECT_EQ(quic_enabled_expected, quic_enabled_system);
45
46 bool quic_enabled_safe_browsing = IsQuicEnabled(safe_browsing_context);
47 EXPECT_EQ(quic_enabled_expected, quic_enabled_safe_browsing);
48
49 bool quic_enabled_profile = IsQuicEnabled(profile_context);
50 EXPECT_EQ(quic_enabled_expected, quic_enabled_profile);
34 51
35 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 52 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
36 done_callback); 53 done_callback);
37 } 54 }
38 55
39 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) { 56 void VerifyQuicEnabledStatusInIOThread(Profile* profile,
57 bool quic_enabled_expected) {
40 base::RunLoop run_loop; 58 base::RunLoop run_loop;
59 net::URLRequestContextGetter* system_context =
60 g_browser_process->system_request_context();
61 net::URLRequestContextGetter* safe_browsing_context =
62 g_browser_process->safe_browsing_service()->url_request_context();
63 net::URLRequestContextGetter* profile_context = profile->GetRequestContext();
64
41 content::BrowserThread::PostTask( 65 content::BrowserThread::PostTask(
42 content::BrowserThread::IO, FROM_HERE, 66 content::BrowserThread::IO, FROM_HERE,
43 base::Bind(VerifyQuicEnabledStatus, 67 base::Bind(VerifyQuicEnabledStatus, base::RetainedRef(system_context),
44 base::RetainedRef(g_browser_process->system_request_context()), 68 base::RetainedRef(safe_browsing_context),
45 quic_enabled_expected, run_loop.QuitClosure())); 69 base::RetainedRef(profile_context), quic_enabled_expected,
70 run_loop.QuitClosure()));
46 run_loop.Run(); 71 run_loop.Run();
47 } 72 }
48 73
49 } // namespace 74 } // namespace
50 75
51 namespace policy { 76 namespace policy {
52 77
53 // The tests are based on the assumption that command line flag kEnableQuic 78 // 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 79 // guarantees that QUIC protocol is enabled which is the case at the moment
55 // when these are being written. 80 // when these are being written.
56 class QuicAllowedPolicyTestBase: public InProcessBrowserTest { 81 class QuicAllowedPolicyTestBase: public InProcessBrowserTest {
57 public: 82 public:
58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} 83 QuicAllowedPolicyTestBase() : InProcessBrowserTest() {}
59 84
60 protected: 85 protected:
61 void SetUpInProcessBrowserTestFixture() override { 86 void SetUpInProcessBrowserTestFixture() override {
62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); 87 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic);
63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) 88 EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
64 .WillRepeatedly(testing::Return(true)); 89 .WillRepeatedly(testing::Return(true));
65 90
66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 91 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
67 PolicyMap values; 92 PolicyMap values;
68 GetQuicAllowedPolicy(&values); 93 GetQuicAllowedPolicy(&values);
69 provider_.UpdateChromePolicy(values); 94 provider_.UpdateChromePolicy(values);
70 } 95 }
71 96
72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; 97 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0;
73 98
99 MockConfigurationPolicyProvider provider_;
100
74 private: 101 private:
75 MockConfigurationPolicyProvider provider_;
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); 102 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
77 }; 103 };
78 104
79 // Policy QuicAllowed set to false. 105 // Policy QuicAllowed set to false.
80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { 106 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
81 public: 107 public:
82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} 108 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase() {}
83 109
84 protected: 110 protected:
85 void GetQuicAllowedPolicy(PolicyMap* values) override { 111 void GetQuicAllowedPolicy(PolicyMap* values) override {
86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 112 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
87 POLICY_SOURCE_CLOUD, 113 POLICY_SOURCE_CLOUD,
88 base::MakeUnique<base::FundamentalValue>(false), nullptr); 114 base::MakeUnique<base::FundamentalValue>(false), nullptr);
89 } 115 }
90 116
91 private: 117 private:
92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); 118 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse);
93 }; 119 };
94 120
95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { 121 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) {
96 VerifyQuicEnabledStatusInIOThread(false); 122 VerifyQuicEnabledStatusInIOThread(browser()->profile(), false);
97 } 123 }
98 124
99 // Policy QuicAllowed set to true. 125 // Policy QuicAllowed set to true.
100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { 126 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase {
101 public: 127 public:
102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} 128 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase() {}
103 129
104 protected: 130 protected:
105 void GetQuicAllowedPolicy(PolicyMap* values) override { 131 void GetQuicAllowedPolicy(PolicyMap* values) override {
106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 132 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
107 POLICY_SOURCE_CLOUD, 133 POLICY_SOURCE_CLOUD,
108 base::MakeUnique<base::FundamentalValue>(true), nullptr); 134 base::MakeUnique<base::FundamentalValue>(true), nullptr);
109 } 135 }
110 136
111 private: 137 private:
112 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); 138 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue);
113 }; 139 };
114 140
115 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { 141 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) {
116 VerifyQuicEnabledStatusInIOThread(true); 142 VerifyQuicEnabledStatusInIOThread(browser()->profile(), true);
117 } 143 }
118 144
119 // Policy QuicAllowed is not set. 145 // Policy QuicAllowed is not set.
120 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { 146 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase {
121 public: 147 public:
122 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} 148 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase() {}
123 149
124 protected: 150 protected:
125 void GetQuicAllowedPolicy(PolicyMap* values) override { 151 void GetQuicAllowedPolicy(PolicyMap* values) override {
126 } 152 }
127 153
128 private: 154 private:
129 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); 155 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet);
130 }; 156 };
131 157
132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { 158 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
133 VerifyQuicEnabledStatusInIOThread(true); 159 VerifyQuicEnabledStatusInIOThread(browser()->profile(), true);
134 } 160 }
135 161
162 // Policy QuicAllowed is set after IOThread initialization.
163 class QuicAllowedPolicyIsSetToFalseAfterInit
164 : public QuicAllowedPolicyTestBase {
165 public:
166 QuicAllowedPolicyIsSetToFalseAfterInit() : QuicAllowedPolicyTestBase() {}
167
168 protected:
169 void GetQuicAllowedPolicy(PolicyMap* values) override {}
170
171 private:
172 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsSetToFalseAfterInit);
173 };
174
175 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsSetToFalseAfterInit, QuicDisallowed) {
176 PolicyMap values;
177 values.Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
178 POLICY_SOURCE_CLOUD,
179 base::MakeUnique<base::FundamentalValue>(false), nullptr);
180 provider_.UpdateChromePolicy(values);
181 base::RunLoop().RunUntilIdle();
182
183 VerifyQuicEnabledStatusInIOThread(browser()->profile(), false);
184 }
136 } // namespace policy 185 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698