| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 17 #include "net/test/gtest_util.h" | 17 #include "net/test/gtest_util.h" |
| 18 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_job.h" | 20 #include "net/url_request/url_request_job.h" |
| 20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using net::test::IsError; | 25 using net::test::IsError; |
| 25 using net::test::IsOk; | 26 using net::test::IsOk; |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 57 URLRequestJob* MaybeCreateJob( | 58 URLRequestJob* MaybeCreateJob( |
| 58 URLRequest* request, | 59 URLRequest* request, |
| 59 NetworkDelegate* network_delegate) const override { | 60 NetworkDelegate* network_delegate) const override { |
| 60 return new MockURLRequestJob(request, network_delegate); | 61 return new MockURLRequestJob(request, network_delegate); |
| 61 } | 62 } |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { | 65 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { |
| 65 TestDelegate delegate; | 66 TestDelegate delegate; |
| 66 TestURLRequestContext request_context; | 67 TestURLRequestContext request_context; |
| 67 std::unique_ptr<URLRequest> request(request_context.CreateRequest( | 68 std::unique_ptr<URLRequest> request( |
| 68 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate)); | 69 request_context.CreateRequest(GURL("foo://bar"), DEFAULT_PRIORITY, |
| 70 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 69 request->Start(); | 71 request->Start(); |
| 70 | 72 |
| 71 base::RunLoop().Run(); | 73 base::RunLoop().Run(); |
| 72 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, delegate.request_status()); | 74 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, delegate.request_status()); |
| 73 } | 75 } |
| 74 | 76 |
| 75 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { | 77 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { |
| 76 TestDelegate delegate; | 78 TestDelegate delegate; |
| 77 URLRequestJobFactoryImpl job_factory; | 79 URLRequestJobFactoryImpl job_factory; |
| 78 TestURLRequestContext request_context; | 80 TestURLRequestContext request_context; |
| 79 request_context.set_job_factory(&job_factory); | 81 request_context.set_job_factory(&job_factory); |
| 80 job_factory.SetProtocolHandler("foo", | 82 job_factory.SetProtocolHandler("foo", |
| 81 base::WrapUnique(new DummyProtocolHandler)); | 83 base::WrapUnique(new DummyProtocolHandler)); |
| 82 std::unique_ptr<URLRequest> request(request_context.CreateRequest( | 84 std::unique_ptr<URLRequest> request( |
| 83 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate)); | 85 request_context.CreateRequest(GURL("foo://bar"), DEFAULT_PRIORITY, |
| 86 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 84 request->Start(); | 87 request->Start(); |
| 85 | 88 |
| 86 base::RunLoop().Run(); | 89 base::RunLoop().Run(); |
| 87 EXPECT_EQ(OK, delegate.request_status()); | 90 EXPECT_EQ(OK, delegate.request_status()); |
| 88 } | 91 } |
| 89 | 92 |
| 90 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { | 93 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { |
| 91 URLRequestJobFactoryImpl job_factory; | 94 URLRequestJobFactoryImpl job_factory; |
| 92 TestURLRequestContext request_context; | 95 TestURLRequestContext request_context; |
| 93 request_context.set_job_factory(&job_factory); | 96 request_context.set_job_factory(&job_factory); |
| 94 job_factory.SetProtocolHandler("foo", | 97 job_factory.SetProtocolHandler("foo", |
| 95 base::WrapUnique(new DummyProtocolHandler)); | 98 base::WrapUnique(new DummyProtocolHandler)); |
| 96 job_factory.SetProtocolHandler("foo", nullptr); | 99 job_factory.SetProtocolHandler("foo", nullptr); |
| 97 } | 100 } |
| 98 | 101 |
| 99 } // namespace | 102 } // namespace |
| 100 | 103 |
| 101 } // namespace net | 104 } // namespace net |
| OLD | NEW |