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

Side by Side Diff: net/proxy/proxy_script_fetcher_impl_unittest.cc

Issue 4192012: Convert implicit scoped_refptr constructor calls to explicit ones, part 1 (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: fix presubmit Created 10 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
« no previous file with comments | « net/proxy/multi_threaded_proxy_resolver.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 public: 71 public:
72 ProxyScriptFetcherImplTest() 72 ProxyScriptFetcherImplTest()
73 : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { 73 : test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
74 } 74 }
75 75
76 protected: 76 protected:
77 net::TestServer test_server_; 77 net::TestServer test_server_;
78 }; 78 };
79 79
80 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { 80 TEST_F(ProxyScriptFetcherImplTest, FileUrl) {
81 scoped_refptr<URLRequestContext> context = new RequestContext; 81 scoped_refptr<URLRequestContext> context(new RequestContext);
82 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 82 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
83 new ProxyScriptFetcherImpl(context)); 83 new ProxyScriptFetcherImpl(context));
84 84
85 { // Fetch a non-existent file. 85 { // Fetch a non-existent file.
86 string16 text; 86 string16 text;
87 TestCompletionCallback callback; 87 TestCompletionCallback callback;
88 int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"), 88 int result = pac_fetcher->Fetch(GetTestFileUrl("does-not-exist"),
89 &text, &callback); 89 &text, &callback);
90 EXPECT_EQ(ERR_IO_PENDING, result); 90 EXPECT_EQ(ERR_IO_PENDING, result);
91 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); 91 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult());
92 EXPECT_TRUE(text.empty()); 92 EXPECT_TRUE(text.empty());
93 } 93 }
94 { // Fetch a file that exists. 94 { // Fetch a file that exists.
95 string16 text; 95 string16 text;
96 TestCompletionCallback callback; 96 TestCompletionCallback callback;
97 int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"), 97 int result = pac_fetcher->Fetch(GetTestFileUrl("pac.txt"),
98 &text, &callback); 98 &text, &callback);
99 EXPECT_EQ(ERR_IO_PENDING, result); 99 EXPECT_EQ(ERR_IO_PENDING, result);
100 EXPECT_EQ(OK, callback.WaitForResult()); 100 EXPECT_EQ(OK, callback.WaitForResult());
101 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); 101 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text);
102 } 102 }
103 } 103 }
104 104
105 // Note that all mime types are allowed for PAC file, to be consistent 105 // Note that all mime types are allowed for PAC file, to be consistent
106 // with other browsers. 106 // with other browsers.
107 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { 107 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) {
108 ASSERT_TRUE(test_server_.Start()); 108 ASSERT_TRUE(test_server_.Start());
109 109
110 scoped_refptr<URLRequestContext> context = new RequestContext; 110 scoped_refptr<URLRequestContext> context(new RequestContext);
111 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 111 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
112 new ProxyScriptFetcherImpl(context)); 112 new ProxyScriptFetcherImpl(context));
113 113
114 { // Fetch a PAC with mime type "text/plain" 114 { // Fetch a PAC with mime type "text/plain"
115 GURL url(test_server_.GetURL("files/pac.txt")); 115 GURL url(test_server_.GetURL("files/pac.txt"));
116 string16 text; 116 string16 text;
117 TestCompletionCallback callback; 117 TestCompletionCallback callback;
118 int result = pac_fetcher->Fetch(url, &text, &callback); 118 int result = pac_fetcher->Fetch(url, &text, &callback);
119 EXPECT_EQ(ERR_IO_PENDING, result); 119 EXPECT_EQ(ERR_IO_PENDING, result);
120 EXPECT_EQ(OK, callback.WaitForResult()); 120 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 15 matching lines...) Expand all
136 int result = pac_fetcher->Fetch(url, &text, &callback); 136 int result = pac_fetcher->Fetch(url, &text, &callback);
137 EXPECT_EQ(ERR_IO_PENDING, result); 137 EXPECT_EQ(ERR_IO_PENDING, result);
138 EXPECT_EQ(OK, callback.WaitForResult()); 138 EXPECT_EQ(OK, callback.WaitForResult());
139 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 139 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
140 } 140 }
141 } 141 }
142 142
143 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { 143 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) {
144 ASSERT_TRUE(test_server_.Start()); 144 ASSERT_TRUE(test_server_.Start());
145 145
146 scoped_refptr<URLRequestContext> context = new RequestContext; 146 scoped_refptr<URLRequestContext> context(new RequestContext);
147 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 147 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
148 new ProxyScriptFetcherImpl(context)); 148 new ProxyScriptFetcherImpl(context));
149 149
150 { // Fetch a PAC which gives a 500 -- FAIL 150 { // Fetch a PAC which gives a 500 -- FAIL
151 GURL url(test_server_.GetURL("files/500.pac")); 151 GURL url(test_server_.GetURL("files/500.pac"));
152 string16 text; 152 string16 text;
153 TestCompletionCallback callback; 153 TestCompletionCallback callback;
154 int result = pac_fetcher->Fetch(url, &text, &callback); 154 int result = pac_fetcher->Fetch(url, &text, &callback);
155 EXPECT_EQ(ERR_IO_PENDING, result); 155 EXPECT_EQ(ERR_IO_PENDING, result);
156 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 156 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
157 EXPECT_TRUE(text.empty()); 157 EXPECT_TRUE(text.empty());
158 } 158 }
159 { // Fetch a PAC which gives a 404 -- FAIL 159 { // Fetch a PAC which gives a 404 -- FAIL
160 GURL url(test_server_.GetURL("files/404.pac")); 160 GURL url(test_server_.GetURL("files/404.pac"));
161 string16 text; 161 string16 text;
162 TestCompletionCallback callback; 162 TestCompletionCallback callback;
163 int result = pac_fetcher->Fetch(url, &text, &callback); 163 int result = pac_fetcher->Fetch(url, &text, &callback);
164 EXPECT_EQ(ERR_IO_PENDING, result); 164 EXPECT_EQ(ERR_IO_PENDING, result);
165 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); 165 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult());
166 EXPECT_TRUE(text.empty()); 166 EXPECT_TRUE(text.empty());
167 } 167 }
168 } 168 }
169 169
170 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { 170 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) {
171 ASSERT_TRUE(test_server_.Start()); 171 ASSERT_TRUE(test_server_.Start());
172 172
173 scoped_refptr<URLRequestContext> context = new RequestContext; 173 scoped_refptr<URLRequestContext> context(new RequestContext);
174 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 174 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
175 new ProxyScriptFetcherImpl(context)); 175 new ProxyScriptFetcherImpl(context));
176 176
177 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should 177 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should
178 // have no effect. 178 // have no effect.
179 GURL url(test_server_.GetURL("files/downloadable.pac")); 179 GURL url(test_server_.GetURL("files/downloadable.pac"));
180 string16 text; 180 string16 text;
181 TestCompletionCallback callback; 181 TestCompletionCallback callback;
182 int result = pac_fetcher->Fetch(url, &text, &callback); 182 int result = pac_fetcher->Fetch(url, &text, &callback);
183 EXPECT_EQ(ERR_IO_PENDING, result); 183 EXPECT_EQ(ERR_IO_PENDING, result);
184 EXPECT_EQ(OK, callback.WaitForResult()); 184 EXPECT_EQ(OK, callback.WaitForResult());
185 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); 185 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text);
186 } 186 }
187 187
188 TEST_F(ProxyScriptFetcherImplTest, NoCache) { 188 TEST_F(ProxyScriptFetcherImplTest, NoCache) {
189 ASSERT_TRUE(test_server_.Start()); 189 ASSERT_TRUE(test_server_.Start());
190 190
191 scoped_refptr<URLRequestContext> context = new RequestContext; 191 scoped_refptr<URLRequestContext> context(new RequestContext);
192 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 192 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
193 new ProxyScriptFetcherImpl(context)); 193 new ProxyScriptFetcherImpl(context));
194 194
195 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. 195 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour.
196 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); 196 GURL url(test_server_.GetURL("files/cacheable_1hr.pac"));
197 { 197 {
198 string16 text; 198 string16 text;
199 TestCompletionCallback callback; 199 TestCompletionCallback callback;
200 int result = pac_fetcher->Fetch(url, &text, &callback); 200 int result = pac_fetcher->Fetch(url, &text, &callback);
201 EXPECT_EQ(ERR_IO_PENDING, result); 201 EXPECT_EQ(ERR_IO_PENDING, result);
(...skipping 12 matching lines...) Expand all
214 TestCompletionCallback callback; 214 TestCompletionCallback callback;
215 int result = pac_fetcher->Fetch(url, &text, &callback); 215 int result = pac_fetcher->Fetch(url, &text, &callback);
216 EXPECT_EQ(ERR_IO_PENDING, result); 216 EXPECT_EQ(ERR_IO_PENDING, result);
217 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); 217 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
218 } 218 }
219 } 219 }
220 220
221 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { 221 TEST_F(ProxyScriptFetcherImplTest, TooLarge) {
222 ASSERT_TRUE(test_server_.Start()); 222 ASSERT_TRUE(test_server_.Start());
223 223
224 scoped_refptr<URLRequestContext> context = new RequestContext; 224 scoped_refptr<URLRequestContext> context(new RequestContext);
225 scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher( 225 scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher(
226 new ProxyScriptFetcherImpl(context)); 226 new ProxyScriptFetcherImpl(context));
227 227
228 // Set the maximum response size to 50 bytes. 228 // Set the maximum response size to 50 bytes.
229 int prev_size = pac_fetcher->SetSizeConstraint(50); 229 int prev_size = pac_fetcher->SetSizeConstraint(50);
230 230
231 // These two URLs are the same file, but are http:// vs file:// 231 // These two URLs are the same file, but are http:// vs file://
232 GURL urls[] = { 232 GURL urls[] = {
233 test_server_.GetURL("files/large-pac.nsproxy"), 233 test_server_.GetURL("files/large-pac.nsproxy"),
234 GetTestFileUrl("large-pac.nsproxy") 234 GetTestFileUrl("large-pac.nsproxy")
(...skipping 21 matching lines...) Expand all
256 int result = pac_fetcher->Fetch(url, &text, &callback); 256 int result = pac_fetcher->Fetch(url, &text, &callback);
257 EXPECT_EQ(ERR_IO_PENDING, result); 257 EXPECT_EQ(ERR_IO_PENDING, result);
258 EXPECT_EQ(OK, callback.WaitForResult()); 258 EXPECT_EQ(OK, callback.WaitForResult());
259 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 259 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
260 } 260 }
261 } 261 }
262 262
263 TEST_F(ProxyScriptFetcherImplTest, Hang) { 263 TEST_F(ProxyScriptFetcherImplTest, Hang) {
264 ASSERT_TRUE(test_server_.Start()); 264 ASSERT_TRUE(test_server_.Start());
265 265
266 scoped_refptr<URLRequestContext> context = new RequestContext; 266 scoped_refptr<URLRequestContext> context(new RequestContext);
267 scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher( 267 scoped_ptr<ProxyScriptFetcherImpl> pac_fetcher(
268 new ProxyScriptFetcherImpl(context)); 268 new ProxyScriptFetcherImpl(context));
269 269
270 // Set the timeout period to 0.5 seconds. 270 // Set the timeout period to 0.5 seconds.
271 base::TimeDelta prev_timeout = pac_fetcher->SetTimeoutConstraint( 271 base::TimeDelta prev_timeout = pac_fetcher->SetTimeoutConstraint(
272 base::TimeDelta::FromMilliseconds(500)); 272 base::TimeDelta::FromMilliseconds(500));
273 273
274 // Try fetching a URL which takes 1.2 seconds. We should abort the request 274 // Try fetching a URL which takes 1.2 seconds. We should abort the request
275 // after 500 ms, and fail with a timeout error. 275 // after 500 ms, and fail with a timeout error.
276 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); 276 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2"));
(...skipping 18 matching lines...) Expand all
295 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); 295 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text);
296 } 296 }
297 } 297 }
298 298
299 // The ProxyScriptFetcher should decode any content-codings 299 // The ProxyScriptFetcher should decode any content-codings
300 // (like gzip, bzip, etc.), and apply any charset conversions to yield 300 // (like gzip, bzip, etc.), and apply any charset conversions to yield
301 // UTF8. 301 // UTF8.
302 TEST_F(ProxyScriptFetcherImplTest, Encodings) { 302 TEST_F(ProxyScriptFetcherImplTest, Encodings) {
303 ASSERT_TRUE(test_server_.Start()); 303 ASSERT_TRUE(test_server_.Start());
304 304
305 scoped_refptr<URLRequestContext> context = new RequestContext; 305 scoped_refptr<URLRequestContext> context(new RequestContext);
306 scoped_ptr<ProxyScriptFetcher> pac_fetcher( 306 scoped_ptr<ProxyScriptFetcher> pac_fetcher(
307 new ProxyScriptFetcherImpl(context)); 307 new ProxyScriptFetcherImpl(context));
308 308
309 // Test a response that is gzip-encoded -- should get inflated. 309 // Test a response that is gzip-encoded -- should get inflated.
310 { 310 {
311 GURL url(test_server_.GetURL("files/gzipped_pac")); 311 GURL url(test_server_.GetURL("files/gzipped_pac"));
312 string16 text; 312 string16 text;
313 TestCompletionCallback callback; 313 TestCompletionCallback callback;
314 int result = pac_fetcher->Fetch(url, &text, &callback); 314 int result = pac_fetcher->Fetch(url, &text, &callback);
315 EXPECT_EQ(ERR_IO_PENDING, result); 315 EXPECT_EQ(ERR_IO_PENDING, result);
316 EXPECT_EQ(OK, callback.WaitForResult()); 316 EXPECT_EQ(OK, callback.WaitForResult());
317 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); 317 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text);
318 } 318 }
319 319
320 // Test a response that was served as UTF-16 (BE). It should 320 // Test a response that was served as UTF-16 (BE). It should
321 // be converted to UTF8. 321 // be converted to UTF8.
322 { 322 {
323 GURL url(test_server_.GetURL("files/utf16be_pac")); 323 GURL url(test_server_.GetURL("files/utf16be_pac"));
324 string16 text; 324 string16 text;
325 TestCompletionCallback callback; 325 TestCompletionCallback callback;
326 int result = pac_fetcher->Fetch(url, &text, &callback); 326 int result = pac_fetcher->Fetch(url, &text, &callback);
327 EXPECT_EQ(ERR_IO_PENDING, result); 327 EXPECT_EQ(ERR_IO_PENDING, result);
328 EXPECT_EQ(OK, callback.WaitForResult()); 328 EXPECT_EQ(OK, callback.WaitForResult());
329 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); 329 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text);
330 } 330 }
331 } 331 }
332 332
333 } // namespace net 333 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/multi_threaded_proxy_resolver.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698