tor-browser

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

browser_inspector_highlighter-keybinding_03.js (2135B)


      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 // Test that the keybindings for Picker work alright
      8 
      9 const IS_OSX = Services.appinfo.OS === "Darwin";
     10 const TEST_URL = URL_ROOT + "doc_inspector_highlighter_dom.html";
     11 
     12 add_task(async function () {
     13  const { inspector, toolbox } = await openInspectorForURL(TEST_URL);
     14 
     15  await startPicker(toolbox);
     16  await hoverElement(inspector, "#another");
     17 
     18  info("Testing enter/return key as pick-node command");
     19  await doKeyPick("VK_RETURN");
     20  is(
     21    inspector.selection.nodeFront.id,
     22    "another",
     23    "The #another node was selected. Passed."
     24  );
     25 
     26  info("Testing escape key as cancel-picker command");
     27  await startPicker(toolbox);
     28  await hoverElement(inspector, "#ahoy");
     29  await doKeyStop("VK_ESCAPE");
     30  is(
     31    inspector.selection.nodeFront.id,
     32    "another",
     33    "The #another DIV is still selected. Passed."
     34  );
     35 
     36  info("Testing Ctrl+Shift+C shortcut as cancel-picker command");
     37  await startPicker(toolbox);
     38  await hoverElement(inspector, "#ahoy");
     39  const eventOptions = { key: "VK_C" };
     40  if (IS_OSX) {
     41    eventOptions.metaKey = true;
     42    eventOptions.altKey = true;
     43  } else {
     44    eventOptions.ctrlKey = true;
     45    eventOptions.shiftKey = true;
     46  }
     47  await doKeyStop("VK_C", eventOptions);
     48  is(
     49    inspector.selection.nodeFront.id,
     50    "another",
     51    "The #another DIV is still selected. Passed."
     52  );
     53 
     54  function doKeyPick(key, options = {}) {
     55    info("Key pressed. Waiting for element to be picked");
     56    BrowserTestUtils.synthesizeKey(key, options, gBrowser.selectedBrowser);
     57    return Promise.all([
     58      inspector.selection.once("new-node-front"),
     59      inspector.once("inspector-updated"),
     60      toolbox.nodePicker.once("picker-stopped"),
     61    ]);
     62  }
     63 
     64  function doKeyStop(key, options = {}) {
     65    info("Key pressed. Waiting for picker to be canceled");
     66    BrowserTestUtils.synthesizeKey(key, options, gBrowser.selectedBrowser);
     67    return toolbox.nodePicker.once("picker-stopped");
     68  }
     69 });