| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_member.h" | 11 #include "base/prefs/pref_member.h" |
| 12 #include "chrome/browser/content_settings/cookie_settings.h" | 12 #include "chrome/browser/content_settings/cookie_settings.h" |
| 13 #include "chrome/browser/net/safe_search_util.h" | 13 #include "chrome/browser/net/safe_search_util.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/testing_pref_service_syncable.h" | 15 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
| 20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 #if defined(ENABLE_EXTENSIONS) | 24 #if defined(ENABLE_EXTENSIONS) |
| 25 #include "chrome/browser/extensions/event_router_forwarder.h" | 25 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 TEST(ChromeNetworkDelegateTest, DisableFirstPartyOnlyCookiesIffFlagDisabled) { |
| 29 BooleanPrefMember pref_member_; |
| 30 scoped_ptr<ChromeNetworkDelegate> delegate; |
| 31 |
| 32 #if defined(ENABLE_EXTENSIONS) |
| 33 scoped_refptr<extensions::EventRouterForwarder> forwarder = |
| 34 new extensions::EventRouterForwarder(); |
| 35 delegate.reset(new ChromeNetworkDelegate(forwarder.get(), &pref_member_)); |
| 36 #else |
| 37 delegate.reset(new ChromeNetworkDelegate(nullptr, &pref_member_)); |
| 38 #endif |
| 39 EXPECT_FALSE(delegate->FirstPartyOnlyCookieExperimentEnabled()); |
| 40 } |
| 41 |
| 42 TEST(ChromeNetworkDelegateTest, EnableFirstPartyOnlyCookiesIffFlagEnabled) { |
| 43 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 44 switches::kEnableExperimentalWebPlatformFeatures); |
| 45 BooleanPrefMember pref_member_; |
| 46 scoped_ptr<ChromeNetworkDelegate> delegate; |
| 47 |
| 48 #if defined(ENABLE_EXTENSIONS) |
| 49 scoped_refptr<extensions::EventRouterForwarder> forwarder = |
| 50 new extensions::EventRouterForwarder(); |
| 51 delegate.reset(new ChromeNetworkDelegate(forwarder.get(), &pref_member_)); |
| 52 #else |
| 53 delegate.reset(new ChromeNetworkDelegate(nullptr, &pref_member_)); |
| 54 #endif |
| 55 EXPECT_TRUE(delegate->FirstPartyOnlyCookieExperimentEnabled()); |
| 56 } |
| 57 |
| 28 #if defined(ENABLE_EXTENSIONS) | 58 #if defined(ENABLE_EXTENSIONS) |
| 29 class ChromeNetworkDelegateThrottlingTest : public testing::Test { | 59 class ChromeNetworkDelegateThrottlingTest : public testing::Test { |
| 30 protected: | 60 protected: |
| 31 ChromeNetworkDelegateThrottlingTest() | 61 ChromeNetworkDelegateThrottlingTest() |
| 32 : forwarder_(new extensions::EventRouterForwarder()) {} | 62 : forwarder_(new extensions::EventRouterForwarder()) {} |
| 33 | 63 |
| 34 void SetUp() override { | 64 void SetUp() override { |
| 35 never_throttle_requests_original_value_ = | 65 never_throttle_requests_original_value_ = |
| 36 ChromeNetworkDelegate::g_never_throttle_requests_; | 66 ChromeNetworkDelegate::g_never_throttle_requests_; |
| 37 ChromeNetworkDelegate::g_never_throttle_requests_ = false; | 67 ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 kBlockedFirstPartySite)); | 339 kBlockedFirstPartySite)); |
| 310 | 340 |
| 311 cookie_settings_->SetCookieSetting( | 341 cookie_settings_->SetCookieSetting( |
| 312 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 342 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
| 313 ContentSettingsPattern::Wildcard(), | 343 ContentSettingsPattern::Wildcard(), |
| 314 CONTENT_SETTING_BLOCK); | 344 CONTENT_SETTING_BLOCK); |
| 315 // Privacy mode is disabled as kAllowedSite is still getting cookies | 345 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 316 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 346 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 317 kBlockedFirstPartySite)); | 347 kBlockedFirstPartySite)); |
| 318 } | 348 } |
| OLD | NEW |