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