Index: content/browser/loader/mock_resource_loader.cc |
diff --git a/content/browser/loader/mock_resource_loader.cc b/content/browser/loader/mock_resource_loader.cc |
index c47403db6be140cdc6931ce9efd1f855006f6536..7a9269253affe8d1491b74a2398674abef24eadc 100644 |
--- a/content/browser/loader/mock_resource_loader.cc |
+++ b/content/browser/loader/mock_resource_loader.cc |
@@ -10,7 +10,6 @@ |
#include "base/memory/ref_counted.h" |
#include "content/browser/loader/resource_controller.h" |
#include "content/browser/loader/resource_handler.h" |
-#include "net/base/io_buffer.h" |
#include "net/url_request/url_request_status.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -89,30 +88,43 @@ MockResourceLoader::Status MockResourceLoader::OnResponseStarted( |
MockResourceLoader::Status MockResourceLoader::OnWillRead(int min_size) { |
EXPECT_EQ(Status::IDLE, status_); |
+ EXPECT_FALSE(io_buffer_); |
+ EXPECT_EQ(0, io_buffer_size_); |
+ |
status_ = Status::CALLING_HANDLER; |
- scoped_refptr<net::IOBuffer> buf; |
- int buf_size; |
- bool result = resource_handler_->OnWillRead(&buf, &buf_size, min_size); |
+ bool result = |
+ resource_handler_->OnWillRead(&io_buffer_, &io_buffer_size_, min_size); |
// The second case isn't really allowed, but a number of classes do it |
// anyways. |
EXPECT_TRUE(status_ == Status::CALLING_HANDLER || |
(result == false && status_ == Status::CANCELED)); |
if (!result) { |
+ EXPECT_EQ(0, io_buffer_size_); |
+ EXPECT_FALSE(io_buffer_); |
status_ = Status::CANCELED; |
} else { |
- EXPECT_LE(min_size, buf_size); |
+ EXPECT_LE(min_size, io_buffer_size_); |
+ EXPECT_LT(0, io_buffer_size_); |
+ EXPECT_TRUE(io_buffer_); |
status_ = Status::IDLE; |
} |
return status_; |
}; |
-MockResourceLoader::Status MockResourceLoader::OnReadCompleted(int bytes_read) { |
+MockResourceLoader::Status MockResourceLoader::OnReadCompleted( |
+ base::StringPiece bytes) { |
EXPECT_EQ(Status::IDLE, status_); |
+ EXPECT_LE(bytes.size(), io_buffer_size_); |
+ |
+ status_ = Status::CALLING_HANDLER; |
+ std::copy(bytes.begin(), bytes.end(), io_buffer_->data()); |
+ io_buffer_ = nullptr; |
+ io_buffer_size_ = 0; |
status_ = Status::CALLING_HANDLER; |
bool defer = false; |
- bool result = resource_handler_->OnReadCompleted(bytes_read, &defer); |
+ bool result = resource_handler_->OnReadCompleted(bytes.size(), &defer); |
// The second case isn't really allowed, but a number of classes do it |
// anyways. |
EXPECT_TRUE(status_ == Status::CALLING_HANDLER || |
@@ -148,6 +160,39 @@ MockResourceLoader::Status MockResourceLoader::OnResponseCompleted( |
return status_; |
} |
+MockResourceLoader::Status |
+MockResourceLoader::OnResponseCompletedFromExternalOutOfBandCancel( |
+ const net::URLRequestStatus& status) { |
Randy Smith (Not in Mondays)
2016/12/21 16:47:37
nit, suggestion: This routine (and possibly other
mmenke
2017/01/05 18:50:25
Done.
|
+ // This can happen at any point, except from a recursive call from |
+ // ResourceHandler. |
+ EXPECT_NE(Status::CALLING_HANDLER, status_); |
+ |
+ status_ = Status::CALLING_HANDLER; |
+ |
+ bool defer = false; |
+ resource_handler_->OnResponseCompleted(status, &defer); |
+ EXPECT_EQ(Status::CALLING_HANDLER, status_); |
+ if (defer) { |
+ status_ = Status::CALLBACK_PENDING; |
+ } else { |
+ status_ = Status::IDLE; |
+ } |
+ return status_; |
+} |
+ |
+void MockResourceLoader::WaitUntilIdleOrCanceled() { |
+ if (status_ != Status::IDLE && status_ != Status::CANCELED) { |
+ EXPECT_FALSE(canceled_or_idle_run_loop_); |
+ canceled_or_idle_run_loop_.reset(new base::RunLoop()); |
+ canceled_or_idle_run_loop_->Run(); |
+ EXPECT_TRUE(status_ == Status::IDLE || status_ == Status::CANCELED); |
+ } |
+} |
+ |
+void MockResourceLoader::ReleaseIOBuffer() { |
Randy Smith (Not in Mondays)
2016/12/21 16:47:37
Is there a reason this can't be done automatically
mmenke
2017/01/05 18:50:25
MojoAsyncResourceHandlerTest.IOBufferFromOnWillRea
Randy Smith (Not in Mondays)
2017/01/10 23:07:47
If I understand this use case correctly, it could
|
+ io_buffer_ = nullptr; |
+} |
+ |
void MockResourceLoader::Cancel() { |
CancelWithError(net::ERR_ABORTED); |
} |
@@ -171,11 +216,15 @@ void MockResourceLoader::CancelWithError(int error_code) { |
status_ == Status::CALLING_HANDLER || status_ == Status::IDLE); |
status_ = Status::CANCELED; |
error_code_ = error_code; |
+ if (canceled_or_idle_run_loop_) |
+ canceled_or_idle_run_loop_->Quit(); |
} |
void MockResourceLoader::Resume() { |
EXPECT_EQ(Status::CALLBACK_PENDING, status_); |
status_ = Status::IDLE; |
+ if (canceled_or_idle_run_loop_) |
+ canceled_or_idle_run_loop_->Quit(); |
} |
} // namespace content |