| Index: content/browser/loader/intercepting_resource_handler_unittest.cc
|
| diff --git a/content/browser/loader/intercepting_resource_handler_unittest.cc b/content/browser/loader/intercepting_resource_handler_unittest.cc
|
| index 8d8dee1ead39e403f6c1a69e668931d3f260cab0..50da6d891753568cb06fd58378d7faf160555669 100644
|
| --- a/content/browser/loader/intercepting_resource_handler_unittest.cc
|
| +++ b/content/browser/loader/intercepting_resource_handler_unittest.cc
|
| @@ -87,19 +87,22 @@ TEST_F(InterceptingResourceHandlerTest, NoSwitching) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_handler_->buffer());
|
|
|
| // The response is received. The handler should not change.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnResponseStarted(
|
| make_scoped_refptr(new ResourceResponse())));
|
|
|
| - // The read is replayed by the MimeSniffingResourceHandler. The data should
|
| - // have been received by the old intercepting_handler.
|
| + // The OnWillRead and OnReadCompleted are replayed by the
|
| + // MimeSniffingResourceHandler. No buffering is done by the
|
| + // InterceptingResourceHandler, so the buffer used should be from
|
| + // the old handling.
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| + ASSERT_EQ(mock_loader_->io_buffer(), old_handler_->buffer());
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnReadCompleted(kData));
|
| +
|
| + // The data should be received by the original handler.
|
| EXPECT_EQ(kData, old_handler_body_);
|
|
|
| // Make sure another read behaves as expected.
|
| @@ -120,9 +123,6 @@ TEST_F(InterceptingResourceHandlerTest, HandlerSwitchNoPayload) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_handler_->buffer());
|
|
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| @@ -140,6 +140,13 @@ TEST_F(InterceptingResourceHandlerTest, HandlerSwitchNoPayload) {
|
| mock_loader_->OnResponseStarted(
|
| make_scoped_refptr(new ResourceResponse())));
|
|
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| +
|
| + // The old handler should have been destroyed at the beginning of the
|
| + // replace.
|
| + ASSERT_FALSE(old_handler_.get());
|
| + ASSERT_TRUE(mock_loader_->io_buffer());
|
| +
|
| EXPECT_FALSE(old_handler_status_.is_success());
|
| EXPECT_EQ(net::ERR_ABORTED, old_handler_status_.error());
|
| EXPECT_EQ(std::string(), old_handler_body_);
|
| @@ -176,9 +183,6 @@ TEST_F(InterceptingResourceHandlerTest, HandlerSwitchWithPayload) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
|
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| @@ -198,14 +202,19 @@ TEST_F(InterceptingResourceHandlerTest, HandlerSwitchWithPayload) {
|
| mock_loader_->OnResponseStarted(
|
| make_scoped_refptr(new ResourceResponse())));
|
|
|
| - // The old handler should have received the payload.
|
| + // The old handler should have received the payload...
|
| EXPECT_EQ(kPayload, old_handler_body_);
|
|
|
| + // ... and been destroyed.
|
| + ASSERT_FALSE(old_handler_.get());
|
| +
|
| EXPECT_TRUE(old_handler_status_.is_success());
|
| EXPECT_EQ(net::OK, old_handler_status_.error());
|
|
|
| // The read is replayed by the MimeSniffingResourceHandler. The data should
|
| // have been received by the new handler.
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| + ASSERT_TRUE(mock_loader_->io_buffer());
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnReadCompleted(kData));
|
| EXPECT_EQ(kData, new_handler_body);
|
| @@ -227,6 +236,9 @@ TEST_F(InterceptingResourceHandlerTest, OldHandlerFailsWillRead) {
|
| // handler should tell the caller to fail.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| + mock_loader_->OnResponseStarted(
|
| + make_scoped_refptr(new ResourceResponse())));
|
| ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead());
|
| EXPECT_EQ(net::ERR_ABORTED, mock_loader_->error_code());
|
| }
|
| @@ -239,10 +251,6 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsOnWillStart) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
| -
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| net::URLRequestStatus new_handler_status;
|
| @@ -256,6 +264,7 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsOnWillStart) {
|
| ASSERT_EQ(MockResourceLoader::Status::CANCELED,
|
| mock_loader_->OnResponseStarted(
|
| make_scoped_refptr(new ResourceResponse())));
|
| +
|
| EXPECT_EQ(net::ERR_ABORTED, mock_loader_->error_code());
|
| }
|
|
|
| @@ -267,10 +276,6 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsResponseStarted) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
| -
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| net::URLRequestStatus new_handler_status;
|
| @@ -289,17 +294,11 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsResponseStarted) {
|
|
|
| // Tests that the handler behaves properly if the new handler fails will read.
|
| TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsWillRead) {
|
| - const char kData[] = "The data";
|
| -
|
| scoped_refptr<net::IOBuffer> old_buffer = old_handler_->buffer();
|
|
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
| -
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| net::URLRequestStatus new_handler_status;
|
| @@ -314,15 +313,14 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsWillRead) {
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnResponseStarted(
|
| make_scoped_refptr(new ResourceResponse())));
|
| - EXPECT_EQ(net::URLRequestStatus::CANCELED, old_handler_status_.status());
|
| - EXPECT_EQ(net::ERR_ABORTED, old_handler_status_.error());
|
|
|
| // The read is replayed by the MimeSniffingResourceHandler. The new
|
| // handler should tell the caller to fail.
|
| -
|
| - ASSERT_EQ(MockResourceLoader::Status::CANCELED,
|
| - mock_loader_->OnReadCompleted(kData));
|
| + ASSERT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->OnWillRead());
|
| EXPECT_EQ(net::ERR_ABORTED, mock_loader_->error_code());
|
| +
|
| + EXPECT_EQ(net::URLRequestStatus::CANCELED, old_handler_status_.status());
|
| + EXPECT_EQ(net::ERR_ABORTED, old_handler_status_.error());
|
| }
|
|
|
| // Tests that the handler behaves properly if the new handler fails read
|
| @@ -332,12 +330,8 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsReadCompleted) {
|
|
|
| scoped_refptr<net::IOBuffer> old_buffer = old_handler_->buffer();
|
|
|
| - // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| -
|
| - ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
|
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| @@ -355,8 +349,11 @@ TEST_F(InterceptingResourceHandlerTest, NewHandlerFailsReadCompleted) {
|
| EXPECT_EQ(net::URLRequestStatus::CANCELED, old_handler_status_.status());
|
| EXPECT_EQ(net::ERR_ABORTED, old_handler_status_.error());
|
|
|
| + // Simulate the MimeSniffingResourceHandler buffering the data.
|
| // The read is replayed by the MimeSniffingResourceHandler. The new handler
|
| // should tell the caller to fail.
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
| + ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
| ASSERT_EQ(MockResourceLoader::Status::CANCELED,
|
| mock_loader_->OnReadCompleted(kData));
|
| EXPECT_EQ(net::ERR_ABORTED, mock_loader_->error_code());
|
| @@ -386,27 +383,6 @@ TEST_F(InterceptingResourceHandlerTest, DeferredOperations) {
|
|
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - // The old handler defers the read.
|
| - ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
|
| - mock_loader_->OnWillRead());
|
| - old_handler_->WaitUntilDeferred();
|
| -
|
| - EXPECT_EQ(net::URLRequestStatus::IO_PENDING, old_handler_status_.status());
|
| - EXPECT_EQ(1, old_handler_->on_will_read_called());
|
| - EXPECT_EQ(0, old_handler_->on_read_completed_called());
|
| - EXPECT_EQ(0, old_handler_->on_response_completed_called());
|
| -
|
| - // Defer the next OnWillRead, too. This is needed to test the case where
|
| - // OnWillRead completes asynchronously when passing the payload to the old
|
| - // handler.
|
| - old_handler_->set_defer_on_will_read(true);
|
| -
|
| - // The old handle resumes the request.
|
| - old_handler_->Resume();
|
| -
|
| - // Resume() call may do work asynchronously. Wait until that's done.
|
| - mock_loader_->WaitUntilIdleOrCanceled();
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status());
|
|
|
| ASSERT_NE(mock_loader_->io_buffer(), old_buffer.get());
|
|
|
| @@ -420,7 +396,6 @@ TEST_F(InterceptingResourceHandlerTest, DeferredOperations) {
|
| new TestResourceHandler(&new_handler_status, &new_handler_body));
|
| base::WeakPtr<TestResourceHandler> new_handler =
|
| scoped_new_handler->GetWeakPtr();
|
| - scoped_new_handler->SetBufferSize(1);
|
| scoped_new_handler->set_defer_on_will_start(true);
|
| scoped_new_handler->set_defer_on_response_started(true);
|
| scoped_new_handler->set_defer_on_will_read(true);
|
| @@ -435,24 +410,19 @@ TEST_F(InterceptingResourceHandlerTest, DeferredOperations) {
|
| make_scoped_refptr(new ResourceResponse())));
|
| old_handler_->WaitUntilDeferred();
|
|
|
| - EXPECT_EQ(1, old_handler_->on_read_completed_called());
|
| + EXPECT_EQ(1, old_handler_->on_will_read_called());
|
| + EXPECT_EQ(0, old_handler_->on_read_completed_called());
|
| EXPECT_EQ(0, old_handler_->on_response_completed_called());
|
| EXPECT_EQ(0, new_handler->on_response_started_called());
|
| -
|
| - // The old handler has received the first N bytes of the payload synchronously
|
| - // where N is the size of the buffer exposed via OnWillRead.
|
| - EXPECT_EQ(std::string(kPayload, 0, kOldHandlerBufferSize), old_handler_body_);
|
| - EXPECT_EQ(std::string(), new_handler_body);
|
| - EXPECT_EQ(net::URLRequestStatus::IO_PENDING, old_handler_status_.status());
|
| - EXPECT_EQ(net::URLRequestStatus::IO_PENDING, new_handler_status.status());
|
| -
|
| - // Run until the old handler's OnWillRead method defers the request while
|
| - // replaying the payload.
|
| old_handler_->Resume();
|
| old_handler_->WaitUntilDeferred();
|
| - EXPECT_EQ(2, old_handler_->on_will_read_called());
|
| +
|
| EXPECT_EQ(1, old_handler_->on_read_completed_called());
|
| EXPECT_EQ(0, old_handler_->on_response_completed_called());
|
| + EXPECT_EQ(0, new_handler->on_response_started_called());
|
| +
|
| + // The old handler has received the first N bytes of the payload synchronously
|
| + // where N is the size of the buffer exposed via OnWillRead.
|
| EXPECT_EQ(std::string(kPayload, 0, kOldHandlerBufferSize), old_handler_body_);
|
| EXPECT_EQ(std::string(), new_handler_body);
|
| EXPECT_EQ(net::URLRequestStatus::IO_PENDING, old_handler_status_.status());
|
| @@ -477,34 +447,33 @@ TEST_F(InterceptingResourceHandlerTest, DeferredOperations) {
|
| // Resume() call may do work asynchronously. Wait until that's done.
|
| new_handler->WaitUntilDeferred();
|
|
|
| + EXPECT_EQ(1, new_handler->on_will_start_called());
|
| EXPECT_EQ(1, new_handler->on_response_started_called());
|
| EXPECT_EQ(0, new_handler->on_will_read_called());
|
| ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
|
| mock_loader_->status());
|
| EXPECT_EQ(std::string(), new_handler_body);
|
| EXPECT_EQ(net::URLRequestStatus::IO_PENDING, new_handler_status.status());
|
| -
|
| - // Resuming should finally call back into the ResourceController.
|
| new_handler->Resume();
|
| - mock_loader_->WaitUntilIdleOrCanceled();
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status());
|
|
|
| - // Data is read, the new handler defers OnWillRead.
|
| + // Data is read, the new handler defers completion of the read buffer return.
|
| ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
|
| - mock_loader_->OnReadCompleted(kData));
|
| + mock_loader_->OnWillRead());
|
| new_handler->WaitUntilDeferred();
|
| EXPECT_EQ(1, new_handler->on_will_read_called());
|
| EXPECT_EQ(0, new_handler->on_read_completed_called());
|
| -
|
| - // The new ResourceHandler resumes, and then defers again in OnReadCompleted.
|
| new_handler->Resume();
|
| + ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->status());
|
| +
|
| + // As well as completion of the read itself.
|
| + ASSERT_EQ(MockResourceLoader::Status::CALLBACK_PENDING,
|
| + mock_loader_->OnReadCompleted(kData));
|
| new_handler->WaitUntilDeferred();
|
| - EXPECT_EQ(1, new_handler->on_will_read_called());
|
| EXPECT_EQ(1, new_handler->on_read_completed_called());
|
| + EXPECT_EQ(0, new_handler->on_read_eof_called());
|
| EXPECT_EQ(0, new_handler->on_response_completed_called());
|
|
|
| - EXPECT_EQ("T", new_handler_body);
|
| -
|
| // New handler resumes again, everything continues synchronously until all
|
| // written data is consumed.
|
| new_handler->Resume();
|
| @@ -553,7 +522,6 @@ TEST_F(InterceptingResourceHandlerTest, CancelNewHandler) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
|
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
| @@ -594,7 +562,6 @@ TEST_F(InterceptingResourceHandlerTest, CancelBothHandlers) {
|
| // Simulate the MimeSniffingResourceHandler buffering the data.
|
| ASSERT_EQ(MockResourceLoader::Status::IDLE,
|
| mock_loader_->OnWillStart(request_->url()));
|
| - ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead());
|
|
|
| // Simulate the MimeSniffingResourceHandler asking the
|
| // InterceptingResourceHandler to switch to a new handler.
|
|
|