Bug 1367679. P5 - add a gtest to test chaining between different promise types. r=gerald
authorJW Wang <jwwang@mozilla.com>
Sat, 27 May 2017 22:03:57 +0800
changeset 410414 ac71a080692d709beb959c95fa554ba9b5f92590
parent 410413 470e0ad1615801291ed95970e20f274b4eeddeb8
child 410415 19acfff499d3ee44cb09ed76b43646c146d06f58
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1367679
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1367679. P5 - add a gtest to test chaining between different promise types. r=gerald 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