| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/loader/mock_resource_loader.h" | 5 #include "content/browser/loader/mock_resource_loader.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // behavior. If |resource_handler_| wants to use |response| asynchronously, it | 86 // behavior. If |resource_handler_| wants to use |response| asynchronously, it |
| 87 // needs to hold onto its own pointer to it. | 87 // needs to hold onto its own pointer to it. |
| 88 resource_handler_->OnResponseStarted( | 88 resource_handler_->OnResponseStarted( |
| 89 response.get(), | 89 response.get(), |
| 90 base::MakeUnique<TestResourceController>(weak_factory_.GetWeakPtr())); | 90 base::MakeUnique<TestResourceController>(weak_factory_.GetWeakPtr())); |
| 91 if (status_ == Status::CALLING_HANDLER) | 91 if (status_ == Status::CALLING_HANDLER) |
| 92 status_ = Status::CALLBACK_PENDING; | 92 status_ = Status::CALLBACK_PENDING; |
| 93 return status_; | 93 return status_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 MockResourceLoader::Status MockResourceLoader::OnWillRead(int min_size) { | 96 MockResourceLoader::Status MockResourceLoader::OnWillRead() { |
| 97 EXPECT_FALSE(weak_factory_.HasWeakPtrs()); | 97 EXPECT_FALSE(weak_factory_.HasWeakPtrs()); |
| 98 EXPECT_EQ(Status::IDLE, status_); | 98 EXPECT_EQ(Status::IDLE, status_); |
| 99 | 99 |
| 100 status_ = Status::CALLING_HANDLER; | 100 status_ = Status::CALLING_HANDLER; |
| 101 bool result = | 101 bool result = |
| 102 resource_handler_->OnWillRead(&io_buffer_, &io_buffer_size_, min_size); | 102 resource_handler_->OnWillRead(&io_buffer_, &io_buffer_size_); |
| 103 | 103 |
| 104 // The second case isn't really allowed, but a number of classes do it | 104 // The second case isn't really allowed, but a number of classes do it |
| 105 // anyways. | 105 // anyways. |
| 106 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || | 106 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || |
| 107 (result == false && status_ == Status::CANCELED)); | 107 (result == false && status_ == Status::CANCELED)); |
| 108 if (!result) { | 108 if (!result) { |
| 109 // In the case of double-cancels, keep the old error code. | 109 // In the case of double-cancels, keep the old error code. |
| 110 if (status_ != Status::CANCELED) | 110 if (status_ != Status::CANCELED) |
| 111 error_code_ = net::ERR_ABORTED; | 111 error_code_ = net::ERR_ABORTED; |
| 112 EXPECT_EQ(0, io_buffer_size_); | 112 EXPECT_EQ(0, io_buffer_size_); |
| 113 EXPECT_FALSE(io_buffer_); | 113 EXPECT_FALSE(io_buffer_); |
| 114 status_ = Status::CANCELED; | 114 status_ = Status::CANCELED; |
| 115 } else { | 115 } else { |
| 116 EXPECT_LE(min_size, io_buffer_size_); | |
| 117 EXPECT_LT(0, io_buffer_size_); | 116 EXPECT_LT(0, io_buffer_size_); |
| 118 EXPECT_TRUE(io_buffer_); | 117 EXPECT_TRUE(io_buffer_); |
| 119 status_ = Status::IDLE; | 118 status_ = Status::IDLE; |
| 120 } | 119 } |
| 121 return status_; | 120 return status_; |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 MockResourceLoader::Status MockResourceLoader::OnReadCompleted( | 123 MockResourceLoader::Status MockResourceLoader::OnReadCompleted( |
| 125 base::StringPiece bytes) { | 124 base::StringPiece bytes) { |
| 126 EXPECT_FALSE(weak_factory_.HasWeakPtrs()); | 125 EXPECT_FALSE(weak_factory_.HasWeakPtrs()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void MockResourceLoader::OnResume() { | 224 void MockResourceLoader::OnResume() { |
| 226 EXPECT_TRUE(status_ == Status::CALLBACK_PENDING || | 225 EXPECT_TRUE(status_ == Status::CALLBACK_PENDING || |
| 227 status_ == Status::CALLING_HANDLER); | 226 status_ == Status::CALLING_HANDLER); |
| 228 | 227 |
| 229 status_ = Status::IDLE; | 228 status_ = Status::IDLE; |
| 230 if (canceled_or_idle_run_loop_) | 229 if (canceled_or_idle_run_loop_) |
| 231 canceled_or_idle_run_loop_->Quit(); | 230 canceled_or_idle_run_loop_->Quit(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 } // namespace content | 233 } // namespace content |
| OLD | NEW |