| 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_job_factory_impl.h" | 5 #include "net/url_request/url_request_job_factory_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
| 13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class MockURLRequestJob : public URLRequestJob { | 20 class MockURLRequestJob : public URLRequestJob { |
| 21 public: | 21 public: |
| 22 MockURLRequestJob(URLRequest* request, | 22 MockURLRequestJob(URLRequest* request, |
| 23 NetworkDelegate* network_delegate, | 23 NetworkDelegate* network_delegate, |
| 24 const URLRequestStatus& status) | 24 const URLRequestStatus& status) |
| 25 : URLRequestJob(request, network_delegate), | 25 : URLRequestJob(request, network_delegate), |
| 26 status_(status), | 26 status_(status), |
| 27 weak_factory_(this) {} | 27 weak_factory_(this) {} |
| 28 | 28 |
| 29 virtual void Start() OVERRIDE { | 29 virtual void Start() override { |
| 30 // Start reading asynchronously so that all error reporting and data | 30 // Start reading asynchronously so that all error reporting and data |
| 31 // callbacks happen as they would for network requests. | 31 // callbacks happen as they would for network requests. |
| 32 base::MessageLoop::current()->PostTask( | 32 base::MessageLoop::current()->PostTask( |
| 33 FROM_HERE, | 33 FROM_HERE, |
| 34 base::Bind(&MockURLRequestJob::StartAsync, weak_factory_.GetWeakPtr())); | 34 base::Bind(&MockURLRequestJob::StartAsync, weak_factory_.GetWeakPtr())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 protected: | 37 protected: |
| 38 virtual ~MockURLRequestJob() {} | 38 virtual ~MockURLRequestJob() {} |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 void StartAsync() { | 41 void StartAsync() { |
| 42 SetStatus(status_); | 42 SetStatus(status_); |
| 43 NotifyHeadersComplete(); | 43 NotifyHeadersComplete(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 URLRequestStatus status_; | 46 URLRequestStatus status_; |
| 47 base::WeakPtrFactory<MockURLRequestJob> weak_factory_; | 47 base::WeakPtrFactory<MockURLRequestJob> weak_factory_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler { | 50 class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler { |
| 51 public: | 51 public: |
| 52 virtual URLRequestJob* MaybeCreateJob( | 52 virtual URLRequestJob* MaybeCreateJob( |
| 53 URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE { | 53 URLRequest* request, NetworkDelegate* network_delegate) const override { |
| 54 return new MockURLRequestJob( | 54 return new MockURLRequestJob( |
| 55 request, | 55 request, |
| 56 network_delegate, | 56 network_delegate, |
| 57 URLRequestStatus(URLRequestStatus::SUCCESS, OK)); | 57 URLRequestStatus(URLRequestStatus::SUCCESS, OK)); |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { | 61 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { |
| 62 TestDelegate delegate; | 62 TestDelegate delegate; |
| 63 TestURLRequestContext request_context; | 63 TestURLRequestContext request_context; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 89 URLRequestJobFactoryImpl job_factory; | 89 URLRequestJobFactoryImpl job_factory; |
| 90 TestURLRequestContext request_context; | 90 TestURLRequestContext request_context; |
| 91 request_context.set_job_factory(&job_factory); | 91 request_context.set_job_factory(&job_factory); |
| 92 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 92 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
| 93 job_factory.SetProtocolHandler("foo", NULL); | 93 job_factory.SetProtocolHandler("foo", NULL); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 } // namespace net | 98 } // namespace net |
| OLD | NEW |