| 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.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/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
| 10 #include "net/url_request/url_request_job.h" | 10 #include "net/url_request/url_request_job.h" |
| 11 #include "net/url_request/url_request_test_util.h" | 11 #include "net/url_request/url_request_test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 101 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 102 request.Start(); | 102 request.Start(); |
| 103 | 103 |
| 104 MessageLoop::current()->Run(); | 104 MessageLoop::current()->Run(); |
| 105 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 105 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
| 106 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); | 106 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { | 109 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { |
| 110 TestDelegate delegate; | 110 TestDelegate delegate; |
| 111 URLRequestJobFactory job_factory; | 111 URLRequestJobFactoryImpl job_factory; |
| 112 TestURLRequestContext request_context; | 112 TestURLRequestContext request_context; |
| 113 request_context.set_job_factory(&job_factory); | 113 request_context.set_job_factory(&job_factory); |
| 114 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 114 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
| 115 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 115 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 116 request.Start(); | 116 request.Start(); |
| 117 | 117 |
| 118 MessageLoop::current()->Run(); | 118 MessageLoop::current()->Run(); |
| 119 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); | 119 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); |
| 120 EXPECT_EQ(OK, request.status().error()); | 120 EXPECT_EQ(OK, request.status().error()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { | 123 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { |
| 124 URLRequestJobFactory job_factory; | 124 URLRequestJobFactoryImpl job_factory; |
| 125 TestURLRequestContext request_context; | 125 TestURLRequestContext request_context; |
| 126 request_context.set_job_factory(&job_factory); | 126 request_context.set_job_factory(&job_factory); |
| 127 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 127 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
| 128 job_factory.SetProtocolHandler("foo", NULL); | 128 job_factory.SetProtocolHandler("foo", NULL); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST(URLRequestJobFactoryTest, BasicInterceptor) { | 131 TEST(URLRequestJobFactoryTest, BasicInterceptor) { |
| 132 TestDelegate delegate; | 132 TestDelegate delegate; |
| 133 URLRequestJobFactory job_factory; | 133 URLRequestJobFactoryImpl job_factory; |
| 134 TestURLRequestContext request_context; | 134 TestURLRequestContext request_context; |
| 135 request_context.set_job_factory(&job_factory); | 135 request_context.set_job_factory(&job_factory); |
| 136 job_factory.AddInterceptor(new DummyInterceptor); | 136 job_factory.AddInterceptor(new DummyInterceptor); |
| 137 TestURLRequest request(GURL("http://bar"), &delegate, &request_context); | 137 TestURLRequest request(GURL("http://bar"), &delegate, &request_context); |
| 138 request.Start(); | 138 request.Start(); |
| 139 | 139 |
| 140 MessageLoop::current()->Run(); | 140 MessageLoop::current()->Run(); |
| 141 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 141 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
| 142 EXPECT_EQ(ERR_FAILED, request.status().error()); | 142 EXPECT_EQ(ERR_FAILED, request.status().error()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { | 145 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { |
| 146 TestDelegate delegate; | 146 TestDelegate delegate; |
| 147 URLRequestJobFactory job_factory; | 147 URLRequestJobFactoryImpl job_factory; |
| 148 TestURLRequestContext request_context; | 148 TestURLRequestContext request_context; |
| 149 request_context.set_job_factory(&job_factory); | 149 request_context.set_job_factory(&job_factory); |
| 150 job_factory.AddInterceptor(new DummyInterceptor); | 150 job_factory.AddInterceptor(new DummyInterceptor); |
| 151 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 151 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 152 request.Start(); | 152 request.Start(); |
| 153 | 153 |
| 154 MessageLoop::current()->Run(); | 154 MessageLoop::current()->Run(); |
| 155 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 155 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
| 156 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); | 156 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { | 159 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { |
| 160 TestDelegate delegate; | 160 TestDelegate delegate; |
| 161 URLRequestJobFactory job_factory; | 161 URLRequestJobFactoryImpl job_factory; |
| 162 TestURLRequestContext request_context; | 162 TestURLRequestContext request_context; |
| 163 request_context.set_job_factory(&job_factory); | 163 request_context.set_job_factory(&job_factory); |
| 164 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); | 164 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); |
| 165 job_factory.AddInterceptor(new DummyInterceptor); | 165 job_factory.AddInterceptor(new DummyInterceptor); |
| 166 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 166 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 167 request.Start(); | 167 request.Start(); |
| 168 | 168 |
| 169 MessageLoop::current()->Run(); | 169 MessageLoop::current()->Run(); |
| 170 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 170 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
| 171 EXPECT_EQ(ERR_FAILED, request.status().error()); | 171 EXPECT_EQ(ERR_FAILED, request.status().error()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { | 174 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { |
| 175 TestDelegate delegate; | 175 TestDelegate delegate; |
| 176 URLRequestJobFactory job_factory; | 176 URLRequestJobFactoryImpl job_factory; |
| 177 TestURLRequestContext request_context; | 177 TestURLRequestContext request_context; |
| 178 request_context.set_job_factory(&job_factory); | 178 request_context.set_job_factory(&job_factory); |
| 179 DummyInterceptor* interceptor = new DummyInterceptor; | 179 DummyInterceptor* interceptor = new DummyInterceptor; |
| 180 job_factory.AddInterceptor(interceptor); | 180 job_factory.AddInterceptor(interceptor); |
| 181 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 181 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 182 request.Start(); | 182 request.Start(); |
| 183 | 183 |
| 184 MessageLoop::current()->Run(); | 184 MessageLoop::current()->Run(); |
| 185 EXPECT_FALSE(interceptor->did_intercept_); | 185 EXPECT_FALSE(interceptor->did_intercept_); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { | 188 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { |
| 189 TestDelegate delegate; | 189 TestDelegate delegate; |
| 190 URLRequestJobFactory job_factory; | 190 URLRequestJobFactoryImpl job_factory; |
| 191 TestURLRequestContext request_context; | 191 TestURLRequestContext request_context; |
| 192 request_context.set_job_factory(&job_factory); | 192 request_context.set_job_factory(&job_factory); |
| 193 DummyInterceptor* interceptor = new DummyInterceptor; | 193 DummyInterceptor* interceptor = new DummyInterceptor; |
| 194 interceptor->handle_all_protocols_ = true; | 194 interceptor->handle_all_protocols_ = true; |
| 195 job_factory.AddInterceptor(interceptor); | 195 job_factory.AddInterceptor(interceptor); |
| 196 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); | 196 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); |
| 197 request.Start(); | 197 request.Start(); |
| 198 | 198 |
| 199 MessageLoop::current()->Run(); | 199 MessageLoop::current()->Run(); |
| 200 EXPECT_TRUE(interceptor->did_intercept_); | 200 EXPECT_TRUE(interceptor->did_intercept_); |
| 201 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); | 201 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); |
| 202 EXPECT_EQ(ERR_FAILED, request.status().error()); | 202 EXPECT_EQ(ERR_FAILED, request.status().error()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) { | 205 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) { |
| 206 DummyInterceptor* interceptor = new DummyInterceptor; | 206 DummyInterceptor* interceptor = new DummyInterceptor; |
| 207 URLRequestJobFactory job_factory; | 207 URLRequestJobFactoryImpl job_factory; |
| 208 job_factory.AddInterceptor(interceptor); | 208 job_factory.AddInterceptor(interceptor); |
| 209 EXPECT_FALSE(interceptor->WillHandleProtocol("anything")); | 209 EXPECT_FALSE(interceptor->WillHandleProtocol("anything")); |
| 210 EXPECT_FALSE(job_factory.IsHandledProtocol("anything")); | 210 EXPECT_FALSE(job_factory.IsHandledProtocol("anything")); |
| 211 interceptor->handle_all_protocols_ = true; | 211 interceptor->handle_all_protocols_ = true; |
| 212 EXPECT_TRUE(interceptor->WillHandleProtocol("anything")); | 212 EXPECT_TRUE(interceptor->WillHandleProtocol("anything")); |
| 213 EXPECT_TRUE(job_factory.IsHandledProtocol("anything")); | 213 EXPECT_TRUE(job_factory.IsHandledProtocol("anything")); |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace | 216 } // namespace |
| 217 | 217 |
| 218 } // namespace net | 218 } // namespace net |
| OLD | NEW |