michael@0: #include "base/basictypes.h" michael@0: michael@0: #include "nsThreadUtils.h" michael@0: michael@0: #include "TestNestedLoops.h" michael@0: michael@0: #include "IPDLUnitTests.h" // fail etc. michael@0: michael@0: template<> michael@0: struct RunnableMethodTraits michael@0: { michael@0: static void RetainCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { } michael@0: static void ReleaseCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { } michael@0: }; michael@0: michael@0: namespace mozilla { michael@0: namespace _ipdltest { michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // parent michael@0: michael@0: TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false) michael@0: { michael@0: MOZ_COUNT_CTOR(TestNestedLoopsParent); michael@0: } michael@0: michael@0: TestNestedLoopsParent::~TestNestedLoopsParent() michael@0: { michael@0: MOZ_COUNT_DTOR(TestNestedLoopsParent); michael@0: } michael@0: michael@0: void michael@0: TestNestedLoopsParent::Main() michael@0: { michael@0: if (!SendStart()) michael@0: fail("sending Start"); michael@0: michael@0: // sigh ... spin for a while to let Nonce arrive michael@0: puts(" (sleeping to wait for nonce ... sorry)"); michael@0: PR_Sleep(5000); michael@0: michael@0: // while waiting for the reply to R, we'll receive Nonce michael@0: if (!CallR()) michael@0: fail("calling R"); michael@0: michael@0: Close(); michael@0: } michael@0: michael@0: bool michael@0: TestNestedLoopsParent::RecvNonce() michael@0: { michael@0: // if we have an OnMaybeDequeueOne waiting for us (we may not, due michael@0: // to the inherent race condition in this test, then this event michael@0: // must be ordered after it in the queue michael@0: MessageLoop::current()->PostTask( michael@0: FROM_HERE, michael@0: NewRunnableMethod(this, &TestNestedLoopsParent::BreakNestedLoop)); michael@0: michael@0: // sigh ... spin for a while to let the reply to R arrive michael@0: puts(" (sleeping to wait for reply to R ... sorry)"); michael@0: PR_Sleep(5000); michael@0: michael@0: // sigh ... we have no idea when code might do this michael@0: do { michael@0: if (!NS_ProcessNextEvent(nullptr, false)) michael@0: fail("expected at least one pending event"); michael@0: } while (!mBreakNestedLoop); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: TestNestedLoopsParent::BreakNestedLoop() michael@0: { michael@0: mBreakNestedLoop = true; michael@0: } michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // child michael@0: michael@0: TestNestedLoopsChild::TestNestedLoopsChild() michael@0: { michael@0: MOZ_COUNT_CTOR(TestNestedLoopsChild); michael@0: } michael@0: michael@0: TestNestedLoopsChild::~TestNestedLoopsChild() michael@0: { michael@0: MOZ_COUNT_DTOR(TestNestedLoopsChild); michael@0: } michael@0: michael@0: bool michael@0: TestNestedLoopsChild::RecvStart() michael@0: { michael@0: if (!SendNonce()) michael@0: fail("sending Nonce"); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: TestNestedLoopsChild::AnswerR() michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: } // namespace _ipdltest michael@0: } // namespace mozilla