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 "net/url_request/url_request_simple_job.h" | 5 #include "net/url_request/url_request_simple_job.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/test/sequenced_worker_pool_owner.h" | 14 #include "base/test/sequenced_worker_pool_owner.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.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_job.h" | 18 #include "net/url_request/url_request_job.h" |
18 #include "net/url_request/url_request_job_factory.h" | 19 #include "net/url_request/url_request_job_factory.h" |
19 #include "net/url_request/url_request_job_factory_impl.h" | 20 #include "net/url_request/url_request_job_factory_impl.h" |
20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
22 | 24 |
| 25 using net::test::IsError; |
| 26 using net::test::IsOk; |
| 27 |
23 namespace net { | 28 namespace net { |
24 | 29 |
25 namespace { | 30 namespace { |
26 | 31 |
27 const char kTestData[] = "Huge data array"; | 32 const char kTestData[] = "Huge data array"; |
28 const int kRangeFirstPosition = 5; | 33 const int kRangeFirstPosition = 5; |
29 const int kRangeLastPosition = 8; | 34 const int kRangeLastPosition = 8; |
30 static_assert(kRangeFirstPosition > 0 && | 35 static_assert(kRangeFirstPosition > 0 && |
31 kRangeFirstPosition < kRangeLastPosition && | 36 kRangeFirstPosition < kRangeLastPosition && |
32 kRangeLastPosition < | 37 kRangeLastPosition < |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 std::string range = base::StringPrintf("bytes=%d-%d,%d-%d", | 187 std::string range = base::StringPrintf("bytes=%d-%d,%d-%d", |
183 kRangeFirstPosition, | 188 kRangeFirstPosition, |
184 middle_pos, | 189 middle_pos, |
185 middle_pos + 1, | 190 middle_pos + 1, |
186 kRangeLastPosition); | 191 kRangeLastPosition); |
187 headers.SetHeader(HttpRequestHeaders::kRange, range); | 192 headers.SetHeader(HttpRequestHeaders::kRange, range); |
188 | 193 |
189 StartRequest(&headers); | 194 StartRequest(&headers); |
190 | 195 |
191 EXPECT_TRUE(delegate_.request_failed()); | 196 EXPECT_TRUE(delegate_.request_failed()); |
192 EXPECT_EQ(ERR_REQUEST_RANGE_NOT_SATISFIABLE, request_->status().error()); | 197 EXPECT_THAT(request_->status().error(), |
| 198 IsError(ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
193 } | 199 } |
194 | 200 |
195 TEST_F(URLRequestSimpleJobTest, InvalidRangeRequest) { | 201 TEST_F(URLRequestSimpleJobTest, InvalidRangeRequest) { |
196 HttpRequestHeaders headers; | 202 HttpRequestHeaders headers; |
197 std::string range = base::StringPrintf( | 203 std::string range = base::StringPrintf( |
198 "bytes=%d-%d", kRangeLastPosition, kRangeFirstPosition); | 204 "bytes=%d-%d", kRangeLastPosition, kRangeFirstPosition); |
199 headers.SetHeader(HttpRequestHeaders::kRange, range); | 205 headers.SetHeader(HttpRequestHeaders::kRange, range); |
200 | 206 |
201 StartRequest(&headers); | 207 StartRequest(&headers); |
202 | 208 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 run_loop.Run(); | 244 run_loop.Run(); |
239 | 245 |
240 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); | 246 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); |
241 EXPECT_EQ(1, cancel_delegate.response_started_count()); | 247 EXPECT_EQ(1, cancel_delegate.response_started_count()); |
242 EXPECT_EQ("", cancel_delegate.data_received()); | 248 EXPECT_EQ("", cancel_delegate.data_received()); |
243 // Destroy the request so it doesn't outlive its delegate. | 249 // Destroy the request so it doesn't outlive its delegate. |
244 request_.reset(); | 250 request_.reset(); |
245 } | 251 } |
246 | 252 |
247 } // namespace net | 253 } // namespace net |
OLD | NEW |