| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "net/base/filename_util.h" | 15 #include "net/base/filename_util.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/network_delegate_impl.h" | 17 #include "net/base/network_delegate_impl.h" |
| 18 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 19 #include "net/cert/mock_cert_verifier.h" | 19 #include "net/cert/mock_cert_verifier.h" |
| 20 #include "net/disk_cache/disk_cache.h" | 20 #include "net/disk_cache/disk_cache.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/http/http_cache.h" | 22 #include "net/http/http_cache.h" |
| 23 #include "net/http/http_network_session.h" | 23 #include "net/http/http_network_session.h" |
| 24 #include "net/http/http_server_properties_impl.h" | 24 #include "net/http/http_server_properties_impl.h" |
| 25 #include "net/http/transport_security_state.h" | 25 #include "net/http/transport_security_state.h" |
| 26 #include "net/ssl/ssl_config_service_defaults.h" | 26 #include "net/ssl/ssl_config_service_defaults.h" |
| 27 #include "net/test/spawned_test_server/spawned_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 28 #include "net/url_request/url_request_context_storage.h" | 28 #include "net/url_request/url_request_context_storage.h" |
| 29 #include "net/url_request/url_request_file_job.h" | 29 #include "net/url_request/url_request_file_job.h" |
| 30 #include "net/url_request/url_request_job_factory_impl.h" | 30 #include "net/url_request/url_request_job_factory_impl.h" |
| 31 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "testing/platform_test.h" | 33 #include "testing/platform_test.h" |
| 34 | 34 |
| 35 #if !defined(DISABLE_FILE_SUPPORT) | 35 #if !defined(DISABLE_FILE_SUPPORT) |
| 36 #include "net/url_request/file_protocol_handler.h" | 36 #include "net/url_request/file_protocol_handler.h" |
| 37 #endif | 37 #endif |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 bool OnCanAccessFile(const URLRequest& request, | 179 bool OnCanAccessFile(const URLRequest& request, |
| 180 const base::FilePath& path) const override { | 180 const base::FilePath& path) const override { |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 | 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 184 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 class ProxyScriptFetcherImplTest : public PlatformTest { | 187 class ProxyScriptFetcherImplTest : public PlatformTest { |
| 188 public: | 188 public: |
| 189 ProxyScriptFetcherImplTest() | 189 ProxyScriptFetcherImplTest() { |
| 190 : test_server_(SpawnedTestServer::TYPE_HTTP, | 190 test_server_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 191 SpawnedTestServer::kLocalhost, | |
| 192 base::FilePath(kDocRoot)) { | |
| 193 context_.set_network_delegate(&network_delegate_); | 191 context_.set_network_delegate(&network_delegate_); |
| 194 } | 192 } |
| 195 | 193 |
| 196 protected: | 194 protected: |
| 197 SpawnedTestServer test_server_; | 195 EmbeddedTestServer test_server_; |
| 198 BasicNetworkDelegate network_delegate_; | 196 BasicNetworkDelegate network_delegate_; |
| 199 RequestContext context_; | 197 RequestContext context_; |
| 200 }; | 198 }; |
| 201 | 199 |
| 202 #if !defined(DISABLE_FILE_SUPPORT) | 200 #if !defined(DISABLE_FILE_SUPPORT) |
| 203 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { | 201 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { |
| 204 ProxyScriptFetcherImpl pac_fetcher(&context_); | 202 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 205 | 203 |
| 206 { // Fetch a non-existent file. | 204 { // Fetch a non-existent file. |
| 207 base::string16 text; | 205 base::string16 text; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 225 #endif // !defined(DISABLE_FILE_SUPPORT) | 223 #endif // !defined(DISABLE_FILE_SUPPORT) |
| 226 | 224 |
| 227 // Note that all mime types are allowed for PAC file, to be consistent | 225 // Note that all mime types are allowed for PAC file, to be consistent |
| 228 // with other browsers. | 226 // with other browsers. |
| 229 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { | 227 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { |
| 230 ASSERT_TRUE(test_server_.Start()); | 228 ASSERT_TRUE(test_server_.Start()); |
| 231 | 229 |
| 232 ProxyScriptFetcherImpl pac_fetcher(&context_); | 230 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 233 | 231 |
| 234 { // Fetch a PAC with mime type "text/plain" | 232 { // Fetch a PAC with mime type "text/plain" |
| 235 GURL url(test_server_.GetURL("files/pac.txt")); | 233 GURL url(test_server_.GetURL("/pac.txt")); |
| 236 base::string16 text; | 234 base::string16 text; |
| 237 TestCompletionCallback callback; | 235 TestCompletionCallback callback; |
| 238 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 236 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 239 EXPECT_EQ(ERR_IO_PENDING, result); | 237 EXPECT_EQ(ERR_IO_PENDING, result); |
| 240 EXPECT_EQ(OK, callback.WaitForResult()); | 238 EXPECT_EQ(OK, callback.WaitForResult()); |
| 241 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); | 239 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
| 242 } | 240 } |
| 243 { // Fetch a PAC with mime type "text/html" | 241 { // Fetch a PAC with mime type "text/html" |
| 244 GURL url(test_server_.GetURL("files/pac.html")); | 242 GURL url(test_server_.GetURL("/pac.html")); |
| 245 base::string16 text; | 243 base::string16 text; |
| 246 TestCompletionCallback callback; | 244 TestCompletionCallback callback; |
| 247 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 245 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 248 EXPECT_EQ(ERR_IO_PENDING, result); | 246 EXPECT_EQ(ERR_IO_PENDING, result); |
| 249 EXPECT_EQ(OK, callback.WaitForResult()); | 247 EXPECT_EQ(OK, callback.WaitForResult()); |
| 250 EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); | 248 EXPECT_EQ(ASCIIToUTF16("-pac.html-\n"), text); |
| 251 } | 249 } |
| 252 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" | 250 { // Fetch a PAC with mime type "application/x-ns-proxy-autoconfig" |
| 253 GURL url(test_server_.GetURL("files/pac.nsproxy")); | 251 GURL url(test_server_.GetURL("/pac.nsproxy")); |
| 254 base::string16 text; | 252 base::string16 text; |
| 255 TestCompletionCallback callback; | 253 TestCompletionCallback callback; |
| 256 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 254 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 257 EXPECT_EQ(ERR_IO_PENDING, result); | 255 EXPECT_EQ(ERR_IO_PENDING, result); |
| 258 EXPECT_EQ(OK, callback.WaitForResult()); | 256 EXPECT_EQ(OK, callback.WaitForResult()); |
| 259 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 257 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 260 } | 258 } |
| 261 } | 259 } |
| 262 | 260 |
| 263 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { | 261 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { |
| 264 ASSERT_TRUE(test_server_.Start()); | 262 ASSERT_TRUE(test_server_.Start()); |
| 265 | 263 |
| 266 ProxyScriptFetcherImpl pac_fetcher(&context_); | 264 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 267 | 265 |
| 268 { // Fetch a PAC which gives a 500 -- FAIL | 266 { // Fetch a PAC which gives a 500 -- FAIL |
| 269 GURL url(test_server_.GetURL("files/500.pac")); | 267 GURL url(test_server_.GetURL("/500.pac")); |
| 270 base::string16 text; | 268 base::string16 text; |
| 271 TestCompletionCallback callback; | 269 TestCompletionCallback callback; |
| 272 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 270 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 273 EXPECT_EQ(ERR_IO_PENDING, result); | 271 EXPECT_EQ(ERR_IO_PENDING, result); |
| 274 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 272 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 275 EXPECT_TRUE(text.empty()); | 273 EXPECT_TRUE(text.empty()); |
| 276 } | 274 } |
| 277 { // Fetch a PAC which gives a 404 -- FAIL | 275 { // Fetch a PAC which gives a 404 -- FAIL |
| 278 GURL url(test_server_.GetURL("files/404.pac")); | 276 GURL url(test_server_.GetURL("/404.pac")); |
| 279 base::string16 text; | 277 base::string16 text; |
| 280 TestCompletionCallback callback; | 278 TestCompletionCallback callback; |
| 281 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 279 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 282 EXPECT_EQ(ERR_IO_PENDING, result); | 280 EXPECT_EQ(ERR_IO_PENDING, result); |
| 283 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 281 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 284 EXPECT_TRUE(text.empty()); | 282 EXPECT_TRUE(text.empty()); |
| 285 } | 283 } |
| 286 } | 284 } |
| 287 | 285 |
| 288 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { | 286 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { |
| 289 ASSERT_TRUE(test_server_.Start()); | 287 ASSERT_TRUE(test_server_.Start()); |
| 290 | 288 |
| 291 ProxyScriptFetcherImpl pac_fetcher(&context_); | 289 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 292 | 290 |
| 293 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should | 291 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should |
| 294 // have no effect. | 292 // have no effect. |
| 295 GURL url(test_server_.GetURL("files/downloadable.pac")); | 293 GURL url(test_server_.GetURL("/downloadable.pac")); |
| 296 base::string16 text; | 294 base::string16 text; |
| 297 TestCompletionCallback callback; | 295 TestCompletionCallback callback; |
| 298 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 296 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 299 EXPECT_EQ(ERR_IO_PENDING, result); | 297 EXPECT_EQ(ERR_IO_PENDING, result); |
| 300 EXPECT_EQ(OK, callback.WaitForResult()); | 298 EXPECT_EQ(OK, callback.WaitForResult()); |
| 301 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); | 299 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); |
| 302 } | 300 } |
| 303 | 301 |
| 304 // Verifies that PAC scripts are not being cached. | 302 // Verifies that PAC scripts are not being cached. |
| 305 TEST_F(ProxyScriptFetcherImplTest, NoCache) { | 303 TEST_F(ProxyScriptFetcherImplTest, NoCache) { |
| 306 ASSERT_TRUE(test_server_.Start()); | 304 ASSERT_TRUE(test_server_.Start()); |
| 307 | 305 |
| 308 ProxyScriptFetcherImpl pac_fetcher(&context_); | 306 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 309 | 307 |
| 310 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 308 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
| 311 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); | 309 GURL url(test_server_.GetURL("/cacheable_1hr.pac")); |
| 312 { | 310 { |
| 313 base::string16 text; | 311 base::string16 text; |
| 314 TestCompletionCallback callback; | 312 TestCompletionCallback callback; |
| 315 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 313 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 316 EXPECT_EQ(ERR_IO_PENDING, result); | 314 EXPECT_EQ(ERR_IO_PENDING, result); |
| 317 EXPECT_EQ(OK, callback.WaitForResult()); | 315 EXPECT_EQ(OK, callback.WaitForResult()); |
| 318 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); | 316 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
| 319 } | 317 } |
| 320 | 318 |
| 321 // Kill the HTTP server. | 319 // Kill the HTTP server. |
| 322 ASSERT_TRUE(test_server_.Stop()); | 320 ASSERT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); |
| 323 | 321 |
| 324 // Try to fetch the file again. Since the server is not running anymore, the | 322 // Try to fetch the file again. Since the server is not running anymore, the |
| 325 // call should fail, thus indicating that the file was not fetched from the | 323 // call should fail, thus indicating that the file was not fetched from the |
| 326 // local cache. | 324 // local cache. |
| 327 { | 325 { |
| 328 base::string16 text; | 326 base::string16 text; |
| 329 TestCompletionCallback callback; | 327 TestCompletionCallback callback; |
| 330 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 328 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 331 EXPECT_EQ(ERR_IO_PENDING, result); | 329 EXPECT_EQ(ERR_IO_PENDING, result); |
| 332 | 330 |
| 333 // Expect any error. The exact error varies by platform. | 331 // Expect any error. The exact error varies by platform. |
| 334 EXPECT_NE(OK, callback.WaitForResult()); | 332 EXPECT_NE(OK, callback.WaitForResult()); |
| 335 } | 333 } |
| 336 } | 334 } |
| 337 | 335 |
| 338 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 336 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
| 339 ASSERT_TRUE(test_server_.Start()); | 337 ASSERT_TRUE(test_server_.Start()); |
| 340 | 338 |
| 341 ProxyScriptFetcherImpl pac_fetcher(&context_); | 339 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 342 | 340 |
| 343 // Set the maximum response size to 50 bytes. | 341 // Set the maximum response size to 50 bytes. |
| 344 int prev_size = pac_fetcher.SetSizeConstraint(50); | 342 int prev_size = pac_fetcher.SetSizeConstraint(50); |
| 345 | 343 |
| 346 // These two URLs are the same file, but are http:// vs file:// | 344 // These two URLs are the same file, but are http:// vs file:// |
| 347 GURL urls[] = { | 345 GURL urls[] = { |
| 348 test_server_.GetURL("files/large-pac.nsproxy"), | 346 test_server_.GetURL("/large-pac.nsproxy"), |
| 349 #if !defined(DISABLE_FILE_SUPPORT) | 347 #if !defined(DISABLE_FILE_SUPPORT) |
| 350 GetTestFileUrl("large-pac.nsproxy") | 348 GetTestFileUrl("large-pac.nsproxy") |
| 351 #endif | 349 #endif |
| 352 }; | 350 }; |
| 353 | 351 |
| 354 // Try fetching URLs that are 101 bytes large. We should abort the request | 352 // Try fetching URLs that are 101 bytes large. We should abort the request |
| 355 // after 50 bytes have been read, and fail with a too large error. | 353 // after 50 bytes have been read, and fail with a too large error. |
| 356 for (size_t i = 0; i < arraysize(urls); ++i) { | 354 for (size_t i = 0; i < arraysize(urls); ++i) { |
| 357 const GURL& url = urls[i]; | 355 const GURL& url = urls[i]; |
| 358 base::string16 text; | 356 base::string16 text; |
| 359 TestCompletionCallback callback; | 357 TestCompletionCallback callback; |
| 360 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 358 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 361 EXPECT_EQ(ERR_IO_PENDING, result); | 359 EXPECT_EQ(ERR_IO_PENDING, result); |
| 362 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); | 360 EXPECT_EQ(ERR_FILE_TOO_BIG, callback.WaitForResult()); |
| 363 EXPECT_TRUE(text.empty()); | 361 EXPECT_TRUE(text.empty()); |
| 364 } | 362 } |
| 365 | 363 |
| 366 // Restore the original size bound. | 364 // Restore the original size bound. |
| 367 pac_fetcher.SetSizeConstraint(prev_size); | 365 pac_fetcher.SetSizeConstraint(prev_size); |
| 368 | 366 |
| 369 { // Make sure we can still fetch regular URLs. | 367 { // Make sure we can still fetch regular URLs. |
| 370 GURL url(test_server_.GetURL("files/pac.nsproxy")); | 368 GURL url(test_server_.GetURL("/pac.nsproxy")); |
| 371 base::string16 text; | 369 base::string16 text; |
| 372 TestCompletionCallback callback; | 370 TestCompletionCallback callback; |
| 373 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 371 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 374 EXPECT_EQ(ERR_IO_PENDING, result); | 372 EXPECT_EQ(ERR_IO_PENDING, result); |
| 375 EXPECT_EQ(OK, callback.WaitForResult()); | 373 EXPECT_EQ(OK, callback.WaitForResult()); |
| 376 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 374 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 377 } | 375 } |
| 378 } | 376 } |
| 379 | 377 |
| 380 TEST_F(ProxyScriptFetcherImplTest, Hang) { | 378 TEST_F(ProxyScriptFetcherImplTest, Hang) { |
| 381 ASSERT_TRUE(test_server_.Start()); | 379 ASSERT_TRUE(test_server_.Start()); |
| 382 | 380 |
| 383 ProxyScriptFetcherImpl pac_fetcher(&context_); | 381 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 384 | 382 |
| 385 // Set the timeout period to 0.5 seconds. | 383 // Set the timeout period to 0.5 seconds. |
| 386 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( | 384 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( |
| 387 base::TimeDelta::FromMilliseconds(500)); | 385 base::TimeDelta::FromMilliseconds(500)); |
| 388 | 386 |
| 389 // Try fetching a URL which takes 1.2 seconds. We should abort the request | 387 // Try fetching a URL which takes 1.2 seconds. We should abort the request |
| 390 // after 500 ms, and fail with a timeout error. | 388 // after 500 ms, and fail with a timeout error. |
| 391 { | 389 { |
| 392 GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); | 390 GURL url(test_server_.GetURL("/slow/proxy.pac?1.2")); |
| 393 base::string16 text; | 391 base::string16 text; |
| 394 TestCompletionCallback callback; | 392 TestCompletionCallback callback; |
| 395 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 393 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 396 EXPECT_EQ(ERR_IO_PENDING, result); | 394 EXPECT_EQ(ERR_IO_PENDING, result); |
| 397 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); | 395 EXPECT_EQ(ERR_TIMED_OUT, callback.WaitForResult()); |
| 398 EXPECT_TRUE(text.empty()); | 396 EXPECT_TRUE(text.empty()); |
| 399 } | 397 } |
| 400 | 398 |
| 401 // Restore the original timeout period. | 399 // Restore the original timeout period. |
| 402 pac_fetcher.SetTimeoutConstraint(prev_timeout); | 400 pac_fetcher.SetTimeoutConstraint(prev_timeout); |
| 403 | 401 |
| 404 { // Make sure we can still fetch regular URLs. | 402 { // Make sure we can still fetch regular URLs. |
| 405 GURL url(test_server_.GetURL("files/pac.nsproxy")); | 403 GURL url(test_server_.GetURL("/pac.nsproxy")); |
| 406 base::string16 text; | 404 base::string16 text; |
| 407 TestCompletionCallback callback; | 405 TestCompletionCallback callback; |
| 408 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 406 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 409 EXPECT_EQ(ERR_IO_PENDING, result); | 407 EXPECT_EQ(ERR_IO_PENDING, result); |
| 410 EXPECT_EQ(OK, callback.WaitForResult()); | 408 EXPECT_EQ(OK, callback.WaitForResult()); |
| 411 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 409 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 412 } | 410 } |
| 413 } | 411 } |
| 414 | 412 |
| 415 // The ProxyScriptFetcher should decode any content-codings | 413 // The ProxyScriptFetcher should decode any content-codings |
| 416 // (like gzip, bzip, etc.), and apply any charset conversions to yield | 414 // (like gzip, bzip, etc.), and apply any charset conversions to yield |
| 417 // UTF8. | 415 // UTF8. |
| 418 TEST_F(ProxyScriptFetcherImplTest, Encodings) { | 416 TEST_F(ProxyScriptFetcherImplTest, Encodings) { |
| 419 ASSERT_TRUE(test_server_.Start()); | 417 ASSERT_TRUE(test_server_.Start()); |
| 420 | 418 |
| 421 ProxyScriptFetcherImpl pac_fetcher(&context_); | 419 ProxyScriptFetcherImpl pac_fetcher(&context_); |
| 422 | 420 |
| 423 // Test a response that is gzip-encoded -- should get inflated. | 421 // Test a response that is gzip-encoded -- should get inflated. |
| 424 { | 422 { |
| 425 GURL url(test_server_.GetURL("files/gzipped_pac")); | 423 GURL url(test_server_.GetURL("/gzipped_pac")); |
| 426 base::string16 text; | 424 base::string16 text; |
| 427 TestCompletionCallback callback; | 425 TestCompletionCallback callback; |
| 428 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 426 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 429 EXPECT_EQ(ERR_IO_PENDING, result); | 427 EXPECT_EQ(ERR_IO_PENDING, result); |
| 430 EXPECT_EQ(OK, callback.WaitForResult()); | 428 EXPECT_EQ(OK, callback.WaitForResult()); |
| 431 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); | 429 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); |
| 432 } | 430 } |
| 433 | 431 |
| 434 // Test a response that was served as UTF-16 (BE). It should | 432 // Test a response that was served as UTF-16 (BE). It should |
| 435 // be converted to UTF8. | 433 // be converted to UTF8. |
| 436 { | 434 { |
| 437 GURL url(test_server_.GetURL("files/utf16be_pac")); | 435 GURL url(test_server_.GetURL("/utf16be_pac")); |
| 438 base::string16 text; | 436 base::string16 text; |
| 439 TestCompletionCallback callback; | 437 TestCompletionCallback callback; |
| 440 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 438 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 441 EXPECT_EQ(ERR_IO_PENDING, result); | 439 EXPECT_EQ(ERR_IO_PENDING, result); |
| 442 EXPECT_EQ(OK, callback.WaitForResult()); | 440 EXPECT_EQ(OK, callback.WaitForResult()); |
| 443 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); | 441 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); |
| 444 } | 442 } |
| 445 } | 443 } |
| 446 | 444 |
| 447 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { | 445 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 477 base::string16 text; | 475 base::string16 text; |
| 478 TestCompletionCallback callback; | 476 TestCompletionCallback callback; |
| 479 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 477 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 480 EXPECT_EQ(ERR_FAILED, result); | 478 EXPECT_EQ(ERR_FAILED, result); |
| 481 } | 479 } |
| 482 } | 480 } |
| 483 | 481 |
| 484 } // namespace | 482 } // namespace |
| 485 | 483 |
| 486 } // namespace net | 484 } // namespace net |
| OLD | NEW |