michael@0: /* -*- Mode: javascript; js-indent-level: 2; -*- */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that we can nest event loops when needed in michael@0: // ThreadActor.prototype.synchronize. michael@0: michael@0: var gClient; michael@0: var gThreadActor; michael@0: michael@0: function run_test() { michael@0: initTestDebuggerServer(); michael@0: let gDebuggee = addTestGlobal("test-nesting"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function () { michael@0: attachTestTabAndResume(gClient, "test-nesting", function (aResponse, aTabClient, aThreadClient) { michael@0: // Reach over the protocol connection and get a reference to the thread actor. michael@0: gThreadActor = aThreadClient._transport._serverConnection.getActor(aThreadClient._actor); michael@0: michael@0: test_nesting(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_nesting() { michael@0: const thread = gThreadActor; michael@0: const { resolve, reject, promise: p } = promise.defer(); michael@0: michael@0: let currentStep = 0; michael@0: michael@0: executeSoon(function () { michael@0: // Should be on the first step michael@0: do_check_eq(++currentStep, 1); michael@0: // We should have one nested event loop from synchronize michael@0: do_check_eq(thread._nestedEventLoops.size, 1); michael@0: resolve(true); michael@0: }); michael@0: michael@0: do_check_eq(thread.synchronize(p), true); michael@0: michael@0: // Should be on the second step michael@0: do_check_eq(++currentStep, 2); michael@0: // There shouldn't be any nested event loops anymore michael@0: do_check_eq(thread._nestedEventLoops.size, 0); michael@0: michael@0: finishClient(gClient); michael@0: }