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.

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

mercurial