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

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

Issue 11369179: Move url_request_test_util into net namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 8 years, 1 month 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 | Annotate | Revision Log
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/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.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/api/prefs/pref_member.h" 10 #include "chrome/browser/api/prefs/pref_member.h"
(...skipping 28 matching lines...) Expand all
39 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { 39 scoped_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() {
40 return scoped_ptr<ChromeNetworkDelegate>(new ChromeNetworkDelegate( 40 return scoped_ptr<ChromeNetworkDelegate>(new ChromeNetworkDelegate(
41 forwarder_.get(), NULL, NULL, NULL, NULL, NULL, &pref_member_, NULL, 41 forwarder_.get(), NULL, NULL, NULL, NULL, NULL, &pref_member_, NULL,
42 NULL, NULL)); 42 NULL, NULL));
43 } 43 }
44 44
45 // Implementation moved here for access to private bits. 45 // Implementation moved here for access to private bits.
46 void NeverThrottleLogicImpl() { 46 void NeverThrottleLogicImpl() {
47 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate()); 47 scoped_ptr<ChromeNetworkDelegate> delegate(CreateNetworkDelegate());
48 48
49 TestURLRequestContext context; 49 net::TestURLRequestContext context;
50 TestURLRequest extension_request( 50 net::TestURLRequest extension_request(
51 GURL("http://example.com/"), NULL, &context); 51 GURL("http://example.com/"), NULL, &context);
52 extension_request.set_first_party_for_cookies( 52 extension_request.set_first_party_for_cookies(
53 GURL("chrome-extension://abcdef/bingo.html")); 53 GURL("chrome-extension://abcdef/bingo.html"));
54 TestURLRequest web_page_request( 54 net::TestURLRequest web_page_request(
55 GURL("http://example.com/"), NULL, &context); 55 GURL("http://example.com/"), NULL, &context);
56 web_page_request.set_first_party_for_cookies( 56 web_page_request.set_first_party_for_cookies(
57 GURL("http://example.com/helloworld.html")); 57 GURL("http://example.com/helloworld.html"));
58 58
59 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request)); 59 ASSERT_TRUE(delegate->OnCanThrottleRequest(extension_request));
60 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request)); 60 ASSERT_FALSE(delegate->OnCanThrottleRequest(web_page_request));
61 61
62 delegate->NeverThrottleRequests(); 62 delegate->NeverThrottleRequests();
63 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_); 63 ASSERT_TRUE(ChromeNetworkDelegate::g_never_throttle_requests_);
64 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request)); 64 ASSERT_FALSE(delegate->OnCanThrottleRequest(extension_request));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 // Does a request using the |url_string| URL and verifies that the expected 125 // Does a request using the |url_string| URL and verifies that the expected
126 // string is equal to the query part (between ? and #) of the final url of 126 // string is equal to the query part (between ? and #) of the final url of
127 // that request. 127 // that request.
128 void CheckAddedParameters(const std::string& url_string, 128 void CheckAddedParameters(const std::string& url_string,
129 const std::string& expected_query_parameters) { 129 const std::string& expected_query_parameters) {
130 // Show the URL in the trace so we know where we failed. 130 // Show the URL in the trace so we know where we failed.
131 SCOPED_TRACE(url_string); 131 SCOPED_TRACE(url_string);
132 132
133 TestURLRequest request(GURL(url_string), &delegate_, &context_); 133 net::TestURLRequest request(GURL(url_string), &delegate_, &context_);
134 134
135 request.Start(); 135 request.Start();
136 MessageLoop::current()->RunUntilIdle(); 136 MessageLoop::current()->RunUntilIdle();
137 137
138 EXPECT_EQ(expected_query_parameters, request.url().query()); 138 EXPECT_EQ(expected_query_parameters, request.url().query());
139 } 139 }
140 140
141 private: 141 private:
142 scoped_refptr<extensions::EventRouterForwarder> forwarder_; 142 scoped_refptr<extensions::EventRouterForwarder> forwarder_;
143 TestingProfile profile_; 143 TestingProfile profile_;
144 TestingPrefService prefs_; 144 TestingPrefService prefs_;
145 BooleanPrefMember enable_referrers_; 145 BooleanPrefMember enable_referrers_;
146 BooleanPrefMember force_google_safe_search_; 146 BooleanPrefMember force_google_safe_search_;
147 scoped_ptr<net::URLRequest> request_; 147 scoped_ptr<net::URLRequest> request_;
148 TestURLRequestContext context_; 148 net::TestURLRequestContext context_;
149 TestDelegate delegate_; 149 net::TestDelegate delegate_;
150 MessageLoopForIO message_loop_; 150 MessageLoopForIO message_loop_;
151 scoped_ptr<content::TestBrowserThread> io_thread_; 151 scoped_ptr<content::TestBrowserThread> io_thread_;
152 }; 152 };
153 153
154 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) { 154 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOn) {
155 // Tests with SafeSearch on, request parameters should be rewritten. 155 // Tests with SafeSearch on, request parameters should be rewritten.
156 const std::string kSafeParameter = chrome::kSafeSearchSafeParameter; 156 const std::string kSafeParameter = chrome::kSafeSearchSafeParameter;
157 const std::string kSsuiParameter = chrome::kSafeSearchSsuiParameter; 157 const std::string kSsuiParameter = chrome::kSafeSearchSsuiParameter;
158 const std::string kBothParameters = kSafeParameter + "&" + kSsuiParameter; 158 const std::string kBothParameters = kSafeParameter + "&" + kSsuiParameter;
159 SetSafeSearch(true); 159 SetSafeSearch(true);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 "q=google"); 275 "q=google");
276 276
277 // Test the home page with parameters and safe set to off. 277 // Test the home page with parameters and safe set to off.
278 CheckAddedParameters("http://google.com/search?q=google&safe=off", 278 CheckAddedParameters("http://google.com/search?q=google&safe=off",
279 "q=google&safe=off"); 279 "q=google&safe=off");
280 280
281 // Test the home page with parameters and safe set to active. 281 // Test the home page with parameters and safe set to active.
282 CheckAddedParameters("http://google.com/search?q=google&safe=active", 282 CheckAddedParameters("http://google.com/search?q=google&safe=active",
283 "q=google&safe=active"); 283 "q=google&safe=active");
284 } 284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698