зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1367679. P5 - add a gtest to test chaining between different promise types. r=gerald
MozReview-Commit-ID: 8l3clGN3pWd --HG-- extra : rebase_source : 5c3a7d74649a44e9d86738942bfe58a34f63332f extra : intermediate-source : 4811c6b4d7c4fb241c633e3c81cc8b032c69386e extra : source : 620a6593190dbb97df105a5bb1ca5fa48d1c73be
This commit is contained in:
Родитель
531fbb106b
Коммит
7348b1e4b3
|
@ -350,4 +350,61 @@ TEST(MozPromise, MoveOnlyType)
|
|||
});
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче