Split off fxv8_unittest.h from cfx_v8_unittest.h

Makes filename match class name. Makes cfx_v8_unittest.cpp more
similar to cfxjs_eninge_unittest.cpp. Allows simpler use of the
FXV8UnitTest component down the road.

Change-Id: I04cb3ff6e996655442ac232ecb4eb0dd80a17192
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71830
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index 6c9e655..c7f42d7 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -219,11 +219,12 @@
     sources = [
       "cfx_globaldata_unittest.cpp",
       "cfx_v8_unittest.cpp",
-      "cfx_v8_unittest.h",
       "cfxjs_engine_unittest.cpp",
       "cjs_publicmethods_unittest.cpp",
       "cjs_util_unittest.cpp",
       "fx_date_helpers_unittest.cpp",
+      "fxv8_unittest.cpp",
+      "fxv8_unittest.h",
     ]
     configs = [ "//v8:external_startup_data" ]
     deps = [ ":fxjs" ]
diff --git a/fxjs/cfx_v8_unittest.cpp b/fxjs/cfx_v8_unittest.cpp
index 428f937..226a8e2 100644
--- a/fxjs/cfx_v8_unittest.cpp
+++ b/fxjs/cfx_v8_unittest.cpp
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "fxjs/cfx_v8_unittest.h"
+#include "fxjs/cfx_v8.h"
 
 #include <cmath>
 #include <memory>
 
-#include "fxjs/cfx_v8.h"
+#include "fxjs/fxv8_unittest.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -15,25 +15,23 @@
 bool setter_sentinel = false;
 }  // namespace
 
-void FXV8UnitTest::V8IsolateDeleter::operator()(v8::Isolate* ptr) const {
-  ptr->Dispose();
-}
+class CFXV8UnitTest : public FXV8UnitTest {
+ public:
+  CFXV8UnitTest() = default;
+  ~CFXV8UnitTest() override = default;
 
-FXV8UnitTest::FXV8UnitTest() = default;
+  void SetUp() override {
+    FXV8UnitTest::SetUp();
+    cfx_v8_ = std::make_unique<CFX_V8>(isolate());
+  }
 
-FXV8UnitTest::~FXV8UnitTest() = default;
+  CFX_V8* cfx_v8() const { return cfx_v8_.get(); }
 
-void FXV8UnitTest::SetUp() {
-  array_buffer_allocator_ = std::make_unique<CFX_V8ArrayBufferAllocator>();
+ protected:
+  std::unique_ptr<CFX_V8> cfx_v8_;
+};
 
-  v8::Isolate::CreateParams params;
-  params.array_buffer_allocator = array_buffer_allocator_.get();
-  isolate_.reset(v8::Isolate::New(params));
-
-  cfx_v8_ = std::make_unique<CFX_V8>(isolate_.get());
-}
-
-TEST_F(FXV8UnitTest, EmptyLocal) {
+TEST_F(CFXV8UnitTest, EmptyLocal) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -61,7 +59,7 @@
   EXPECT_EQ(0u, cfx_v8()->GetArrayLength(empty_array));
 }
 
-TEST_F(FXV8UnitTest, NewNull) {
+TEST_F(CFXV8UnitTest, NewNull) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -76,7 +74,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(nullz).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewUndefined) {
+TEST_F(CFXV8UnitTest, NewUndefined) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -91,7 +89,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(undef).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewBoolean) {
+TEST_F(CFXV8UnitTest, NewBoolean) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -115,7 +113,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(boolz).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewNumber) {
+TEST_F(CFXV8UnitTest, NewNumber) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -130,7 +128,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(num).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewString) {
+TEST_F(CFXV8UnitTest, NewString) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -154,7 +152,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(str2).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewDate) {
+TEST_F(CFXV8UnitTest, NewDate) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -169,7 +167,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(date).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, NewArray) {
+TEST_F(CFXV8UnitTest, NewArray) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -196,7 +194,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(array)->IsArray());
 }
 
