Chromium Code Reviews| Index: content/browser/loader/mojo_async_resource_handler_unittest.cc |
| diff --git a/content/browser/loader/mojo_async_resource_handler_unittest.cc b/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| index d52679c366cf42b9e9428f12aa33b53961aeea67..05ab70d8308113695fba9279395bfb0ccbd64d05 100644 |
| --- a/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| +++ b/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| @@ -174,10 +174,10 @@ class TestResourceDispatcherHostDelegate final |
| DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); |
| }; |
| -class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| +class MojoAsyncResourceHandlerWithStubOperations |
| : public MojoAsyncResourceHandler { |
| public: |
| - MojoAsyncResourceHandlerWithCustomDataPipeOperations( |
| + MojoAsyncResourceHandlerWithStubOperations( |
| net::URLRequest* request, |
| ResourceDispatcherHostImpl* rdh, |
| mojom::URLLoaderAssociatedRequest mojo_request, |
| @@ -186,7 +186,7 @@ class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| rdh, |
| std::move(mojo_request), |
| std::move(url_loader_client)) {} |
| - ~MojoAsyncResourceHandlerWithCustomDataPipeOperations() override {} |
| + ~MojoAsyncResourceHandlerWithStubOperations() override {} |
| void ResetBeginWriteExpectation() { is_begin_write_expectation_set_ = false; } |
| @@ -199,6 +199,9 @@ class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| end_write_expectation_ = end_write_expectation; |
| } |
| bool has_received_bad_message() const { return has_received_bad_message_; } |
| + void SetMetadata(scoped_refptr<net::IOBufferWithSize> metadata) { |
| + metadata_ = std::move(metadata); |
| + } |
| private: |
| MojoResult BeginWrite(void** data, uint32_t* available) override { |
| @@ -211,6 +214,11 @@ class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| return end_write_expectation_; |
| return MojoAsyncResourceHandler::EndWrite(written); |
| } |
| + net::IOBufferWithSize* GetResponseMetadata( |
| + net::URLRequest* request) override { |
| + return metadata_.get(); |
| + } |
| + |
| void ReportBadMessage(const std::string& error) override { |
| has_received_bad_message_ = true; |
| } |
| @@ -220,9 +228,9 @@ class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| bool has_received_bad_message_ = false; |
| MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN; |
| MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN; |
| + scoped_refptr<net::IOBufferWithSize> metadata_; |
| - DISALLOW_COPY_AND_ASSIGN( |
| - MojoAsyncResourceHandlerWithCustomDataPipeOperations); |
| + DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerWithStubOperations); |
| }; |
| class TestURLLoaderFactory final : public mojom::URLLoaderFactory { |
| @@ -308,7 +316,7 @@ class MojoAsyncResourceHandlerTestBase { |
| mojom::URLLoaderClientAssociatedPtr client_ptr; |
| client_ptr.Bind(factory_impl->PassClientPtrInfo()); |
| - handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations( |
| + handler_.reset(new MojoAsyncResourceHandlerWithStubOperations( |
| request_.get(), &rdh_, factory_impl->PassLoaderRequest(), |
| std::move(client_ptr))); |
| mock_loader_.reset(new MockResourceLoader(handler_.get())); |
| @@ -352,8 +360,7 @@ class MojoAsyncResourceHandlerTestBase { |
| std::unique_ptr<TestBrowserContext> browser_context_; |
| net::TestDelegate url_request_delegate_; |
| std::unique_ptr<net::URLRequest> request_; |
| - std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations> |
| - handler_; |
| + std::unique_ptr<MojoAsyncResourceHandlerWithStubOperations> handler_; |
| std::unique_ptr<MockResourceLoader> mock_loader_; |
| DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase); |
| @@ -386,6 +393,10 @@ TEST_F(MojoAsyncResourceHandlerTest, OnWillStart) { |
| TEST_F(MojoAsyncResourceHandlerTest, OnResponseStarted) { |
| rdh_delegate_.set_num_on_response_started_calls_expectation(1); |
| + scoped_refptr<net::IOBufferWithSize> metadata = new net::IOBufferWithSize(5); |
| + strncpy(metadata->data(), "hello", 5); |
|
dcheng
2017/01/18 00:23:52
Please use memcpy (strncpy doesn't null terminate,
yhirano
2017/01/18 06:22:42
Done.
|
| + handler_->SetMetadata(metadata); |
| + |
| ASSERT_EQ(MockResourceLoader::Status::IDLE, |
| mock_loader_->OnWillStart(request_->url())); |
| @@ -413,6 +424,12 @@ TEST_F(MojoAsyncResourceHandlerTest, OnResponseStarted) { |
| EXPECT_EQ(response->head.response_start, |
| url_loader_client_.response_head().response_start); |
| EXPECT_EQ(99, url_loader_client_.response_head().content_length); |
| + |
| + url_loader_client_.RunUntilCachedMetadataReceived(); |
| + EXPECT_EQ("hello", |
| + std::string(reinterpret_cast<const char*>( |
| + url_loader_client_.cached_metadata().data()), |
| + url_loader_client_.cached_metadata().size())); |
|
mmenke
2017/01/17 18:39:57
Suggest moving this std::string call into TestURLL
yhirano
2017/01/18 06:22:42
Done.
|
| } |
| TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) { |