Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1227)

Side by Side Diff: net/url_request/url_request_job_factory_unittest.cc

Issue 10836248: Turned job_factory into a pure virtual class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
mmenke 2012/08/23 15:00:21 Think this file should now be called url_request_j
shalev 2012/08/23 15:15:46 Done.
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_context.h" 10 #include "net/url_request/url_request_context.h"
11 #include "net/url_request/url_request_job.h" 11 #include "net/url_request/url_request_job.h"
12 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace net { 15 namespace net {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 93 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
94 request.Start(); 94 request.Start();
95 95
96 MessageLoop::current()->Run(); 96 MessageLoop::current()->Run();
97 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 97 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
98 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 98 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
99 } 99 }
100 100
101 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { 101 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) {
102 TestDelegate delegate; 102 TestDelegate delegate;
103 URLRequestJobFactory job_factory; 103 URLRequestJobFactoryImpl job_factory;
104 TestURLRequestContext request_context; 104 TestURLRequestContext request_context;
105 request_context.set_job_factory(&job_factory); 105 request_context.set_job_factory(&job_factory);
106 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 106 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
107 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 107 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
108 request.Start(); 108 request.Start();
109 109
110 MessageLoop::current()->Run(); 110 MessageLoop::current()->Run();
111 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); 111 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status());
112 EXPECT_EQ(OK, request.status().error()); 112 EXPECT_EQ(OK, request.status().error());
113 } 113 }
114 114
115 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { 115 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) {
116 URLRequestJobFactory job_factory; 116 URLRequestJobFactoryImpl job_factory;
117 TestURLRequestContext request_context; 117 TestURLRequestContext request_context;
118 request_context.set_job_factory(&job_factory); 118 request_context.set_job_factory(&job_factory);
119 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 119 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
120 job_factory.SetProtocolHandler("foo", NULL); 120 job_factory.SetProtocolHandler("foo", NULL);
121 } 121 }
122 122
123 TEST(URLRequestJobFactoryTest, BasicInterceptor) { 123 TEST(URLRequestJobFactoryTest, BasicInterceptor) {
124 TestDelegate delegate; 124 TestDelegate delegate;
125 URLRequestJobFactory job_factory; 125 URLRequestJobFactoryImpl job_factory;
126 TestURLRequestContext request_context; 126 TestURLRequestContext request_context;
127 request_context.set_job_factory(&job_factory); 127 request_context.set_job_factory(&job_factory);
128 job_factory.AddInterceptor(new DummyInterceptor); 128 job_factory.AddInterceptor(new DummyInterceptor);
129 TestURLRequest request(GURL("http://bar"), &delegate, &request_context); 129 TestURLRequest request(GURL("http://bar"), &delegate, &request_context);
130 request.Start(); 130 request.Start();
131 131
132 MessageLoop::current()->Run(); 132 MessageLoop::current()->Run();
133 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 133 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
134 EXPECT_EQ(ERR_FAILED, request.status().error()); 134 EXPECT_EQ(ERR_FAILED, request.status().error());
135 } 135 }
136 136
137 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { 137 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) {
138 TestDelegate delegate; 138 TestDelegate delegate;
139 URLRequestJobFactory job_factory; 139 URLRequestJobFactoryImpl job_factory;
140 TestURLRequestContext request_context; 140 TestURLRequestContext request_context;
141 request_context.set_job_factory(&job_factory); 141 request_context.set_job_factory(&job_factory);
142 job_factory.AddInterceptor(new DummyInterceptor); 142 job_factory.AddInterceptor(new DummyInterceptor);
143 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 143 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
144 request.Start(); 144 request.Start();
145 145
146 MessageLoop::current()->Run(); 146 MessageLoop::current()->Run();
147 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 147 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
148 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 148 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
149 } 149 }
150 150
151 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { 151 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
152 TestDelegate delegate; 152 TestDelegate delegate;
153 URLRequestJobFactory job_factory; 153 URLRequestJobFactoryImpl job_factory;
154 TestURLRequestContext request_context; 154 TestURLRequestContext request_context;
155 request_context.set_job_factory(&job_factory); 155 request_context.set_job_factory(&job_factory);
156 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 156 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
157 job_factory.AddInterceptor(new DummyInterceptor); 157 job_factory.AddInterceptor(new DummyInterceptor);
158 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 158 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
159 request.Start(); 159 request.Start();
160 160
161 MessageLoop::current()->Run(); 161 MessageLoop::current()->Run();
162 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 162 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
163 EXPECT_EQ(ERR_FAILED, request.status().error()); 163 EXPECT_EQ(ERR_FAILED, request.status().error());
164 } 164 }
165 165
166 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { 166 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
167 TestDelegate delegate; 167 TestDelegate delegate;
168 URLRequestJobFactory job_factory; 168 URLRequestJobFactoryImpl job_factory;
169 TestURLRequestContext request_context; 169 TestURLRequestContext request_context;
170 request_context.set_job_factory(&job_factory); 170 request_context.set_job_factory(&job_factory);
171 DummyInterceptor* interceptor = new DummyInterceptor; 171 DummyInterceptor* interceptor = new DummyInterceptor;
172 job_factory.AddInterceptor(interceptor); 172 job_factory.AddInterceptor(interceptor);
173 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 173 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
174 request.Start(); 174 request.Start();
175 175
176 MessageLoop::current()->Run(); 176 MessageLoop::current()->Run();
177 EXPECT_FALSE(interceptor->did_intercept_); 177 EXPECT_FALSE(interceptor->did_intercept_);
178 } 178 }
179 179
180 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { 180 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
181 TestDelegate delegate; 181 TestDelegate delegate;
182 URLRequestJobFactory job_factory; 182 URLRequestJobFactoryImpl job_factory;
183 TestURLRequestContext request_context; 183 TestURLRequestContext request_context;
184 request_context.set_job_factory(&job_factory); 184 request_context.set_job_factory(&job_factory);
185 DummyInterceptor* interceptor = new DummyInterceptor; 185 DummyInterceptor* interceptor = new DummyInterceptor;
186 interceptor->handle_all_protocols_ = true; 186 interceptor->handle_all_protocols_ = true;
187 job_factory.AddInterceptor(interceptor); 187 job_factory.AddInterceptor(interceptor);
188 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context); 188 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
189 request.Start(); 189 request.Start();
190 190
191 MessageLoop::current()->Run(); 191 MessageLoop::current()->Run();
192 EXPECT_TRUE(interceptor->did_intercept_); 192 EXPECT_TRUE(interceptor->did_intercept_);
193 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 193 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
194 EXPECT_EQ(ERR_FAILED, request.status().error()); 194 EXPECT_EQ(ERR_FAILED, request.status().error());
195 } 195 }
196 196
197 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) { 197 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) {
198 DummyInterceptor* interceptor = new DummyInterceptor; 198 DummyInterceptor* interceptor = new DummyInterceptor;
199 URLRequestJobFactory job_factory; 199 URLRequestJobFactoryImpl job_factory;
200 job_factory.AddInterceptor(interceptor); 200 job_factory.AddInterceptor(interceptor);
201 EXPECT_FALSE(interceptor->WillHandleProtocol("anything")); 201 EXPECT_FALSE(interceptor->WillHandleProtocol("anything"));
202 EXPECT_FALSE(job_factory.IsHandledProtocol("anything")); 202 EXPECT_FALSE(job_factory.IsHandledProtocol("anything"));
203 interceptor->handle_all_protocols_ = true; 203 interceptor->handle_all_protocols_ = true;
204 EXPECT_TRUE(interceptor->WillHandleProtocol("anything")); 204 EXPECT_TRUE(interceptor->WillHandleProtocol("anything"));
205 EXPECT_TRUE(job_factory.IsHandledProtocol("anything")); 205 EXPECT_TRUE(job_factory.IsHandledProtocol("anything"));
206 } 206 }
207 207
208 } // namespace 208 } // namespace
209 209
210 } // namespace net 210 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698