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/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "net/base/request_priority.h" |
9 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
10 #include "net/url_request/url_request_job.h" | 11 #include "net/url_request/url_request_job.h" |
11 #include "net/url_request/url_request_test_util.h" | 12 #include "net/url_request/url_request_test_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class MockURLRequestJob : public URLRequestJob { | 19 class MockURLRequestJob : public URLRequestJob { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return new MockURLRequestJob( | 53 return new MockURLRequestJob( |
53 request, | 54 request, |
54 network_delegate, | 55 network_delegate, |
55 URLRequestStatus(URLRequestStatus::SUCCESS, OK)); | 56 URLRequestStatus(URLRequestStatus::SUCCESS, OK)); |
56 } | 57 } |
57 }; | 58 }; |
58 | 59 |
59 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { | 60 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { |
60 TestDelegate delegate; | 61 TestDelegate delegate; |
61 TestURLRequestContext request_context; | 62 TestURLRequestContext request_context; |
62 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context, NULL); | 63 TestURLRequest request( |
| 64 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate, &request_context); |
63 request.Start(); | 65 request.Start(); |
64 | 66 |
65 base::MessageLoop::current()->Run(); | 67 base::MessageLoop::current()->Run(); |
66 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 68 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
67 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); | 69 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); |
68 } | 70 } |
69 | 71 |
70 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { | 72 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { |
71 TestDelegate delegate; | 73 TestDelegate delegate; |
72 URLRequestJobFactoryImpl job_factory; | 74 URLRequestJobFactoryImpl job_factory; |
73 TestURLRequestContext request_context; | 75 TestURLRequestContext request_context; |
74 request_context.set_job_factory(&job_factory); | 76 request_context.set_job_factory(&job_factory); |
75 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 77 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
76 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context, NULL); | 78 TestURLRequest request( |
| 79 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate, &request_context); |
77 request.Start(); | 80 request.Start(); |
78 | 81 |
79 base::MessageLoop::current()->Run(); | 82 base::MessageLoop::current()->Run(); |
80 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); | 83 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); |
81 EXPECT_EQ(OK, request.status().error()); | 84 EXPECT_EQ(OK, request.status().error()); |
82 } | 85 } |
83 | 86 |
84 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { | 87 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { |
85 URLRequestJobFactoryImpl job_factory; | 88 URLRequestJobFactoryImpl job_factory; |
86 TestURLRequestContext request_context; | 89 TestURLRequestContext request_context; |
87 request_context.set_job_factory(&job_factory); | 90 request_context.set_job_factory(&job_factory); |
88 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 91 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
89 job_factory.SetProtocolHandler("foo", NULL); | 92 job_factory.SetProtocolHandler("foo", NULL); |
90 } | 93 } |
91 | 94 |
92 } // namespace | 95 } // namespace |
93 | 96 |
94 } // namespace net | 97 } // namespace net |
OLD | NEW |