summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_stepping-15.js
blob: 6981758b8f2d71697518aaaef061065ea9d74b25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Test stepping from inside a blackboxed function
 * test-page: https://dbg-blackbox-stepping.glitch.me/
 */

async function invokeAndPause({ global, threadFront }, expression, url) {
  return executeOnNextTickAndWaitForPause(
    () => Cu.evalInSandbox(expression, global, "1.8", url, 1),
    threadFront
  );
}
add_task(
  threadFrontTest(async ({ threadFront, targetFront, debuggee }) => {
    const consoleFront = await targetFront.getFront("console");
    const dbg = { global: debuggee, threadFront };

    // Test stepping from a blackboxed location
    async function testStepping(action, expectedLine) {
      consoleFront.evaluateJSAsync(`outermost()`);
      await waitForPause(threadFront);
      await blackBox(blackboxedSourceFront);
      const packet = await action(threadFront);
      const { line, actor } = packet.frame.where;
      equal(actor, unblackboxedActor, "paused in unblackboxed source");
      equal(line, expectedLine, "paused at correct line");
      await threadFront.resume();
      await unBlackBox(blackboxedSourceFront);
    }

    invokeAndPause(
      dbg,
      `function outermost() {
        const value = blackboxed1();
        return value + 1;
      }
      function innermost() {
        return 1;
      }`,
      "http://example.com/unblackboxed.js"
    );
    invokeAndPause(
      dbg,
      `function blackboxed1() {
        return blackboxed2();
      }
      function blackboxed2() {
        return innermost();
      }`,
      "http://example.com/blackboxed.js"
    );

    const { sources } = await getSources(threadFront);
    const blackboxedSourceFront = threadFront.source(
      sources.find(source => source.url == "http://example.com/blackboxed.js")
    );
    const unblackboxedActor = sources.find(
      source => source.url == "http://example.com/unblackboxed.js"
    ).actor;

    await setBreakpoint(threadFront, {
      sourceUrl: blackboxedSourceFront.url,
      line: 5,
    });

    info("Step Out to outermost");
    await testStepping(stepOut, 3);

    info("Step Over to outermost");
    await testStepping(stepOver, 3);

    info("Step In to innermost");
    await testStepping(stepIn, 6);
  })
);