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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 940373002: First-Party Cookies: Wire it up as an experimental web platform feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@first-party
Patch Set: Created 5 years, 10 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) 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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_member.h" 11 #include "base/prefs/pref_member.h"
11 #include "chrome/browser/content_settings/cookie_settings.h" 12 #include "chrome/browser/content_settings/cookie_settings.h"
12 #include "chrome/browser/net/safe_search_util.h" 13 #include "chrome/browser/net/safe_search_util.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_pref_service_syncable.h" 15 #include "chrome/test/base/testing_pref_service_syncable.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/common/content_switches.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/base/request_priority.h" 19 #include "net/base/request_priority.h"
18 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 #if defined(ENABLE_EXTENSIONS) 24 #if defined(ENABLE_EXTENSIONS)
23 #include "chrome/browser/extensions/event_router_forwarder.h" 25 #include "chrome/browser/extensions/event_router_forwarder.h"
24 #endif 26 #endif
25 27
26 #if defined(ENABLE_EXTENSIONS)
27 class ChromeNetworkDelegateTest : public testing::Test { 28 class ChromeNetworkDelegateTest : public testing::Test {
28 protected: 29 protected:
29 ChromeNetworkDelegateTest() 30 ChromeNetworkDelegateTest()
30 : forwarder_(new extensions::EventRouterForwarder()) { 31 #if defined(ENABLE_EXTENSIONS)
32 : forwarder_(new extensions::EventRouterForwarder())
33 #endif
34 {
31 } 35 }
32 36
33 void SetUp() override { 37 void SetUp() override {
34 never_throttle_requests_original_value_ = 38 never_throttle_requests_original_value_ =
35 ChromeNetworkDelegate::g_never_throttle_requests_; 39 ChromeNetworkDelegate::g_never_throttle_requests_;
36 ChromeNetworkDelegate::g_never_throttle_requests_ = false; 40 ChromeNetworkDelegate::g_never_throttle_requests_ = false;
37 } 41 }
38 42
39 void TearDown() override { 43 void TearDown() override {
40 ChromeNetworkDelegate::g_never_throttle_requests_ = 44 ChromeNetworkDelegate::g_never_throttle_requests_ =
41 never_throttle_requests_original_value_; 45 never_throttle_requests_original_value_;
42 } 46 }
43 47
44 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { 48 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
45 return make_scoped_ptr( 49 return make_scoped_ptr(
46 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); 50 new ChromeNetworkDelegate(forwarder(), &pref_member_));
47 } 51 }
48 52
53 #if defined(ENABLE_EXTENSIONS)
49 // Implementation moved here for access to private bits. 54 // Implementation moved here for access to private bits.
50 void NeverThrottleLogicImpl() { 55 void NeverThrottleLogicImpl() {
51 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); 56 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
52 57
53 net::TestURLRequestContext context; 58 net::TestURLRequestContext context;
54 scoped_ptr<net::URLRequest> extension_request(context.CreateRequest( 59 scoped_ptr<net::URLRequest> extension_request(context.CreateRequest(
55 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL)); 60 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL));
56 extension_request->set_first_party_for_cookies( 61 extension_request->set_first_party_for_cookies(
57 GURL("chrome-extension://abcdef/bingo.html")); 62 GURL("chrome-extension://abcdef/bingo.html"));
58 scoped_ptr<net::URLRequest> web_page_request(context.CreateRequest( 63 scoped_ptr<net::URLRequest> web_page_request(context.CreateRequest(
(...skipping 13 matching lines...) Expand all
72 // ChromeNetworkDelegate. 77 // ChromeNetworkDelegate.
73 // 78 //
74 // We test the side effects of the flag rather than just the flag 79 // We test the side effects of the flag rather than just the flag
75 // itself (which we did above) to help ensure that a changed 80 // itself (which we did above) to help ensure that a changed
76 // implementation would show the same behavior, i.e. all instances 81 // implementation would show the same behavior, i.e. all instances
77 // of ChromeNetworkDelegate after the flag is set obey the flag. 82 // of ChromeNetworkDelegate after the flag is set obey the flag.
78 scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate()); 83 scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate());
79 ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request)); 84 ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request));
80 ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request)); 85 ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request));
81 } 86 }
87 #endif
82 88
83 private: 89 private:
90 extensions::EventRouterForwarder* forwarder() {
91 #if defined(ENABLE_EXTENSIONS)
mmenke 2015/02/20 16:30:39 All these ifdefs seem ugly, and this setup all see
Mike West 2015/02/23 15:51:17 I either have ifdefs here, or in the new test, as
92 return forwarder_.get();
93 #else
94 return NULL;
95 #endif
96 }
97
84 bool never_throttle_requests_original_value_; 98 bool never_throttle_requests_original_value_;
85 base::MessageLoopForIO message_loop_; 99 base::MessageLoopForIO message_loop_;
86 100
101 #if defined(ENABLE_EXTENSIONS)
87 scoped_refptr<extensions::EventRouterForwarder> forwarder_; 102 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
103 #endif
88 BooleanPrefMember pref_member_; 104 BooleanPrefMember pref_member_;
89 }; 105 };
90 106
107 #if defined(ENABLE_EXTENSIONS)
91 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { 108 TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) {
92 NeverThrottleLogicImpl(); 109 NeverThrottleLogicImpl();
93 } 110 }
94 #endif // defined(ENABLE_EXTENSIONS) 111 #endif // defined(ENABLE_EXTENSIONS)
95 112
113 TEST_F(ChromeNetworkDelegateTest, EnableFirstPartyCookiesIffFlagEnabled) {
114 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
115
116 // Off by default, on if the switch is present.
117 EXPECT_FALSE(delegate->FirstPartyCookieExperimentEnabled());
118 delegate->SetExperimentalWebPlatformFeaturesEnabled();
119 EXPECT_TRUE(delegate->FirstPartyCookieExperimentEnabled());
120 }
121
96 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { 122 class ChromeNetworkDelegateSafeSearchTest : public testing::Test {
97 public: 123 public:
98 ChromeNetworkDelegateSafeSearchTest() 124 ChromeNetworkDelegateSafeSearchTest()
99 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 125 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
100 #if defined(ENABLE_EXTENSIONS) 126 #if defined(ENABLE_EXTENSIONS)
101 forwarder_ = new extensions::EventRouterForwarder(); 127 forwarder_ = new extensions::EventRouterForwarder();
102 #endif 128 #endif
103 } 129 }
104 130
105 void SetUp() override { 131 void SetUp() override {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 kBlockedFirstPartySite)); 332 kBlockedFirstPartySite));
307 333
308 cookie_settings_->SetCookieSetting( 334 cookie_settings_->SetCookieSetting(
309 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), 335 ContentSettingsPattern::FromURL(kBlockedFirstPartySite),
310 ContentSettingsPattern::Wildcard(), 336 ContentSettingsPattern::Wildcard(),
311 CONTENT_SETTING_BLOCK); 337 CONTENT_SETTING_BLOCK);
312 // Privacy mode is disabled as kAllowedSite is still getting cookies 338 // Privacy mode is disabled as kAllowedSite is still getting cookies
313 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 339 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
314 kBlockedFirstPartySite)); 340 kBlockedFirstPartySite));
315 } 341 }
316
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698