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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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_impl.h" 5 #include "net/url_request/url_request_job_factory_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "net/base/request_priority.h" 16 #include "net/base/request_priority.h"
17 #include "net/test/gtest_util.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_job.h" 19 #include "net/url_request/url_request_job.h"
19 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
24 using net::test::IsError;
25 using net::test::IsOk;
26
22 namespace net { 27 namespace net {
23 28
24 namespace { 29 namespace {
25 30
26 class MockURLRequestJob : public URLRequestJob { 31 class MockURLRequestJob : public URLRequestJob {
27 public: 32 public:
28 MockURLRequestJob(URLRequest* request, NetworkDelegate* network_delegate) 33 MockURLRequestJob(URLRequest* request, NetworkDelegate* network_delegate)
29 : URLRequestJob(request, network_delegate), weak_factory_(this) {} 34 : URLRequestJob(request, network_delegate), weak_factory_(this) {}
30 35
31 void Start() override { 36 void Start() override {
(...skipping 26 matching lines...) Expand all
58 63
59 TEST(URLRequestJobFactoryTest, NoProtocolHandler) { 64 TEST(URLRequestJobFactoryTest, NoProtocolHandler) {
60 TestDelegate delegate; 65 TestDelegate delegate;
61 TestURLRequestContext request_context; 66 TestURLRequestContext request_context;
62 std::unique_ptr<URLRequest> request(request_context.CreateRequest( 67 std::unique_ptr<URLRequest> request(request_context.CreateRequest(
63 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate)); 68 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate));
64 request->Start(); 69 request->Start();
65 70
66 base::RunLoop().Run(); 71 base::RunLoop().Run();
67 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); 72 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status());
68 EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request->status().error()); 73 EXPECT_THAT(request->status().error(), IsError(ERR_UNKNOWN_URL_SCHEME));
69 } 74 }
70 75
71 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) { 76 TEST(URLRequestJobFactoryTest, BasicProtocolHandler) {
72 TestDelegate delegate; 77 TestDelegate delegate;
73 URLRequestJobFactoryImpl job_factory; 78 URLRequestJobFactoryImpl job_factory;
74 TestURLRequestContext request_context; 79 TestURLRequestContext request_context;
75 request_context.set_job_factory(&job_factory); 80 request_context.set_job_factory(&job_factory);
76 job_factory.SetProtocolHandler("foo", 81 job_factory.SetProtocolHandler("foo",
77 base::WrapUnique(new DummyProtocolHandler)); 82 base::WrapUnique(new DummyProtocolHandler));
78 std::unique_ptr<URLRequest> request(request_context.CreateRequest( 83 std::unique_ptr<URLRequest> request(request_context.CreateRequest(
79 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate)); 84 GURL("foo://bar"), DEFAULT_PRIORITY, &delegate));
80 request->Start(); 85 request->Start();
81 86
82 base::RunLoop().Run(); 87 base::RunLoop().Run();
83 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); 88 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status());
84 EXPECT_EQ(OK, request->status().error()); 89 EXPECT_THAT(request->status().error(), IsOk());
85 } 90 }
86 91
87 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { 92 TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) {
88 URLRequestJobFactoryImpl job_factory; 93 URLRequestJobFactoryImpl job_factory;
89 TestURLRequestContext request_context; 94 TestURLRequestContext request_context;
90 request_context.set_job_factory(&job_factory); 95 request_context.set_job_factory(&job_factory);
91 job_factory.SetProtocolHandler("foo", 96 job_factory.SetProtocolHandler("foo",
92 base::WrapUnique(new DummyProtocolHandler)); 97 base::WrapUnique(new DummyProtocolHandler));
93 job_factory.SetProtocolHandler("foo", nullptr); 98 job_factory.SetProtocolHandler("foo", nullptr);
94 } 99 }
95 100
96 } // namespace 101 } // namespace
97 102
98 } // namespace net 103 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job_unittest.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