browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Bug 978019: Setting a breakpoint on the last line of a Debugger.Script and
michael@0 6 * reloading should still hit the breakpoint.
michael@0 7 */
michael@0 8
michael@0 9 const TAB_URL = EXAMPLE_URL + "doc_breakpoints-break-on-last-line-of-script-on-reload.html";
michael@0 10 const CODE_URL = EXAMPLE_URL + "code_breakpoints-break-on-last-line-of-script-on-reload.js";
michael@0 11
michael@0 12 function test() {
michael@0 13 let gPanel, gDebugger, gThreadClient, gEvents;
michael@0 14
michael@0 15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 16 gPanel = aPanel;
michael@0 17 gDebugger = gPanel.panelWin;
michael@0 18 gThreadClient = gDebugger.gThreadClient;
michael@0 19 gEvents = gDebugger.EVENTS;
michael@0 20
michael@0 21 Task.spawn(function* () {
michael@0 22 try {
michael@0 23
michael@0 24 // Refresh and hit the debugger statement before the location we want to
michael@0 25 // set our breakpoints. We have to pause before the breakpoint locations
michael@0 26 // so that GC doesn't get a chance to kick in and collect the IIFE's
michael@0 27 // script, which would causes us to receive a 'noScript' error from the
michael@0 28 // server when we try to set the breakpoints.
michael@0 29 const [paused, ] = yield promise.all([
michael@0 30 waitForThreadEvents(gPanel, "paused"),
michael@0 31 reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN),
michael@0 32 ]);
michael@0 33
michael@0 34 is(paused.why.type, "debuggerStatement");
michael@0 35
michael@0 36 // Set our breakpoints.
michael@0 37 const [bp1, bp2, bp3] = yield promise.all([
michael@0 38 setBreakpoint({
michael@0 39 url: CODE_URL,
michael@0 40 line: 3
michael@0 41 }),
michael@0 42 setBreakpoint({
michael@0 43 url: CODE_URL,
michael@0 44 line: 4
michael@0 45 }),
michael@0 46 setBreakpoint({
michael@0 47 url: CODE_URL,
michael@0 48 line: 5
michael@0 49 })
michael@0 50 ]);
michael@0 51
michael@0 52 // Refresh and hit the debugger statement again.
michael@0 53 yield promise.all([
michael@0 54 reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN),
michael@0 55 waitForCaretAndScopes(gPanel, 1)
michael@0 56 ]);
michael@0 57
michael@0 58 // And we should hit the breakpoints as we resume.
michael@0 59 yield promise.all([
michael@0 60 doResume(gPanel),
michael@0 61 waitForCaretAndScopes(gPanel, 3)
michael@0 62 ]);
michael@0 63 yield promise.all([
michael@0 64 doResume(gPanel),
michael@0 65 waitForCaretAndScopes(gPanel, 4)
michael@0 66 ]);
michael@0 67 yield promise.all([
michael@0 68 doResume(gPanel),
michael@0 69 waitForCaretAndScopes(gPanel, 5)
michael@0 70 ]);
michael@0 71
michael@0 72 // Clean up the breakpoints.
michael@0 73 yield promise.all([
michael@0 74 rdpInvoke(bp1, bp1.remove),
michael@0 75 rdpInvoke(bp2, bp1.remove),
michael@0 76 rdpInvoke(bp3, bp1.remove),
michael@0 77 ]);
michael@0 78
michael@0 79 yield resumeDebuggerThenCloseAndFinish(gPanel);
michael@0 80
michael@0 81 } catch (e) {
michael@0 82 DevToolsUtils.reportException(
michael@0 83 "browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js",
michael@0 84 e
michael@0 85 );
michael@0 86 ok(false);
michael@0 87 }
michael@0 88 });
michael@0 89 });
michael@0 90
michael@0 91 function setBreakpoint(location) {
michael@0 92 let deferred = promise.defer();
michael@0 93 gThreadClient.setBreakpoint(location, ({ error, message }, bpClient) => {
michael@0 94 if (error) {
michael@0 95 deferred.reject(error + ": " + message);
michael@0 96 }
michael@0 97 deferred.resolve(bpClient);
michael@0 98 });
michael@0 99 return deferred.promise;
michael@0 100 }
michael@0 101 }

mercurial