| 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 "net/proxy/proxy_script_fetcher_impl.h" | 5 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 new HttpNetworkSession(params)); | 89 new HttpNetworkSession(params)); |
| 90 storage_.set_http_transaction_factory(new HttpCache( | 90 storage_.set_http_transaction_factory(new HttpCache( |
| 91 network_session, | 91 network_session, |
| 92 HttpCache::DefaultBackend::InMemory(0))); | 92 HttpCache::DefaultBackend::InMemory(0))); |
| 93 url_request_job_factory_.reset(new URLRequestJobFactory); | 93 url_request_job_factory_.reset(new URLRequestJobFactory); |
| 94 set_job_factory(url_request_job_factory_.get()); | 94 set_job_factory(url_request_job_factory_.get()); |
| 95 url_request_job_factory_->AddInterceptor( | 95 url_request_job_factory_->AddInterceptor( |
| 96 new CheckNoRevocationFlagSetInterceptor); | 96 new CheckNoRevocationFlagSetInterceptor); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 virtual ~RequestContext() { |
| 100 ~RequestContext() { | |
| 101 } | 100 } |
| 102 | 101 |
| 102 private: |
| 103 URLRequestContextStorage storage_; | 103 URLRequestContextStorage storage_; |
| 104 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; | 104 scoped_ptr<URLRequestJobFactory> url_request_job_factory_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. | 107 // Get a file:// url relative to net/data/proxy/proxy_script_fetcher_unittest. |
| 108 GURL GetTestFileUrl(const std::string& relpath) { | 108 GURL GetTestFileUrl(const std::string& relpath) { |
| 109 FilePath path; | 109 FilePath path; |
| 110 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 110 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 111 path = path.AppendASCII("net"); | 111 path = path.AppendASCII("net"); |
| 112 path = path.AppendASCII("data"); | 112 path = path.AppendASCII("data"); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 class ProxyScriptFetcherImplTest : public PlatformTest { | 194 class ProxyScriptFetcherImplTest : public PlatformTest { |
| 195 public: | 195 public: |
| 196 ProxyScriptFetcherImplTest() | 196 ProxyScriptFetcherImplTest() |
| 197 : test_server_(TestServer::TYPE_HTTP, | 197 : test_server_(TestServer::TYPE_HTTP, |
| 198 net::TestServer::kLocalhost, | 198 net::TestServer::kLocalhost, |
| 199 FilePath(kDocRoot)) { | 199 FilePath(kDocRoot)) { |
| 200 } | 200 context_.set_network_delegate(&network_delegate_); |
| 201 | |
| 202 // testing::Test overrides | |
| 203 virtual void SetUp() OVERRIDE { | |
| 204 context_ = new RequestContext; | |
| 205 context_->set_network_delegate(&network_delegate_); | |
| 206 } | 201 } |
| 207 | 202 |
| 208 protected: | 203 protected: |
| 209 TestServer test_server_; | 204 TestServer test_server_; |
| 210 BasicNetworkDelegate network_delegate_; | 205 BasicNetworkDelegate network_delegate_; |
| 211 scoped_refptr<URLRequestContext> context_; | 206 RequestContext context_; |
| 212 }; | 207 }; |
| 213 | 208 |
| 214 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { | 209 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { |
| 215 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 210 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 216 | 211 |
| 217 { // Fetch a non-existent file. | 212 { // Fetch a non-existent file. |
| 218 string16 text; | 213 string16 text; |
| 219 TestCompletionCallback callback; | 214 TestCompletionCallback callback; |
| 220 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), | 215 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), |
| 221 &text, callback.callback()); | 216 &text, callback.callback()); |
| 222 EXPECT_EQ(ERR_IO_PENDING, result); | 217 EXPECT_EQ(ERR_IO_PENDING, result); |
| 223 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); | 218 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); |
| 224 EXPECT_TRUE(text.empty()); | 219 EXPECT_TRUE(text.empty()); |
| 225 } | 220 } |
| 226 { // Fetch a file that exists. | 221 { // Fetch a file that exists. |
| 227 string16 text; | 222 string16 text; |
| 228 TestCompletionCallback callback; | 223 TestCompletionCallback callback; |
| 229 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), | 224 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), |
| 230 &text, callback.callback()); | 225 &text, callback.callback()); |
| 231 EXPECT_EQ(ERR_IO_PENDING, result); | 226 EXPECT_EQ(ERR_IO_PENDING, result); |
| 232 EXPECT_EQ(OK, callback.WaitForResult()); | 227 EXPECT_EQ(OK, callback.WaitForResult()); |
| 233 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); | 228 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
| 234 } | 229 } |
| 235 } | 230 } |
| 236 | 231 |
| 237 // Note that all mime types are allowed for PAC file, to be consistent | 232 // Note that all mime types are allowed for PAC file, to be consistent |
| 238 // with other browsers. | 233 // with other browsers. |
| 239 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { | 234 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { |
| 240 ASSERT_TRUE(test_server_.Start()); | 235 ASSERT_TRUE(test_server_.Start()); |
| 241 | 236 |
| 242 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 237 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 243 | 238 |
| 244 { // Fetch a PAC with mime type "text/plain" | 239 { // Fetch a PAC with mime type "text/plain" |
| 245 GURL url(test_server_.GetURL("files/pac.txt")); | 240 GURL url(test_server_.GetURL("files/pac.txt")); |
| 246 string16 text; | 241 string16 text; |
| 247 TestCompletionCallback callback; | 242 TestCompletionCallback callback; |
| 248 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 243 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 249 EXPECT_EQ(ERR_IO_PENDING, result); | 244 EXPECT_EQ(ERR_IO_PENDING, result); |
| 250 EXPECT_EQ(OK, callback.WaitForResult()); | 245 EXPECT_EQ(OK, callback.WaitForResult()); |
| 251 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); | 246 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
| 252 } | 247 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 266 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 261 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 267 EXPECT_EQ(ERR_IO_PENDING, result); | 262 EXPECT_EQ(ERR_IO_PENDING, result); |
| 268 EXPECT_EQ(OK, callback.WaitForResult()); | 263 EXPECT_EQ(OK, callback.WaitForResult()); |
| 269 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 264 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 270 } | 265 } |
| 271 } | 266 } |
| 272 | 267 |
| 273 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { | 268 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { |
| 274 ASSERT_TRUE(test_server_.Start()); | 269 ASSERT_TRUE(test_server_.Start()); |
| 275 | 270 |
| 276 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 271 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 277 | 272 |
| 278 { // Fetch a PAC which gives a 500 -- FAIL | 273 { // Fetch a PAC which gives a 500 -- FAIL |
| 279 GURL url(test_server_.GetURL("files/500.pac")); | 274 GURL url(test_server_.GetURL("files/500.pac")); |
| 280 string16 text; | 275 string16 text; |
| 281 TestCompletionCallback callback; | 276 TestCompletionCallback callback; |
| 282 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 277 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 283 EXPECT_EQ(ERR_IO_PENDING, result); | 278 EXPECT_EQ(ERR_IO_PENDING, result); |
| 284 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 279 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 285 EXPECT_TRUE(text.empty()); | 280 EXPECT_TRUE(text.empty()); |
| 286 } | 281 } |
| 287 { // Fetch a PAC which gives a 404 -- FAIL | 282 { // Fetch a PAC which gives a 404 -- FAIL |
| 288 GURL url(test_server_.GetURL("files/404.pac")); | 283 GURL url(test_server_.GetURL("files/404.pac")); |
| 289 string16 text; | 284 string16 text; |
| 290 TestCompletionCallback callback; | 285 TestCompletionCallback callback; |
| 291 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 286 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 292 EXPECT_EQ(ERR_IO_PENDING, result); | 287 EXPECT_EQ(ERR_IO_PENDING, result); |
| 293 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 288 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 294 EXPECT_TRUE(text.empty()); | 289 EXPECT_TRUE(text.empty()); |
| 295 } | 290 } |
| 296 } | 291 } |
| 297 | 292 |
| 298 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { | 293 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { |
| 299 ASSERT_TRUE(test_server_.Start()); | 294 ASSERT_TRUE(test_server_.Start()); |
| 300 | 295 |
| 301 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 296 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 302 | 297 |
| 303 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should | 298 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should |
| 304 // have no effect. | 299 // have no effect. |
| 305 GURL url(test_server_.GetURL("files/downloadable.pac")); | 300 GURL url(test_server_.GetURL("files/downloadable.pac")); |
| 306 string16 text; | 301 string16 text; |
| 307 TestCompletionCallback callback; | 302 TestCompletionCallback callback; |
| 308 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 303 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 309 EXPECT_EQ(ERR_IO_PENDING, result); | 304 EXPECT_EQ(ERR_IO_PENDING, result); |
| 310 EXPECT_EQ(OK, callback.WaitForResult()); | 305 EXPECT_EQ(OK, callback.WaitForResult()); |
| 311 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); | 306 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); |
| 312 } | 307 } |
| 313 | 308 |
| 314 TEST_F(ProxyScriptFetcherImplTest, NoCache) { | 309 TEST_F(ProxyScriptFetcherImplTest, NoCache) { |
| 315 ASSERT_TRUE(test_server_.Start()); | 310 ASSERT_TRUE(test_server_.Start()); |
| 316 | 311 |
| 317 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 312 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 318 | 313 |
| 319 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 314 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
| 320 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); | 315 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); |
| 321 { | 316 { |
| 322 string16 text; | 317 string16 text; |
| 323 TestCompletionCallback callback; | 318 TestCompletionCallback callback; |
| 324 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 319 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 325 EXPECT_EQ(ERR_IO_PENDING, result); | 320 EXPECT_EQ(ERR_IO_PENDING, result); |
| 326 EXPECT_EQ(OK, callback.WaitForResult()); | 321 EXPECT_EQ(OK, callback.WaitForResult()); |
| 327 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); | 322 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 338 TestCompletionCallback callback; | 333 TestCompletionCallback callback; |
| 339 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 334 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 340 EXPECT_EQ(ERR_IO_PENDING, result); | 335 EXPECT_EQ(ERR_IO_PENDING, result); |
| 341 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 336 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
| 342 } | 337 } |
| 343 } | 338 } |
| 344 | 339 |
| 345 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 340 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
| 346 ASSERT_TRUE(test_server_.Start()); | 341 ASSERT_TRUE(test_server_.Start()); |
| 347 | 342 |
| 348 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 343 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 349 | 344 |
| 350 // Set the maximum response size to 50 bytes. | 345 // Set the maximum response size to 50 bytes. |
| 351 int prev_size = pac_fetcher.SetSizeConstraint(50); | 346 int prev_size = pac_fetcher.SetSizeConstraint(50); |
| 352 | 347 |
| 353 // These two URLs are the same file, but are http:// vs file:// | 348 // These two URLs are the same file, but are http:// vs file:// |
| 354 GURL urls[] = { | 349 GURL urls[] = { |
| 355 test_server_.GetURL("files/large-pac.nsproxy"), | 350 test_server_.GetURL("files/large-pac.nsproxy"), |
| 356 GetTestFileUrl("large-pac.nsproxy") | 351 GetTestFileUrl("large-pac.nsproxy") |
| 357 }; | 352 }; |
| 358 | 353 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 378 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 373 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 379 EXPECT_EQ(ERR_IO_PENDING, result); | 374 EXPECT_EQ(ERR_IO_PENDING, result); |
| 380 EXPECT_EQ(OK, callback.WaitForResult()); | 375 EXPECT_EQ(OK, callback.WaitForResult()); |
| 381 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 376 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 382 } | 377 } |
| 383 } | 378 } |
| 384 | 379 |
| 385 TEST_F(ProxyScriptFetcherImplTest, Hang) { | 380 TEST_F(ProxyScriptFetcherImplTest, Hang) { |
| 386 ASSERT_TRUE(test_server_.Start()); | 381 ASSERT_TRUE(test_server_.Start()); |
| 387 | 382 |
| 388 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 383 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 389 | 384 |
| 390 // Set the timeout period to 0.5 seconds. | 385 // Set the timeout period to 0.5 seconds. |
| 391 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( | 386 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( |
| 392 base::TimeDelta::FromMilliseconds(500)); | 387 base::TimeDelta::FromMilliseconds(500)); |
| 393 | 388 |
| 394 // Try fetching a URL which takes 1.2 seconds. We should abort the request | 389 // Try fetching a URL which takes 1.2 seconds. We should abort the request |
| 395 // after 500 ms, and fail with a timeout error. | 390 // after 500 ms, and fail with a timeout error. |
| 396 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); | 391 { |
| 392 GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); |
| 397 string16 text; | 393 string16 text; |
| 398 TestCompletionCallback callback; | 394 TestCompletionCallback callback; |
| 399 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 395 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 400 EXPECT_EQ(ERR_IO_PENDING, result); | 396 EXPECT_EQ(ERR_IO_PENDING, result); |
| 401 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); | 397 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); |
| 402 EXPECT_TRUE(text.empty()); | 398 EXPECT_TRUE(text.empty()); |
| 403 } | 399 } |
| 404 | 400 |
| 405 // Restore the original timeout period. | 401 // Restore the original timeout period. |
| 406 pac_fetcher.SetTimeoutConstraint(prev_timeout); | 402 pac_fetcher.SetTimeoutConstraint(prev_timeout); |
| 407 | 403 |
| 408 { // Make sure we can still fetch regular URLs. | 404 { // Make sure we can still fetch regular URLs. |
| 409 GURL url(test_server_.GetURL("files/pac.nsproxy")); | 405 GURL url(test_server_.GetURL("files/pac.nsproxy")); |
| 410 string16 text; | 406 string16 text; |
| 411 TestCompletionCallback callback; | 407 TestCompletionCallback callback; |
| 412 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 408 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 413 EXPECT_EQ(ERR_IO_PENDING, result); | 409 EXPECT_EQ(ERR_IO_PENDING, result); |
| 414 EXPECT_EQ(OK, callback.WaitForResult()); | 410 EXPECT_EQ(OK, callback.WaitForResult()); |
| 415 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 411 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 416 } | 412 } |
| 417 } | 413 } |
| 418 | 414 |
| 419 // The ProxyScriptFetcher should decode any content-codings | 415 // The ProxyScriptFetcher should decode any content-codings |
| 420 // (like gzip, bzip, etc.), and apply any charset conversions to yield | 416 // (like gzip, bzip, etc.), and apply any charset conversions to yield |
| 421 // UTF8. | 417 // UTF8. |
| 422 TEST_F(ProxyScriptFetcherImplTest, Encodings) { | 418 TEST_F(ProxyScriptFetcherImplTest, Encodings) { |
| 423 ASSERT_TRUE(test_server_.Start()); | 419 ASSERT_TRUE(test_server_.Start()); |
| 424 | 420 |
| 425 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 421 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 426 | 422 |
| 427 // Test a response that is gzip-encoded -- should get inflated. | 423 // Test a response that is gzip-encoded -- should get inflated. |
| 428 { | 424 { |
| 429 GURL url(test_server_.GetURL("files/gzipped_pac")); | 425 GURL url(test_server_.GetURL("files/gzipped_pac")); |
| 430 string16 text; | 426 string16 text; |
| 431 TestCompletionCallback callback; | 427 TestCompletionCallback callback; |
| 432 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 428 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 433 EXPECT_EQ(ERR_IO_PENDING, result); | 429 EXPECT_EQ(ERR_IO_PENDING, result); |
| 434 EXPECT_EQ(OK, callback.WaitForResult()); | 430 EXPECT_EQ(OK, callback.WaitForResult()); |
| 435 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); | 431 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); |
| 436 } | 432 } |
| 437 | 433 |
| 438 // Test a response that was served as UTF-16 (BE). It should | 434 // Test a response that was served as UTF-16 (BE). It should |
| 439 // be converted to UTF8. | 435 // be converted to UTF8. |
| 440 { | 436 { |
| 441 GURL url(test_server_.GetURL("files/utf16be_pac")); | 437 GURL url(test_server_.GetURL("files/utf16be_pac")); |
| 442 string16 text; | 438 string16 text; |
| 443 TestCompletionCallback callback; | 439 TestCompletionCallback callback; |
| 444 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 440 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 445 EXPECT_EQ(ERR_IO_PENDING, result); | 441 EXPECT_EQ(ERR_IO_PENDING, result); |
| 446 EXPECT_EQ(OK, callback.WaitForResult()); | 442 EXPECT_EQ(OK, callback.WaitForResult()); |
| 447 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); | 443 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); |
| 448 } | 444 } |
| 449 } | 445 } |
| 450 | 446 |
| 451 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { | 447 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { |
| 452 ProxyScriptFetcherImpl pac_fetcher(context_.get()); | 448 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 453 | 449 |
| 454 const char kEncodedUrl[] = | 450 const char kEncodedUrl[] = |
| 455 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" | 451 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" |
| 456 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" | 452 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" |
| 457 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; | 453 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; |
| 458 const char kPacScript[] = | 454 const char kPacScript[] = |
| 459 "function FindProxyForURL(url, host) {\n" | 455 "function FindProxyForURL(url, host) {\n" |
| 460 " if (host == 'foobar.com')\n" | 456 " if (host == 'foobar.com')\n" |
| 461 " return 'PROXY blackhole:80';\n" | 457 " return 'PROXY blackhole:80';\n" |
| 462 " return 'DIRECT';\n" | 458 " return 'DIRECT';\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 479 { | 475 { |
| 480 GURL url(kEncodedUrlBroken); | 476 GURL url(kEncodedUrlBroken); |
| 481 string16 text; | 477 string16 text; |
| 482 TestCompletionCallback callback; | 478 TestCompletionCallback callback; |
| 483 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 479 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 484 EXPECT_EQ(ERR_FAILED, result); | 480 EXPECT_EQ(ERR_FAILED, result); |
| 485 } | 481 } |
| 486 } | 482 } |
| 487 | 483 |
| 488 } // namespace net | 484 } // namespace net |
| OLD | NEW |