OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind_helpers.h" | 5 #include "base/bind_helpers.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 : task_runner_(task_runner) {} | 98 : task_runner_(task_runner) {} |
99 URLRequestJob* MaybeCreateJob( | 99 URLRequestJob* MaybeCreateJob( |
100 URLRequest* request, | 100 URLRequest* request, |
101 NetworkDelegate* network_delegate) const override { | 101 NetworkDelegate* network_delegate) const override { |
102 if (request->url().spec() == "data:empty") | 102 if (request->url().spec() == "data:empty") |
103 return new MockSimpleJob(request, network_delegate, task_runner_, ""); | 103 return new MockSimpleJob(request, network_delegate, task_runner_, ""); |
104 return new MockSimpleJob(request, network_delegate, task_runner_, | 104 return new MockSimpleJob(request, network_delegate, task_runner_, |
105 kTestData); | 105 kTestData); |
106 } | 106 } |
107 | 107 |
| 108 ~SimpleJobProtocolHandler() override {} |
| 109 |
108 private: | 110 private: |
109 scoped_refptr<base::TaskRunner> task_runner_; | 111 scoped_refptr<base::TaskRunner> task_runner_; |
110 | |
111 ~SimpleJobProtocolHandler() override {} | |
112 }; | 112 }; |
113 | 113 |
114 class URLRequestSimpleJobTest : public ::testing::Test { | 114 class URLRequestSimpleJobTest : public ::testing::Test { |
115 public: | 115 public: |
116 URLRequestSimpleJobTest() | 116 URLRequestSimpleJobTest() |
117 : worker_pool_( | 117 : worker_pool_( |
118 new base::SequencedWorkerPool(1, "URLRequestSimpleJobTest")), | 118 new base::SequencedWorkerPool(1, "URLRequestSimpleJobTest")), |
119 task_runner_(worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior( | 119 task_runner_(worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior( |
120 worker_pool_->GetSequenceToken(), | 120 worker_pool_->GetSequenceToken(), |
121 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 121 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
122 context_(true) { | 122 context_(true) { |
123 job_factory_.SetProtocolHandler("data", | 123 job_factory_.SetProtocolHandler( |
124 new SimpleJobProtocolHandler(task_runner_)); | 124 "data", make_scoped_ptr(new SimpleJobProtocolHandler(task_runner_))); |
125 context_.set_job_factory(&job_factory_); | 125 context_.set_job_factory(&job_factory_); |
126 context_.Init(); | 126 context_.Init(); |
127 | 127 |
128 request_ = | 128 request_ = |
129 context_.CreateRequest(GURL("data:test"), DEFAULT_PRIORITY, &delegate_); | 129 context_.CreateRequest(GURL("data:test"), DEFAULT_PRIORITY, &delegate_); |
130 } | 130 } |
131 | 131 |
132 ~URLRequestSimpleJobTest() override { worker_pool_->Shutdown(); } | 132 ~URLRequestSimpleJobTest() override { worker_pool_->Shutdown(); } |
133 | 133 |
134 void StartRequest(const HttpRequestHeaders* headers) { | 134 void StartRequest(const HttpRequestHeaders* headers) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 run_loop.Run(); | 237 run_loop.Run(); |
238 | 238 |
239 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); | 239 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); |
240 EXPECT_EQ(1, cancel_delegate.response_started_count()); | 240 EXPECT_EQ(1, cancel_delegate.response_started_count()); |
241 EXPECT_EQ("", cancel_delegate.data_received()); | 241 EXPECT_EQ("", cancel_delegate.data_received()); |
242 // Destroy the request so it doesn't outlive its delegate. | 242 // Destroy the request so it doesn't outlive its delegate. |
243 request_.reset(); | 243 request_.reset(); |
244 } | 244 } |
245 | 245 |
246 } // namespace net | 246 } // namespace net |
OLD | NEW |