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

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

Issue 2546533003: Respect QuicAllowed policy for new streams (Closed)
Patch Set: Fixed accesses to iothread globals from UI thread Created 4 years 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_for_new_streams =
Bence 2016/12/02 18:53:26 Please run git cl format to reformat this multi-li
pmarko 2016/12/08 17:01:59 Done.
32 params().enable_quic; 32 context->http_transaction_factory()->GetSession()->
33 EXPECT_EQ(quic_enabled_expected, quic_enabled); 33 params().is_enable_quic_for_new_streams();
34 EXPECT_EQ(quic_enabled_expected, quic_enabled_for_new_streams);
34 35
35 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 36 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
36 done_callback); 37 done_callback);
37 } 38 }
38 39
39 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) { 40 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) {
40 base::RunLoop run_loop; 41 base::RunLoop run_loop;
41 content::BrowserThread::PostTask( 42 content::BrowserThread::PostTask(
42 content::BrowserThread::IO, FROM_HERE, 43 content::BrowserThread::IO, FROM_HERE,
43 base::Bind(VerifyQuicEnabledStatus, 44 base::Bind(VerifyQuicEnabledStatus,
44 base::RetainedRef(g_browser_process->system_request_context()), 45 base::RetainedRef(g_browser_process->system_request_context()),
45 quic_enabled_expected, run_loop.QuitClosure())); 46 quic_enabled_expected, run_loop.QuitClosure()));
46 run_loop.Run(); 47 run_loop.Run();
47 } 48 }
48 49
49 } // namespace 50 } // namespace
50 51
51 namespace policy { 52 namespace policy {
52 53
53 // The tests are based on the assumption that command line flag kEnableQuic 54 // 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 // guarantees that QUIC protocol is enabled which is the case at the moment
55 // when these are being written. 56 // when these are being written.
56 class QuicAllowedPolicyTestBase: public InProcessBrowserTest { 57 class QuicAllowedPolicyTestBase: public InProcessBrowserTest {
57 public: 58 public:
58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} 59 QuicAllowedPolicyTestBase() : InProcessBrowserTest() {}
59 60
60 protected: 61 protected:
61 void SetUpInProcessBrowserTestFixture() override { 62 void SetUpInProcessBrowserTestFixture() override {
62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); 63 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic);
63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) 64 EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
64 .WillRepeatedly(testing::Return(true)); 65 .WillRepeatedly(testing::Return(true));
65 66
66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 67 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
67 PolicyMap values; 68 PolicyMap values;
68 GetQuicAllowedPolicy(&values); 69 GetQuicAllowedPolicy(&values);
69 provider_.UpdateChromePolicy(values); 70 provider_.UpdateChromePolicy(values);
70 } 71 }
71 72
72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; 73 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0;
73 74
75 MockConfigurationPolicyProvider provider_;
74 private: 76 private:
75 MockConfigurationPolicyProvider provider_;
76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); 77 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase);
77 }; 78 };
78 79
79 // Policy QuicAllowed set to false. 80 // Policy QuicAllowed set to false.
80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { 81 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase {
81 public: 82 public:
82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} 83 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase() {}
83 84
84 protected: 85 protected:
85 void GetQuicAllowedPolicy(PolicyMap* values) override { 86 void GetQuicAllowedPolicy(PolicyMap* values) override {
86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 87 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
87 POLICY_SOURCE_CLOUD, 88 POLICY_SOURCE_CLOUD,
88 base::MakeUnique<base::FundamentalValue>(false), nullptr); 89 base::MakeUnique<base::FundamentalValue>(false), nullptr);
89 } 90 }
90 91
91 private: 92 private:
92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); 93 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse);
93 }; 94 };
94 95
95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { 96 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) {
96 VerifyQuicEnabledStatusInIOThread(false); 97 VerifyQuicEnabledStatusInIOThread(false);
97 } 98 }
98 99
99 // Policy QuicAllowed set to true. 100 // Policy QuicAllowed set to true.
100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { 101 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase {
101 public: 102 public:
102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} 103 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase() {}
103 104
104 protected: 105 protected:
105 void GetQuicAllowedPolicy(PolicyMap* values) override { 106 void GetQuicAllowedPolicy(PolicyMap* values) override {
106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 107 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
107 POLICY_SOURCE_CLOUD, 108 POLICY_SOURCE_CLOUD,
108 base::MakeUnique<base::FundamentalValue>(true), nullptr); 109 base::MakeUnique<base::FundamentalValue>(true), nullptr);
109 } 110 }
110 111
111 private: 112 private:
112 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); 113 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue);
113 }; 114 };
114 115
115 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { 116 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) {
116 VerifyQuicEnabledStatusInIOThread(true); 117 VerifyQuicEnabledStatusInIOThread(true);
117 } 118 }
118 119
119 // Policy QuicAllowed is not set. 120 // Policy QuicAllowed is not set.
120 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { 121 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase {
121 public: 122 public:
122 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} 123 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase() {}
123 124
124 protected: 125 protected:
125 void GetQuicAllowedPolicy(PolicyMap* values) override { 126 void GetQuicAllowedPolicy(PolicyMap* values) override {
126 } 127 }
127 128
128 private: 129 private:
129 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); 130 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet);
130 }; 131 };
131 132
132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { 133 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) {
133 VerifyQuicEnabledStatusInIOThread(true); 134 VerifyQuicEnabledStatusInIOThread(true);
134 } 135 }
135 136
137 // Policy QuicAllowed is set after IOThread initialization.
138 class QuicAllowedPolicyIsSetToFalseAfterInit: public QuicAllowedPolicyTestBase {
Bence 2016/12/02 18:53:26 Space required before ":". With that, this line i
pmarko 2016/12/08 17:01:59 Done.
139 public:
140 QuicAllowedPolicyIsSetToFalseAfterInit() : QuicAllowedPolicyTestBase() {}
Bence 2016/12/02 18:53:25 I believe that it is unnecessary to define this co
pmarko 2016/12/08 17:01:59 The problem is that all classes in this file have
Bence 2016/12/08 17:41:59 Sorry, I didn't realize that. Then I think it's b
pmarko 2016/12/08 19:56:54 Acknowledged.
141
142 protected:
143 void GetQuicAllowedPolicy(PolicyMap* values) override {
144 }
Bence 2016/12/02 18:53:25 Move this closing brace to the previous line.
pmarko 2016/12/08 17:01:59 Done.
145
146 void SetUpOnMainThread() override {
147 PolicyMap values;
148 values.Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
149 POLICY_SOURCE_CLOUD,
Bence 2016/12/02 18:53:25 Move these two lines one space to the left please.
pmarko 2016/12/08 17:01:59 Done.
150 base::MakeUnique<base::FundamentalValue>(false), nullptr);
151 provider_.UpdateChromePolicy(values);
152 base::RunLoop().RunUntilIdle();
153 }
154
155 private:
156 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsSetToFalseAfterInit);
157 };
158
159 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsSetToFalseAfterInit, QuicDisallowed) {
160 VerifyQuicEnabledStatusInIOThread(false);
161 }
136 } // namespace policy 162 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698