| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "net/base/mock_cert_verifier.h" | 13 #include "net/base/mock_cert_verifier.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/base/ssl_config_service_defaults.h" | 16 #include "net/base/ssl_config_service_defaults.h" |
| 17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
| 18 #include "net/disk_cache/disk_cache.h" | 18 #include "net/disk_cache/disk_cache.h" |
| 19 #include "net/http/http_cache.h" | 19 #include "net/http/http_cache.h" |
| 20 #include "net/http/http_network_session.h" | 20 #include "net/http/http_network_session.h" |
| 21 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
| 22 #include "net/test/test_server.h" | 22 #include "net/test/test_server.h" |
| 23 #include "net/url_request/url_request_context_storage.h" | 23 #include "net/url_request/url_request_context_storage.h" |
| 24 #include "net/url_request/url_request_file_job.h" |
| 24 #include "net/url_request/url_request_job_factory.h" | 25 #include "net/url_request/url_request_job_factory.h" |
| 25 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "testing/platform_test.h" | 28 #include "testing/platform_test.h" |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 // TODO(eroman): | 32 // TODO(eroman): |
| 32 // - Test canceling an outstanding request. | 33 // - Test canceling an outstanding request. |
| 33 // - Test deleting ProxyScriptFetcher while a request is in progress. | 34 // - Test deleting ProxyScriptFetcher while a request is in progress. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 GURL GetTestFileUrl(const std::string& relpath) { | 108 GURL GetTestFileUrl(const std::string& relpath) { |
| 108 FilePath path; | 109 FilePath path; |
| 109 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 110 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 110 path = path.AppendASCII("net"); | 111 path = path.AppendASCII("net"); |
| 111 path = path.AppendASCII("data"); | 112 path = path.AppendASCII("data"); |
| 112 path = path.AppendASCII("proxy_script_fetcher_unittest"); | 113 path = path.AppendASCII("proxy_script_fetcher_unittest"); |
| 113 GURL base_url = FilePathToFileURL(path); | 114 GURL base_url = FilePathToFileURL(path); |
| 114 return GURL(base_url.spec() + "/" + relpath); | 115 return GURL(base_url.spec() + "/" + relpath); |
| 115 } | 116 } |
| 116 | 117 |
| 118 // Really simple NetworkDelegate so we can allow local file access on ChromeOS |
| 119 // without introducing layering violations. |
| 120 class BasicNetworkDelegate : public NetworkDelegate { |
| 121 public: |
| 122 BasicNetworkDelegate() {} |
| 123 virtual ~BasicNetworkDelegate() {} |
| 124 |
| 125 private: |
| 126 virtual int OnBeforeURLRequest(URLRequest* request, |
| 127 const CompletionCallback& callback, |
| 128 GURL* new_url) OVERRIDE { |
| 129 return OK; |
| 130 } |
| 131 |
| 132 virtual int OnBeforeSendHeaders(URLRequest* request, |
| 133 const CompletionCallback& callback, |
| 134 HttpRequestHeaders* headers) OVERRIDE { |
| 135 return OK; |
| 136 } |
| 137 |
| 138 virtual void OnSendHeaders(URLRequest* request, |
| 139 const HttpRequestHeaders& headers) OVERRIDE {} |
| 140 |
| 141 virtual int OnHeadersReceived( |
| 142 URLRequest* request, |
| 143 const CompletionCallback& callback, |
| 144 HttpResponseHeaders* original_response_headers, |
| 145 scoped_refptr<HttpResponseHeaders>* override_response_headers) |
| 146 OVERRIDE { |
| 147 return OK; |
| 148 } |
| 149 |
| 150 virtual void OnBeforeRedirect(URLRequest* request, |
| 151 const GURL& new_location) OVERRIDE {} |
| 152 |
| 153 virtual void OnResponseStarted(URLRequest* request) OVERRIDE {} |
| 154 |
| 155 virtual void OnRawBytesRead(const URLRequest& request, |
| 156 int bytes_read) OVERRIDE {} |
| 157 |
| 158 virtual void OnCompleted(URLRequest* request, bool started) OVERRIDE {} |
| 159 |
| 160 virtual void OnURLRequestDestroyed(URLRequest* request) OVERRIDE {} |
| 161 |
| 162 virtual void OnPACScriptError(int line_number, |
| 163 const string16& error) OVERRIDE {} |
| 164 |
| 165 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired( |
| 166 URLRequest* request, |
| 167 const AuthChallengeInfo& auth_info, |
| 168 const AuthCallback& callback, |
| 169 AuthCredentials* credentials) OVERRIDE { |
| 170 return NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
| 171 } |
| 172 |
| 173 virtual bool OnCanGetCookies(const URLRequest& request, |
| 174 const CookieList& cookie_list) OVERRIDE { |
| 175 return true; |
| 176 } |
| 177 |
| 178 virtual bool OnCanSetCookie(const URLRequest& request, |
| 179 const std::string& cookie_line, |
| 180 CookieOptions* options) OVERRIDE { |
| 181 return true; |
| 182 } |
| 183 |
| 184 virtual bool OnCanAccessFile(const net::URLRequest& request, |
| 185 const FilePath& path) const OVERRIDE { |
| 186 return true; |
| 187 } |
| 188 |
| 189 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 190 }; |
| 191 |
| 117 } // namespace | 192 } // namespace |
| 118 | 193 |
| 119 class ProxyScriptFetcherImplTest : public PlatformTest { | 194 class ProxyScriptFetcherImplTest : public PlatformTest { |
| 120 public: | 195 public: |
| 121 ProxyScriptFetcherImplTest() | 196 ProxyScriptFetcherImplTest() |
| 122 : test_server_(TestServer::TYPE_HTTP, | 197 : test_server_(TestServer::TYPE_HTTP, |
| 123 net::TestServer::kLocalhost, | 198 net::TestServer::kLocalhost, |
| 124 FilePath(kDocRoot)) { | 199 FilePath(kDocRoot)) { |
| 125 } | 200 } |
| 126 | 201 |
| 127 static void SetUpTestCase() { | 202 // testing::Test overrides |
| 128 URLRequest::AllowFileAccess(); | 203 virtual void SetUp() OVERRIDE { |
| 204 context_ = new RequestContext; |
| 205 context_->set_network_delegate(&network_delegate_); |
| 129 } | 206 } |
| 130 | 207 |
| 131 protected: | 208 protected: |
| 132 TestServer test_server_; | 209 TestServer test_server_; |
| 210 BasicNetworkDelegate network_delegate_; |
| 211 scoped_refptr<URLRequestContext> context_; |
| 133 }; | 212 }; |
| 134 | 213 |
| 135 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { | 214 TEST_F(ProxyScriptFetcherImplTest, FileUrl) { |
| 136 scoped_refptr<URLRequestContext> context(new RequestContext); | 215 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 137 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 138 | 216 |
| 139 { // Fetch a non-existent file. | 217 { // Fetch a non-existent file. |
| 140 string16 text; | 218 string16 text; |
| 141 TestCompletionCallback callback; | 219 TestCompletionCallback callback; |
| 142 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), | 220 int result = pac_fetcher.Fetch(GetTestFileUrl("does-not-exist"), |
| 143 &text, callback.callback()); | 221 &text, callback.callback()); |
| 144 EXPECT_EQ(ERR_IO_PENDING, result); | 222 EXPECT_EQ(ERR_IO_PENDING, result); |
| 145 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); | 223 EXPECT_EQ(ERR_FILE_NOT_FOUND, callback.WaitForResult()); |
| 146 EXPECT_TRUE(text.empty()); | 224 EXPECT_TRUE(text.empty()); |
| 147 } | 225 } |
| 148 { // Fetch a file that exists. | 226 { // Fetch a file that exists. |
| 149 string16 text; | 227 string16 text; |
| 150 TestCompletionCallback callback; | 228 TestCompletionCallback callback; |
| 151 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), | 229 int result = pac_fetcher.Fetch(GetTestFileUrl("pac.txt"), |
| 152 &text, callback.callback()); | 230 &text, callback.callback()); |
| 153 EXPECT_EQ(ERR_IO_PENDING, result); | 231 EXPECT_EQ(ERR_IO_PENDING, result); |
| 154 EXPECT_EQ(OK, callback.WaitForResult()); | 232 EXPECT_EQ(OK, callback.WaitForResult()); |
| 155 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); | 233 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
| 156 } | 234 } |
| 157 } | 235 } |
| 158 | 236 |
| 159 // Note that all mime types are allowed for PAC file, to be consistent | 237 // Note that all mime types are allowed for PAC file, to be consistent |
| 160 // with other browsers. | 238 // with other browsers. |
| 161 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { | 239 TEST_F(ProxyScriptFetcherImplTest, HttpMimeType) { |
| 162 ASSERT_TRUE(test_server_.Start()); | 240 ASSERT_TRUE(test_server_.Start()); |
| 163 | 241 |
| 164 scoped_refptr<URLRequestContext> context(new RequestContext); | 242 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 165 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 166 | 243 |
| 167 { // Fetch a PAC with mime type "text/plain" | 244 { // Fetch a PAC with mime type "text/plain" |
| 168 GURL url(test_server_.GetURL("files/pac.txt")); | 245 GURL url(test_server_.GetURL("files/pac.txt")); |
| 169 string16 text; | 246 string16 text; |
| 170 TestCompletionCallback callback; | 247 TestCompletionCallback callback; |
| 171 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 248 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 172 EXPECT_EQ(ERR_IO_PENDING, result); | 249 EXPECT_EQ(ERR_IO_PENDING, result); |
| 173 EXPECT_EQ(OK, callback.WaitForResult()); | 250 EXPECT_EQ(OK, callback.WaitForResult()); |
| 174 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); | 251 EXPECT_EQ(ASCIIToUTF16("-pac.txt-\n"), text); |
| 175 } | 252 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 189 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 266 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 190 EXPECT_EQ(ERR_IO_PENDING, result); | 267 EXPECT_EQ(ERR_IO_PENDING, result); |
| 191 EXPECT_EQ(OK, callback.WaitForResult()); | 268 EXPECT_EQ(OK, callback.WaitForResult()); |
| 192 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 269 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 193 } | 270 } |
| 194 } | 271 } |
| 195 | 272 |
| 196 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { | 273 TEST_F(ProxyScriptFetcherImplTest, HttpStatusCode) { |
| 197 ASSERT_TRUE(test_server_.Start()); | 274 ASSERT_TRUE(test_server_.Start()); |
| 198 | 275 |
| 199 scoped_refptr<URLRequestContext> context(new RequestContext); | 276 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 200 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 201 | 277 |
| 202 { // Fetch a PAC which gives a 500 -- FAIL | 278 { // Fetch a PAC which gives a 500 -- FAIL |
| 203 GURL url(test_server_.GetURL("files/500.pac")); | 279 GURL url(test_server_.GetURL("files/500.pac")); |
| 204 string16 text; | 280 string16 text; |
| 205 TestCompletionCallback callback; | 281 TestCompletionCallback callback; |
| 206 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 282 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 207 EXPECT_EQ(ERR_IO_PENDING, result); | 283 EXPECT_EQ(ERR_IO_PENDING, result); |
| 208 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 284 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 209 EXPECT_TRUE(text.empty()); | 285 EXPECT_TRUE(text.empty()); |
| 210 } | 286 } |
| 211 { // Fetch a PAC which gives a 404 -- FAIL | 287 { // Fetch a PAC which gives a 404 -- FAIL |
| 212 GURL url(test_server_.GetURL("files/404.pac")); | 288 GURL url(test_server_.GetURL("files/404.pac")); |
| 213 string16 text; | 289 string16 text; |
| 214 TestCompletionCallback callback; | 290 TestCompletionCallback callback; |
| 215 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 291 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 216 EXPECT_EQ(ERR_IO_PENDING, result); | 292 EXPECT_EQ(ERR_IO_PENDING, result); |
| 217 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); | 293 EXPECT_EQ(ERR_PAC_STATUS_NOT_OK, callback.WaitForResult()); |
| 218 EXPECT_TRUE(text.empty()); | 294 EXPECT_TRUE(text.empty()); |
| 219 } | 295 } |
| 220 } | 296 } |
| 221 | 297 |
| 222 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { | 298 TEST_F(ProxyScriptFetcherImplTest, ContentDisposition) { |
| 223 ASSERT_TRUE(test_server_.Start()); | 299 ASSERT_TRUE(test_server_.Start()); |
| 224 | 300 |
| 225 scoped_refptr<URLRequestContext> context(new RequestContext); | 301 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 226 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 227 | 302 |
| 228 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should | 303 // Fetch PAC scripts via HTTP with a Content-Disposition header -- should |
| 229 // have no effect. | 304 // have no effect. |
| 230 GURL url(test_server_.GetURL("files/downloadable.pac")); | 305 GURL url(test_server_.GetURL("files/downloadable.pac")); |
| 231 string16 text; | 306 string16 text; |
| 232 TestCompletionCallback callback; | 307 TestCompletionCallback callback; |
| 233 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 308 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 234 EXPECT_EQ(ERR_IO_PENDING, result); | 309 EXPECT_EQ(ERR_IO_PENDING, result); |
| 235 EXPECT_EQ(OK, callback.WaitForResult()); | 310 EXPECT_EQ(OK, callback.WaitForResult()); |
| 236 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); | 311 EXPECT_EQ(ASCIIToUTF16("-downloadable.pac-\n"), text); |
| 237 } | 312 } |
| 238 | 313 |
| 239 TEST_F(ProxyScriptFetcherImplTest, NoCache) { | 314 TEST_F(ProxyScriptFetcherImplTest, NoCache) { |
| 240 ASSERT_TRUE(test_server_.Start()); | 315 ASSERT_TRUE(test_server_.Start()); |
| 241 | 316 |
| 242 scoped_refptr<URLRequestContext> context(new RequestContext); | 317 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 243 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 244 | 318 |
| 245 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. | 319 // Fetch a PAC script whose HTTP headers make it cacheable for 1 hour. |
| 246 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); | 320 GURL url(test_server_.GetURL("files/cacheable_1hr.pac")); |
| 247 { | 321 { |
| 248 string16 text; | 322 string16 text; |
| 249 TestCompletionCallback callback; | 323 TestCompletionCallback callback; |
| 250 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 324 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 251 EXPECT_EQ(ERR_IO_PENDING, result); | 325 EXPECT_EQ(ERR_IO_PENDING, result); |
| 252 EXPECT_EQ(OK, callback.WaitForResult()); | 326 EXPECT_EQ(OK, callback.WaitForResult()); |
| 253 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); | 327 EXPECT_EQ(ASCIIToUTF16("-cacheable_1hr.pac-\n"), text); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 264 TestCompletionCallback callback; | 338 TestCompletionCallback callback; |
| 265 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 339 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 266 EXPECT_EQ(ERR_IO_PENDING, result); | 340 EXPECT_EQ(ERR_IO_PENDING, result); |
| 267 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); | 341 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
| 268 } | 342 } |
| 269 } | 343 } |
| 270 | 344 |
| 271 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { | 345 TEST_F(ProxyScriptFetcherImplTest, TooLarge) { |
| 272 ASSERT_TRUE(test_server_.Start()); | 346 ASSERT_TRUE(test_server_.Start()); |
| 273 | 347 |
| 274 scoped_refptr<URLRequestContext> context(new RequestContext); | 348 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 275 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 276 | 349 |
| 277 // Set the maximum response size to 50 bytes. | 350 // Set the maximum response size to 50 bytes. |
| 278 int prev_size = pac_fetcher.SetSizeConstraint(50); | 351 int prev_size = pac_fetcher.SetSizeConstraint(50); |
| 279 | 352 |
| 280 // These two URLs are the same file, but are http:// vs file:// | 353 // These two URLs are the same file, but are http:// vs file:// |
| 281 GURL urls[] = { | 354 GURL urls[] = { |
| 282 test_server_.GetURL("files/large-pac.nsproxy"), | 355 test_server_.GetURL("files/large-pac.nsproxy"), |
| 283 GetTestFileUrl("large-pac.nsproxy") | 356 GetTestFileUrl("large-pac.nsproxy") |
| 284 }; | 357 }; |
| 285 | 358 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 305 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 378 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 306 EXPECT_EQ(ERR_IO_PENDING, result); | 379 EXPECT_EQ(ERR_IO_PENDING, result); |
| 307 EXPECT_EQ(OK, callback.WaitForResult()); | 380 EXPECT_EQ(OK, callback.WaitForResult()); |
| 308 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 381 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 309 } | 382 } |
| 310 } | 383 } |
| 311 | 384 |
| 312 TEST_F(ProxyScriptFetcherImplTest, Hang) { | 385 TEST_F(ProxyScriptFetcherImplTest, Hang) { |
| 313 ASSERT_TRUE(test_server_.Start()); | 386 ASSERT_TRUE(test_server_.Start()); |
| 314 | 387 |
| 315 scoped_refptr<URLRequestContext> context(new RequestContext); | 388 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 316 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 317 | 389 |
| 318 // Set the timeout period to 0.5 seconds. | 390 // Set the timeout period to 0.5 seconds. |
| 319 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( | 391 base::TimeDelta prev_timeout = pac_fetcher.SetTimeoutConstraint( |
| 320 base::TimeDelta::FromMilliseconds(500)); | 392 base::TimeDelta::FromMilliseconds(500)); |
| 321 | 393 |
| 322 // Try fetching a URL which takes 1.2 seconds. We should abort the request | 394 // Try fetching a URL which takes 1.2 seconds. We should abort the request |
| 323 // after 500 ms, and fail with a timeout error. | 395 // after 500 ms, and fail with a timeout error. |
| 324 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); | 396 { GURL url(test_server_.GetURL("slow/proxy.pac?1.2")); |
| 325 string16 text; | 397 string16 text; |
| 326 TestCompletionCallback callback; | 398 TestCompletionCallback callback; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 343 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); | 415 EXPECT_EQ(ASCIIToUTF16("-pac.nsproxy-\n"), text); |
| 344 } | 416 } |
| 345 } | 417 } |
| 346 | 418 |
| 347 // The ProxyScriptFetcher should decode any content-codings | 419 // The ProxyScriptFetcher should decode any content-codings |
| 348 // (like gzip, bzip, etc.), and apply any charset conversions to yield | 420 // (like gzip, bzip, etc.), and apply any charset conversions to yield |
| 349 // UTF8. | 421 // UTF8. |
| 350 TEST_F(ProxyScriptFetcherImplTest, Encodings) { | 422 TEST_F(ProxyScriptFetcherImplTest, Encodings) { |
| 351 ASSERT_TRUE(test_server_.Start()); | 423 ASSERT_TRUE(test_server_.Start()); |
| 352 | 424 |
| 353 scoped_refptr<URLRequestContext> context(new RequestContext); | 425 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 354 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 355 | 426 |
| 356 // Test a response that is gzip-encoded -- should get inflated. | 427 // Test a response that is gzip-encoded -- should get inflated. |
| 357 { | 428 { |
| 358 GURL url(test_server_.GetURL("files/gzipped_pac")); | 429 GURL url(test_server_.GetURL("files/gzipped_pac")); |
| 359 string16 text; | 430 string16 text; |
| 360 TestCompletionCallback callback; | 431 TestCompletionCallback callback; |
| 361 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 432 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 362 EXPECT_EQ(ERR_IO_PENDING, result); | 433 EXPECT_EQ(ERR_IO_PENDING, result); |
| 363 EXPECT_EQ(OK, callback.WaitForResult()); | 434 EXPECT_EQ(OK, callback.WaitForResult()); |
| 364 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); | 435 EXPECT_EQ(ASCIIToUTF16("This data was gzipped.\n"), text); |
| 365 } | 436 } |
| 366 | 437 |
| 367 // Test a response that was served as UTF-16 (BE). It should | 438 // Test a response that was served as UTF-16 (BE). It should |
| 368 // be converted to UTF8. | 439 // be converted to UTF8. |
| 369 { | 440 { |
| 370 GURL url(test_server_.GetURL("files/utf16be_pac")); | 441 GURL url(test_server_.GetURL("files/utf16be_pac")); |
| 371 string16 text; | 442 string16 text; |
| 372 TestCompletionCallback callback; | 443 TestCompletionCallback callback; |
| 373 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 444 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 374 EXPECT_EQ(ERR_IO_PENDING, result); | 445 EXPECT_EQ(ERR_IO_PENDING, result); |
| 375 EXPECT_EQ(OK, callback.WaitForResult()); | 446 EXPECT_EQ(OK, callback.WaitForResult()); |
| 376 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); | 447 EXPECT_EQ(ASCIIToUTF16("This was encoded as UTF-16BE.\n"), text); |
| 377 } | 448 } |
| 378 } | 449 } |
| 379 | 450 |
| 380 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { | 451 TEST_F(ProxyScriptFetcherImplTest, DataURLs) { |
| 381 scoped_refptr<URLRequestContext> context(new RequestContext); | 452 ProxyScriptFetcherImpl pac_fetcher(context_.get()); |
| 382 ProxyScriptFetcherImpl pac_fetcher(context); | |
| 383 | 453 |
| 384 const char kEncodedUrl[] = | 454 const char kEncodedUrl[] = |
| 385 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" | 455 "data:application/x-ns-proxy-autoconfig;base64,ZnVuY3Rpb24gRmluZFByb3h5R" |
| 386 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" | 456 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" |
| 387 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; | 457 "dHVybiAnUFJPWFkgYmxhY2tob2xlOjgwJzsKICByZXR1cm4gJ0RJUkVDVCc7Cn0="; |
| 388 const char kPacScript[] = | 458 const char kPacScript[] = |
| 389 "function FindProxyForURL(url, host) {\n" | 459 "function FindProxyForURL(url, host) {\n" |
| 390 " if (host == 'foobar.com')\n" | 460 " if (host == 'foobar.com')\n" |
| 391 " return 'PROXY blackhole:80';\n" | 461 " return 'PROXY blackhole:80';\n" |
| 392 " return 'DIRECT';\n" | 462 " return 'DIRECT';\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 409 { | 479 { |
| 410 GURL url(kEncodedUrlBroken); | 480 GURL url(kEncodedUrlBroken); |
| 411 string16 text; | 481 string16 text; |
| 412 TestCompletionCallback callback; | 482 TestCompletionCallback callback; |
| 413 int result = pac_fetcher.Fetch(url, &text, callback.callback()); | 483 int result = pac_fetcher.Fetch(url, &text, callback.callback()); |
| 414 EXPECT_EQ(ERR_FAILED, result); | 484 EXPECT_EQ(ERR_FAILED, result); |
| 415 } | 485 } |
| 416 } | 486 } |
| 417 | 487 |
| 418 } // namespace net | 488 } // namespace net |
| OLD | NEW |