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

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

Issue 10559036: Added URLRequestContext to constructor for URLRequest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: merged with latest version, fixed some bugs Created 8 years, 6 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
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.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_job.h" 9 #include "net/url_request/url_request_job.h"
10 #include "net/url_request/url_request_test_util.h" 10 #include "net/url_request/url_request_test_util.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return handle_all_protocols_; 81 return handle_all_protocols_;
82 } 82 }
83 83
84 mutable bool did_intercept_; 84 mutable bool did_intercept_;
85 mutable bool handle_all_protocols_; 85 mutable bool handle_all_protocols_;
86 }; 86 };
87 87
88 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { 88 TEST(URLRequestJobFactoryTest, NoProtocolHandler) {
89 TestDelegate delegate; 89 TestDelegate delegate;
90 TestURLRequestContext request_context; 90 TestURLRequestContext request_context;
91 TestURLRequest request(GURL("foo://bar"), &delegate); 91 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
92 request.set_context(&request_context);
93 request.Start(); 92 request.Start();
94 93
95 MessageLoop::current()->Run(); 94 MessageLoop::current()->Run();
96 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 95 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
97 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 96 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
98 } 97 }
99 98
100 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { 99 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) {
101 TestDelegate delegate; 100 TestDelegate delegate;
102 URLRequestJobFactory job_factory; 101 URLRequestJobFactory job_factory;
103 TestURLRequestContext request_context; 102 TestURLRequestContext request_context;
104 request_context.set_job_factory(&job_factory); 103 request_context.set_job_factory(&job_factory);
105 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 104 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
106 TestURLRequest request(GURL("foo://bar"), &delegate); 105 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
107 request.set_context(&request_context);
108 request.Start(); 106 request.Start();
109 107
110 MessageLoop::current()->Run(); 108 MessageLoop::current()->Run();
111 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); 109 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status());
112 EXPECT_EQ(OK, request.status().error()); 110 EXPECT_EQ(OK, request.status().error());
113 } 111 }
114 112
115 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { 113 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) {
116 URLRequestJobFactory job_factory; 114 URLRequestJobFactory job_factory;
117 TestURLRequestContext request_context; 115 TestURLRequestContext request_context;
118 request_context.set_job_factory(&job_factory); 116 request_context.set_job_factory(&job_factory);
119 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 117 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
120 job_factory.SetProtocolHandler("foo", NULL); 118 job_factory.SetProtocolHandler("foo", NULL);
121 } 119 }
122 120
123 TEST(URLRequestJobFactoryTest, BasicInterceptor) { 121 TEST(URLRequestJobFactoryTest, BasicInterceptor) {
124 TestDelegate delegate; 122 TestDelegate delegate;
125 URLRequestJobFactory job_factory; 123 URLRequestJobFactory job_factory;
126 TestURLRequestContext request_context; 124 TestURLRequestContext request_context;
127 request_context.set_job_factory(&job_factory); 125 request_context.set_job_factory(&job_factory);
128 job_factory.AddInterceptor(new DummyInterceptor); 126 job_factory.AddInterceptor(new DummyInterceptor);
129 TestURLRequest request(GURL("http://bar"), &delegate); 127 TestURLRequest request(GURL("http://bar"), &delegate, &request_context);
130 request.set_context(&request_context);
131 request.Start(); 128 request.Start();
132 129
133 MessageLoop::current()->Run(); 130 MessageLoop::current()->Run();
134 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 131 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
135 EXPECT_EQ(ERR_FAILED, request.status().error()); 132 EXPECT_EQ(ERR_FAILED, request.status().error());
136 } 133 }
137 134
138 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { 135 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) {
139 TestDelegate delegate; 136 TestDelegate delegate;
140 URLRequestJobFactory job_factory; 137 URLRequestJobFactory job_factory;
141 TestURLRequestContext request_context; 138 TestURLRequestContext request_context;
142 request_context.set_job_factory(&job_factory); 139 request_context.set_job_factory(&job_factory);
143 job_factory.AddInterceptor(new DummyInterceptor); 140 job_factory.AddInterceptor(new DummyInterceptor);
144 TestURLRequest request(GURL("foo://bar"), &delegate); 141 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
145 request.set_context(&request_context);
146 request.Start(); 142 request.Start();
147 143
148 MessageLoop::current()->Run(); 144 MessageLoop::current()->Run();
149 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 145 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
150 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 146 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
151 } 147 }
152 148
153 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { 149 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
154 TestDelegate delegate; 150 TestDelegate delegate;
155 URLRequestJobFactory job_factory; 151 URLRequestJobFactory job_factory;
156 TestURLRequestContext request_context; 152 TestURLRequestContext request_context;
157 request_context.set_job_factory(&job_factory); 153 request_context.set_job_factory(&job_factory);
158 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 154 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
159 job_factory.AddInterceptor(new DummyInterceptor); 155 job_factory.AddInterceptor(new DummyInterceptor);
160 TestURLRequest request(GURL("foo://bar"), &delegate); 156 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
161 request.set_context(&request_context);
162 request.Start(); 157 request.Start();
163 158
164 MessageLoop::current()->Run(); 159 MessageLoop::current()->Run();
165 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 160 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
166 EXPECT_EQ(ERR_FAILED, request.status().error()); 161 EXPECT_EQ(ERR_FAILED, request.status().error());
167 } 162 }
168 163
169 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { 164 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
170 TestDelegate delegate; 165 TestDelegate delegate;
171 URLRequestJobFactory job_factory; 166 URLRequestJobFactory job_factory;
172 TestURLRequestContext request_context; 167 TestURLRequestContext request_context;
173 request_context.set_job_factory(&job_factory); 168 request_context.set_job_factory(&job_factory);
174 DummyInterceptor* interceptor = new DummyInterceptor; 169 DummyInterceptor* interceptor = new DummyInterceptor;
175 job_factory.AddInterceptor(interceptor); 170 job_factory.AddInterceptor(interceptor);
176 TestURLRequest request(GURL("foo://bar"), &delegate); 171 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
177 request.set_context(&request_context);
178 request.Start(); 172 request.Start();
179 173
180 MessageLoop::current()->Run(); 174 MessageLoop::current()->Run();
181 EXPECT_FALSE(interceptor->did_intercept_); 175 EXPECT_FALSE(interceptor->did_intercept_);
182 } 176 }
183 177
184 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { 178 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
185 TestDelegate delegate; 179 TestDelegate delegate;
186 URLRequestJobFactory job_factory; 180 URLRequestJobFactory job_factory;
187 TestURLRequestContext request_context; 181 TestURLRequestContext request_context;
188 request_context.set_job_factory(&job_factory); 182 request_context.set_job_factory(&job_factory);
189 DummyInterceptor* interceptor = new DummyInterceptor; 183 DummyInterceptor* interceptor = new DummyInterceptor;
190 interceptor->handle_all_protocols_ = true; 184 interceptor->handle_all_protocols_ = true;
191 job_factory.AddInterceptor(interceptor); 185 job_factory.AddInterceptor(interceptor);
192 TestURLRequest request(GURL("foo://bar"), &delegate); 186 TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
193 request.set_context(&request_context);
194 request.Start(); 187 request.Start();
195 188
196 MessageLoop::current()->Run(); 189 MessageLoop::current()->Run();
197 EXPECT_TRUE(interceptor->did_intercept_); 190 EXPECT_TRUE(interceptor->did_intercept_);
198 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 191 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
199 EXPECT_EQ(ERR_FAILED, request.status().error()); 192 EXPECT_EQ(ERR_FAILED, request.status().error());
200 } 193 }
201 194
202 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) { 195 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) {
203 DummyInterceptor* interceptor = new DummyInterceptor; 196 DummyInterceptor* interceptor = new DummyInterceptor;
204 URLRequestJobFactory job_factory; 197 URLRequestJobFactory job_factory;
205 job_factory.AddInterceptor(interceptor); 198 job_factory.AddInterceptor(interceptor);
206 EXPECT_FALSE(interceptor->WillHandleProtocol("anything")); 199 EXPECT_FALSE(interceptor->WillHandleProtocol("anything"));
207 EXPECT_FALSE(job_factory.IsHandledProtocol("anything")); 200 EXPECT_FALSE(job_factory.IsHandledProtocol("anything"));
208 interceptor->handle_all_protocols_ = true; 201 interceptor->handle_all_protocols_ = true;
209 EXPECT_TRUE(interceptor->WillHandleProtocol("anything")); 202 EXPECT_TRUE(interceptor->WillHandleProtocol("anything"));
210 EXPECT_TRUE(job_factory.IsHandledProtocol("anything")); 203 EXPECT_TRUE(job_factory.IsHandledProtocol("anything"));
211 } 204 }
212 205
213 } // namespace 206 } // namespace
214 207
215 } // namespace net 208 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698