browser/devtools/debugger/test/browser_dbg_pretty-print-09.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 /* -*- Mode: javascript; js-indent-level: 2; -*- */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 // Test pretty printing source mapped sources.
michael@0 6
michael@0 7 var gDebuggee;
michael@0 8 var gClient;
michael@0 9 var gThreadClient;
michael@0 10 var gSource;
michael@0 11
michael@0 12 let gTab, gDebuggee, gPanel, gClient, gThreadClient, gSource;
michael@0 13
michael@0 14 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html";
michael@0 15
michael@0 16 function test() {
michael@0 17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 18 gTab = aTab;
michael@0 19 gDebuggee = aDebuggee;
michael@0 20 gPanel = aPanel;
michael@0 21 gClient = gPanel.panelWin.gClient;
michael@0 22 gThreadClient = gPanel.panelWin.DebuggerController.activeThread;
michael@0 23
michael@0 24 findSource();
michael@0 25 });
michael@0 26 }
michael@0 27
michael@0 28 const dataUrl = s => "data:text/javascript," + s;
michael@0 29
michael@0 30 // These should match the instructions in code_ugly-4.js.
michael@0 31 const A = "function a(){b()}";
michael@0 32 const A_URL = dataUrl(A);
michael@0 33 const B = "function b(){debugger}";
michael@0 34 const B_URL = dataUrl(B);
michael@0 35
michael@0 36 function findSource() {
michael@0 37 gThreadClient.getSources(({ error, sources }) => {
michael@0 38 ok(!error);
michael@0 39 sources = sources.filter(s => s.url === B_URL);
michael@0 40 is(sources.length, 1);
michael@0 41 gSource = sources[0];
michael@0 42 prettyPrint();
michael@0 43 });
michael@0 44 }
michael@0 45
michael@0 46 function prettyPrint() {
michael@0 47 gThreadClient.source(gSource).prettyPrint(2, runCode);
michael@0 48 }
michael@0 49
michael@0 50 function runCode({ error }) {
michael@0 51 ok(!error);
michael@0 52 gClient.addOneTimeListener("paused", testDbgStatement);
michael@0 53 gDebuggee.a();
michael@0 54 }
michael@0 55
michael@0 56 function testDbgStatement(event, { frame, why }) {
michael@0 57 is(why.type, "debuggerStatement");
michael@0 58 const { url, line } = frame.where;
michael@0 59 is(url, B_URL);
michael@0 60 is(line, 2);
michael@0 61
michael@0 62 disablePrettyPrint();
michael@0 63 }
michael@0 64
michael@0 65 function disablePrettyPrint() {
michael@0 66 gThreadClient.source(gSource).disablePrettyPrint(testUgly);
michael@0 67 }
michael@0 68
michael@0 69 function testUgly({ error, source }) {
michael@0 70 ok(!error);
michael@0 71 ok(!source.contains("\n "));
michael@0 72 getFrame();
michael@0 73 }
michael@0 74
michael@0 75 function getFrame() {
michael@0 76 gThreadClient.getFrames(0, 1, testFrame);
michael@0 77 }
michael@0 78
michael@0 79 function testFrame({ frames: [frame] }) {
michael@0 80 const { url, line } = frame.where;
michael@0 81 is(url, B_URL);
michael@0 82 is(line, 1);
michael@0 83
michael@0 84 resumeDebuggerThenCloseAndFinish(gPanel);
michael@0 85 }
michael@0 86
michael@0 87 registerCleanupFunction(function() {
michael@0 88 gTab = gDebuggee = gPanel = gClient = gThreadClient = null;
michael@0 89 });

mercurial