tor-browser

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

browser_dbg-paused-overlay.js (5266B)


      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 // Tests the paused overlay
      6 
      7 "use strict";
      8 
      9 add_task(async function () {
     10  const dbg = await initDebugger("doc-scripts.html");
     11 
     12  // Sanity check
     13  const highlighterTestFront = await getHighlighterTestFront(dbg.toolbox);
     14  let isPausedOverlayVisible =
     15    await highlighterTestFront.isPausedDebuggerOverlayVisible();
     16  is(
     17    isPausedOverlayVisible,
     18    false,
     19    "The pause overlay is not visible in the beginning"
     20  );
     21 
     22  info("Create an eval script that pauses itself.");
     23  invokeInTab("doEval");
     24  await waitForPaused(dbg);
     25 
     26  info("Check that the paused overlay is displayed");
     27  await waitFor(() => highlighterTestFront.isPausedDebuggerOverlayVisible());
     28  ok(true, "Paused debugger overlay is visible");
     29 
     30  const pauseLine = getVisibleSelectedFrameLine(dbg);
     31  is(pauseLine, 2, "We're paused at the expected location");
     32 
     33  info("Test clicking the step over button");
     34  await highlighterTestFront.clickPausedDebuggerOverlayButton(
     35    "paused-dbg-step-button"
     36  );
     37  await waitFor(() => isPaused(dbg) && getVisibleSelectedFrameLine(dbg) === 4);
     38  ok(true, "We're paused at the expected location after stepping");
     39 
     40  isPausedOverlayVisible =
     41    await highlighterTestFront.isPausedDebuggerOverlayVisible();
     42  is(isPausedOverlayVisible, true, "The pause overlay is still visible");
     43 
     44  info("Test clicking the highlighter resume button");
     45  await highlighterTestFront.clickPausedDebuggerOverlayButton(
     46    "paused-dbg-resume-button"
     47  );
     48 
     49  await waitForResumed(dbg);
     50  ok("The debugger isn't paused after clicking on the resume button");
     51 
     52  await waitFor(async () => {
     53    const visible = await highlighterTestFront.isPausedDebuggerOverlayVisible();
     54    return !visible;
     55  });
     56  ok(true, "The overlay is now hidden");
     57 
     58  info(
     59    "Check that the highlighter is removed when clicking on the debugger resume button"
     60  );
     61  invokeInTab("doEval");
     62  await waitFor(() => highlighterTestFront.isPausedDebuggerOverlayVisible());
     63  ok(true, "Paused debugger overlay is visible again");
     64 
     65  info("Click debugger UI resume button");
     66  const resumeButton = await waitFor(() => findElement(dbg, "resume"));
     67  resumeButton.click();
     68  await waitFor(async () => {
     69    const visible = await highlighterTestFront.isPausedDebuggerOverlayVisible();
     70    return !visible;
     71  });
     72  ok(true, "The overlay is hidden after clicking on the resume button");
     73 });
     74 
     75 add_task(async function testOverlayDisabled() {
     76  const dbg = await initDebugger("doc-scripts.html");
     77  const overlayMenuItemClassName =
     78    ".debugger-settings-menu-item-toggle-pause-overlay";
     79 
     80  info("Disabling the overlay with the settings menu");
     81  // Sanity check
     82  is(
     83    Services.prefs.getBoolPref("devtools.debugger.features.overlay"),
     84    true,
     85    "overlay pref is enabled by default"
     86  );
     87  let onThreadConfigurationApplied = dbg.toolbox.once(
     88    "new-configuration-applied"
     89  );
     90  await toggleDebuggerSettingsMenuItem(dbg, {
     91    className: overlayMenuItemClassName,
     92    isChecked: true,
     93  });
     94  await onThreadConfigurationApplied;
     95  is(
     96    Services.prefs.getBoolPref("devtools.debugger.features.overlay"),
     97    false,
     98    "overlay pref is disabled after toggling the setting menu item"
     99  );
    100 
    101  const highlighterTestFront = await getHighlighterTestFront(dbg.toolbox);
    102 
    103  info("Create an eval script that pauses itself.");
    104  invokeInTab("doEval");
    105 
    106  await waitForPaused(dbg);
    107 
    108  // Let a chance to regress and still show the overlay
    109  await wait(500);
    110 
    111  const isPausedOverlayVisible =
    112    await highlighterTestFront.isPausedDebuggerOverlayVisible();
    113  ok(
    114    !isPausedOverlayVisible,
    115    "The paused overlay wasn't shown when the related feature preference is false"
    116  );
    117 
    118  info("Re-enable the overlay while paused");
    119  onThreadConfigurationApplied = dbg.toolbox.once("new-configuration-applied");
    120  await toggleDebuggerSettingsMenuItem(dbg, {
    121    className: overlayMenuItemClassName,
    122    isChecked: false,
    123  });
    124  await onThreadConfigurationApplied;
    125  is(
    126    Services.prefs.getBoolPref("devtools.debugger.features.overlay"),
    127    true,
    128    "overlay pref is enabled again after toggling the setting menu item"
    129  );
    130 
    131  info("Wait for the overlay to be displayed");
    132  await waitFor(
    133    async () => await highlighterTestFront.isPausedDebuggerOverlayVisible()
    134  );
    135  ok(
    136    true,
    137    "The overlay gets shown when the setting is toggled to true and the page is paused"
    138  );
    139 
    140  info("Disable the overlay while paused");
    141  onThreadConfigurationApplied = dbg.toolbox.once("new-configuration-applied");
    142  await toggleDebuggerSettingsMenuItem(dbg, {
    143    className: overlayMenuItemClassName,
    144    isChecked: true,
    145  });
    146  await onThreadConfigurationApplied;
    147  is(
    148    Services.prefs.getBoolPref("devtools.debugger.features.overlay"),
    149    false,
    150    "overlay pref is disabled again after toggling the setting menu item"
    151  );
    152 
    153  info("Wait for the overlay to be hidden");
    154  await waitFor(
    155    async () => !(await highlighterTestFront.isPausedDebuggerOverlayVisible())
    156  );
    157  ok(
    158    true,
    159    "The overlay gets hidden when the setting is toggled to false and the page is paused"
    160  );
    161 
    162  await waitForResumed;
    163 });