browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Bug 978019: Setting a breakpoint on the last line of a Debugger.Script and
     1.9 + * reloading should still hit the breakpoint.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_breakpoints-break-on-last-line-of-script-on-reload.html";
    1.13 +const CODE_URL = EXAMPLE_URL + "code_breakpoints-break-on-last-line-of-script-on-reload.js";
    1.14 +
    1.15 +function test() {
    1.16 +  let gPanel, gDebugger, gThreadClient, gEvents;
    1.17 +
    1.18 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.19 +    gPanel = aPanel;
    1.20 +    gDebugger = gPanel.panelWin;
    1.21 +    gThreadClient = gDebugger.gThreadClient;
    1.22 +    gEvents = gDebugger.EVENTS;
    1.23 +
    1.24 +    Task.spawn(function* () {
    1.25 +      try {
    1.26 +
    1.27 +        // Refresh and hit the debugger statement before the location we want to
    1.28 +        // set our breakpoints. We have to pause before the breakpoint locations
    1.29 +        // so that GC doesn't get a chance to kick in and collect the IIFE's
    1.30 +        // script, which would causes us to receive a 'noScript' error from the
    1.31 +        // server when we try to set the breakpoints.
    1.32 +        const [paused, ] = yield promise.all([
    1.33 +          waitForThreadEvents(gPanel, "paused"),
    1.34 +          reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN),
    1.35 +        ]);
    1.36 +
    1.37 +        is(paused.why.type, "debuggerStatement");
    1.38 +
    1.39 +        // Set our breakpoints.
    1.40 +        const [bp1, bp2, bp3] = yield promise.all([
    1.41 +          setBreakpoint({
    1.42 +            url: CODE_URL,
    1.43 +            line: 3
    1.44 +          }),
    1.45 +          setBreakpoint({
    1.46 +            url: CODE_URL,
    1.47 +            line: 4
    1.48 +          }),
    1.49 +          setBreakpoint({
    1.50 +            url: CODE_URL,
    1.51 +            line: 5
    1.52 +          })
    1.53 +        ]);
    1.54 +
    1.55 +        // Refresh and hit the debugger statement again.
    1.56 +        yield promise.all([
    1.57 +          reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN),
    1.58 +          waitForCaretAndScopes(gPanel, 1)
    1.59 +        ]);
    1.60 +
    1.61 +        // And we should hit the breakpoints as we resume.
    1.62 +        yield promise.all([
    1.63 +          doResume(gPanel),
    1.64 +          waitForCaretAndScopes(gPanel, 3)
    1.65 +        ]);
    1.66 +        yield promise.all([
    1.67 +          doResume(gPanel),
    1.68 +          waitForCaretAndScopes(gPanel, 4)
    1.69 +        ]);
    1.70 +        yield promise.all([
    1.71 +          doResume(gPanel),
    1.72 +          waitForCaretAndScopes(gPanel, 5)
    1.73 +        ]);
    1.74 +
    1.75 +        // Clean up the breakpoints.
    1.76 +        yield promise.all([
    1.77 +          rdpInvoke(bp1, bp1.remove),
    1.78 +          rdpInvoke(bp2, bp1.remove),
    1.79 +          rdpInvoke(bp3, bp1.remove),
    1.80 +        ]);
    1.81 +
    1.82 +        yield resumeDebuggerThenCloseAndFinish(gPanel);
    1.83 +
    1.84 +      } catch (e) {
    1.85 +        DevToolsUtils.reportException(
    1.86 +          "browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js",
    1.87 +          e
    1.88 +        );
    1.89 +        ok(false);
    1.90 +      }
    1.91 +    });
    1.92 +  });
    1.93 +
    1.94 +  function setBreakpoint(location) {
    1.95 +    let deferred = promise.defer();
    1.96 +    gThreadClient.setBreakpoint(location, ({ error, message }, bpClient) => {
    1.97 +      if (error) {
    1.98 +        deferred.reject(error + ": " + message);
    1.99 +      }
   1.100 +      deferred.resolve(bpClient);
   1.101 +    });
   1.102 +    return deferred.promise;
   1.103 +  }
   1.104 +}

mercurial