-TEST_F(FXV8UnitTest, NewObject) {
+TEST_F(CFXV8UnitTest, NewObject) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(v8::Context::New(isolate()));
@@ -223,7 +221,7 @@
   EXPECT_TRUE(cfx_v8()->ToArray(object).IsEmpty());
 }
 
-TEST_F(FXV8UnitTest, ThrowFromGetter) {
+TEST_F(CFXV8UnitTest, ThrowFromGetter) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Local<v8::Context> context = v8::Context::New(isolate());
@@ -245,7 +243,7 @@
   EXPECT_TRUE(getter_sentinel);
 }
 
-TEST_F(FXV8UnitTest, ThrowFromSetter) {
+TEST_F(CFXV8UnitTest, ThrowFromSetter) {
   v8::Isolate::Scope isolate_scope(isolate());
   v8::HandleScope handle_scope(isolate());
   v8::Local<v8::Context> context = v8::Context::New(isolate());
diff --git a/fxjs/cfxjs_engine_unittest.cpp b/fxjs/cfxjs_engine_unittest.cpp
index c8e844c..6566d82 100644
--- a/fxjs/cfxjs_engine_unittest.cpp
+++ b/fxjs/cfxjs_engine_unittest.cpp
@@ -6,8 +6,8 @@
 
 #include <memory>
 
-#include "fxjs/cfx_v8_unittest.h"
 #include "fxjs/cjs_object.h"
+#include "fxjs/fxv8_unittest.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 class FXJSEngineUnitTest : public FXV8UnitTest {
diff --git a/fxjs/fxv8_unittest.cpp b/fxjs/fxv8_unittest.cpp
new file mode 100644
index 0000000..509178a
--- /dev/null
+++ b/fxjs/fxv8_unittest.cpp
@@ -0,0 +1,24 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fxjs/fxv8_unittest.h"
+
+#include "fxjs/cfx_v8.h"
+#include "v8/include/v8.h"
+
+void FXV8UnitTest::V8IsolateDeleter::operator()(v8::Isolate* ptr) const {
+  ptr->Dispose();
+}
+
+FXV8UnitTest::FXV8UnitTest() = default;
+
+FXV8UnitTest::~FXV8UnitTest() = default;
+
+void FXV8UnitTest::SetUp() {
+  array_buffer_allocator_ = std::make_unique<CFX_V8ArrayBufferAllocator>();
+
+  v8::Isolate::CreateParams params;
+  params.array_buffer_allocator = array_buffer_allocator_.get();
+  isolate_.reset(v8::Isolate::New(params));
+}
diff --git a/fxjs/cfx_v8_unittest.h b/fxjs/fxv8_unittest.h
similarity index 74%
rename from fxjs/cfx_v8_unittest.h
rename to fxjs/fxv8_unittest.h
index e5d4e3f..e7390e0 100644
--- a/fxjs/cfx_v8_unittest.h
+++ b/fxjs/fxv8_unittest.h
@@ -1,9 +1,9 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2020 PDFium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef FXJS_CFX_V8_UNITTEST_H_
-#define FXJS_CFX_V8_UNITTEST_H_
+#ifndef FXJS_FXV8_UNITTEST_H_
+#define FXJS_FXV8_UNITTEST_H_
 
 #include <memory>
 
@@ -28,12 +28,10 @@
   void SetUp() override;
 
   v8::Isolate* isolate() const { return isolate_.get(); }
-  CFX_V8* cfx_v8() const { return cfx_v8_.get(); }
 
  protected:
   std::unique_ptr<CFX_V8ArrayBufferAllocator> array_buffer_allocator_;
   std::unique_ptr<v8::Isolate, V8IsolateDeleter> isolate_;
-  std::unique_ptr<CFX_V8> cfx_v8_;
 };
 
-#endif  // FXJS_CFX_V8_UNITTEST_H_
+#endif  // FXJS_FXV8_UNITTEST_H_