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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { | 45 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { |
46 return make_scoped_ptr( | 46 return make_scoped_ptr( |
47 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); | 47 new ChromeNetworkDelegate(forwarder_.get(), &pref_member_)); |
48 } | 48 } |
49 | 49 |
50 // Implementation moved here for access to private bits. | 50 // Implementation moved here for access to private bits. |
51 void NeverThrottleLogicImpl() { | 51 void NeverThrottleLogicImpl() { |
52 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); | 52 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); |
53 | 53 |
54 net::TestURLRequestContext context; | 54 net::TestURLRequestContext context; |
55 net::TestURLRequest extension_request( | 55 scoped_ptr<net::URLRequest> extension_request(context.CreateRequest( |
56 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context); | 56 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL)); |
57 extension_request.set_first_party_for_cookies( | 57 extension_request->set_first_party_for_cookies( |
58 GURL("chrome-extension://abcdef/bingo.html")); | 58 GURL("chrome-extension://abcdef/bingo.html")); |
59 net::TestURLRequest web_page_request( | 59 scoped_ptr<net::URLRequest> web_page_request(context.CreateRequest( |
60 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, &context); | 60 GURL("http://example.com/"), net::DEFAULT_PRIORITY, NULL, NULL)); |
61 web_page_request.set_first_party_for_cookies( | 61 web_page_request->set_first_party_for_cookies( |
62 GURL("http://example.com/helloworld.html")); | 62 GURL("http://example.com/helloworld.html")); |
63 | 63 |
64 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request)); | 64 ASSERT_TRUE(delegate->OnCanThrottleRequest(*extension_request)); |
65 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); | 65 ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request)); |
66 | 66 |
67 delegate->NeverThrottleRequests(); | 67 delegate->NeverThrottleRequests(); |
68 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); | 68 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); |
69 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); | 69 ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request)); |
70 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); | 70 ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request)); |
71 | 71 |
72 // Verify that the flag applies to later instances of the | 72 // Verify that the flag applies to later instances of the |
73 // ChromeNetworkDelegate. | 73 // ChromeNetworkDelegate. |
74 // | 74 // |
75 // We test the side effects of the flag rather than just the flag | 75 // We test the side effects of the flag rather than just the flag |
76 // itself (which we did above) to help ensure that a changed | 76 // itself (which we did above) to help ensure that a changed |
77 // implementation would show the same behavior, i.e. all instances | 77 // implementation would show the same behavior, i.e. all instances |
78 // of ChromeNetworkDelegate after the flag is set obey the flag. | 78 // of ChromeNetworkDelegate after the flag is set obey the flag. |
79 scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate()); | 79 scoped_ptr<ChromeNetworkDelegate> second_delegate(CreateNetworkDelegate()); |
80 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); | 80 ASSERT_FALSE(delegate->OnCanThrottleRequest(*extension_request)); |
81 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); | 81 ASSERT_FALSE(delegate->OnCanThrottleRequest(*web_page_request)); |
82 } | 82 } |
83 | 83 |
84 private: | 84 private: |
85 bool never_throttle_requests_original_value_; | 85 bool never_throttle_requests_original_value_; |
86 base::MessageLoopForIO message_loop_; | 86 base::MessageLoopForIO message_loop_; |
87 | 87 |
88 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 88 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
89 BooleanPrefMember pref_member_; | 89 BooleanPrefMember pref_member_; |
90 }; | 90 }; |
91 | 91 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 // Does a request using the |url_string| URL and verifies that the expected | 129 // Does a request using the |url_string| URL and verifies that the expected |
130 // string is equal to the query part (between ? and #) of the final url of | 130 // string is equal to the query part (between ? and #) of the final url of |
131 // that request. | 131 // that request. |
132 void CheckAddedParameters(const std::string& url_string, | 132 void CheckAddedParameters(const std::string& url_string, |
133 const std::string& expected_query_parameters) { | 133 const std::string& expected_query_parameters) { |
134 // Show the URL in the trace so we know where we failed. | 134 // Show the URL in the trace so we know where we failed. |
135 SCOPED_TRACE(url_string); | 135 SCOPED_TRACE(url_string); |
136 | 136 |
137 net::TestURLRequest request( | 137 scoped_ptr<net::URLRequest> request(context_.CreateRequest( |
138 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, &context_); | 138 GURL(url_string), net::DEFAULT_PRIORITY, &delegate_, NULL)); |
139 | 139 |
140 request.Start(); | 140 request->Start(); |
141 base::MessageLoop::current()->RunUntilIdle(); | 141 base::MessageLoop::current()->RunUntilIdle(); |
142 | 142 |
143 EXPECT_EQ(expected_query_parameters, request.url().query()); | 143 EXPECT_EQ(expected_query_parameters, request->url().query()); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 extensions::EventRouterForwarder* forwarder() { | 147 extensions::EventRouterForwarder* forwarder() { |
148 #if defined(ENABLE_EXTENSIONS) | 148 #if defined(ENABLE_EXTENSIONS) |
149 return forwarder_.get(); | 149 return forwarder_.get(); |
150 #else | 150 #else |
151 return NULL; | 151 return NULL; |
152 #endif | 152 #endif |
153 } | 153 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 407 |
408 cookie_settings_->SetCookieSetting( | 408 cookie_settings_->SetCookieSetting( |
409 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 409 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
410 ContentSettingsPattern::Wildcard(), | 410 ContentSettingsPattern::Wildcard(), |
411 CONTENT_SETTING_BLOCK); | 411 CONTENT_SETTING_BLOCK); |
412 // Privacy mode is disabled as kAllowedSite is still getting cookies | 412 // Privacy mode is disabled as kAllowedSite is still getting cookies |
413 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 413 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
414 kBlockedFirstPartySite)); | 414 kBlockedFirstPartySite)); |
415 } | 415 } |
416 | 416 |
OLD | NEW |