Add move-assign tests for cppgc::Member<> and cppgc::Persistent<>.

Ensure behaviour remains consistent with our assumptions.

Change-Id: I7795e22841cef36b730a83a13546057e58c14cdc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73150
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 731374e..53eb78b 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -235,6 +235,7 @@
         "gc/gced_tree_node_mixin_unittest.cpp",
         "gc/gced_tree_node_unittest.cpp",
         "gc/heap_unittest.cpp",
+        "gc/move_unittest.cpp",
       ]
       deps += [ "//v8:cppgc" ]
     }
diff --git a/fxjs/gc/move_unittest.cpp b/fxjs/gc/move_unittest.cpp
new file mode 100644
index 0000000..8f12331
--- /dev/null
+++ b/fxjs/gc/move_unittest.cpp
@@ -0,0 +1,61 @@
+// 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/gc/heap.h"
+
+#include "testing/fxgc_unittest.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "v8/include/cppgc/member.h"
+#include "v8/include/cppgc/persistent.h"
+
+namespace {
+
+class HeapObject : public cppgc::GarbageCollected<HeapObject> {
+ public:
+  CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
+
+  void Trace(cppgc::Visitor* visitor) const {
+    visitor->Trace(frick_);
+    visitor->Trace(frack_);
+  }
+
+  cppgc::Member<HeapObject> frick_;
+  cppgc::Member<HeapObject> frack_;
+
+ private:
+  HeapObject() = default;
+};
+
+class CppObject {
+ public:
+  CppObject() = default;
+
+  cppgc::Persistent<HeapObject> click_;
+  cppgc::Persistent<HeapObject> clack_;
+};
+
+}  // namespace
+
+class MoveUnitTest : public FXGCUnitTest {};
+
+TEST_F(MoveUnitTest, Member) {
+  // Moving a Member<> leaves the moved-from object intact.
+  auto* obj =
+      cppgc::MakeGarbageCollected<HeapObject>(heap()->GetAllocationHandle());
+  obj->frick_ = obj;
+  obj->frack_ = std::move(obj->frick_);
+  EXPECT_EQ(obj, obj->frick_);
+  EXPECT_EQ(obj, obj->frack_);
+}
+
+TEST_F(MoveUnitTest, Persistent) {
+  // Moving a Persistent<> leaves the moved-from object as null.
+  auto* obj =
+      cppgc::MakeGarbageCollected<HeapObject>(heap()->GetAllocationHandle());
+  CppObject outsider;
+  outsider.click_ = obj;
+  outsider.clack_ = std::move(outsider.click_);
+  EXPECT_EQ(nullptr, outsider.click_);
+  EXPECT_EQ(obj, outsider.clack_);
+}