Wed, 31 Dec 2014 06:09:35 +0100
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 | * Test that we get the expected frame enter/exit logs in the tracer view. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_tracing-01.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | SpecialPowers.pushPrefEnv({'set': [["devtools.debugger.tracer", true]]}, () => { |
michael@0 | 14 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 15 | gTab = aTab; |
michael@0 | 16 | gDebuggee = aDebuggee; |
michael@0 | 17 | gPanel = aPanel; |
michael@0 | 18 | gDebugger = gPanel.panelWin; |
michael@0 | 19 | |
michael@0 | 20 | waitForSourceShown(gPanel, "code_tracing-01.js") |
michael@0 | 21 | .then(() => startTracing(gPanel)) |
michael@0 | 22 | .then(clickButton) |
michael@0 | 23 | .then(() => waitForClientEvents(aPanel, "traces")) |
michael@0 | 24 | .then(testTraceLogs) |
michael@0 | 25 | .then(() => stopTracing(gPanel)) |
michael@0 | 26 | .then(() => { |
michael@0 | 27 | const deferred = promise.defer(); |
michael@0 | 28 | SpecialPowers.popPrefEnv(deferred.resolve); |
michael@0 | 29 | return deferred.promise; |
michael@0 | 30 | }) |
michael@0 | 31 | .then(() => closeDebuggerAndFinish(gPanel)) |
michael@0 | 32 | .then(null, aError => { |
michael@0 | 33 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 34 | }); |
michael@0 | 35 | }); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function clickButton() { |
michael@0 | 40 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 41 | gDebuggee.document.querySelector("button"), |
michael@0 | 42 | gDebuggee); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function testTraceLogs() { |
michael@0 | 46 | const onclickLogs = filterTraces(gPanel, |
michael@0 | 47 | t => t.querySelector(".trace-name[value=onclick]")); |
michael@0 | 48 | is(onclickLogs.length, 2, "Should have two logs from 'onclick'"); |
michael@0 | 49 | ok(onclickLogs[0].querySelector(".trace-call"), |
michael@0 | 50 | "The first 'onclick' log should be a call."); |
michael@0 | 51 | ok(onclickLogs[1].querySelector(".trace-return"), |
michael@0 | 52 | "The second 'onclick' log should be a return."); |
michael@0 | 53 | for (let t of onclickLogs) { |
michael@0 | 54 | ok(t.querySelector(".trace-item").getAttribute("tooltiptext") |
michael@0 | 55 | .contains("doc_tracing-01.html")); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | const nonOnclickLogs = filterTraces(gPanel, |
michael@0 | 59 | t => !t.querySelector(".trace-name[value=onclick]")); |
michael@0 | 60 | for (let t of nonOnclickLogs) { |
michael@0 | 61 | ok(t.querySelector(".trace-item").getAttribute("tooltiptext") |
michael@0 | 62 | .contains("code_tracing-01.js")); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | const mainLogs = filterTraces(gPanel, |
michael@0 | 66 | t => t.querySelector(".trace-name[value=main]")); |
michael@0 | 67 | is(mainLogs.length, 2, "Should have an enter and an exit for 'main'"); |
michael@0 | 68 | ok(mainLogs[0].querySelector(".trace-call"), |
michael@0 | 69 | "The first 'main' log should be a call."); |
michael@0 | 70 | ok(mainLogs[1].querySelector(".trace-return"), |
michael@0 | 71 | "The second 'main' log should be a return."); |
michael@0 | 72 | |
michael@0 | 73 | const factorialLogs = filterTraces(gPanel, |
michael@0 | 74 | t => t.querySelector(".trace-name[value=factorial]")); |
michael@0 | 75 | is(factorialLogs.length, 10, "Should have 5 enter, and 5 exit frames for 'factorial'"); |
michael@0 | 76 | ok(factorialLogs.slice(0, 5).every(t => t.querySelector(".trace-call")), |
michael@0 | 77 | "The first five 'factorial' logs should be calls."); |
michael@0 | 78 | ok(factorialLogs.slice(5).every(t => t.querySelector(".trace-return")), |
michael@0 | 79 | "The second five 'factorial' logs should be returns.") |
michael@0 | 80 | |
michael@0 | 81 | // Test that the depth affects padding so that calls are indented properly. |
michael@0 | 82 | let lastDepth = -Infinity; |
michael@0 | 83 | for (let t of factorialLogs.slice(0, 5)) { |
michael@0 | 84 | let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10); |
michael@0 | 85 | ok(depth > lastDepth, "The depth should be increasing"); |
michael@0 | 86 | lastDepth = depth; |
michael@0 | 87 | } |
michael@0 | 88 | lastDepth = Infinity; |
michael@0 | 89 | for (let t of factorialLogs.slice(5)) { |
michael@0 | 90 | let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10); |
michael@0 | 91 | ok(depth < lastDepth, "The depth should be decreasing"); |
michael@0 | 92 | lastDepth = depth; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | const throwerLogs = filterTraces(gPanel, |
michael@0 | 96 | t => t.querySelector(".trace-name[value=thrower]")); |
michael@0 | 97 | is(throwerLogs.length, 2, "Should have an enter and an exit for 'thrower'"); |
michael@0 | 98 | ok(throwerLogs[0].querySelector(".trace-call"), |
michael@0 | 99 | "The first 'thrower' log should be a call."); |
michael@0 | 100 | ok(throwerLogs[1].querySelector(".trace-throw", |
michael@0 | 101 | "The second 'thrower' log should be a throw.")); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | registerCleanupFunction(function() { |
michael@0 | 105 | gTab = null; |
michael@0 | 106 | gDebuggee = null; |
michael@0 | 107 | gPanel = null; |
michael@0 | 108 | gDebugger = null; |
michael@0 | 109 | }); |