tor-browser

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

browser_toolbox_options_frames_button.js (3532B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the frames button is always visible when the user is on the options panel.
      7 // Test that the button is disabled if the current target has no frames.
      8 // Test that the button is enabled otherwise.
      9 
     10 const TEST_URL = "data:text/html;charset=utf8,test frames button visibility";
     11 const TEST_IFRAME_URL = "data:text/plain,iframe";
     12 const TEST_IFRAME_URL2 = "data:text/plain,iframe2";
     13 const TEST_URL_FRAMES =
     14  TEST_URL +
     15  `<iframe src="${TEST_IFRAME_URL}"></iframe>` +
     16  `<iframe src="${TEST_IFRAME_URL2}"></iframe>`;
     17 const FRAME_BUTTON_PREF = "devtools.command-button-frames.enabled";
     18 
     19 add_task(async function () {
     20  // Hide the button by default.
     21  await pushPref(FRAME_BUTTON_PREF, false);
     22 
     23  const tab = await addTab(TEST_URL);
     24 
     25  info("Open the toolbox on the Options panel");
     26  const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "options" });
     27  const doc = toolbox.doc;
     28 
     29  const optionsPanel = toolbox.getCurrentPanel();
     30 
     31  let framesButton = doc.getElementById("command-button-frames");
     32  ok(!framesButton, "Frames button is not rendered.");
     33 
     34  const optionsDoc = optionsPanel.panelWin.document;
     35  const framesButtonCheckbox = optionsDoc.getElementById(
     36    "command-button-frames"
     37  );
     38  framesButtonCheckbox.click();
     39 
     40  info("Wait for the frame button to be rendered");
     41  framesButton = await waitFor(() =>
     42    doc.getElementById("command-button-frames")
     43  );
     44  ok(framesButton.disabled, "Frames button is disabled.");
     45 
     46  info("Leave the options panel, the frames button should not be rendered.");
     47  await toolbox.selectTool("webconsole");
     48  framesButton = doc.getElementById("command-button-frames");
     49  ok(!framesButton, "Frames button is no longer rendered.");
     50 
     51  info("Go back to the options panel, the frames button should rendered.");
     52  await toolbox.selectTool("options");
     53  framesButton = doc.getElementById("command-button-frames");
     54  ok(framesButton, "Frames button is rendered again.");
     55 
     56  info("Navigate to a page with frames, the frames button should be enabled.");
     57  await navigateTo(TEST_URL_FRAMES);
     58 
     59  framesButton = doc.getElementById("command-button-frames");
     60  ok(framesButton, "Frames button is still rendered.");
     61 
     62  await waitFor(() => {
     63    framesButton = doc.getElementById("command-button-frames");
     64    return framesButton && !framesButton.disabled;
     65  });
     66 
     67  const { targetCommand } = toolbox.commands;
     68  const iframeTarget = targetCommand
     69    .getAllTargets([targetCommand.TYPES.FRAME])
     70    .find(target => target.url == TEST_IFRAME_URL);
     71  ok(iframeTarget, "Found the target for the iframe");
     72 
     73  ok(
     74    !framesButton.classList.contains("checked"),
     75    "Before selecting an iframe, the button is not checked"
     76  );
     77  await toolbox.commands.targetCommand.selectTarget(iframeTarget);
     78  ok(
     79    framesButton.classList.contains("checked"),
     80    "After selecting an iframe, the button is checked"
     81  );
     82 
     83  info("Remove this first iframe, which is currently selected");
     84  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     85    content.document.querySelector("iframe").remove();
     86  });
     87 
     88  await waitFor(() => {
     89    return targetCommand.selectedTargetFront == targetCommand.targetFront;
     90  }, "Wait for the selected target to be back on the top target");
     91 
     92  ok(
     93    !framesButton.classList.contains("checked"),
     94    "The button is back unchecked after having removed the selected iframe"
     95  );
     96 
     97  Services.prefs.clearUserPref(FRAME_BUTTON_PREF);
     98 });