| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 CHECK(!g_current_job); | 42 CHECK(!g_current_job); |
| 43 g_current_job = this; | 43 g_current_job = this; |
| 44 } | 44 } |
| 45 | 45 |
| 46 Status status() { return status_; } | 46 Status status() { return status_; } |
| 47 | 47 |
| 48 int buf_size() { return buf_size_; } | 48 int buf_size() { return buf_size_; } |
| 49 | 49 |
| 50 void Start() override { status_ = STARTED; } | 50 void Start() override { status_ = STARTED; } |
| 51 | 51 |
| 52 int ReadRawData(net::IOBuffer* buf, int buf_size) override { | 52 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { |
| 53 status_ = READING; | 53 status_ = READING; |
| 54 buf_size_ = buf_size; | 54 buf_size_ = buf_size; |
| 55 return net::ERR_IO_PENDING; | 55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 56 return false; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } | 59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } |
| 59 | 60 |
| 60 void NotifyReadComplete(int result) { | 61 void NotifyReadComplete(int bytes_read) { |
| 61 // Map errors to net::ERR_FAILED. | 62 if (bytes_read < 0) { |
| 62 if (result < 0) | 63 status_ = COMPLETED; |
| 63 result = net::ERR_FAILED; | 64 NotifyDone(net::URLRequestStatus( |
| 64 | 65 net::URLRequestStatus::FromError(net::ERR_FAILED))); |
| 65 ReadRawDataComplete(result); | 66 net::URLRequestJob::NotifyReadComplete(0); |
| 66 // Set this after calling ReadRawDataComplete since that ends up calling | 67 } else if (bytes_read == 0) { |
| 67 // ReadRawData. | 68 status_ = COMPLETED; |
| 68 status_ = result <= 0 ? COMPLETED : STARTED; | 69 NotifyDone(net::URLRequestStatus()); |
| 70 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 71 } else { |
| 72 status_ = STARTED; |
| 73 SetStatus(net::URLRequestStatus()); |
| 74 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 75 } |
| 69 } | 76 } |
| 70 | 77 |
| 71 private: | 78 private: |
| 72 ~TestURLRequestJob() override { | 79 ~TestURLRequestJob() override { |
| 73 CHECK(g_current_job == this); | 80 CHECK(g_current_job == this); |
| 74 g_current_job = nullptr; | 81 g_current_job = nullptr; |
| 75 } | 82 } |
| 76 | 83 |
| 77 Status status_; | 84 Status status_; |
| 78 int buf_size_; | 85 int buf_size_; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 276 |
| 270 EXPECT_TRUE(IsUrlLoaderValid()); | 277 EXPECT_TRUE(IsUrlLoaderValid()); |
| 271 | 278 |
| 272 g_current_job->NotifyReadComplete(-1); | 279 g_current_job->NotifyReadComplete(-1); |
| 273 | 280 |
| 274 while (IsUrlLoaderValid()) | 281 while (IsUrlLoaderValid()) |
| 275 base::RunLoop().RunUntilIdle(); | 282 base::RunLoop().RunUntilIdle(); |
| 276 } | 283 } |
| 277 | 284 |
| 278 } // namespace mojo | 285 } // namespace mojo |
| OLD | NEW |