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