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

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

Issue 10299002: Stop refcounting URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initialize to NULL Created 8 years, 7 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
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const std::string& /* protocol */) const OVERRIDE { 80 const std::string& /* protocol */) const OVERRIDE {
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 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext); 90 TestURLRequestContext request_context;
91 TestURLRequest request(GURL("foo://bar"), &delegate); 91 TestURLRequest request(GURL("foo://bar"), &delegate);
92 request.set_context(request_context); 92 request.set_context(&request_context);
93 request.Start(); 93 request.Start();
94 94
95 MessageLoop::current()->Run(); 95 MessageLoop::current()->Run();
96 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 96 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
97 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 97 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
98 } 98 }
99 99
100 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { 100 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) {
101 TestDelegate delegate; 101 TestDelegate delegate;
102 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
103 URLRequestJobFactory job_factory; 102 URLRequestJobFactory job_factory;
104 request_context->set_job_factory(&job_factory); 103 TestURLRequestContext request_context;
104 request_context.set_job_factory(&job_factory);
105 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 105 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
106 TestURLRequest request(GURL("foo://bar"), &delegate); 106 TestURLRequest request(GURL("foo://bar"), &delegate);
107 request.set_context(request_context); 107 request.set_context(&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 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
117 URLRequestJobFactory job_factory; 116 URLRequestJobFactory job_factory;
118 request_context->set_job_factory(&job_factory); 117 TestURLRequestContext request_context;
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 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
126 URLRequestJobFactory job_factory; 125 URLRequestJobFactory job_factory;
127 request_context->set_job_factory(&job_factory); 126 TestURLRequestContext request_context;
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); 129 TestURLRequest request(GURL("http://bar"), &delegate);
130 request.set_context(request_context); 130 request.set_context(&request_context);
131 request.Start(); 131 request.Start();
132 132
133 MessageLoop::current()->Run(); 133 MessageLoop::current()->Run();
134 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 134 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
135 EXPECT_EQ(ERR_FAILED, request.status().error()); 135 EXPECT_EQ(ERR_FAILED, request.status().error());
136 } 136 }
137 137
138 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) { 138 TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) {
139 TestDelegate delegate; 139 TestDelegate delegate;
140 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
141 URLRequestJobFactory job_factory; 140 URLRequestJobFactory job_factory;
142 request_context->set_job_factory(&job_factory); 141 TestURLRequestContext request_context;
142 request_context.set_job_factory(&job_factory);
143 job_factory.AddInterceptor(new DummyInterceptor); 143 job_factory.AddInterceptor(new DummyInterceptor);
144 TestURLRequest request(GURL("foo://bar"), &delegate); 144 TestURLRequest request(GURL("foo://bar"), &delegate);
145 request.set_context(request_context); 145 request.set_context(&request_context);
146 request.Start(); 146 request.Start();
147 147
148 MessageLoop::current()->Run(); 148 MessageLoop::current()->Run();
149 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 149 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
150 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error()); 150 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
151 } 151 }
152 152
153 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) { 153 TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
154 TestDelegate delegate; 154 TestDelegate delegate;
155 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
156 URLRequestJobFactory job_factory; 155 URLRequestJobFactory job_factory;
157 request_context->set_job_factory(&job_factory); 156 TestURLRequestContext request_context;
157 request_context.set_job_factory(&job_factory);
158 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler); 158 job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
159 job_factory.AddInterceptor(new DummyInterceptor); 159 job_factory.AddInterceptor(new DummyInterceptor);
160 TestURLRequest request(GURL("foo://bar"), &delegate); 160 TestURLRequest request(GURL("foo://bar"), &delegate);
161 request.set_context(request_context); 161 request.set_context(&request_context);
162 request.Start(); 162 request.Start();
163 163
164 MessageLoop::current()->Run(); 164 MessageLoop::current()->Run();
165 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 165 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
166 EXPECT_EQ(ERR_FAILED, request.status().error()); 166 EXPECT_EQ(ERR_FAILED, request.status().error());
167 } 167 }
168 168
169 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) { 169 TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
170 TestDelegate delegate; 170 TestDelegate delegate;
171 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
172 URLRequestJobFactory job_factory; 171 URLRequestJobFactory job_factory;
173 request_context->set_job_factory(&job_factory); 172 TestURLRequestContext request_context;
173 request_context.set_job_factory(&job_factory);
174 DummyInterceptor* interceptor = new DummyInterceptor; 174 DummyInterceptor* interceptor = new DummyInterceptor;
175 job_factory.AddInterceptor(interceptor); 175 job_factory.AddInterceptor(interceptor);
176 TestURLRequest request(GURL("foo://bar"), &delegate); 176 TestURLRequest request(GURL("foo://bar"), &delegate);
177 request.set_context(request_context); 177 request.set_context(&request_context);
178 request.Start(); 178 request.Start();
179 179
180 MessageLoop::current()->Run(); 180 MessageLoop::current()->Run();
181 EXPECT_FALSE(interceptor->did_intercept_); 181 EXPECT_FALSE(interceptor->did_intercept_);
182 } 182 }
183 183
184 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) { 184 TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
185 TestDelegate delegate; 185 TestDelegate delegate;
186 scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
187 URLRequestJobFactory job_factory; 186 URLRequestJobFactory job_factory;
188 request_context->set_job_factory(&job_factory); 187 TestURLRequestContext request_context;
188 request_context.set_job_factory(&job_factory);
189 DummyInterceptor* interceptor = new DummyInterceptor; 189 DummyInterceptor* interceptor = new DummyInterceptor;
190 interceptor->handle_all_protocols_ = true; 190 interceptor->handle_all_protocols_ = true;
191 job_factory.AddInterceptor(interceptor); 191 job_factory.AddInterceptor(interceptor);
192 TestURLRequest request(GURL("foo://bar"), &delegate); 192 TestURLRequest request(GURL("foo://bar"), &delegate);
193 request.set_context(request_context); 193 request.set_context(&request_context);
194 request.Start(); 194 request.Start();
195 195
196 MessageLoop::current()->Run(); 196 MessageLoop::current()->Run();
197 EXPECT_TRUE(interceptor->did_intercept_); 197 EXPECT_TRUE(interceptor->did_intercept_);
198 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status()); 198 EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
199 EXPECT_EQ(ERR_FAILED, request.status().error()); 199 EXPECT_EQ(ERR_FAILED, request.status().error());
200 } 200 }
201 201
202 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) { 202 TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) {
203 DummyInterceptor* interceptor = new DummyInterceptor; 203 DummyInterceptor* interceptor = new DummyInterceptor;
204 URLRequestJobFactory job_factory; 204 URLRequestJobFactory job_factory;
205 job_factory.AddInterceptor(interceptor); 205 job_factory.AddInterceptor(interceptor);
206 EXPECT_FALSE(interceptor->WillHandleProtocol("anything")); 206 EXPECT_FALSE(interceptor->WillHandleProtocol("anything"));
207 EXPECT_FALSE(job_factory.IsHandledProtocol("anything")); 207 EXPECT_FALSE(job_factory.IsHandledProtocol("anything"));
208 interceptor->handle_all_protocols_ = true; 208 interceptor->handle_all_protocols_ = true;
209 EXPECT_TRUE(interceptor->WillHandleProtocol("anything")); 209 EXPECT_TRUE(interceptor->WillHandleProtocol("anything"));
210 EXPECT_TRUE(job_factory.IsHandledProtocol("anything")); 210 EXPECT_TRUE(job_factory.IsHandledProtocol("anything"));
211 } 211 }
212 212
213 } // namespace 213 } // namespace
214 214
215 } // namespace net 215 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698