Bug 1367679. P5 - add a gtest to test chaining between different promise types. draft
authorJW Wang <jwwang@mozilla.com>
Sat, 27 May 2017 22:03:57 +0800
changeset 588116 1056242fa74258ac15854cfd54507f3232c2107f
parent 588115 99ef0109a439d88645181d4a3c5ce09f37a49191
child 588119 a3f466b63da03a4989c799c169666bf0df937917
push id61915
push userjwwang@mozilla.com
push dateFri, 02 Jun 2017 06:48:13 +0000
bugs1367679
milestone55.0a1
Bug 1367679. P5 - add a gtest to test chaining between different promise types. MozReview-Commit-ID: 8l3clGN3pWd
dom/media/gtest/TestMozPromise.cpp
--- a/dom/media/gtest/TestMozPromise.cpp
+++ b/dom/media/gtest/TestMozPromise.cpp
@@ -345,9 +345,66 @@ TEST(MozPromise, MoveOnlyType)
       EXPECT_TRUE(aVal.IsResolve());
       EXPECT_EQ(nullptr, aVal.ResolveValue().get());
       EXPECT_EQ(87, *val.ResolveValue());
 
       queue->BeginShutdown();
     });
 }
 
+TEST(MozPromise, HeterogeneousChaining)
+{
+  using Promise1 = MozPromise<UniquePtr<char>, bool, true>;
+  using Promise2 = MozPromise<UniquePtr<int>, bool, true>;
+  using RRValue1 = Promise1::ResolveOrRejectValue;
+  using RRValue2 = Promise2::ResolveOrRejectValue;
+
+  MozPromiseRequestHolder<Promise2> holder;
+
+  AutoTaskQueue atq;
+  RefPtr<TaskQueue> queue = atq.Queue();
+
+  RunOnTaskQueue(queue, [queue, &holder]() {
+    Promise1::CreateAndResolve(MakeUnique<char>(0), __func__)
+      ->Then(queue,
+             __func__,
+             [&holder]() {
+               holder.Disconnect();
+               return Promise2::CreateAndResolve(MakeUnique<int>(0), __func__);
+             })
+      ->Then(queue,
+             __func__,
+             []() {
+               // Shouldn't be called for we've disconnected the request.
+               EXPECT_FALSE(true);
+             })
+      ->Track(holder);
+  });
+
+  Promise1::CreateAndResolve(MakeUnique<char>(87), __func__)
+    ->Then(queue,
+           __func__,
+           [](UniquePtr<char> aVal) {
+             EXPECT_EQ(87, *aVal);
+             return Promise2::CreateAndResolve(MakeUnique<int>(94), __func__);
+           },
+           []() {
+             return Promise2::CreateAndResolve(MakeUnique<int>(95), __func__);
+           })
+    ->Then(queue,
+           __func__,
+           [](UniquePtr<int> aVal) { EXPECT_EQ(94, *aVal); },
+           []() { EXPECT_FALSE(true); });
+
+  Promise1::CreateAndResolve(MakeUnique<char>(87), __func__)
+    ->Then(queue,
+           __func__,
+           [](RRValue1&& aVal) {
+             EXPECT_EQ(87, *aVal.ResolveValue());
+             return Promise2::CreateAndResolve(MakeUnique<int>(94), __func__);
+           })
+    ->Then(queue, __func__, [queue](RRValue2&& aVal) {
+      EXPECT_EQ(94, *aVal.ResolveValue());
+      queue->BeginShutdown();
+    });
+}
+
 #undef DO_FAIL