Bug 1362910. P3 - add a gtest to test move-only types with MozPromise. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 11 May 2017 11:51:58 +0800
changeset 576060 27ddd27c9025a127f733ce4d195637d968ee55b6
parent 576021 7cf13fa4b7562b7ef3aa12bf0105e94e1d4f2073
child 628103 a12b2cbc057e78f71a910e1a86a5ed846fb95da2
push id58257
push userjwwang@mozilla.com
push dateThu, 11 May 2017 09:19:44 +0000
bugs1362910
milestone55.0a1
Bug 1362910. P3 - add a gtest to test move-only types with MozPromise. MozReview-Commit-ID: 5LP7POyxNt3
dom/media/gtest/TestMozPromise.cpp
--- a/dom/media/gtest/TestMozPromise.cpp
+++ b/dom/media/gtest/TestMozPromise.cpp
@@ -309,9 +309,42 @@ TEST(MozPromise, ResolveOrRejectValue)
 
   // IsResolve() should remain true after Move().
   UniquePtr<int> i = Move(val.ResolveValue());
   EXPECT_EQ(87, *i);
   EXPECT_TRUE(val.IsResolve());
   EXPECT_EQ(val.ResolveValue().get(), nullptr);
 }
 
+TEST(MozPromise, MoveOnlyType)
+{
+  using MyPromise = MozPromise<UniquePtr<int>, bool, true>;
+  using RRValue = MyPromise::ResolveOrRejectValue;
+
+  AutoTaskQueue atq;
+  RefPtr<TaskQueue> queue = atq.Queue();
+
+  MyPromise::CreateAndResolve(MakeUnique<int>(87), __func__)
+  ->Then(queue, __func__,
+    [](UniquePtr<int> aVal) {
+      EXPECT_EQ(87, *aVal);
+    },
+    []() { EXPECT_TRUE(false); });
+
+  MyPromise::CreateAndResolve(MakeUnique<int>(87), __func__)
+  ->Then(queue, __func__,
+    [queue](RRValue&& aVal) {
+      EXPECT_FALSE(aVal.IsNothing());
+      EXPECT_TRUE(aVal.IsResolve());
+      EXPECT_FALSE(aVal.IsReject());
+      EXPECT_EQ(87, *aVal.ResolveValue());
+
+      // Move() shouldn't change the resolve/reject state of aVal.
+      RRValue val = Move(aVal);
+      EXPECT_TRUE(aVal.IsResolve());
+      EXPECT_EQ(nullptr, aVal.ResolveValue().get());
+      EXPECT_EQ(87, *val.ResolveValue());
+
+      queue->BeginShutdown();
+    });
+}
+
 #undef DO_FAIL