toolkit/devtools/server/tests/unit/test_trace_actor-02.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.

     1 /* Any copyright is dedicated to the Public Domain.
     2  http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests re-entrant startTrace/stopTrace calls on TraceActor.  Tests
     6  * that stopTrace ends the most recently started trace when not
     7  * provided with a name. Tests that starting a trace with the same
     8  * name twice results in only one trace being collected for that name.
     9  */
    11 var gDebuggee;
    12 var gClient;
    13 var gTraceClient;
    15 function run_test()
    16 {
    17   initTestTracerServer();
    18   gDebuggee = addTestGlobal("test-tracer-actor");
    19   gClient = new DebuggerClient(DebuggerServer.connectPipe());
    20   gClient.connect(function() {
    21     attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) {
    22       gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) {
    23         gTraceClient = aTraceClient;
    24         test_start_stop_reentrant();
    25       });
    26     });
    27   });
    28   do_test_pending();
    29 }
    31 function test_start_stop_reentrant()
    32 {
    33   do_check_true(!gTraceClient.tracing, "TraceClient should start in idle state");
    35   start_named_trace("foo")
    36     .then(start_named_trace.bind(null, "foo"))
    37     .then(start_named_trace.bind(null, "bar"))
    38     .then(start_named_trace.bind(null, "baz"))
    39     .then(stop_trace.bind(null, "bar", "bar"))
    40     .then(stop_trace.bind(null, null, "baz"))
    41     .then(stop_trace.bind(null, null, "foo"))
    42     .then(function() {
    43       do_check_true(!gTraceClient.tracing, "TraceClient should finish in idle state");
    44       finishClient(gClient);
    45     });
    46 }
    48 function start_named_trace(aName)
    49 {
    50   let deferred = promise.defer();
    51   gTraceClient.startTrace([], aName, function(aResponse) {
    52     do_check_true(!!gTraceClient.tracing, "TraceClient should be in tracing state");
    53     do_check_true(!aResponse.error,
    54                   'startTrace should not respond with error: ' + aResponse.error);
    55     do_check_eq(aResponse.type, "startedTrace",
    56                 'startTrace response should have "type":"startedTrace" property');
    57     do_check_eq(aResponse.why, "requested",
    58                 'startTrace response should have "why":"requested" property');
    59     do_check_eq(aResponse.name, aName,
    60                 'startTrace response should have the given name');
    61     deferred.resolve();
    62   });
    63   return deferred.promise;
    64 }
    66 function stop_trace(aName, aExpectedName)
    67 {
    68   let deferred = promise.defer();
    69   gTraceClient.stopTrace(aName, function(aResponse) {
    70     do_check_true(!aResponse.error,
    71                   'stopTrace should not respond with error: ' + aResponse.error);
    72     do_check_true(aResponse.type === "stoppedTrace",
    73                   'stopTrace response should have "type":"stoppedTrace" property');
    74     do_check_true(aResponse.why === "requested",
    75                   'stopTrace response should have "why":"requested" property');
    76     do_check_true(aResponse.name === aExpectedName,
    77                   'stopTrace response should have name "' + aExpectedName
    78                   + '", but had "' + aResponse.name + '"');
    79     deferred.resolve();
    80   });
    81   return deferred.promise;
    82 }

mercurial