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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
11 #include "chrome/browser/content_settings/cookie_settings.h" | 11 #include "chrome/browser/content_settings/cookie_settings.h" |
12 #include "chrome/browser/extensions/event_router_forwarder.h" | 12 #include "chrome/browser/extensions/event_router_forwarder.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.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/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 19 #include "net/base/request_priority.h" |
19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 class ChromeNetworkDelegateTest : public testing::Test { | 24 class ChromeNetworkDelegateTest : public testing::Test { |
24 protected: | 25 protected: |
25 ChromeNetworkDelegateTest() | 26 ChromeNetworkDelegateTest() |
26 : forwarder_(new extensions::EventRouterForwarder()) { | 27 : forwarder_(new extensions::EventRouterForwarder()) { |
27 } | 28 } |
28 | 29 |
(...skipping 12 matching lines...) Expand all Loading... |
41 return make_scoped_ptr( | 42 return make_scoped_ptr( |
42 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); | 43 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); |
43 } | 44 } |
44 | 45 |
45 // Implementation moved here for access to private bits. | 46 // Implementation moved here for access to private bits. |
46 void NeverThrottleLogicImpl() { | 47 void NeverThrottleLogicImpl() { |
47 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); | 48 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); |
48 | 49 |
49 net::TestURLRequestContext context; | 50 net::TestURLRequestContext context; |
50 net::TestURLRequest extension_request( | 51 net::TestURLRequest extension_request( |
51 GURL("http://example.com/"), NULL, &context, NULL); | 52 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context); |
52 extension_request.set_first_party_for_cookies( | 53 extension_request.set_first_party_for_cookies( |
53 GURL("chrome-extension://abcdef/bingo.html")); | 54 GURL("chrome-extension://abcdef/bingo.html")); |
54 net::TestURLRequest web_page_request( | 55 net::TestURLRequest web_page_request( |
55 GURL("http://example.com/"), NULL, &context, NULL); | 56 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context); |
56 web_page_request.set_first_party_for_cookies( | 57 web_page_request.set_first_party_for_cookies( |
57 GURL("http://example.com/helloworld.html")); | 58 GURL("http://example.com/helloworld.html")); |
58 | 59 |
59 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request)); | 60 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request)); |
60 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); | 61 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); |
61 | 62 |
62 delegate->NeverThrottleRequests(); | 63 delegate->NeverThrottleRequests(); |
63 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); | 64 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); |
64 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); | 65 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); |
65 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); | 66 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 121 |
121 // Does a request using the |url_string| URL and verifies that the expected | 122 // Does a request using the |url_string| URL and verifies that the expected |
122 // string is equal to the query part (between ? and #) of the final url of | 123 // string is equal to the query part (between ? and #) of the final url of |
123 // that request. | 124 // that request. |
124 void CheckAddedParameters(const std::string& url_string, | 125 void CheckAddedParameters(const std::string& url_string, |
125 const std::string& expected_query_parameters) { | 126 const std::string& expected_query_parameters) { |
126 // Show the URL in the trace so we know where we failed. | 127 // Show the URL in the trace so we know where we failed. |
127 SCOPED_TRACE(url_string); | 128 SCOPED_TRACE(url_string); |
128 | 129 |
129 net::TestURLRequest request( | 130 net::TestURLRequest request( |
130 GURL(url_string), &delegate_, &context_, network_delegate_); | 131 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_); |
131 | 132 |
132 request.Start(); | 133 request.Start(); |
133 base::MessageLoop::current()->RunUntilIdle(); | 134 base::MessageLoop::current()->RunUntilIdle(); |
134 | 135 |
135 EXPECT_EQ(expected_query_parameters, request.url().query()); | 136 EXPECT_EQ(expected_query_parameters, request.url().query()); |
136 } | 137 } |
137 | 138 |
138 private: | 139 private: |
139 content::TestBrowserThreadBundle thread_bundle_; | 140 content::TestBrowserThreadBundle thread_bundle_; |
140 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 141 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 378 |
378 cookie_settings_->SetCookieSetting( | 379 cookie_settings_->SetCookieSetting( |
379 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 380 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
380 ContentSettingsPattern::Wildcard(), | 381 ContentSettingsPattern::Wildcard(), |
381 CONTENT_SETTING_BLOCK); | 382 CONTENT_SETTING_BLOCK); |
382 // Privacy mode is disabled as kAllowedSite is still getting cookies | 383 // Privacy mode is disabled as kAllowedSite is still getting cookies |
383 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 384 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
384 kBlockedFirstPartySite)); | 385 kBlockedFirstPartySite)); |
385 } | 386 } |
386 | 387 |
OLD | NEW |