Browser process changes for Resource Timing sizes.

This is part of the changes to add the size fields to the
PerformanceResourceTiming API.

See the design doc at
https://docs.google.com/document/d/1ckL-rKLFRsdI4nn1golvQ6I1zRIvxgFkDXMrZb8KduY/edit

These are the browser-side changes to pass the "encodedBodySize" field to the
renderer. The field is named encoded_body_length in the //content code for
consistency with the existing encoded_data_length field.

For async resource fetches the value is passed one chunk at a time in the
ResourceMsg_InlinedDataChunkReceived and ResourceMsg_DataReceived IPCs. For sync
XHR it is passed in the ResourceResponseInfo struct.

BUG=467945

Review-Url: https://codereview.chromium.org/2092993002
Cr-Commit-Position: refs/heads/master@{#405015}
diff --git a/content/child/resource_dispatcher_unittest.cc b/content/child/resource_dispatcher_unittest.cc
index 07fbecf..5d072120 100644
--- a/content/child/resource_dispatcher_unittest.cc
+++ b/content/child/resource_dispatcher_unittest.cc
@@ -13,6 +13,7 @@
 #include <utility>
 #include <vector>
 
+#include "base/feature_list.h"
 #include "base/macros.h"
 #include "base/memory/ptr_util.h"
 #include "base/memory/shared_memory.h"
@@ -30,6 +31,7 @@
 #include "content/public/child/fixed_received_data.h"
 #include "content/public/child/request_peer.h"
 #include "content/public/child/resource_dispatcher_delegate.h"
+#include "content/public/common/content_features.h"
 #include "content/public/common/resource_response.h"
 #include "net/base/net_errors.h"
 #include "net/http/http_response_headers.h"
@@ -275,11 +277,19 @@
     memcpy(shared_memory_map_[request_id]->memory(), data.c_str(),
            data.length());
 
-    EXPECT_TRUE(dispatcher_->OnMessageReceived(
-        ResourceMsg_DataReceived(request_id, 0, data.length(), data.length())));
+    EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataReceived(
+        request_id, 0, data.length(), data.length(), data.length())));
   }
 
-  void NotifyDataDownloaded(int request_id, int decoded_length,
+  void NotifyInlinedDataChunkReceived(int request_id,
+                                      const std::vector<char>& data) {
+    auto size = data.size();
+    EXPECT_TRUE(dispatcher_->OnMessageReceived(
+        ResourceMsg_InlinedDataChunkReceived(request_id, data, size, size)));
+  }
+
+  void NotifyDataDownloaded(int request_id,
+                            int decoded_length,
                             int encoded_length) {
     EXPECT_TRUE(dispatcher_->OnMessageReceived(ResourceMsg_DataDownloaded(
         request_id, decoded_length, encoded_length)));
@@ -369,6 +379,35 @@
   EXPECT_EQ(0u, queued_messages());
 }
 
+// A simple request with an inline data response.
+TEST_F(ResourceDispatcherTest, ResponseWithInlinedData) {
+  auto feature_list = base::MakeUnique<base::FeatureList>();
+  feature_list->InitializeFromCommandLine(
+      features::kOptimizeLoadingIPCForSmallResources.name, std::string());
+  base::FeatureList::ClearInstanceForTesting();
+  base::FeatureList::SetInstance(std::move(feature_list));
+  std::unique_ptr<RequestInfo> request_info(CreateRequestInfo(false));
+  TestRequestPeer::Context peer_context;
+  StartAsync(*request_info.get(), NULL, &peer_context);
+
+  int id = ConsumeRequestResource();
+  EXPECT_EQ(0u, queued_messages());
+
+  NotifyReceivedResponse(id);
+  EXPECT_EQ(0u, queued_messages());
+  EXPECT_TRUE(peer_context.received_response);
+
+  std::vector<char> data(kTestPageContents,
+                         kTestPageContents + strlen(kTestPageContents));
+  NotifyInlinedDataChunkReceived(id, data);
+  EXPECT_EQ(0u, queued_messages());
+
+  NotifyRequestComplete(id, strlen(kTestPageContents));
+  EXPECT_EQ(kTestPageContents, peer_context.data);
+  EXPECT_TRUE(peer_context.complete);
+  EXPECT_EQ(0u, queued_messages());
+}
+
 // Tests that the request IDs are straight when there are two interleaving
 // requests.
 TEST_F(ResourceDispatcherTest, MultipleRequests) {