tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_dbg-slow-script.js (3046B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 "use strict";
      6 
      7 // Tests the slow script warning
      8 
      9 add_task(async function openDebuggerFirst() {
     10  // In mochitest, the timeout is disable, so set it to a short, but non zero duration
     11  await pushPref("dom.max_script_run_time", 1);
     12  // Prevents having to click on the page to have the dialog to appear
     13  await pushPref("dom.max_script_run_time.require_critical_input", false);
     14 
     15  const dbg = await initDebugger("doc-slow-script.html");
     16 
     17  const alert = BrowserTestUtils.waitForGlobalNotificationBar(
     18    window,
     19    "process-hang"
     20  );
     21 
     22  info("Execute an infinite loop");
     23  invokeInTab("infiniteLoop");
     24 
     25  info("Wait for the slow script warning");
     26  const notification = await alert;
     27 
     28  info("Click on the debug script button");
     29  const buttons = notification.buttonContainer.getElementsByTagName("button");
     30  // The first button is "stop", the second is "debug script"
     31  buttons[1].click();
     32 
     33  info("Waiting for the debugger to be paused");
     34  await waitForPaused(dbg);
     35  const source = findSource(dbg, "doc-slow-script.html");
     36  await assertPausedAtSourceAndLine(dbg, source.id, 14);
     37 
     38  await closeTabAndToolbox();
     39 });
     40 
     41 add_task(async function openDebuggerFromDialog() {
     42  const tab = await addTab(EXAMPLE_URL + "doc-slow-script.html");
     43 
     44  const alert = BrowserTestUtils.waitForGlobalNotificationBar(
     45    window,
     46    "process-hang"
     47  );
     48 
     49  // /!\ Hack this attribute in order to force showing the "debug script" button
     50  //     on all channels. Otherwise it is only displayed in dev edition.
     51  tab.linkedBrowser.browsingContext.watchedByDevTools = true;
     52 
     53  info("Execute an infinite loop");
     54  // Note that spawn will return a promise that may be rejected because of the infinite loop
     55  // And mochitest may consider this as an error. So ignore any rejection.
     56  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     57    content.wrappedJSObject.infiniteLoop();
     58  }).catch(() => {});
     59 
     60  info("Wait for the slow script warning");
     61  const notification = await alert;
     62 
     63  info("Click on the debug script button");
     64  const buttons = notification.buttonContainer.getElementsByTagName("button");
     65  // The first button is "stop", the second is "debug script"
     66  buttons[1].click();
     67 
     68  info("Wait for the toolbox to appear and have the debugger initialized");
     69  await waitFor(async () => {
     70    const tb = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     71    if (tb) {
     72      await tb.getPanelWhenReady("jsdebugger");
     73      return true;
     74    }
     75    return false;
     76  });
     77  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     78  ok(toolbox, "Got a toolbox");
     79  const dbg = createDebuggerContext(toolbox);
     80 
     81  info("Waiting for the debugger to be paused");
     82  await waitForPaused(dbg);
     83  const source = findSource(dbg, "doc-slow-script.html");
     84  await assertPausedAtSourceAndLine(dbg, source.id, 14);
     85 
     86  await closeTabAndToolbox();
     87 });