Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | #include "base/basictypes.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "nsThreadUtils.h" |
michael@0 | 4 | |
michael@0 | 5 | #include "TestNestedLoops.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 8 | |
michael@0 | 9 | template<> |
michael@0 | 10 | struct RunnableMethodTraits<mozilla::_ipdltest::TestNestedLoopsParent> |
michael@0 | 11 | { |
michael@0 | 12 | static void RetainCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { } |
michael@0 | 13 | static void ReleaseCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { } |
michael@0 | 14 | }; |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace _ipdltest { |
michael@0 | 18 | |
michael@0 | 19 | //----------------------------------------------------------------------------- |
michael@0 | 20 | // parent |
michael@0 | 21 | |
michael@0 | 22 | TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false) |
michael@0 | 23 | { |
michael@0 | 24 | MOZ_COUNT_CTOR(TestNestedLoopsParent); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | TestNestedLoopsParent::~TestNestedLoopsParent() |
michael@0 | 28 | { |
michael@0 | 29 | MOZ_COUNT_DTOR(TestNestedLoopsParent); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void |
michael@0 | 33 | TestNestedLoopsParent::Main() |
michael@0 | 34 | { |
michael@0 | 35 | if (!SendStart()) |
michael@0 | 36 | fail("sending Start"); |
michael@0 | 37 | |
michael@0 | 38 | // sigh ... spin for a while to let Nonce arrive |
michael@0 | 39 | puts(" (sleeping to wait for nonce ... sorry)"); |
michael@0 | 40 | PR_Sleep(5000); |
michael@0 | 41 | |
michael@0 | 42 | // while waiting for the reply to R, we'll receive Nonce |
michael@0 | 43 | if (!CallR()) |
michael@0 | 44 | fail("calling R"); |
michael@0 | 45 | |
michael@0 | 46 | Close(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | bool |
michael@0 | 50 | TestNestedLoopsParent::RecvNonce() |
michael@0 | 51 | { |
michael@0 | 52 | // if we have an OnMaybeDequeueOne waiting for us (we may not, due |
michael@0 | 53 | // to the inherent race condition in this test, then this event |
michael@0 | 54 | // must be ordered after it in the queue |
michael@0 | 55 | MessageLoop::current()->PostTask( |
michael@0 | 56 | FROM_HERE, |
michael@0 | 57 | NewRunnableMethod(this, &TestNestedLoopsParent::BreakNestedLoop)); |
michael@0 | 58 | |
michael@0 | 59 | // sigh ... spin for a while to let the reply to R arrive |
michael@0 | 60 | puts(" (sleeping to wait for reply to R ... sorry)"); |
michael@0 | 61 | PR_Sleep(5000); |
michael@0 | 62 | |
michael@0 | 63 | // sigh ... we have no idea when code might do this |
michael@0 | 64 | do { |
michael@0 | 65 | if (!NS_ProcessNextEvent(nullptr, false)) |
michael@0 | 66 | fail("expected at least one pending event"); |
michael@0 | 67 | } while (!mBreakNestedLoop); |
michael@0 | 68 | |
michael@0 | 69 | return true; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | void |
michael@0 | 73 | TestNestedLoopsParent::BreakNestedLoop() |
michael@0 | 74 | { |
michael@0 | 75 | mBreakNestedLoop = true; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | //----------------------------------------------------------------------------- |
michael@0 | 79 | // child |
michael@0 | 80 | |
michael@0 | 81 | TestNestedLoopsChild::TestNestedLoopsChild() |
michael@0 | 82 | { |
michael@0 | 83 | MOZ_COUNT_CTOR(TestNestedLoopsChild); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | TestNestedLoopsChild::~TestNestedLoopsChild() |
michael@0 | 87 | { |
michael@0 | 88 | MOZ_COUNT_DTOR(TestNestedLoopsChild); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | bool |
michael@0 | 92 | TestNestedLoopsChild::RecvStart() |
michael@0 | 93 | { |
michael@0 | 94 | if (!SendNonce()) |
michael@0 | 95 | fail("sending Nonce"); |
michael@0 | 96 | return true; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | bool |
michael@0 | 100 | TestNestedLoopsChild::AnswerR() |
michael@0 | 101 | { |
michael@0 | 102 | return true; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | } // namespace _ipdltest |
michael@0 | 106 | } // namespace mozilla |