Reland "blink/bindings: Check that decompression is correct, and add UTF-16 testing."

This reverts commit 9bdce258ade342f621d1f7f7b48412607c88dbb4.

Reason for reland: Fixed the test failure issue in https://chromium-review.googlesource.com/c/chromium/src/+/1577423

Original change's description:
> Revert "blink/bindings: Check that decompression is correct, and add UTF-16 testing."
> 
> This reverts commit 8ca571cb6ddefcc76906bffa17fd1159709a5de5.
> 
> Reason for revert: This change caused blink_platform_unittests failing on multiple builders
> 
> sample build:
> https://analysis.chromium.org/waterfall/failure?url=https://ci.chromium.org/p/chromium/builders/ci/Win%207%20Tests%20x64%20%281%29/52324
> 
> Original change's description:
> > blink/bindings: Check that decompression is correct, and add UTF-16 testing.
> > 
> > There are crashes in ParkableString decompression, which are assumed to be OOM
> > conditions. Add a check to make sure this is the case, and add testing for UTF16
> > strings to make sure that this doesn't instead come from such strings.
> > 
> > Bug: 946203
> > Change-Id: Iaafde8c3c7b9c79bf87de67e6c5de5b71e1a310a
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1575499
> > Reviewed-by: Kentaro Hara <haraken@chromium.org>
> > Commit-Queue: Benoit L <lizeb@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#652513}
> 
> TBR=haraken@chromium.org,lizeb@chromium.org
> 
> Change-Id: Id697c7df2b13d7ff8a40e68a80b3189600f781c4
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 946203
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574286
> Reviewed-by: Chan Li <chanli@chromium.org>
> Commit-Queue: Chan Li <chanli@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#652547}

TBR=haraken@chromium.org,lizeb@chromium.org,chanli@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 946203
Change-Id: If03319ed1c94c66e38f8e6e3523edcc080de1865
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578604
Reviewed-by: Benoit L <lizeb@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653177}
diff --git a/third_party/blink/renderer/platform/bindings/parkable_string.cc b/third_party/blink/renderer/platform/bindings/parkable_string.cc
index 7136c79..97fe705 100644
--- a/third_party/blink/renderer/platform/bindings/parkable_string.cc
+++ b/third_party/blink/renderer/platform/bindings/parkable_string.cc
@@ -493,12 +493,15 @@
         base::StringPiece(reinterpret_cast<const char*>(data), size);
   }
 
+  // If the buffer size is incorrect, then we have a corrupted data issue,
+  // and in such case there is nothing else to do than crash.
+  CHECK_EQ(compression::GetUncompressedSize(compressed_string_piece),
+           uncompressed_string_piece.size());
   // If decompression fails, this is either because:
-  // 1. The output buffer is too small
-  // 2. Compressed data is corrupted
-  // 3. Cannot allocate memory in zlib
+  // 1. Compressed data is corrupted
+  // 2. Cannot allocate memory in zlib
   //
-  // (1-2) are data corruption, and (3) is OOM. In all cases, we cannot
+  // (1) is data corruption, and (2) is OOM. In all cases, we cannot
   // recover the string we need, nothing else to do than to abort.
   //
   // Stability sheriffs: If you see this, this is likely an OOM.
diff --git a/third_party/blink/renderer/platform/bindings/parkable_string_test.cc b/third_party/blink/renderer/platform/bindings/parkable_string_test.cc
index 5594821..846a200 100644
--- a/third_party/blink/renderer/platform/bindings/parkable_string_test.cc
+++ b/third_party/blink/renderer/platform/bindings/parkable_string_test.cc
@@ -157,6 +157,36 @@
   EXPECT_EQ(MakeLargeString(), parkable.ToString());
 }
 
+TEST_F(ParkableStringTest, DecompressUtf16String) {
+  UChar emoji_grinning_face[2] = {0xd83d, 0xde00};
+  size_t size_in_chars = 2 * kSizeKb * 1000 / sizeof(UChar);
+
+  std::vector<UChar> data(size_in_chars);
+  for (size_t i = 0; i < size_in_chars / 2; ++i) {
+    data[i * 2] = emoji_grinning_face[0];
+    data[i * 2 + 1] = emoji_grinning_face[1];
+  }
+
+  String large_string = String(&data[0], size_in_chars);
+  String copy = large_string.IsolatedCopy();
+  ParkableString parkable(large_string.ReleaseImpl());
+  large_string = String();
+  EXPECT_FALSE(parkable.Is8Bit());
+  EXPECT_EQ(size_in_chars, parkable.length());
+  EXPECT_EQ(sizeof(UChar) * size_in_chars, parkable.CharactersSizeInBytes());
+
+  EXPECT_TRUE(parkable.Impl()->Park(ParkableStringImpl::ParkingMode::kAlways));
+  RunPostedTasks();
+  EXPECT_TRUE(parkable.Impl()->is_parked());
+
+  // Decompression checks that the size is correct.
+  String unparked = parkable.ToString();
+  EXPECT_FALSE(unparked.Is8Bit());
+  EXPECT_EQ(size_in_chars, unparked.length());
+  EXPECT_EQ(sizeof(UChar) * size_in_chars, unparked.CharactersSizeInBytes());
+  EXPECT_EQ(copy, unparked);
+}
+
 TEST_F(ParkableStringTest, Simple) {
   ParkableString parkable_abc(String("abc").ReleaseImpl());