tor-browser

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

browser_jsterm_ctrl_a_select_all.js (1654B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Map Control + A to Select All, In the web console input
      5 
      6 "use strict";
      7 
      8 const TEST_URI =
      9  "data:text/html;charset=utf-8,<!DOCTYPE html>Test console select all";
     10 
     11 add_task(async function () {
     12  // The TabContextMenu initializes its strings only on a focus or mouseover event.
     13  // Calls focus event on the TabContextMenu early in the test.
     14  gBrowser.selectedTab.focus();
     15  const hud = await openNewTabAndConsole(TEST_URI);
     16  const { jsterm } = hud;
     17 
     18  setInputValue(hud, "Ignore These Four Words");
     19 
     20  // Test select all with (cmd|control) + a.
     21  EventUtils.synthesizeKey("a", { accelKey: true });
     22 
     23  const inputLength = getSelectionTextLength(jsterm);
     24  is(inputLength, getInputValue(hud).length, "Select all of input");
     25 
     26  // (cmd|control) + e cannot be disabled on Linux so skip this section on that OS.
     27  if (Services.appinfo.OS !== "Linux") {
     28    // Test do nothing on Control + E.
     29    setInputValue(hud, "Ignore These Four Words");
     30    setCursorAtStart(jsterm);
     31    EventUtils.synthesizeKey("e", { accelKey: true });
     32    checkSelectionStart(
     33      jsterm,
     34      0,
     35      "control|cmd + e does not move to end of input"
     36    );
     37  }
     38 });
     39 
     40 function getSelectionTextLength(jsterm) {
     41  return jsterm.editor.getSelection().length;
     42 }
     43 
     44 function setCursorAtStart(jsterm) {
     45  jsterm.editor.setCursor({ line: 0, ch: 0 });
     46 }
     47 
     48 function checkSelectionStart(jsterm, expectedCursorIndex, assertionInfo) {
     49  const [selection] = jsterm.editor.codeMirror.listSelections();
     50  const { head } = selection;
     51  is(head.ch, expectedCursorIndex, assertionInfo);
     52 }