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

Unified 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: Latest merge 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_job_factory_impl_unittest.cc ('k') | net/url_request/url_request_test_util.cc » ('j') | 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
deleted file mode 100644
index 673e007add3d46e24bf174b2c71a69b8ced57c38..0000000000000000000000000000000000000000
--- a/net/url_request/url_request_job_factory_unittest.cc
+++ /dev/null
@@ -1,218 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/url_request/url_request_job_factory.h"
-
-#include "base/bind.h"
-#include "base/memory/weak_ptr.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_test_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-
-namespace {
-
-class MockURLRequestJob : public URLRequestJob {
- public:
- MockURLRequestJob(URLRequest* request,
- NetworkDelegate* network_delegate,
- const URLRequestStatus& status)
- : URLRequestJob(request, network_delegate),
- status_(status),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
-
- virtual void Start() OVERRIDE {
- // Start reading asynchronously so that all error reporting and data
- // callbacks happen as they would for network requests.
- MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&MockURLRequestJob::StartAsync,
- weak_factory_.GetWeakPtr()));
- }
-
- protected:
- virtual ~MockURLRequestJob() {}
-
- private:
- void StartAsync() {
- SetStatus(status_);
- NotifyHeadersComplete();
- }
-
- URLRequestStatus status_;
- base::WeakPtrFactory<MockURLRequestJob> weak_factory_;
-};
-
-class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
- public:
- virtual URLRequestJob* MaybeCreateJob(
- URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE {
- return new MockURLRequestJob(
- request,
- network_delegate,
- URLRequestStatus(URLRequestStatus::SUCCESS, OK));
- }
-};
-
-class DummyInterceptor : public URLRequestJobFactory::Interceptor {
- public:
- DummyInterceptor()
- : did_intercept_(false),
- handle_all_protocols_(false) {
- }
-
- virtual URLRequestJob* MaybeIntercept(
- URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE {
- did_intercept_ = true;
- return new MockURLRequestJob(
- request,
- network_delegate,
- URLRequestStatus(URLRequestStatus::FAILED, ERR_FAILED));
- }
-
- virtual URLRequestJob* MaybeInterceptRedirect(
- const GURL& /* location */,
- URLRequest* /* request */,
- NetworkDelegate* network_delegate /* network delegate */) const OVERRIDE {
- return NULL;
- }
-
- virtual URLRequestJob* MaybeInterceptResponse(
- URLRequest* /* request */,
- NetworkDelegate* network_delegate /* network delegate */) const OVERRIDE {
- return NULL;
- }
-
- virtual bool WillHandleProtocol(
- const std::string& /* protocol */) const OVERRIDE {
- return handle_all_protocols_;
- }
-
- mutable bool did_intercept_;
- mutable bool handle_all_protocols_;
-};
-
-TEST(URLRequestJobFactoryTest, NoProtocolHandler) {
- TestDelegate delegate;
- TestURLRequestContext request_context;
- TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
- EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
-}
-
-TEST(URLRequestJobFactoryTest, BasicProtocolHandler) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
- TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status());
- EXPECT_EQ(OK, request.status().error());
-}
-
-TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) {
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
- job_factory.SetProtocolHandler("foo", NULL);
-}
-
-TEST(URLRequestJobFactoryTest, BasicInterceptor) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- job_factory.AddInterceptor(new DummyInterceptor);
- TestURLRequest request(GURL("http://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
- EXPECT_EQ(ERR_FAILED, request.status().error());
-}
-
-TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- job_factory.AddInterceptor(new DummyInterceptor);
- TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
- EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
-}
-
-TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
- job_factory.AddInterceptor(new DummyInterceptor);
- TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
- EXPECT_EQ(ERR_FAILED, request.status().error());
-}
-
-TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- request_context.set_job_factory(&job_factory);
- DummyInterceptor* interceptor = new DummyInterceptor;
- job_factory.AddInterceptor(interceptor);
- TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_FALSE(interceptor->did_intercept_);
-}
-
-TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
- TestDelegate delegate;
- URLRequestJobFactory job_factory;
- TestURLRequestContext request_context;
- 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_context);
- request.Start();
-
- MessageLoop::current()->Run();
- EXPECT_TRUE(interceptor->did_intercept_);
- EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
- EXPECT_EQ(ERR_FAILED, request.status().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_impl_unittest.cc ('k') | net/url_request/url_request_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698