| 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/url_request/url_request_test_job.h" | 5 #include "net/url_request/url_request_test_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 typedef std::list<URLRequestTestJob*> URLRequestJobList; | 23 typedef std::list<URLRequestTestJob*> URLRequestJobList; |
| 24 base::LazyInstance<URLRequestJobList>::Leaky | 24 base::LazyInstance<URLRequestJobList>::Leaky |
| 25 g_pending_jobs = LAZY_INSTANCE_INITIALIZER; | 25 g_pending_jobs = LAZY_INSTANCE_INITIALIZER; |
| 26 | 26 |
| 27 class TestJobProtocolHandler : public URLRequestJobFactory::ProtocolHandler { |
| 28 public: |
| 29 // URLRequestJobFactory::ProtocolHandler implementation: |
| 30 virtual URLRequestJob* MaybeCreateJob( |
| 31 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE { |
| 32 return new URLRequestTestJob(request, network_delegate); |
| 33 } |
| 34 }; |
| 35 |
| 27 } // namespace | 36 } // namespace |
| 28 | 37 |
| 29 // static getters for known URLs | 38 // static getters for known URLs |
| 30 GURL URLRequestTestJob::test_url_1() { | 39 GURL URLRequestTestJob::test_url_1() { |
| 31 return GURL("test:url1"); | 40 return GURL("test:url1"); |
| 32 } | 41 } |
| 33 GURL URLRequestTestJob::test_url_2() { | 42 GURL URLRequestTestJob::test_url_2() { |
| 34 return GURL("test:url2"); | 43 return GURL("test:url2"); |
| 35 } | 44 } |
| 36 GURL URLRequestTestJob::test_url_3() { | 45 GURL URLRequestTestJob::test_url_3() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 100 |
| 92 // static getter for error response headers | 101 // static getter for error response headers |
| 93 std::string URLRequestTestJob::test_error_headers() { | 102 std::string URLRequestTestJob::test_error_headers() { |
| 94 static const char kHeaders[] = | 103 static const char kHeaders[] = |
| 95 "HTTP/1.1 500 BOO HOO\0" | 104 "HTTP/1.1 500 BOO HOO\0" |
| 96 "\0"; | 105 "\0"; |
| 97 return std::string(kHeaders, arraysize(kHeaders)); | 106 return std::string(kHeaders, arraysize(kHeaders)); |
| 98 } | 107 } |
| 99 | 108 |
| 100 // static | 109 // static |
| 101 URLRequestJob* URLRequestTestJob::Factory(URLRequest* request, | 110 URLRequestJobFactory::ProtocolHandler* |
| 102 NetworkDelegate* network_delegate, | 111 URLRequestTestJob::CreateProtocolHandler() { |
| 103 const std::string& scheme) { | 112 return new TestJobProtocolHandler(); |
| 104 return new URLRequestTestJob(request, network_delegate); | |
| 105 } | 113 } |
| 106 | 114 |
| 107 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 115 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 108 NetworkDelegate* network_delegate) | 116 NetworkDelegate* network_delegate) |
| 109 : URLRequestJob(request, network_delegate), | 117 : URLRequestJob(request, network_delegate), |
| 110 auto_advance_(false), | 118 auto_advance_(false), |
| 111 stage_(WAITING), | 119 stage_(WAITING), |
| 112 priority_(DEFAULT_PRIORITY), | 120 priority_(DEFAULT_PRIORITY), |
| 113 offset_(0), | 121 offset_(0), |
| 114 async_buf_(NULL), | 122 async_buf_(NULL), |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 | 344 |
| 337 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 345 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 338 g_pending_jobs.Get().pop_front(); | 346 g_pending_jobs.Get().pop_front(); |
| 339 | 347 |
| 340 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 348 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 341 next_job->ProcessNextOperation(); | 349 next_job->ProcessNextOperation(); |
| 342 return true; | 350 return true; |
| 343 } | 351 } |
| 344 | 352 |
| 345 } // namespace net | 353 } // namespace net |
| OLD | NEW |