Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/policy/profile_policy_connector_factory.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/profiles/profile_manager.h" | |
| 15 #include "chrome/browser/profiles/profiles_state.h" | |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 17 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "components/policy/core/browser/browser_policy_connector.h" | 20 #include "components/policy/core/browser/browser_policy_connector.h" |
| 15 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 21 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 16 #include "components/policy/core/common/policy_map.h" | 22 #include "components/policy/core/common/policy_map.h" |
| 17 #include "components/policy/core/common/policy_types.h" | 23 #include "components/policy/core/common/policy_types.h" |
| 18 #include "components/policy/policy_constants.h" | 24 #include "components/policy/policy_constants.h" |
| 19 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/test/browser_test.h" | 26 #include "content/public/test/browser_test.h" |
| 21 #include "net/http/http_transaction_factory.h" | 27 #include "net/http/http_transaction_factory.h" |
| 22 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 24 | 30 |
| 31 #if defined(OS_CHROMEOS) | |
| 32 #include "chromeos/chromeos_switches.h" | |
| 33 #endif | |
| 34 | |
| 25 namespace { | 35 namespace { |
| 26 | 36 |
| 27 void VerifyQuicEnabledStatus(net::URLRequestContextGetter* getter, | 37 // Checks if QUIC is enabled for new streams in the passed |request_context|. |
| 28 bool quic_enabled_expected, | 38 // Will set the bool pointed to by |quic_enabled|. |
| 29 const base::Closure& done_callback) { | 39 void IsQuicEnabledOnIOThread( |
| 30 net::URLRequestContext* context = getter->GetURLRequestContext(); | 40 net::URLRequestContextGetter* request_context_getter, |
| 31 bool quic_enabled = context->http_transaction_factory()->GetSession()-> | 41 bool* quic_enabled) { |
| 32 params().enable_quic; | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 33 EXPECT_EQ(quic_enabled_expected, quic_enabled); | |
| 34 | 43 |
| 35 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 44 *quic_enabled = request_context_getter->GetURLRequestContext() |
| 36 done_callback); | 45 ->http_transaction_factory() |
| 46 ->GetSession() | |
| 47 ->IsQuicEnabled(); | |
| 37 } | 48 } |
| 38 | 49 |
| 39 void VerifyQuicEnabledStatusInIOThread(bool quic_enabled_expected) { | 50 // Can be called on the UI thread, returns if QUIC is enabled for new streams in |
| 51 // the passed |request_context|. | |
| 52 bool IsQuicEnabled(net::URLRequestContextGetter* request_context_getter) { | |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 54 | |
| 40 base::RunLoop run_loop; | 55 base::RunLoop run_loop; |
| 41 content::BrowserThread::PostTask( | 56 bool is_quic_enabled = false; |
| 57 content::BrowserThread::PostTaskAndReply( | |
| 42 content::BrowserThread::IO, FROM_HERE, | 58 content::BrowserThread::IO, FROM_HERE, |
| 43 base::Bind(VerifyQuicEnabledStatus, | 59 base::Bind(IsQuicEnabledOnIOThread, request_context_getter, |
| 44 base::RetainedRef(g_browser_process->system_request_context()), | 60 &is_quic_enabled), |
| 45 quic_enabled_expected, run_loop.QuitClosure())); | 61 run_loop.QuitClosure()); |
| 46 run_loop.Run(); | 62 run_loop.Run(); |
| 63 return is_quic_enabled; | |
| 64 } | |
| 65 | |
| 66 // Short-hand access to global SafeBrowsingService's URLRequestContextGetter for | |
| 67 // better readability. | |
| 68 net::URLRequestContextGetter* safe_browsing_service_request_context() { | |
|
mmenke
2017/01/10 22:12:19
May want to make these return scoped_refptrs, and
pmarko
2017/01/11 08:34:49
Done.
Good point, I was tricked into settling on p
| |
| 69 return g_browser_process->safe_browsing_service() | |
| 70 ->url_request_context() | |
| 71 .get(); | |
| 72 } | |
| 73 | |
| 74 // Short-hand access to global system request context getter for better | |
| 75 // readability. | |
| 76 net::URLRequestContextGetter* system_request_context() { | |
| 77 return g_browser_process->system_request_context(); | |
| 78 } | |
| 79 | |
| 80 // Called when an additional profile has been created. | |
| 81 // The created profile is stored in *|out_created_profile|. | |
| 82 void OnProfileInitialized(Profile** out_created_profile, | |
| 83 const base::Closure& closure, | |
| 84 Profile* profile, | |
| 85 Profile::CreateStatus status) { | |
| 86 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
| 87 *out_created_profile = profile; | |
| 88 closure.Run(); | |
| 89 } | |
| 47 } | 90 } |
| 48 | 91 |
| 49 } // namespace | 92 } // namespace |
| 50 | 93 |
| 51 namespace policy { | 94 namespace policy { |
| 52 | 95 |
| 53 // The tests are based on the assumption that command line flag kEnableQuic | 96 // 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 | 97 // guarantees that QUIC protocol is enabled which is the case at the moment |
| 55 // when these are being written. | 98 // when these are being written. |
| 56 class QuicAllowedPolicyTestBase: public InProcessBrowserTest { | 99 class QuicAllowedPolicyTestBase: public InProcessBrowserTest { |
| 57 public: | 100 public: |
| 58 QuicAllowedPolicyTestBase() : InProcessBrowserTest(){} | 101 QuicAllowedPolicyTestBase() : InProcessBrowserTest() {} |
| 59 | 102 |
| 60 protected: | 103 protected: |
| 61 void SetUpInProcessBrowserTestFixture() override { | 104 void SetUpInProcessBrowserTestFixture() override { |
| 62 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); | 105 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableQuic); |
| 63 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) | 106 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)) |
| 64 .WillRepeatedly(testing::Return(true)); | 107 .WillRepeatedly(testing::Return(true)); |
| 65 | 108 |
| 66 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 109 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 67 PolicyMap values; | 110 PolicyMap values; |
| 68 GetQuicAllowedPolicy(&values); | 111 GetQuicAllowedPolicy(&values); |
| 69 provider_.UpdateChromePolicy(values); | 112 provider_.UpdateChromePolicy(values); |
| 70 } | 113 } |
| 71 | 114 |
| 72 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; | 115 virtual void GetQuicAllowedPolicy(PolicyMap* values) = 0; |
| 73 | 116 |
| 74 private: | 117 private: |
| 75 MockConfigurationPolicyProvider provider_; | 118 MockConfigurationPolicyProvider provider_; |
| 76 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); | 119 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyTestBase); |
| 77 }; | 120 }; |
| 78 | 121 |
| 79 // Policy QuicAllowed set to false. | 122 // Policy QuicAllowed set to false. |
| 80 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { | 123 class QuicAllowedPolicyIsFalse: public QuicAllowedPolicyTestBase { |
| 81 public: | 124 public: |
| 82 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase(){} | 125 QuicAllowedPolicyIsFalse() : QuicAllowedPolicyTestBase() {} |
| 83 | 126 |
| 84 protected: | 127 protected: |
| 85 void GetQuicAllowedPolicy(PolicyMap* values) override { | 128 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 86 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 129 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 87 POLICY_SOURCE_CLOUD, | 130 POLICY_SOURCE_CLOUD, |
| 88 base::MakeUnique<base::FundamentalValue>(false), nullptr); | 131 base::MakeUnique<base::FundamentalValue>(false), nullptr); |
| 89 } | 132 } |
| 90 | 133 |
| 91 private: | 134 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); | 135 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsFalse); |
| 93 }; | 136 }; |
| 94 | 137 |
| 95 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { | 138 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsFalse, QuicDisallowed) { |
| 96 VerifyQuicEnabledStatusInIOThread(false); | 139 EXPECT_FALSE(IsQuicEnabled(system_request_context())); |
| 140 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 141 EXPECT_FALSE(IsQuicEnabled(browser()->profile()->GetRequestContext())); | |
| 97 } | 142 } |
| 98 | 143 |
| 99 // Policy QuicAllowed set to true. | 144 // Policy QuicAllowed set to true. |
| 100 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { | 145 class QuicAllowedPolicyIsTrue: public QuicAllowedPolicyTestBase { |
| 101 public: | 146 public: |
| 102 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase(){} | 147 QuicAllowedPolicyIsTrue() : QuicAllowedPolicyTestBase() {} |
| 103 | 148 |
| 104 protected: | 149 protected: |
| 105 void GetQuicAllowedPolicy(PolicyMap* values) override { | 150 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 106 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 151 values->Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 107 POLICY_SOURCE_CLOUD, | 152 POLICY_SOURCE_CLOUD, |
| 108 base::MakeUnique<base::FundamentalValue>(true), nullptr); | 153 base::MakeUnique<base::FundamentalValue>(true), nullptr); |
| 109 } | 154 } |
| 110 | 155 |
| 111 private: | 156 private: |
| 112 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); | 157 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsTrue); |
| 113 }; | 158 }; |
| 114 | 159 |
| 115 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { | 160 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsTrue, QuicAllowed) { |
| 116 VerifyQuicEnabledStatusInIOThread(true); | 161 EXPECT_TRUE(IsQuicEnabled(system_request_context())); |
| 162 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 163 EXPECT_TRUE(IsQuicEnabled(browser()->profile()->GetRequestContext())); | |
| 117 } | 164 } |
| 118 | 165 |
| 119 // Policy QuicAllowed is not set. | 166 // Policy QuicAllowed is not set. |
| 120 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { | 167 class QuicAllowedPolicyIsNotSet: public QuicAllowedPolicyTestBase { |
| 121 public: | 168 public: |
| 122 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase(){} | 169 QuicAllowedPolicyIsNotSet() : QuicAllowedPolicyTestBase() {} |
| 123 | 170 |
| 124 protected: | 171 protected: |
| 125 void GetQuicAllowedPolicy(PolicyMap* values) override { | 172 void GetQuicAllowedPolicy(PolicyMap* values) override { |
| 126 } | 173 } |
| 127 | 174 |
| 128 private: | 175 private: |
| 129 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); | 176 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyIsNotSet); |
| 130 }; | 177 }; |
| 131 | 178 |
| 132 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { | 179 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyIsNotSet, NoQuicRegulations) { |
| 133 VerifyQuicEnabledStatusInIOThread(true); | 180 EXPECT_TRUE(IsQuicEnabled(system_request_context())); |
| 181 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 182 EXPECT_TRUE(IsQuicEnabled(browser()->profile()->GetRequestContext())); | |
| 183 } | |
| 184 | |
| 185 // Policy QuicAllowed is set dynamically after profile creation. | |
| 186 // Supports creation of an additional profile. | |
| 187 class QuicAllowedPolicyDynamicTest : public InProcessBrowserTest { | |
| 188 public: | |
| 189 QuicAllowedPolicyDynamicTest() | |
| 190 : InProcessBrowserTest(), profile_1_(nullptr), profile_2_(nullptr) {} | |
| 191 | |
| 192 protected: | |
| 193 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 194 #if defined(OS_CHROMEOS) | |
| 195 command_line->AppendSwitch( | |
| 196 chromeos::switches::kIgnoreUserProfileMappingForTests); | |
| 197 #endif | |
| 198 } | |
| 199 | |
| 200 void SetUpInProcessBrowserTestFixture() override { | |
| 201 // Set the overriden policy provider for the first Profile (profile_1_). | |
| 202 EXPECT_CALL(policy_for_profile_1_, IsInitializationComplete(testing::_)) | |
| 203 .WillRepeatedly(testing::Return(true)); | |
| 204 policy::ProfilePolicyConnectorFactory::GetInstance() | |
| 205 ->PushProviderForTesting(&policy_for_profile_1_); | |
| 206 } | |
| 207 | |
| 208 void SetUpOnMainThread() override { profile_1_ = browser()->profile(); } | |
| 209 | |
| 210 // Creates a second Profile for testing. The Profile can then be accessed by | |
| 211 // profile_2() and its policy by policy_for_profile_2(). | |
| 212 void CreateSecondProfile() { | |
| 213 EXPECT_FALSE(profile_2_); | |
| 214 | |
| 215 // Prepare policy provider for second profile. | |
| 216 EXPECT_CALL(policy_for_profile_2_, IsInitializationComplete(testing::_)) | |
| 217 .WillRepeatedly(testing::Return(true)); | |
| 218 policy::ProfilePolicyConnectorFactory::GetInstance() | |
| 219 ->PushProviderForTesting(&policy_for_profile_2_); | |
| 220 | |
| 221 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 222 | |
| 223 // Create an additional profile. | |
| 224 base::FilePath path_profile = | |
| 225 profile_manager->GenerateNextProfileDirectoryPath(); | |
| 226 base::RunLoop run_loop; | |
| 227 profile_manager->CreateProfileAsync( | |
| 228 path_profile, | |
| 229 base::Bind(&OnProfileInitialized, &profile_2_, run_loop.QuitClosure()), | |
| 230 base::string16(), std::string(), std::string()); | |
| 231 | |
| 232 // Run the message loop to allow profile creation to take place; the loop is | |
| 233 // terminated by OnProfileInitialized calling the loop's QuitClosure when | |
| 234 // the profile is created. | |
| 235 run_loop.Run(); | |
| 236 | |
| 237 // Make sure second profile creation does what we think it does. | |
| 238 EXPECT_TRUE(profile_1() != profile_2()); | |
| 239 } | |
| 240 | |
| 241 // Sets the QuicAllowed policy for a Profile. | |
| 242 // |provider| is supposed to be the MockConfigurationPolicyProvider for the | |
| 243 // Profile, as returned by policy_for_profile_1() / policy_for_profile_2(). | |
| 244 void SetQuicAllowedPolicy(MockConfigurationPolicyProvider* provider, | |
| 245 bool value) { | |
| 246 PolicyMap policy_map; | |
| 247 policy_map.Set(key::kQuicAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
| 248 POLICY_SOURCE_CLOUD, | |
| 249 base::MakeUnique<base::FundamentalValue>(value), nullptr); | |
| 250 provider->UpdateChromePolicy(policy_map); | |
| 251 base::RunLoop().RunUntilIdle(); | |
| 252 } | |
| 253 | |
| 254 // Removes all policies for a Profile. | |
| 255 // |provider| is supposed to be the MockConfigurationPolicyProvider for the | |
| 256 // Profile, as returned by policy_for_profile_1() / policy_for_profile_2(). | |
| 257 void RemoveAllPolicies(MockConfigurationPolicyProvider* provider) { | |
| 258 PolicyMap policy_map; | |
| 259 provider->UpdateChromePolicy(policy_map); | |
| 260 base::RunLoop().RunUntilIdle(); | |
| 261 } | |
| 262 | |
| 263 // Returns the first Profile. | |
| 264 Profile* profile_1() { return profile_1_; } | |
| 265 | |
| 266 // Returns the second Profile. May only be called after CreateSecondProfile | |
| 267 // has been called. | |
| 268 Profile* profile_2() { | |
| 269 // Only valid after CreateSecondProfile() has been called. | |
| 270 EXPECT_TRUE(profile_2_); | |
| 271 return profile_2_; | |
| 272 } | |
| 273 | |
| 274 // Returns the MockConfigurationPolicyProvider for profile_1. | |
| 275 MockConfigurationPolicyProvider* policy_for_profile_1() { | |
| 276 return &policy_for_profile_1_; | |
| 277 } | |
| 278 | |
| 279 // Returns the MockConfigurationPolicyProvider for profile_2. | |
| 280 MockConfigurationPolicyProvider* policy_for_profile_2() { | |
| 281 return &policy_for_profile_2_; | |
| 282 } | |
| 283 | |
| 284 private: | |
| 285 // The first profile. | |
| 286 Profile* profile_1_; | |
| 287 // The second profile. Only valid after CreateSecondProfile() has been called. | |
| 288 Profile* profile_2_; | |
| 289 | |
| 290 // Mock Policy for profile_1_. | |
| 291 MockConfigurationPolicyProvider policy_for_profile_1_; | |
| 292 // Mock Policy for profile_2_. | |
| 293 MockConfigurationPolicyProvider policy_for_profile_2_; | |
| 294 | |
| 295 DISALLOW_COPY_AND_ASSIGN(QuicAllowedPolicyDynamicTest); | |
| 296 }; | |
| 297 | |
| 298 // QUIC is disallowed by policy after the profile has been initialized. | |
| 299 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyDynamicTest, QuicAllowedFalseThenTrue) { | |
| 300 // After browser start, QuicAllowed=false comes in dynamically | |
| 301 SetQuicAllowedPolicy(policy_for_profile_1(), false); | |
| 302 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 303 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 304 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 305 | |
| 306 // Set the QuicAllowed policy to true again | |
| 307 SetQuicAllowedPolicy(policy_for_profile_1(), true); | |
| 308 // Effectively, QUIC is still disabled because QUIC re-enabling is not | |
| 309 // supported. | |
| 310 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 311 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 312 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 313 | |
| 314 // Completely remove the QuicAllowed policy | |
| 315 RemoveAllPolicies(policy_for_profile_1()); | |
| 316 // Effectively, QUIC is still disabled because QUIC re-enabling is not | |
| 317 // supported. | |
| 318 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 319 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 320 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 321 | |
| 322 // QuicAllowed=false is set again | |
| 323 SetQuicAllowedPolicy(policy_for_profile_1(), false); | |
| 324 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 325 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 326 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 327 } | |
| 328 | |
| 329 // QUIC is allowed, then disallowed by policy after the profile has been | |
| 330 // initialized. | |
| 331 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyDynamicTest, QuicAllowedTrueThenFalse) { | |
| 332 // After browser start, QuicAllowed=true comes in dynamically | |
| 333 SetQuicAllowedPolicy(policy_for_profile_1(), true); | |
| 334 EXPECT_TRUE(IsQuicEnabled(system_request_context())); | |
| 335 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 336 EXPECT_TRUE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 337 | |
| 338 // Completely remove the QuicAllowed policy | |
| 339 RemoveAllPolicies(policy_for_profile_1()); | |
| 340 EXPECT_TRUE(IsQuicEnabled(system_request_context())); | |
| 341 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 342 EXPECT_TRUE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 343 | |
| 344 // Set the QuicAllowed policy to true again | |
| 345 SetQuicAllowedPolicy(policy_for_profile_1(), true); | |
| 346 // Effectively, QUIC is still disabled because QUIC re-enabling is not | |
| 347 // supported. | |
| 348 EXPECT_TRUE(IsQuicEnabled(system_request_context())); | |
| 349 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 350 EXPECT_TRUE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 351 | |
| 352 // Now set QuicAllowed=false | |
| 353 SetQuicAllowedPolicy(policy_for_profile_1(), false); | |
| 354 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 355 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 356 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 357 } | |
| 358 | |
| 359 // A second Profile is created when QuicAllowed=false policy is in effect for | |
| 360 // the first profile. | |
| 361 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyDynamicTest, | |
| 362 SecondProfileCreatedWhenQuicAllowedFalse) { | |
| 363 // If multiprofile mode is not enabled, you can't switch between profiles. | |
| 364 if (!profiles::IsMultipleProfilesEnabled()) | |
| 365 return; | |
| 366 | |
| 367 SetQuicAllowedPolicy(policy_for_profile_1(), false); | |
| 368 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 369 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 370 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 371 | |
| 372 CreateSecondProfile(); | |
| 373 | |
| 374 // QUIC is disabled in both profiles | |
| 375 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 376 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 377 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 378 EXPECT_FALSE(IsQuicEnabled(profile_2()->GetRequestContext())); | |
| 379 } | |
| 380 | |
| 381 // A second Profile is created when no QuicAllowed policy is in effect for the | |
| 382 // first profile. | |
| 383 // Then QuicAllowed=false policy is dynamically set for both profiles. | |
| 384 IN_PROC_BROWSER_TEST_F(QuicAllowedPolicyDynamicTest, | |
| 385 QuicAllowedFalseAfterTwoProfilesCreated) { | |
| 386 // If multiprofile mode is not enabled, you can't switch between profiles. | |
| 387 if (!profiles::IsMultipleProfilesEnabled()) | |
| 388 return; | |
| 389 | |
| 390 CreateSecondProfile(); | |
| 391 | |
| 392 // QUIC is enabled in both profiles | |
| 393 EXPECT_TRUE(IsQuicEnabled(system_request_context())); | |
| 394 EXPECT_TRUE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 395 EXPECT_TRUE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 396 EXPECT_TRUE(IsQuicEnabled(profile_2()->GetRequestContext())); | |
| 397 | |
| 398 // Disable QUIC in first profile | |
| 399 SetQuicAllowedPolicy(policy_for_profile_1(), false); | |
| 400 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 401 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 402 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 403 EXPECT_TRUE(IsQuicEnabled(profile_2()->GetRequestContext())); | |
| 404 | |
| 405 // Disable QUIC in second profile | |
| 406 SetQuicAllowedPolicy(policy_for_profile_2(), false); | |
| 407 EXPECT_FALSE(IsQuicEnabled(system_request_context())); | |
| 408 EXPECT_FALSE(IsQuicEnabled(safe_browsing_service_request_context())); | |
| 409 EXPECT_FALSE(IsQuicEnabled(profile_1()->GetRequestContext())); | |
| 410 EXPECT_FALSE(IsQuicEnabled(profile_2()->GetRequestContext())); | |
| 134 } | 411 } |
| 135 | 412 |
| 136 } // namespace policy | 413 } // namespace policy |
| OLD | NEW |