Split off HeapEmbedderTest into GCedEmbedderTest.
Permit re-use of cppgc-based SetUp() and TearDown() in other
embedder test .cpp files in future CLs.
Change-Id: I6c2b8530d7596d3661e71635386ff2e869a6a47f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70590
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/gc/heap_embeddertest.cpp b/fxjs/gc/heap_embeddertest.cpp
index 381bd13..5f77914 100644
--- a/fxjs/gc/heap_embeddertest.cpp
+++ b/fxjs/gc/heap_embeddertest.cpp
@@ -7,12 +7,11 @@
#include <memory>
#include <set>
-#include "testing/embedder_test.h"
+#include "testing/gced_embeddertest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/base/stl_util.h"
#include "v8/include/cppgc/allocation.h"
#include "v8/include/cppgc/persistent.h"
-#include "v8/include/v8.h"
namespace {
@@ -47,38 +46,9 @@
std::set<const PseudoCollectible*> PseudoCollectible::s_dead_;
cppgc::Persistent<PseudoCollectible> PseudoCollectible::s_persistent_;
-struct V8IsolateDeleter {
- inline void operator()(v8::Isolate* ptr) { ptr->Dispose(); }
-};
-
} // namespace
-class HeapEmbedderTest : public EmbedderTest {
- public:
- void SetUp() override {
- v8::Isolate::CreateParams params;
- params.array_buffer_allocator = static_cast<v8::ArrayBuffer::Allocator*>(
- FPDF_GetArrayBufferAllocatorSharedInstance());
- isolate_.reset(v8::Isolate::New(params));
- EmbedderTest::SetExternalIsolate(isolate_.get());
- EmbedderTest::SetUp();
- }
-
- void TearDown() override {
- EmbedderTest::TearDown();
- isolate_.reset();
- }
-
- void PumpPlatformMessageLoop() {
- while (v8::platform::PumpMessageLoop(
- EmbedderTestEnvironment::GetInstance()->platform(), isolate_.get())) {
- continue;
- }
- }
-
- private:
- std::unique_ptr<v8::Isolate, V8IsolateDeleter> isolate_;
-};
+class HeapEmbedderTest : public GCedEmbedderTest {};
TEST_F(HeapEmbedderTest, SeveralHeaps) {
FXGCScopedHeap heap1 = FXGC_CreateHeap();
diff --git a/testing/BUILD.gn b/testing/BUILD.gn
index 35e9d31..15c621c 100644
--- a/testing/BUILD.gn
+++ b/testing/BUILD.gn
@@ -55,7 +55,6 @@
testonly = true
sources = []
deps = []
-
configs += [ "../:pdfium_core_config" ]
visibility = [ "../*" ]
@@ -109,6 +108,8 @@
if (pdf_enable_xfa) {
sources += [
+ "gced_embeddertest.cpp",
+ "gced_embeddertest.h",
"xfa_js_embedder_test.cpp",
"xfa_js_embedder_test.h",
]
@@ -117,6 +118,8 @@
"../fpdfsdk/fpdfxfa",
"../xfa/fxfa",
"../xfa/fxfa/parser",
+ "//v8:cppgc",
+ "//v8:v8_libplatform",
]
}
}
diff --git a/testing/gced_embeddertest.cpp b/testing/gced_embeddertest.cpp
new file mode 100644
index 0000000..395d7dc
--- /dev/null
+++ b/testing/gced_embeddertest.cpp
@@ -0,0 +1,35 @@
+// 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 "testing/gced_embeddertest.h"
+
+#include "public/fpdfview.h"
+#include "v8/include/cppgc/allocation.h"
+#include "v8/include/cppgc/persistent.h"
+#include "v8/include/libplatform/libplatform.h"
+#include "v8/include/v8.h"
+
+void GCedEmbedderTest::SetUp() {
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator = static_cast<v8::ArrayBuffer::Allocator*>(
+ FPDF_GetArrayBufferAllocatorSharedInstance());
+ isolate_.reset(v8::Isolate::New(params));
+ EmbedderTest::SetExternalIsolate(isolate_.get());
+ EmbedderTest::SetUp();
+}
+
+void GCedEmbedderTest::TearDown() {
+ EmbedderTest::TearDown();
+ isolate_.reset();
+}
+
+void GCedEmbedderTest::PumpPlatformMessageLoop() {
+ v8::Platform* platform = EmbedderTestEnvironment::GetInstance()->platform();
+ while (v8::platform::PumpMessageLoop(platform, isolate_.get()))
+ continue;
+}
+
+void GCedEmbedderTest::IsolateDeleter::operator()(v8::Isolate* ptr) {
+ ptr->Dispose();
+}
diff --git a/testing/gced_embeddertest.h b/testing/gced_embeddertest.h
new file mode 100644
index 0000000..3313be9
--- /dev/null
+++ b/testing/gced_embeddertest.h
@@ -0,0 +1,30 @@
+// 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 TESTING_GCED_EMBEDDER_TEST_H_
+#define TESTING_GCED_EMBEDDER_TEST_H_
+
+#include <memory>
+
+#include "testing/embedder_test.h"
+
+namespace v8 {
+class Isolate;
+} // namespace v8
+
+class GCedEmbedderTest : public EmbedderTest {
+ public:
+ void SetUp() override;
+ void TearDown() override;
+ void PumpPlatformMessageLoop();
+
+ private:
+ struct IsolateDeleter {
+ void operator()(v8::Isolate* ptr);
+ };
+
+ std::unique_ptr<v8::Isolate, IsolateDeleter> isolate_;
+};
+
+#endif // TESTING_GCED_EMBEDDER_TEST_H_