Merge ArrayBufferBuilder into FetchDataLoaderAsArrayBuffer

FetchDataLoaderAsArrayBuffer is the only user of ArrayBufferBuilder.
So rather than keeping this utility class in WTF,
we should just merge the ArrayBufferBuilder code into FetchDataLoaderAsArrayBuffer.

Bug: 937390
Change-Id: I2a89f2409280c5ac544be9294c3f17eaea366ff3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1536042
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Yeol Park <peary2@gmail.com>
Auto-Submit: Yeol Park <peary2@gmail.com>
Cr-Commit-Position: refs/heads/master@{#644201}
diff --git a/third_party/blink/renderer/core/fetch/fetch_data_loader.cc b/third_party/blink/renderer/core/fetch/fetch_data_loader.cc
index e144222..474348b 100644
--- a/third_party/blink/renderer/core/fetch/fetch_data_loader.cc
+++ b/third_party/blink/renderer/core/fetch/fetch_data_loader.cc
@@ -19,12 +19,13 @@
 #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
 #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
-#include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h"
 
 namespace blink {
 
 namespace {
 
+static const int kDefaultBufferCapacity = 32768;
+
 class FetchDataLoaderAsBlobHandle final : public FetchDataLoader,
                                           public BytesConsumer::Client {
   USING_GARBAGE_COLLECTED_MIXIN(FetchDataLoaderAsBlobHandle);
@@ -122,10 +123,11 @@
   void Start(BytesConsumer* consumer,
              FetchDataLoader::Client* client) override {
     DCHECK(!client_);
-    DCHECK(!raw_data_);
+    DCHECK(!IsValid());
     DCHECK(!consumer_);
     client_ = client;
-    raw_data_ = std::make_unique<ArrayBufferBuilder>();
+    buffer_ = ArrayBuffer::Create(kDefaultBufferCapacity, 1);
+    bytes_used_ = 0;
     consumer_ = consumer;
     consumer_->SetClient(this);
     OnStateChange();
@@ -143,7 +145,7 @@
       if (result == BytesConsumer::Result::kOk) {
         if (available > 0) {
           unsigned bytes_appended =
-              raw_data_->Append(buffer, SafeCast<wtf_size_t>(available));
+              Append(buffer, SafeCast<wtf_size_t>(available));
           if (!bytes_appended) {
             auto unused = consumer_->EndRead(0);
             ALLOW_UNUSED_LOCAL(unused);
@@ -163,7 +165,7 @@
           return;
         case BytesConsumer::Result::kDone:
           client_->DidFetchDataLoadedArrayBuffer(
-              DOMArrayBuffer::Create(raw_data_->PassArrayBuffer()));
+              DOMArrayBuffer::Create(PassArrayBuffer()));
           return;
         case BytesConsumer::Result::kError:
           client_->DidFetchDataLoadFailed();
@@ -181,11 +183,81 @@
     BytesConsumer::Client::Trace(visitor);
   }
 
+  bool IsValid() const { return buffer_.get(); }
+
+  // Appending empty data is not allowed.
+  unsigned Append(const char* data, unsigned length) {
+    DCHECK_GT(length, 0u);
+
+    size_t current_buffer_size = buffer_->ByteLength();
+
+    DCHECK_LE(bytes_used_, current_buffer_size);
+
+    size_t remaining_buffer_space = current_buffer_size - bytes_used_;
+
+    if (length > remaining_buffer_space && !ExpandCapacity(length))
+      return 0;
+
+    memcpy(static_cast<char*>(buffer_->Data()) + bytes_used_, data, length);
+    bytes_used_ += length;
+
+    return length;
+  }
+
+  // Number of bytes currently accumulated.
+  unsigned ByteLength() const { return bytes_used_; }
+
+  // Returns the accumulated data as an ArrayBuffer instance. This transfers
+  // ownership of the internal buffer, making this ArrayBufferBuilder invalid
+  // for future use.
+  scoped_refptr<ArrayBuffer> PassArrayBuffer() {
+    DCHECK_LE(bytes_used_, buffer_->ByteLength());
+
+    if (buffer_->ByteLength() > bytes_used_)
+      buffer_ = buffer_->Slice(0, bytes_used_);
+    return std::move(buffer_);
+  }
+
  private:
+  // Expands the size of m_buffer to size + m_bytesUsed bytes. Returns true
+  // iff successful. If reallocation is needed, copies only data in
+  // [0, m_bytesUsed) range.
+  bool ExpandCapacity(unsigned size_to_increase) {
+    size_t current_buffer_size = buffer_->ByteLength();
+
+    // If the size of the buffer exceeds max of unsigned, it can't be grown any
+    // more.
+    if (size_to_increase > std::numeric_limits<unsigned>::max() - bytes_used_)
+      return false;
+
+    unsigned new_buffer_size = bytes_used_ + size_to_increase;
+
+    // Grow exponentially if possible.
+    unsigned exponential_growth_new_buffer_size =
+        std::numeric_limits<unsigned>::max();
+    if (current_buffer_size <= std::numeric_limits<unsigned>::max() / 2) {
+      exponential_growth_new_buffer_size =
+          static_cast<unsigned>(current_buffer_size * 2);
+    }
+    if (exponential_growth_new_buffer_size > new_buffer_size)
+      new_buffer_size = exponential_growth_new_buffer_size;
+
+    // Copy existing data in current buffer to new buffer.
+    scoped_refptr<ArrayBuffer> new_buffer =
+        ArrayBuffer::Create(new_buffer_size, 1);
+    if (!new_buffer)
+      return false;
+
+    memcpy(new_buffer->Data(), buffer_->Data(), bytes_used_);
+    buffer_ = new_buffer;
+    return true;
+  }
+
   TraceWrapperMember<BytesConsumer> consumer_;
   Member<FetchDataLoader::Client> client_;
 
-  std::unique_ptr<ArrayBufferBuilder> raw_data_;
+  unsigned bytes_used_;
+  scoped_refptr<ArrayBuffer> buffer_;
 };
 
 class FetchDataLoaderAsFailure final : public FetchDataLoader,
diff --git a/third_party/blink/renderer/platform/wtf/BUILD.gn b/third_party/blink/renderer/platform/wtf/BUILD.gn
index 2c0a35d..a4d51f2 100644
--- a/third_party/blink/renderer/platform/wtf/BUILD.gn
+++ b/third_party/blink/renderer/platform/wtf/BUILD.gn
@@ -198,8 +198,6 @@
     "type_traits.h",
     "typed_arrays/array_buffer.cc",
     "typed_arrays/array_buffer.h",
-    "typed_arrays/array_buffer_builder.cc",
-    "typed_arrays/array_buffer_builder.h",
     "typed_arrays/array_buffer_contents.cc",
     "typed_arrays/array_buffer_contents.h",
     "typed_arrays/array_buffer_view.cc",
@@ -333,7 +331,6 @@
     "threading_primitives_test.cc",
     "tree_node_test.cc",
     "type_traits_test.cc",
-    "typed_arrays/array_buffer_builder_test.cc",
     "vector_test.cc",
   ]
 
diff --git a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.cc b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.cc
deleted file mode 100644
index 4586b47..0000000
--- a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.cc
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h"
-
-#include <limits>
-#include <utility>
-
-#include "third_party/blink/renderer/platform/wtf/assertions.h"
-
-namespace WTF {
-
-static const int kDefaultBufferCapacity = 32768;
-
-ArrayBufferBuilder::ArrayBufferBuilder() : bytes_used_(0) {
-  buffer_ = ArrayBuffer::Create(kDefaultBufferCapacity, 1);
-}
-
-bool ArrayBufferBuilder::ExpandCapacity(unsigned size_to_increase) {
-  size_t current_buffer_size = buffer_->ByteLength();
-
-  // If the size of the buffer exceeds max of unsigned, it can't be grown any
-  // more.
-  if (size_to_increase > std::numeric_limits<unsigned>::max() - bytes_used_)
-    return false;
-
-  unsigned new_buffer_size = bytes_used_ + size_to_increase;
-
-  // Grow exponentially if possible.
-  unsigned exponential_growth_new_buffer_size =
-      std::numeric_limits<unsigned>::max();
-  if (current_buffer_size <= std::numeric_limits<unsigned>::max() / 2) {
-    exponential_growth_new_buffer_size =
-        static_cast<unsigned>(current_buffer_size * 2);
-  }
-  if (exponential_growth_new_buffer_size > new_buffer_size)
-    new_buffer_size = exponential_growth_new_buffer_size;
-
-  // Copy existing data in current buffer to new buffer.
-  scoped_refptr<ArrayBuffer> new_buffer =
-      ArrayBuffer::Create(new_buffer_size, 1);
-  if (!new_buffer)
-    return false;
-
-  memcpy(new_buffer->Data(), buffer_->Data(), bytes_used_);
-  buffer_ = new_buffer;
-  return true;
-}
-
-unsigned ArrayBufferBuilder::Append(const char* data, unsigned length) {
-  DCHECK_GT(length, 0u);
-
-  size_t current_buffer_size = buffer_->ByteLength();
-
-  DCHECK_LE(bytes_used_, current_buffer_size);
-
-  size_t remaining_buffer_space = current_buffer_size - bytes_used_;
-
-  if (length > remaining_buffer_space && !ExpandCapacity(length))
-    return 0;
-
-  memcpy(static_cast<char*>(buffer_->Data()) + bytes_used_, data, length);
-  bytes_used_ += length;
-
-  return length;
-}
-
-scoped_refptr<ArrayBuffer> ArrayBufferBuilder::PassArrayBuffer() {
-  ShrinkToFit();
-  return std::move(buffer_);
-}
-
-void ArrayBufferBuilder::ShrinkToFit() {
-  DCHECK_LE(bytes_used_, buffer_->ByteLength());
-
-  if (buffer_->ByteLength() > bytes_used_)
-    buffer_ = buffer_->Slice(0, bytes_used_);
-}
-
-}  // namespace WTF
diff --git a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h
deleted file mode 100644
index 6254a69..0000000
--- a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_ARRAY_BUFFER_BUILDER_H_
-#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_ARRAY_BUFFER_BUILDER_H_
-
-#include "base/macros.h"
-#include "base/memory/scoped_refptr.h"
-#include "third_party/blink/renderer/platform/wtf/allocator.h"
-#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
-#include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer.h"
-
-namespace WTF {
-
-// A utility class to build an ArrayBuffer instance. Validity must be checked
-// by isValid() before using an instance.
-class WTF_EXPORT ArrayBufferBuilder final {
-  // Disallow copying since it's expensive and we don't want code to do it by
-  // accident.
-  USING_FAST_MALLOC(ArrayBufferBuilder);
-
- public:
-  // Creates an ArrayBufferBuilder using the default capacity.
-  ArrayBufferBuilder();
-
-  explicit ArrayBufferBuilder(unsigned capacity) : bytes_used_(0) {
-    buffer_ = ArrayBuffer::Create(capacity, 1);
-  }
-
-  bool IsValid() const { return buffer_.get(); }
-
-  // Appending empty data is not allowed.
-  unsigned Append(const char* data, unsigned length);
-
-  // Returns the accumulated data as an ArrayBuffer instance. This transfers
-  // ownership of the internal buffer, making this ArrayBufferBuilder invalid
-  // for future use.
-  scoped_refptr<ArrayBuffer> PassArrayBuffer();
-
-  // Number of bytes currently accumulated.
-  unsigned ByteLength() const { return bytes_used_; }
-
-  // Number of bytes allocated.
-  size_t Capacity() const { return buffer_->ByteLength(); }
-
-  void ShrinkToFit();
-
-  const void* Data() const { return buffer_->Data(); }
-
- private:
-  // Expands the size of m_buffer to size + m_bytesUsed bytes. Returns true
-  // iff successful. If reallocation is needed, copies only data in
-  // [0, m_bytesUsed) range.
-  bool ExpandCapacity(unsigned size);
-
-  unsigned bytes_used_;
-  scoped_refptr<ArrayBuffer> buffer_;
-
-  DISALLOW_COPY_AND_ASSIGN(ArrayBufferBuilder);
-};
-
-}  // namespace WTF
-
-using WTF::ArrayBufferBuilder;
-
-#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPED_ARRAYS_ARRAY_BUFFER_BUILDER_H_
diff --git a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder_test.cc b/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder_test.cc
deleted file mode 100644
index 391ed2b..0000000
--- a/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder_test.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h"
-
-#include <limits.h>
-#include <string.h>
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/blink/renderer/platform/wtf/assertions.h"
-
-namespace WTF {
-
-TEST(ArrayBufferBuilderTest, Constructor) {
-  ArrayBufferBuilder zero_builder(0);
-  EXPECT_EQ(0u, zero_builder.ByteLength());
-  EXPECT_EQ(0u, zero_builder.Capacity());
-
-  ArrayBufferBuilder small_builder(1024);
-  EXPECT_EQ(0u, zero_builder.ByteLength());
-  EXPECT_EQ(1024u, small_builder.Capacity());
-
-  ArrayBufferBuilder big_builder(2048);
-  EXPECT_EQ(0u, zero_builder.ByteLength());
-  EXPECT_EQ(2048u, big_builder.Capacity());
-}
-
-TEST(ArrayBufferBuilderTest, Append) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder(2 * data_size);
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(data_size * 2, builder.Capacity());
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_EQ(data_size * 2, builder.ByteLength());
-  EXPECT_EQ(data_size * 2, builder.Capacity());
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_EQ(data_size * 3, builder.ByteLength());
-  EXPECT_GE(builder.Capacity(), data_size * 3);
-}
-
-TEST(ArrayBufferBuilderTest, AppendRepeatedly) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder(37);  // Some number coprime with dataSize.
-
-  for (uint32_t i = 1; i < 1000U; ++i) {
-    EXPECT_EQ(data_size, builder.Append(kData, data_size));
-    EXPECT_EQ(data_size * i, builder.ByteLength());
-    EXPECT_GE(builder.Capacity(), data_size * i);
-  }
-}
-
-TEST(ArrayBufferBuilderTest, DefaultConstructorAndAppendRepeatedly) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder;
-
-  for (uint32_t i = 1; i < 4000U; ++i) {
-    EXPECT_EQ(data_size, builder.Append(kData, data_size));
-    EXPECT_EQ(data_size * i, builder.ByteLength());
-    EXPECT_GE(builder.Capacity(), data_size * i);
-  }
-}
-
-TEST(ArrayBufferBuilderTest, PassArrayBuffer) {
-  const char kData1[] = "HelloWorld";
-  uint32_t data1_size = sizeof(kData1) - 1;
-
-  const char kData2[] = "GoodbyeWorld";
-  uint32_t data2_size = sizeof(kData2) - 1;
-
-  ArrayBufferBuilder builder(1024);
-  builder.Append(kData1, data1_size);
-  builder.Append(kData2, data2_size);
-
-  const char kExpected[] = "HelloWorldGoodbyeWorld";
-  uint32_t expected_size = sizeof(kExpected) - 1;
-
-  scoped_refptr<ArrayBuffer> result = builder.PassArrayBuffer();
-  EXPECT_FALSE(builder.IsValid());
-  ASSERT_EQ(data1_size + data2_size, result->ByteLength());
-  ASSERT_EQ(expected_size, result->ByteLength());
-  EXPECT_EQ(0, memcmp(kExpected, result->Data(), expected_size));
-}
-
-TEST(ArrayBufferBuilderTest, ShrinkToFitNoAppend) {
-  ArrayBufferBuilder builder(1024);
-  EXPECT_EQ(1024u, builder.Capacity());
-  builder.ShrinkToFit();
-  EXPECT_EQ(0u, builder.ByteLength());
-  EXPECT_EQ(0u, builder.Capacity());
-}
-
-TEST(ArrayBufferBuilderTest, ShrinkToFit) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder(32);
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(32u, builder.Capacity());
-
-  builder.ShrinkToFit();
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(data_size, builder.Capacity());
-}
-
-TEST(ArrayBufferBuilderTest, ShrinkToFitFullyUsed) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder(data_size);
-  const void* internal_address = builder.Data();
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(data_size, builder.Capacity());
-
-  builder.ShrinkToFit();
-  // Reallocation should not happen.
-  EXPECT_EQ(internal_address, builder.Data());
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(data_size, builder.Capacity());
-}
-
-TEST(ArrayBufferBuilderTest, ShrinkToFitAfterGrowth) {
-  const char kData[] = "HelloWorld";
-  uint32_t data_size = sizeof(kData) - 1;
-
-  ArrayBufferBuilder builder(5);
-
-  EXPECT_EQ(data_size, builder.Append(kData, data_size));
-  EXPECT_GE(builder.Capacity(), data_size);
-  builder.ShrinkToFit();
-  EXPECT_EQ(data_size, builder.ByteLength());
-  EXPECT_EQ(data_size, builder.Capacity());
-}
-
-}  // namespace WTF