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" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(MockSimpleJob); | 74 DISALLOW_COPY_AND_ASSIGN(MockSimpleJob); |
75 }; | 75 }; |
76 | 76 |
77 class CancelAfterFirstReadURLRequestDelegate : public TestDelegate { | 77 class CancelAfterFirstReadURLRequestDelegate : public TestDelegate { |
78 public: | 78 public: |
79 CancelAfterFirstReadURLRequestDelegate() : run_loop_(new base::RunLoop) {} | 79 CancelAfterFirstReadURLRequestDelegate() : run_loop_(new base::RunLoop) {} |
80 | 80 |
81 ~CancelAfterFirstReadURLRequestDelegate() override {} | 81 ~CancelAfterFirstReadURLRequestDelegate() override {} |
82 | 82 |
83 void OnResponseStarted(URLRequest* request) override { | 83 void OnResponseStarted(URLRequest* request, int net_error) override { |
| 84 DCHECK_NE(ERR_IO_PENDING, net_error); |
84 // net::TestDelegate will start the first read. | 85 // net::TestDelegate will start the first read. |
85 TestDelegate::OnResponseStarted(request); | 86 TestDelegate::OnResponseStarted(request, net_error); |
86 request->Cancel(); | 87 request->Cancel(); |
87 run_loop_->Quit(); | 88 run_loop_->Quit(); |
88 } | 89 } |
89 | 90 |
90 void OnReadCompleted(URLRequest* request, int bytes_read) override { | 91 void OnReadCompleted(URLRequest* request, int bytes_read) override { |
91 // Read should have been cancelled. | 92 // Read should have been cancelled. |
92 EXPECT_EQ(-1, bytes_read); | 93 EXPECT_EQ(ERR_ABORTED, bytes_read); |
93 } | 94 } |
94 | 95 |
95 void WaitUntilHeadersReceived() const { run_loop_->Run(); } | 96 void WaitUntilHeadersReceived() const { run_loop_->Run(); } |
96 | 97 |
97 private: | 98 private: |
98 std::unique_ptr<base::RunLoop> run_loop_; | 99 std::unique_ptr<base::RunLoop> run_loop_; |
99 | 100 |
100 DISALLOW_COPY_AND_ASSIGN(CancelAfterFirstReadURLRequestDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(CancelAfterFirstReadURLRequestDelegate); |
101 }; | 102 }; |
102 | 103 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 run_loop.Run(); | 245 run_loop.Run(); |
245 | 246 |
246 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); | 247 EXPECT_EQ(URLRequestStatus::CANCELED, request_->status().status()); |
247 EXPECT_EQ(1, cancel_delegate.response_started_count()); | 248 EXPECT_EQ(1, cancel_delegate.response_started_count()); |
248 EXPECT_EQ("", cancel_delegate.data_received()); | 249 EXPECT_EQ("", cancel_delegate.data_received()); |
249 // Destroy the request so it doesn't outlive its delegate. | 250 // Destroy the request so it doesn't outlive its delegate. |
250 request_.reset(); | 251 request_.reset(); |
251 } | 252 } |
252 | 253 |
253 } // namespace net | 254 } // namespace net |
OLD | NEW |