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 stepping through pretty printed sources.
7 let gTab, gDebuggee, gPanel, gClient, gThreadClient, gSource;
9 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html";
11 function test() {
12 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
13 gTab = aTab;
14 gDebuggee = aDebuggee;
15 gPanel = aPanel;
16 gClient = gPanel.panelWin.gClient;
17 gThreadClient = gPanel.panelWin.DebuggerController.activeThread;
19 gDebuggee.noop = x => x;
20 findSource();
21 });
22 }
24 let CODE_URL;
26 const BP_LOCATION = {
27 line: 5,
28 column: 11
29 };
31 function findSource() {
32 gThreadClient.getSources(({ error, sources }) => {
33 ok(!error);
34 sources = sources.filter(s => s.url.contains("code_ugly-3.js"));
35 is(sources.length, 1);
36 [gSource] = sources;
37 CODE_URL = BP_LOCATION.url = gSource.url;
39 prettyPrintSource(sources[0]);
40 });
41 }
43 function prettyPrintSource(source) {
44 gThreadClient.source(gSource).prettyPrint(2, runCode);
45 }
47 function runCode({ error }) {
48 ok(!error);
49 gClient.addOneTimeListener("paused", testDbgStatement);
50 gDebuggee.main3();
51 }
53 function testDbgStatement(event, { why, frame }) {
54 is(why.type, "debuggerStatement");
55 const { url, line, column } = frame.where;
56 is(url, CODE_URL);
57 is(line, 3);
58 setBreakpoint();
59 }
61 function setBreakpoint() {
62 gThreadClient.setBreakpoint(BP_LOCATION, ({ error, actualLocation }) => {
63 ok(!error);
64 ok(!actualLocation);
65 testStepping();
66 });
67 }
69 function testStepping() {
70 gClient.addOneTimeListener("paused", (event, { why, frame }) => {
71 is(why.type, "resumeLimit");
72 const { url, line } = frame.where;
73 is(url, CODE_URL);
74 is(line, 4);
75 testHitBreakpoint();
76 });
77 gThreadClient.stepIn();
78 }
80 function testHitBreakpoint() {
81 gClient.addOneTimeListener("paused", (event, { why, frame }) => {
82 is(why.type, "breakpoint");
83 const { url, line } = frame.where;
84 is(url, CODE_URL);
85 is(line, BP_LOCATION.line);
87 resumeDebuggerThenCloseAndFinish(gPanel);
88 });
89 gThreadClient.resume();
90 }
92 registerCleanupFunction(function() {
93 gTab = gDebuggee = gPanel = gClient = gThreadClient = gSource = null;
94 });