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: * Test that we get the expected frame enter/exit logs in the tracer view. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_tracing-01.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: michael@0: function test() { michael@0: SpecialPowers.pushPrefEnv({'set': [["devtools.debugger.tracer", true]]}, () => { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: michael@0: waitForSourceShown(gPanel, "code_tracing-01.js") michael@0: .then(() => startTracing(gPanel)) michael@0: .then(clickButton) michael@0: .then(() => waitForClientEvents(aPanel, "traces")) michael@0: .then(testTraceLogs) michael@0: .then(() => stopTracing(gPanel)) michael@0: .then(() => { michael@0: const deferred = promise.defer(); michael@0: SpecialPowers.popPrefEnv(deferred.resolve); michael@0: return deferred.promise; michael@0: }) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function clickButton() { michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gDebuggee.document.querySelector("button"), michael@0: gDebuggee); michael@0: } michael@0: michael@0: function testTraceLogs() { michael@0: const onclickLogs = filterTraces(gPanel, michael@0: t => t.querySelector(".trace-name[value=onclick]")); michael@0: is(onclickLogs.length, 2, "Should have two logs from 'onclick'"); michael@0: ok(onclickLogs[0].querySelector(".trace-call"), michael@0: "The first 'onclick' log should be a call."); michael@0: ok(onclickLogs[1].querySelector(".trace-return"), michael@0: "The second 'onclick' log should be a return."); michael@0: for (let t of onclickLogs) { michael@0: ok(t.querySelector(".trace-item").getAttribute("tooltiptext") michael@0: .contains("doc_tracing-01.html")); michael@0: } michael@0: michael@0: const nonOnclickLogs = filterTraces(gPanel, michael@0: t => !t.querySelector(".trace-name[value=onclick]")); michael@0: for (let t of nonOnclickLogs) { michael@0: ok(t.querySelector(".trace-item").getAttribute("tooltiptext") michael@0: .contains("code_tracing-01.js")); michael@0: } michael@0: michael@0: const mainLogs = filterTraces(gPanel, michael@0: t => t.querySelector(".trace-name[value=main]")); michael@0: is(mainLogs.length, 2, "Should have an enter and an exit for 'main'"); michael@0: ok(mainLogs[0].querySelector(".trace-call"), michael@0: "The first 'main' log should be a call."); michael@0: ok(mainLogs[1].querySelector(".trace-return"), michael@0: "The second 'main' log should be a return."); michael@0: michael@0: const factorialLogs = filterTraces(gPanel, michael@0: t => t.querySelector(".trace-name[value=factorial]")); michael@0: is(factorialLogs.length, 10, "Should have 5 enter, and 5 exit frames for 'factorial'"); michael@0: ok(factorialLogs.slice(0, 5).every(t => t.querySelector(".trace-call")), michael@0: "The first five 'factorial' logs should be calls."); michael@0: ok(factorialLogs.slice(5).every(t => t.querySelector(".trace-return")), michael@0: "The second five 'factorial' logs should be returns.") michael@0: michael@0: // Test that the depth affects padding so that calls are indented properly. michael@0: let lastDepth = -Infinity; michael@0: for (let t of factorialLogs.slice(0, 5)) { michael@0: let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10); michael@0: ok(depth > lastDepth, "The depth should be increasing"); michael@0: lastDepth = depth; michael@0: } michael@0: lastDepth = Infinity; michael@0: for (let t of factorialLogs.slice(5)) { michael@0: let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10); michael@0: ok(depth < lastDepth, "The depth should be decreasing"); michael@0: lastDepth = depth; michael@0: } michael@0: michael@0: const throwerLogs = filterTraces(gPanel, michael@0: t => t.querySelector(".trace-name[value=thrower]")); michael@0: is(throwerLogs.length, 2, "Should have an enter and an exit for 'thrower'"); michael@0: ok(throwerLogs[0].querySelector(".trace-call"), michael@0: "The first 'thrower' log should be a call."); michael@0: ok(throwerLogs[1].querySelector(".trace-throw", michael@0: "The second 'thrower' log should be a throw.")); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: });