michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests re-entrant startTrace/stopTrace calls on TraceActor. Tests michael@0: * that stopTrace ends the most recently started trace when not michael@0: * provided with a name. Tests that starting a trace with the same michael@0: * name twice results in only one trace being collected for that name. michael@0: */ michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gTraceClient; michael@0: michael@0: function run_test() michael@0: { michael@0: initTestTracerServer(); michael@0: gDebuggee = addTestGlobal("test-tracer-actor"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function() { michael@0: attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) { michael@0: gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) { michael@0: gTraceClient = aTraceClient; michael@0: test_start_stop_reentrant(); michael@0: }); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_start_stop_reentrant() michael@0: { michael@0: do_check_true(!gTraceClient.tracing, "TraceClient should start in idle state"); michael@0: michael@0: start_named_trace("foo") michael@0: .then(start_named_trace.bind(null, "foo")) michael@0: .then(start_named_trace.bind(null, "bar")) michael@0: .then(start_named_trace.bind(null, "baz")) michael@0: .then(stop_trace.bind(null, "bar", "bar")) michael@0: .then(stop_trace.bind(null, null, "baz")) michael@0: .then(stop_trace.bind(null, null, "foo")) michael@0: .then(function() { michael@0: do_check_true(!gTraceClient.tracing, "TraceClient should finish in idle state"); michael@0: finishClient(gClient); michael@0: }); michael@0: } michael@0: michael@0: function start_named_trace(aName) michael@0: { michael@0: let deferred = promise.defer(); michael@0: gTraceClient.startTrace([], aName, function(aResponse) { michael@0: do_check_true(!!gTraceClient.tracing, "TraceClient should be in tracing state"); michael@0: do_check_true(!aResponse.error, michael@0: 'startTrace should not respond with error: ' + aResponse.error); michael@0: do_check_eq(aResponse.type, "startedTrace", michael@0: 'startTrace response should have "type":"startedTrace" property'); michael@0: do_check_eq(aResponse.why, "requested", michael@0: 'startTrace response should have "why":"requested" property'); michael@0: do_check_eq(aResponse.name, aName, michael@0: 'startTrace response should have the given name'); michael@0: deferred.resolve(); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function stop_trace(aName, aExpectedName) michael@0: { michael@0: let deferred = promise.defer(); michael@0: gTraceClient.stopTrace(aName, function(aResponse) { michael@0: do_check_true(!aResponse.error, michael@0: 'stopTrace should not respond with error: ' + aResponse.error); michael@0: do_check_true(aResponse.type === "stoppedTrace", michael@0: 'stopTrace response should have "type":"stoppedTrace" property'); michael@0: do_check_true(aResponse.why === "requested", michael@0: 'stopTrace response should have "why":"requested" property'); michael@0: do_check_true(aResponse.name === aExpectedName, michael@0: 'stopTrace response should have name "' + aExpectedName michael@0: + '", but had "' + aResponse.name + '"'); michael@0: deferred.resolve(); michael@0: }); michael@0: return deferred.promise; michael@0: }