toolkit/devtools/server/tests/unit/test_nesting-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial