diff --git a/dom/media/gtest/moz.build b/dom/media/gtest/moz.build index c66ac4a9437f..595a530d12fc 100644 --- a/dom/media/gtest/moz.build +++ b/dom/media/gtest/moz.build @@ -19,7 +19,6 @@ UNIFIED_SOURCES += [ 'TestMediaDataDecoder.cpp', 'TestMediaEventSource.cpp', 'TestMediaMIMETypes.cpp', - 'TestMozPromise.cpp', 'TestMP3Demuxer.cpp', 'TestMP4Demuxer.cpp', 'TestRust.cpp', diff --git a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp index 9370c0c50527..471c003fdac7 100644 --- a/ipc/ipdl/test/cxx/TestAsyncReturns.cpp +++ b/ipc/ipdl/test/cxx/TestAsyncReturns.cpp @@ -27,10 +27,7 @@ TestAsyncReturnsParent::~TestAsyncReturnsParent() void TestAsyncReturnsParent::Main() { - if (!AbstractThread::MainThread()) { - fail("AbstractThread not initalized"); - } - SendNoReturn()->Then(AbstractThread::MainThread(), __func__, + SendNoReturn()->Then(MessageLoop::current()->SerialEventTarget(), __func__, [](bool unused) { fail("resolve handler should not be called"); }, @@ -42,7 +39,7 @@ TestAsyncReturnsParent::Main() } passed("reject handler called on channel close"); }); - SendPing()->Then(AbstractThread::MainThread(), __func__, + SendPing()->Then(MessageLoop::current()->SerialEventTarget(), __func__, [this](bool one) { if (one) { passed("take one argument"); @@ -88,10 +85,7 @@ TestAsyncReturnsChild::RecvNoReturn(NoReturnResolver&& aResolve) mozilla::ipc::IPCResult TestAsyncReturnsChild::RecvPing(PingResolver&& aResolve) { - if (!AbstractThread::MainThread()) { - fail("AbstractThread not initalized"); - } - SendPong()->Then(AbstractThread::MainThread(), __func__, + SendPong()->Then(MessageLoop::current()->SerialEventTarget(), __func__, [aResolve](const Tuple& aParam) { if (Get<0>(aParam) == sMagic1 && Get<1>(aParam) == sMagic2) { passed("take two arguments"); diff --git a/dom/media/gtest/TestMozPromise.cpp b/xpcom/tests/gtest/TestMozPromise.cpp similarity index 95% rename from dom/media/gtest/TestMozPromise.cpp rename to xpcom/tests/gtest/TestMozPromise.cpp index 1267fbede496..0d82fc9fdad6 100644 --- a/dom/media/gtest/TestMozPromise.cpp +++ b/xpcom/tests/gtest/TestMozPromise.cpp @@ -5,6 +5,8 @@ #include "gtest/gtest.h" +#include "base/message_loop.h" + #include "mozilla/TaskQueue.h" #include "mozilla/MozPromise.h" @@ -407,4 +409,24 @@ TEST(MozPromise, HeterogeneousChaining) }); } +TEST(MozPromise, XPCOMEventTarget) +{ + TestPromise::CreateAndResolve(42, __func__)->Then(GetCurrentThreadSerialEventTarget(), __func__, + [] (int aResolveValue) -> void { EXPECT_EQ(aResolveValue, 42); }, + DO_FAIL); + + // Spin the event loop. + NS_ProcessPendingEvents(nullptr); +} + +TEST(MozPromise, MessageLoopEventTarget) +{ + TestPromise::CreateAndResolve(42, __func__)->Then(MessageLoop::current()->SerialEventTarget(), __func__, + [] (int aResolveValue) -> void { EXPECT_EQ(aResolveValue, 42); }, + DO_FAIL); + + // Spin the event loop. + NS_ProcessPendingEvents(nullptr); +} + #undef DO_FAIL diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build index c49af4dc49ca..c1a4fe02201a 100644 --- a/xpcom/tests/gtest/moz.build +++ b/xpcom/tests/gtest/moz.build @@ -22,6 +22,7 @@ UNIFIED_SOURCES += [ 'TestFile.cpp', 'TestGCPostBarriers.cpp', 'TestID.cpp', + 'TestMozPromise.cpp', 'TestMultiplexInputStream.cpp', 'TestNsDeque.cpp', 'TestNSPRLogModulesParser.cpp', @@ -85,3 +86,5 @@ LOCAL_INCLUDES += [ ] FINAL_LIBRARY = 'xul-gtest' + +include('/ipc/chromium/chromium-config.mozbuild')