|
1 /* -*- Mode: javascript; js-indent-level: 2; -*- */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 // Test that we can nest event loops when needed in |
|
6 // ThreadActor.prototype.synchronize. |
|
7 |
|
8 var gClient; |
|
9 var gThreadActor; |
|
10 |
|
11 function run_test() { |
|
12 initTestDebuggerServer(); |
|
13 let gDebuggee = addTestGlobal("test-nesting"); |
|
14 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
15 gClient.connect(function () { |
|
16 attachTestTabAndResume(gClient, "test-nesting", function (aResponse, aTabClient, aThreadClient) { |
|
17 // Reach over the protocol connection and get a reference to the thread actor. |
|
18 gThreadActor = aThreadClient._transport._serverConnection.getActor(aThreadClient._actor); |
|
19 |
|
20 test_nesting(); |
|
21 }); |
|
22 }); |
|
23 do_test_pending(); |
|
24 } |
|
25 |
|
26 function test_nesting() { |
|
27 const thread = gThreadActor; |
|
28 const { resolve, reject, promise: p } = promise.defer(); |
|
29 |
|
30 let currentStep = 0; |
|
31 |
|
32 executeSoon(function () { |
|
33 // Should be on the first step |
|
34 do_check_eq(++currentStep, 1); |
|
35 // We should have one nested event loop from synchronize |
|
36 do_check_eq(thread._nestedEventLoops.size, 1); |
|
37 resolve(true); |
|
38 }); |
|
39 |
|
40 do_check_eq(thread.synchronize(p), true); |
|
41 |
|
42 // Should be on the second step |
|
43 do_check_eq(++currentStep, 2); |
|
44 // There shouldn't be any nested event loops anymore |
|
45 do_check_eq(thread._nestedEventLoops.size, 0); |
|
46 |
|
47 finishClient(gClient); |
|
48 } |