|
1 #include "base/basictypes.h" |
|
2 |
|
3 #include "nsThreadUtils.h" |
|
4 |
|
5 #include "TestNestedLoops.h" |
|
6 |
|
7 #include "IPDLUnitTests.h" // fail etc. |
|
8 |
|
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 }; |
|
15 |
|
16 namespace mozilla { |
|
17 namespace _ipdltest { |
|
18 |
|
19 //----------------------------------------------------------------------------- |
|
20 // parent |
|
21 |
|
22 TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false) |
|
23 { |
|
24 MOZ_COUNT_CTOR(TestNestedLoopsParent); |
|
25 } |
|
26 |
|
27 TestNestedLoopsParent::~TestNestedLoopsParent() |
|
28 { |
|
29 MOZ_COUNT_DTOR(TestNestedLoopsParent); |
|
30 } |
|
31 |
|
32 void |
|
33 TestNestedLoopsParent::Main() |
|
34 { |
|
35 if (!SendStart()) |
|
36 fail("sending Start"); |
|
37 |
|
38 // sigh ... spin for a while to let Nonce arrive |
|
39 puts(" (sleeping to wait for nonce ... sorry)"); |
|
40 PR_Sleep(5000); |
|
41 |
|
42 // while waiting for the reply to R, we'll receive Nonce |
|
43 if (!CallR()) |
|
44 fail("calling R"); |
|
45 |
|
46 Close(); |
|
47 } |
|
48 |
|
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)); |
|
58 |
|
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); |
|
62 |
|
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); |
|
68 |
|
69 return true; |
|
70 } |
|
71 |
|
72 void |
|
73 TestNestedLoopsParent::BreakNestedLoop() |
|
74 { |
|
75 mBreakNestedLoop = true; |
|
76 } |
|
77 |
|
78 //----------------------------------------------------------------------------- |
|
79 // child |
|
80 |
|
81 TestNestedLoopsChild::TestNestedLoopsChild() |
|
82 { |
|
83 MOZ_COUNT_CTOR(TestNestedLoopsChild); |
|
84 } |
|
85 |
|
86 TestNestedLoopsChild::~TestNestedLoopsChild() |
|
87 { |
|
88 MOZ_COUNT_DTOR(TestNestedLoopsChild); |
|
89 } |
|
90 |
|
91 bool |
|
92 TestNestedLoopsChild::RecvStart() |
|
93 { |
|
94 if (!SendNonce()) |
|
95 fail("sending Nonce"); |
|
96 return true; |
|
97 } |
|
98 |
|
99 bool |
|
100 TestNestedLoopsChild::AnswerR() |
|
101 { |
|
102 return true; |
|
103 } |
|
104 |
|
105 } // namespace _ipdltest |
|
106 } // namespace mozilla |