diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /ipc/ipdl/test/cxx/TestAsyncReturns.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ipc/ipdl/test/cxx/TestAsyncReturns.cpp')
-rw-r--r-- | ipc/ipdl/test/cxx/TestAsyncReturns.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp new file mode 100644 index 0000000000..76597143c0 --- /dev/null +++ b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp @@ -0,0 +1,101 @@ +#include "TestAsyncReturns.h" + +#include "IPDLUnitTests.h" // fail etc. + +#include "mozilla/AbstractThread.h" +#include "mozilla/Unused.h" + +namespace mozilla { +namespace _ipdltest { + +static uint32_t sMagic1 = 0x105b59fb; +static uint32_t sMagic2 = 0x09b6f5e3; + +//----------------------------------------------------------------------------- +// parent + +TestAsyncReturnsParent::TestAsyncReturnsParent() { + MOZ_COUNT_CTOR(TestAsyncReturnsParent); +} + +TestAsyncReturnsParent::~TestAsyncReturnsParent() { + MOZ_COUNT_DTOR(TestAsyncReturnsParent); +} + +void TestAsyncReturnsParent::Main() { + SendNoReturn()->Then( + MessageLoop::current()->SerialEventTarget(), __func__, + [](bool unused) { fail("resolve handler should not be called"); }, + [](ResponseRejectReason&& aReason) { + // MozPromise asserts in debug build if the + // handler is not called + if (aReason != ResponseRejectReason::ChannelClosed) { + fail("reject with wrong reason"); + } + passed("reject handler called on channel close"); + }); + SendPing()->Then( + MessageLoop::current()->SerialEventTarget(), __func__, + [this](bool one) { + if (one) { + passed("take one argument"); + } else { + fail("get one argument but has wrong value"); + } + + // Also try with the callback-based API. + SendPing( + [this](bool one) { + if (one) { + passed("take one argument"); + } else { + fail("get one argument but has wrong value"); + } + Close(); + }, + [](ResponseRejectReason&& aReason) { fail("sending Ping"); }); + }, + [](ResponseRejectReason&& aReason) { fail("sending Ping"); }); +} + +mozilla::ipc::IPCResult TestAsyncReturnsParent::RecvPong( + PongResolver&& aResolve) { + aResolve(std::tuple<const uint32_t&, const uint32_t&>(sMagic1, sMagic2)); + return IPC_OK(); +} + +//----------------------------------------------------------------------------- +// child + +TestAsyncReturnsChild::TestAsyncReturnsChild() { + MOZ_COUNT_CTOR(TestAsyncReturnsChild); +} + +TestAsyncReturnsChild::~TestAsyncReturnsChild() { + MOZ_COUNT_DTOR(TestAsyncReturnsChild); +} + +mozilla::ipc::IPCResult TestAsyncReturnsChild::RecvNoReturn( + NoReturnResolver&& aResolve) { + // Not resolving the promise intentionally + return IPC_OK(); +} + +mozilla::ipc::IPCResult TestAsyncReturnsChild::RecvPing( + PingResolver&& aResolve) { + SendPong()->Then( + MessageLoop::current()->SerialEventTarget(), __func__, + [aResolve](const std::tuple<uint32_t, uint32_t>& aParam) { + if (std::get<0>(aParam) == sMagic1 && std::get<1>(aParam) == sMagic2) { + passed("take two arguments"); + } else { + fail("get two argument but has wrong value"); + } + aResolve(true); + }, + [](ResponseRejectReason&& aReason) { fail("sending Pong"); }); + return IPC_OK(); +} + +} // namespace _ipdltest +} // namespace mozilla |