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.h" | 5 #include "base/bind.h" |
6 #include "base/lazy_instance.h" | 6 #include "base/lazy_instance.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/application/public/cpp/application_test_base.h" | 10 #include "mojo/application/public/cpp/application_test_base.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 status_ = READING; | 53 status_ = READING; |
54 buf_size_ = buf_size; | 54 buf_size_ = buf_size; |
55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } | 59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } |
60 | 60 |
61 void NotifyReadComplete(int bytes_read) { | 61 void NotifyReadComplete(int bytes_read) { |
62 if (bytes_read < 0) { | 62 if (bytes_read < 0) { |
63 status_ = COMPLETED; | |
64 NotifyDone(net::URLRequestStatus( | 63 NotifyDone(net::URLRequestStatus( |
65 net::URLRequestStatus::FromError(net::ERR_FAILED))); | 64 net::URLRequestStatus::FromError(net::ERR_FAILED))); |
66 net::URLRequestJob::NotifyReadComplete(0); | 65 net::URLRequestJob::NotifyReadComplete(0); |
| 66 // Set this after calling ReadRawDataComplete since that ends up calling |
| 67 // ReadRawData. |
| 68 status_ = COMPLETED; |
67 } else if (bytes_read == 0) { | 69 } else if (bytes_read == 0) { |
68 status_ = COMPLETED; | |
69 NotifyDone(net::URLRequestStatus()); | 70 NotifyDone(net::URLRequestStatus()); |
70 net::URLRequestJob::NotifyReadComplete(bytes_read); | 71 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 72 // Set this after calling ReadRawDataComplete since that ends up calling |
| 73 // ReadRawData. |
| 74 status_ = COMPLETED; |
71 } else { | 75 } else { |
72 status_ = STARTED; | |
73 SetStatus(net::URLRequestStatus()); | 76 SetStatus(net::URLRequestStatus()); |
74 net::URLRequestJob::NotifyReadComplete(bytes_read); | 77 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 78 // Set this after calling ReadRawDataComplete since that ends up calling |
| 79 // ReadRawData. |
| 80 status_ = STARTED; |
75 } | 81 } |
76 } | 82 } |
77 | 83 |
78 private: | 84 private: |
79 ~TestURLRequestJob() override { | 85 ~TestURLRequestJob() override { |
80 CHECK(g_current_job == this); | 86 CHECK(g_current_job == this); |
81 g_current_job = nullptr; | 87 g_current_job = nullptr; |
82 } | 88 } |
83 | 89 |
84 Status status_; | 90 Status status_; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 282 |
277 EXPECT_TRUE(IsUrlLoaderValid()); | 283 EXPECT_TRUE(IsUrlLoaderValid()); |
278 | 284 |
279 g_current_job->NotifyReadComplete(-1); | 285 g_current_job->NotifyReadComplete(-1); |
280 | 286 |
281 while (IsUrlLoaderValid()) | 287 while (IsUrlLoaderValid()) |
282 base::RunLoop().RunUntilIdle(); | 288 base::RunLoop().RunUntilIdle(); |
283 } | 289 } |
284 | 290 |
285 } // namespace mojo | 291 } // namespace mojo |
OLD | NEW |