tor-browser

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

browser_toolbox_window_title_frame_select.js (4864B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check that the detached devtools window title is not updated when switching
      8 * the selected frame. Also check that frames command button has 'open'
      9 * attribute set when the list of frames is opened.
     10 */
     11 
     12 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js");
     13 const URL =
     14  URL_ROOT_SSL + "browser_toolbox_window_title_frame_select_page.html";
     15 const IFRAME_URL =
     16  URL_ROOT_SSL + "browser_toolbox_window_title_changes_page.html";
     17 const L10N = new LocalizationHelper(
     18  "devtools/client/locales/toolbox.properties"
     19 );
     20 
     21 /**
     22 * Wait for a given toolbox to get its title updated.
     23 */
     24 function waitForTitleChange(toolbox) {
     25  return new Promise(resolve => {
     26    toolbox.topWindow.addEventListener("message", function onmessage(event) {
     27      if (event.data.name == "set-host-title") {
     28        toolbox.topWindow.removeEventListener("message", onmessage);
     29        resolve();
     30      }
     31    });
     32  });
     33 }
     34 
     35 add_task(async function () {
     36  Services.prefs.setBoolPref("devtools.command-button-frames.enabled", true);
     37 
     38  await addTab(URL);
     39  const tab = gBrowser.selectedTab;
     40  let toolbox = await gDevTools.showToolboxForTab(tab, {
     41    hostType: Toolbox.HostType.BOTTOM,
     42  });
     43 
     44  await toolbox.switchHost(Toolbox.HostType.WINDOW);
     45  // Wait for title change event *after* switch host, in order to listen
     46  // for the event on the WINDOW host window, which only exists after switchHost
     47  await waitForTitleChange(toolbox);
     48 
     49  is(
     50    getTitle(),
     51    `Developer Tools — Page title — ${URL}`,
     52    "Devtools title correct after switching to detached window host"
     53  );
     54 
     55  // Wait for tick to avoid unexpected 'popuphidden' event, which
     56  // blocks the frame popup menu opened below. See also bug 1276873
     57  await waitForTick();
     58 
     59  const btn = toolbox.doc.getElementById("command-button-frames");
     60 
     61  await testShortcutToOpenFrames(btn, toolbox);
     62 
     63  // Open frame menu and wait till it's available on the screen.
     64  // Also check 'aria-expanded' attribute on the command button.
     65  is(
     66    btn.getAttribute("aria-expanded"),
     67    "false",
     68    "The aria-expanded attribute must be set to false"
     69  );
     70  btn.click();
     71 
     72  const panel = toolbox.doc.getElementById("command-button-frames-panel");
     73  ok(panel, "popup panel has created.");
     74  await waitUntil(() => panel.classList.contains("tooltip-visible"));
     75 
     76  is(
     77    btn.getAttribute("aria-expanded"),
     78    "true",
     79    "The aria-expanded attribute must be set to true"
     80  );
     81 
     82  // Verify that the frame list menu is populated
     83  const menuList = toolbox.doc.getElementById("toolbox-frame-menu");
     84  const frames = Array.from(menuList.querySelectorAll(".command"));
     85  is(frames.length, 2, "We have both frames in the list");
     86 
     87  const topFrameBtn = frames.filter(
     88    b => b.querySelector(".label").textContent == URL
     89  )[0];
     90  const iframeBtn = frames.filter(
     91    b => b.querySelector(".label").textContent == IFRAME_URL
     92  )[0];
     93  ok(topFrameBtn, "Got top level document in the list");
     94  ok(iframeBtn, "Got iframe document in the list");
     95 
     96  // Only select the iframe after we are able to select an element from the top
     97  // level document.
     98  const onInspectorReloaded = toolbox.getPanel("inspector").once("reloaded");
     99  info("Select the iframe");
    100  iframeBtn.click();
    101 
    102  await onInspectorReloaded;
    103  // wait a bit more in case an eventual title update would happen later
    104  await wait(1000);
    105 
    106  info("Navigation to the iframe is done, the inspector should be back up");
    107  is(
    108    getTitle(),
    109    `Developer Tools — Toolbox test for title update — ${IFRAME_URL}`,
    110    "Devtools title is updated to match the selected iframe document"
    111  );
    112 
    113  info("Cleanup toolbox and test preferences.");
    114  await toolbox.destroy();
    115  toolbox = null;
    116  gBrowser.removeCurrentTab();
    117  finish();
    118 });
    119 
    120 function getTitle() {
    121  return Services.wm.getMostRecentWindow("devtools:toolbox").document.title;
    122 }
    123 
    124 async function testShortcutToOpenFrames(btn, toolbox) {
    125  info("Tests if shortcut Alt+Down opens the frames");
    126  // focus the button so that keyPress can be performed
    127  btn.focus();
    128  // perform keyPress - Alt+Down
    129  const shortcut = L10N.getStr("toolbox.showFrames.key");
    130  synthesizeKeyShortcut(shortcut, toolbox.win);
    131 
    132  const panel = toolbox.doc.getElementById("command-button-frames-panel");
    133  ok(panel, "popup panel has created.");
    134  await waitUntil(() => panel.classList.contains("tooltip-visible"));
    135 
    136  is(
    137    btn.getAttribute("aria-expanded"),
    138    "true",
    139    "The aria-expanded attribute must be set to true"
    140  );
    141 
    142  // pressing Esc should hide the menu again
    143  EventUtils.sendKey("ESCAPE", toolbox.win);
    144  await waitUntil(() => !panel.classList.contains("tooltip-visible"));
    145 
    146  is(
    147    btn.getAttribute("aria-expanded"),
    148    "false",
    149    "The aria-expanded attribute must be set to false"
    150  );
    151 }