toolkit/devtools/server/tests/unit/test_trace_actor-08.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_trace_actor-08.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Test the "depth" trace type.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gTraceClient;
    1.14 +
    1.15 +function run_test()
    1.16 +{
    1.17 +  initTestTracerServer();
    1.18 +  gDebuggee = addTestGlobal("test-tracer-actor");
    1.19 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.20 +  gClient.connect(function() {
    1.21 +    attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) {
    1.22 +      gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) {
    1.23 +        gTraceClient = aTraceClient;
    1.24 +        test_frame_depths();
    1.25 +      });
    1.26 +    });
    1.27 +  });
    1.28 +  do_test_pending();
    1.29 +}
    1.30 +
    1.31 +function test_frame_depths()
    1.32 +{
    1.33 +  const tracesStopped = promise.defer();
    1.34 +  gClient.addListener("traces", (aEvent, { traces }) => {
    1.35 +    for (let t of traces) {
    1.36 +      check_trace(t);
    1.37 +    }
    1.38 +    tracesStopped.resolve();
    1.39 +  });
    1.40 +
    1.41 +  start_trace()
    1.42 +    .then(eval_code)
    1.43 +    .then(() => tracesStopped.promise)
    1.44 +    .then(stop_trace)
    1.45 +    .then(function() {
    1.46 +      finishClient(gClient);
    1.47 +    }).then(null, error => {
    1.48 +      do_check_true(false, "Should not get an error, got: " + error);
    1.49 +    });
    1.50 +}
    1.51 +
    1.52 +function start_trace()
    1.53 +{
    1.54 +  let deferred = promise.defer();
    1.55 +  gTraceClient.startTrace(["depth", "name"], null, function() { deferred.resolve(); });
    1.56 +  return deferred.promise;
    1.57 +}
    1.58 +
    1.59 +function eval_code()
    1.60 +{
    1.61 +  gDebuggee.eval("(" + function iife() {
    1.62 +    function first() {
    1.63 +      second();
    1.64 +    }
    1.65 +
    1.66 +    function second() {
    1.67 +      third();
    1.68 +    }
    1.69 +
    1.70 +    function third() {
    1.71 +    }
    1.72 +
    1.73 +    first();
    1.74 +  } + ")()");
    1.75 +}
    1.76 +
    1.77 +function stop_trace()
    1.78 +{
    1.79 +  let deferred = promise.defer();
    1.80 +  gTraceClient.stopTrace(null, function() { deferred.resolve(); });
    1.81 +  return deferred.promise;
    1.82 +}
    1.83 +
    1.84 +function check_trace({ sequence, depth, name })
    1.85 +{
    1.86 +  switch(sequence) {
    1.87 +  case 0:
    1.88 +    do_check_eq(name, "(eval)");
    1.89 +    // Fall through
    1.90 +  case 9:
    1.91 +    do_check_eq(depth, 0);
    1.92 +    break;
    1.93 +
    1.94 +  case 1:
    1.95 +    do_check_eq(name, "iife");
    1.96 +    // Fall through
    1.97 +  case 8:
    1.98 +    do_check_eq(depth, 1);
    1.99 +    break;
   1.100 +
   1.101 +  case 2:
   1.102 +    do_check_eq(name, "first");
   1.103 +    // Fall through
   1.104 +  case 7:
   1.105 +    do_check_eq(depth, 2);
   1.106 +    break;
   1.107 +
   1.108 +  case 3:
   1.109 +    do_check_eq(name, "second");
   1.110 +    // Fall through
   1.111 +  case 6:
   1.112 +    do_check_eq(depth, 3);
   1.113 +    break;
   1.114 +
   1.115 +  case 4:
   1.116 +    do_check_eq(name, "third");
   1.117 +    // Fall through
   1.118 +  case 5:
   1.119 +    do_check_eq(depth, 4);
   1.120 +    break;
   1.121 +
   1.122 +  default:
   1.123 +    // Should have covered all sequences.
   1.124 +    do_check_true(false);
   1.125 +  }
   1.126 +}

mercurial