tor-browser

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

browser_utilityOverlay.js (2629B)


      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 add_task(async function test_eventMatchesKey() {
      6  let eventMatchResult;
      7  let key;
      8  let checkEvent = function (e) {
      9    e.stopPropagation();
     10    e.preventDefault();
     11    eventMatchResult = eventMatchesKey(e, key);
     12  };
     13  document.addEventListener("keypress", checkEvent);
     14 
     15  try {
     16    key = document.createXULElement("key");
     17    let keyset = document.getElementById("mainKeyset");
     18    key.setAttribute("key", "t");
     19    key.setAttribute("modifiers", "accel");
     20    keyset.appendChild(key);
     21    EventUtils.synthesizeKey("t", { accelKey: true });
     22    is(eventMatchResult, true, "eventMatchesKey: one modifier");
     23    keyset.removeChild(key);
     24 
     25    key = document.createXULElement("key");
     26    key.setAttribute("key", "g");
     27    key.setAttribute("modifiers", "accel,shift");
     28    keyset.appendChild(key);
     29    EventUtils.synthesizeKey("g", { accelKey: true, shiftKey: true });
     30    is(eventMatchResult, true, "eventMatchesKey: combination modifiers");
     31    keyset.removeChild(key);
     32 
     33    key = document.createXULElement("key");
     34    key.setAttribute("key", "w");
     35    key.setAttribute("modifiers", "accel");
     36    keyset.appendChild(key);
     37    EventUtils.synthesizeKey("f", { accelKey: true });
     38    is(eventMatchResult, false, "eventMatchesKey: mismatch keys");
     39    keyset.removeChild(key);
     40 
     41    key = document.createXULElement("key");
     42    key.setAttribute("keycode", "VK_DELETE");
     43    keyset.appendChild(key);
     44    EventUtils.synthesizeKey("VK_DELETE", { accelKey: true });
     45    is(eventMatchResult, false, "eventMatchesKey: mismatch modifiers");
     46    keyset.removeChild(key);
     47  } finally {
     48    // Make sure to remove the event listener so future tests don't
     49    // fail when they simulate key presses.
     50    document.removeEventListener("keypress", checkEvent);
     51  }
     52 });
     53 
     54 add_task(async function test_getTargetWindow() {
     55  is(URILoadingHelper.getTargetWindow(window), window, "got top window");
     56 });
     57 
     58 add_task(async function test_openUILink() {
     59  const kURL = "https://example.org/";
     60  let tab = await BrowserTestUtils.openNewForegroundTab(
     61    gBrowser,
     62    "about:blank"
     63  );
     64  let loadPromise = BrowserTestUtils.browserLoaded(
     65    tab.linkedBrowser,
     66    false,
     67    kURL
     68  );
     69 
     70  openUILink(kURL, null, {
     71    triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
     72  }); // defaults to "current"
     73 
     74  await loadPromise;
     75 
     76  is(tab.linkedBrowser.currentURI.spec, kURL, "example.org loaded");
     77  gBrowser.removeCurrentTab();
     78 });