1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_trace_actor-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 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 + * Tests re-entrant startTrace/stopTrace calls on TraceActor. Tests 1.9 + * that stopTrace ends the most recently started trace when not 1.10 + * provided with a name. Tests that starting a trace with the same 1.11 + * name twice results in only one trace being collected for that name. 1.12 + */ 1.13 + 1.14 +var gDebuggee; 1.15 +var gClient; 1.16 +var gTraceClient; 1.17 + 1.18 +function run_test() 1.19 +{ 1.20 + initTestTracerServer(); 1.21 + gDebuggee = addTestGlobal("test-tracer-actor"); 1.22 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.23 + gClient.connect(function() { 1.24 + attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) { 1.25 + gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) { 1.26 + gTraceClient = aTraceClient; 1.27 + test_start_stop_reentrant(); 1.28 + }); 1.29 + }); 1.30 + }); 1.31 + do_test_pending(); 1.32 +} 1.33 + 1.34 +function test_start_stop_reentrant() 1.35 +{ 1.36 + do_check_true(!gTraceClient.tracing, "TraceClient should start in idle state"); 1.37 + 1.38 + start_named_trace("foo") 1.39 + .then(start_named_trace.bind(null, "foo")) 1.40 + .then(start_named_trace.bind(null, "bar")) 1.41 + .then(start_named_trace.bind(null, "baz")) 1.42 + .then(stop_trace.bind(null, "bar", "bar")) 1.43 + .then(stop_trace.bind(null, null, "baz")) 1.44 + .then(stop_trace.bind(null, null, "foo")) 1.45 + .then(function() { 1.46 + do_check_true(!gTraceClient.tracing, "TraceClient should finish in idle state"); 1.47 + finishClient(gClient); 1.48 + }); 1.49 +} 1.50 + 1.51 +function start_named_trace(aName) 1.52 +{ 1.53 + let deferred = promise.defer(); 1.54 + gTraceClient.startTrace([], aName, function(aResponse) { 1.55 + do_check_true(!!gTraceClient.tracing, "TraceClient should be in tracing state"); 1.56 + do_check_true(!aResponse.error, 1.57 + 'startTrace should not respond with error: ' + aResponse.error); 1.58 + do_check_eq(aResponse.type, "startedTrace", 1.59 + 'startTrace response should have "type":"startedTrace" property'); 1.60 + do_check_eq(aResponse.why, "requested", 1.61 + 'startTrace response should have "why":"requested" property'); 1.62 + do_check_eq(aResponse.name, aName, 1.63 + 'startTrace response should have the given name'); 1.64 + deferred.resolve(); 1.65 + }); 1.66 + return deferred.promise; 1.67 +} 1.68 + 1.69 +function stop_trace(aName, aExpectedName) 1.70 +{ 1.71 + let deferred = promise.defer(); 1.72 + gTraceClient.stopTrace(aName, function(aResponse) { 1.73 + do_check_true(!aResponse.error, 1.74 + 'stopTrace should not respond with error: ' + aResponse.error); 1.75 + do_check_true(aResponse.type === "stoppedTrace", 1.76 + 'stopTrace response should have "type":"stoppedTrace" property'); 1.77 + do_check_true(aResponse.why === "requested", 1.78 + 'stopTrace response should have "why":"requested" property'); 1.79 + do_check_true(aResponse.name === aExpectedName, 1.80 + 'stopTrace response should have name "' + aExpectedName 1.81 + + '", but had "' + aResponse.name + '"'); 1.82 + deferred.resolve(); 1.83 + }); 1.84 + return deferred.promise; 1.85 +}