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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_nesting-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* -*- Mode: javascript; js-indent-level: 2; -*- */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +// Test that we can nest event loops when needed in
     1.9 +// ThreadActor.prototype.synchronize.
    1.10 +
    1.11 +var gClient;
    1.12 +var gThreadActor;
    1.13 +
    1.14 +function run_test() {
    1.15 +  initTestDebuggerServer();
    1.16 +  let gDebuggee = addTestGlobal("test-nesting");
    1.17 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.18 +  gClient.connect(function () {
    1.19 +    attachTestTabAndResume(gClient, "test-nesting", function (aResponse, aTabClient, aThreadClient) {
    1.20 +      // Reach over the protocol connection and get a reference to the thread actor.
    1.21 +      gThreadActor = aThreadClient._transport._serverConnection.getActor(aThreadClient._actor);
    1.22 +
    1.23 +      test_nesting();
    1.24 +    });
    1.25 +  });
    1.26 +  do_test_pending();
    1.27 +}
    1.28 +
    1.29 +function test_nesting() {
    1.30 +  const thread = gThreadActor;
    1.31 +  const { resolve, reject, promise: p } = promise.defer();
    1.32 +
    1.33 +  let currentStep = 0;
    1.34 +
    1.35 +  executeSoon(function () {
    1.36 +    // Should be on the first step
    1.37 +    do_check_eq(++currentStep, 1);
    1.38 +    // We should have one nested event loop from synchronize
    1.39 +    do_check_eq(thread._nestedEventLoops.size, 1);
    1.40 +    resolve(true);
    1.41 +  });
    1.42 +
    1.43 +  do_check_eq(thread.synchronize(p), true);
    1.44 +
    1.45 +  // Should be on the second step
    1.46 +  do_check_eq(++currentStep, 2);
    1.47 +  // There shouldn't be any nested event loops anymore
    1.48 +  do_check_eq(thread._nestedEventLoops.size, 0);
    1.49 +
    1.50 +  finishClient(gClient);
    1.51 +}

mercurial