summaryrefslogtreecommitdiffstats
path: root/devtools/shared/tests/unit/test_executeSoon.js
blob: 6154a3e67e3578611a113375e9611e90b2b31373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Client request stacks should span the entire process from before making the
 * request to handling the reply from the server.  The server frames are not
 * included, nor can they be in most cases, since the server can be a remote
 * device.
 */

var { executeSoon } = require("devtools/shared/DevToolsUtils");
var promise = require("promise");
var defer = require("devtools/shared/defer");
var Services = require("Services");

var asyncStackEnabled =
  Services.prefs.getBoolPref("javascript.options.asyncstack");

do_register_cleanup(() => {
  Services.prefs.setBoolPref("javascript.options.asyncstack",
                             asyncStackEnabled);
});

add_task(function* () {
  Services.prefs.setBoolPref("javascript.options.asyncstack", true);

  yield waitForTick();

  let stack = Components.stack;
  while (stack) {
    do_print(stack.name);
    if (stack.name == "waitForTick") {
      // Reached back to outer function before executeSoon
      ok(true, "Complete stack");
      return;
    }
    stack = stack.asyncCaller || stack.caller;
  }
  ok(false, "Incomplete stack");
});

function waitForTick() {
  let deferred = defer();
  executeSoon(deferred.resolve);
  return deferred.promise;
}