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

Unified Diff: net/url_request/url_request_job_factory_unittest.cc

Issue 7056003: Give URLRequestJobFactory::Interceptors the ability to specify protocols they handle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_job_factory.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_job_factory_unittest.cc
diff --git a/net/url_request/url_request_job_factory_unittest.cc b/net/url_request/url_request_job_factory_unittest.cc
index 46c952cf03baa3a847c09ba0347e0528956f98eb..33c5456a74b8d3658b2511048fa9bdb243ed82d1 100644
--- a/net/url_request/url_request_job_factory_unittest.cc
+++ b/net/url_request/url_request_job_factory_unittest.cc
@@ -48,7 +48,12 @@ class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
class DummyInterceptor : public URLRequestJobFactory::Interceptor {
public:
+ DummyInterceptor()
+ : did_intercept_(false),
+ handle_all_protocols_(false) { }
+
virtual URLRequestJob* MaybeIntercept(URLRequest* request) const {
+ did_intercept_ = true;
return new MockURLRequestJob(
request,
URLRequestStatus(URLRequestStatus::FAILED, ERR_FAILED));
@@ -64,6 +69,14 @@ class DummyInterceptor : public URLRequestJobFactory::Interceptor {
URLRequest* /* request */) const {
return NULL;
}
+
+ virtual bool WillHandleProtocol(
+ const std::string& /* protocol */) const {
+ return handle_all_protocols_;
+ }
+
+ mutable bool did_intercept_;
+ mutable bool handle_all_protocols_;
};
TEST(URLRequestJobFactoryTest, NoProtocolHandler) {
@@ -147,6 +160,50 @@ TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
EXPECT_EQ(ERR_FAILED, request.status().os_error());
}
+TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
+ TestDelegate delegate;
+ scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
+ URLRequestJobFactory job_factory;
+ request_context->set_job_factory(&job_factory);
+ DummyInterceptor* interceptor = new DummyInterceptor;
oshima 2011/05/25 22:45:23 This seems to be leaking. I also wonder if "new Du
willchan no longer on Chromium 2011/05/25 22:53:56 Yes, that's correct. We should fix this.
koz (OOO until 15th September) 2011/05/25 22:54:58 Yep, fixing now.
+ job_factory.AddInterceptor(new DummyInterceptor);
+ TestURLRequest request(GURL("foo://bar"), &delegate);
+ request.set_context(request_context);
+ request.Start();
+
+ MessageLoop::current()->Run();
+ EXPECT_FALSE(interceptor->did_intercept_);
+}
+
+TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
+ TestDelegate delegate;
+ scoped_refptr<URLRequestContext> request_context(new TestURLRequestContext);
+ URLRequestJobFactory job_factory;
+ request_context->set_job_factory(&job_factory);
+ DummyInterceptor* interceptor = new DummyInterceptor;
+ interceptor->handle_all_protocols_ = true;
+ job_factory.AddInterceptor(interceptor);
+ TestURLRequest request(GURL("foo://bar"), &delegate);
+ request.set_context(request_context);
+ request.Start();
+
+ MessageLoop::current()->Run();
+ EXPECT_TRUE(interceptor->did_intercept_);
+ EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
+ EXPECT_EQ(ERR_FAILED, request.status().os_error());
+}
+
+TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) {
+ DummyInterceptor* interceptor = new DummyInterceptor;
+ URLRequestJobFactory job_factory;
+ job_factory.AddInterceptor(interceptor);
+ EXPECT_FALSE(interceptor->WillHandleProtocol("anything"));
+ EXPECT_FALSE(job_factory.IsHandledProtocol("anything"));
+ interceptor->handle_all_protocols_ = true;
+ EXPECT_TRUE(interceptor->WillHandleProtocol("anything"));
+ EXPECT_TRUE(job_factory.IsHandledProtocol("anything"));
+}
+
} // namespace
} // namespace net
« no previous file with comments | « net/url_request/url_request_job_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698