Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1279)

Unified Diff: content/browser/loader/mojo_async_resource_handler_unittest.cc

Issue 2629513003: Implement CachedMetadata handling on MojoAsyncResourceHandler (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 953095aa69f18c80317277b6394f9fdf57e54ef7..f27a3faff4831fa2b6f8be8848208c14fdb46ef8 100644
--- a/content/browser/loader/mojo_async_resource_handler_unittest.cc
+++ b/content/browser/loader/mojo_async_resource_handler_unittest.cc
@@ -223,10 +223,10 @@ class TestResourceController : public ResourceController {
DISALLOW_COPY_AND_ASSIGN(TestResourceController);
};
-class MojoAsyncResourceHandlerWithCustomDataPipeOperations
+class MojoAsyncResourceHandlerWithStubOperations
: public MojoAsyncResourceHandler {
public:
- MojoAsyncResourceHandlerWithCustomDataPipeOperations(
+ MojoAsyncResourceHandlerWithStubOperations(
net::URLRequest* request,
ResourceDispatcherHostImpl* rdh,
mojom::URLLoaderAssociatedRequest mojo_request,
@@ -235,7 +235,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; }
@@ -248,6 +248,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_ = metadata;
tzik 2017/01/13 02:41:23 std::move()
yhirano 2017/01/13 12:36:13 Done.
+ }
private:
MojoResult BeginWrite(void** data, uint32_t* available) override {
@@ -260,6 +263,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;
}
@@ -269,9 +277,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 {
@@ -357,7 +365,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)));
handler_->SetController(&resource_controller_);
@@ -418,8 +426,7 @@ class MojoAsyncResourceHandlerTestBase {
std::unique_ptr<TestBrowserContext> browser_context_;
std::unique_ptr<net::TestDelegate> url_request_delegate_;
std::unique_ptr<net::URLRequest> request_;
- std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations>
- handler_;
+ std::unique_ptr<MojoAsyncResourceHandlerWithStubOperations> handler_;
DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase);
};
@@ -452,6 +459,11 @@ 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);
+
+ handler_->SetMetadata(metadata);
+
ASSERT_TRUE(CallOnWillStart());
scoped_refptr<ResourceResponse> response = new ResourceResponse();
@@ -480,6 +492,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()));
}
TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) {
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler.cc ('k') | content/browser/loader/test_url_loader_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698