| 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" |
| 11 #include "mojo/common/message_pump_mojo.h" | 11 #include "mojo/common/message_pump_mojo.h" |
| 12 #include "mojo/services/network/network_context.h" | 12 #include "mojo/services/network/network_context.h" |
| 13 #include "mojo/services/network/url_loader_impl.h" | 13 #include "mojo/services/network/url_loader_impl.h" |
| 14 #include "net/base/net_errors.h" |
| 14 #include "net/url_request/url_request_job.h" | 15 #include "net/url_request/url_request_job.h" |
| 15 #include "net/url_request/url_request_job_factory_impl.h" | 16 #include "net/url_request/url_request_job_factory_impl.h" |
| 17 #include "net/url_request/url_request_status.h" |
| 16 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 20 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
| 19 | 21 |
| 20 namespace mojo { | 22 namespace mojo { |
| 21 | 23 |
| 22 class TestURLRequestJob; | 24 class TestURLRequestJob; |
| 23 | 25 |
| 24 TestURLRequestJob* g_current_job = nullptr; | 26 TestURLRequestJob* g_current_job = nullptr; |
| 25 | 27 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 buf_size_ = buf_size; | 54 buf_size_ = buf_size; |
| 53 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 54 return false; | 56 return false; |
| 55 } | 57 } |
| 56 | 58 |
| 57 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } | 59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } |
| 58 | 60 |
| 59 void NotifyReadComplete(int bytes_read) { | 61 void NotifyReadComplete(int bytes_read) { |
| 60 if (bytes_read < 0) { | 62 if (bytes_read < 0) { |
| 61 status_ = COMPLETED; | 63 status_ = COMPLETED; |
| 62 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, 0)); | 64 NotifyDone(net::URLRequestStatus( |
| 65 net::URLRequestStatus::FromError(net::ERR_FAILED))); |
| 63 net::URLRequestJob::NotifyReadComplete(0); | 66 net::URLRequestJob::NotifyReadComplete(0); |
| 64 } else if (bytes_read == 0) { | 67 } else if (bytes_read == 0) { |
| 65 status_ = COMPLETED; | 68 status_ = COMPLETED; |
| 66 NotifyDone(net::URLRequestStatus()); | 69 NotifyDone(net::URLRequestStatus()); |
| 67 net::URLRequestJob::NotifyReadComplete(bytes_read); | 70 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 68 } else { | 71 } else { |
| 69 status_ = STARTED; | 72 status_ = STARTED; |
| 70 SetStatus(net::URLRequestStatus()); | 73 SetStatus(net::URLRequestStatus()); |
| 71 net::URLRequestJob::NotifyReadComplete(bytes_read); | 74 net::URLRequestJob::NotifyReadComplete(bytes_read); |
| 72 } | 75 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 266 |
| 264 EXPECT_TRUE(IsUrlLoaderValid()); | 267 EXPECT_TRUE(IsUrlLoaderValid()); |
| 265 | 268 |
| 266 g_current_job->NotifyReadComplete(-1); | 269 g_current_job->NotifyReadComplete(-1); |
| 267 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
| 268 | 271 |
| 269 EXPECT_FALSE(IsUrlLoaderValid()); | 272 EXPECT_FALSE(IsUrlLoaderValid()); |
| 270 } | 273 } |
| 271 | 274 |
| 272 } // namespace mojo | 275 } // namespace mojo |
| OLD | NEW |