tor-browser

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

browser_subdialog_esc.js (3453B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_ROOT_CHROME = getRootDirectory(gTestPath);
      7 const TEST_DIALOG_PATH = TEST_ROOT_CHROME + "subdialog.xhtml";
      8 
      9 const WEB_ROOT = TEST_ROOT_CHROME.replace(
     10  "chrome://mochitests/content",
     11  "https://example.com"
     12 );
     13 const TEST_LOAD_PAGE = WEB_ROOT + "loadDelayedReply.sjs";
     14 
     15 /**
     16 * Tests that ESC on a SubDialog does not cancel ongoing loads in the parent.
     17 */
     18 add_task(async function test_subdialog_esc_does_not_cancel_load() {
     19  await BrowserTestUtils.withNewTab(
     20    "https://example.com",
     21    async function (browser) {
     22      // Start loading a page
     23      let loadStartedPromise = BrowserTestUtils.startLoadingURIString(
     24        browser,
     25        TEST_LOAD_PAGE
     26      );
     27      let loadedPromise = BrowserTestUtils.browserLoaded(browser);
     28      await loadStartedPromise;
     29 
     30      // Open a dialog
     31      let dialogBox = gBrowser.getTabDialogBox(browser);
     32      let dialogClose = dialogBox.open(TEST_DIALOG_PATH, {
     33        keepOpenSameOriginNav: true,
     34      }).closedPromise;
     35 
     36      let dialogs = dialogBox.getTabDialogManager()._dialogs;
     37 
     38      is(dialogs.length, 1, "Dialog manager has a dialog.");
     39 
     40      info("Waiting for dialogs to open.");
     41      await dialogs[0]._dialogReady;
     42 
     43      // Close the dialog with esc key
     44      EventUtils.synthesizeKey("KEY_Escape");
     45 
     46      info("Waiting for dialog to close.");
     47      await dialogClose;
     48 
     49      info("Triggering load complete");
     50      fetch(TEST_LOAD_PAGE, {
     51        method: "POST",
     52      });
     53 
     54      // Load must complete
     55      info("Waiting for load to complete");
     56      await loadedPromise;
     57      ok(true, "Load completed");
     58    }
     59  );
     60 });
     61 
     62 /**
     63 * Tests that ESC on a SubDialog with an open dropdown doesn't close the dialog.
     64 */
     65 add_task(async function test_subdialog_esc_on_dropdown_does_not_close_dialog() {
     66  await BrowserTestUtils.withNewTab(
     67    "https://example.com",
     68    async function (browser) {
     69      // Open the test dialog
     70      let dialogBox = gBrowser.getTabDialogBox(browser);
     71      let dialogClose = dialogBox.open(TEST_DIALOG_PATH, {
     72        keepOpenSameOriginNav: true,
     73      }).closedPromise;
     74 
     75      let dialogs = dialogBox.getTabDialogManager()._dialogs;
     76 
     77      is(dialogs.length, 1, "Dialog manager has a dialog.");
     78 
     79      let dialog = dialogs[0];
     80 
     81      info("Waiting for dialog to open.");
     82      await dialog._dialogReady;
     83 
     84      // Open dropdown
     85      let select = dialog._frame.contentDocument.getElementById("select");
     86      let shownPromise = BrowserTestUtils.waitForSelectPopupShown(window);
     87 
     88      info("Opening dropdown");
     89      select.focus();
     90      EventUtils.synthesizeKey("VK_SPACE", {}, dialog._frame.contentWindow);
     91 
     92      let selectPopup = await shownPromise;
     93 
     94      let hiddenPromise = BrowserTestUtils.waitForEvent(
     95        selectPopup,
     96        "popuphiding",
     97        true
     98      );
     99 
    100      // Race dropdown closing vs SubDialog close
    101      let race = Promise.race([
    102        hiddenPromise.then(() => true),
    103        dialogClose.then(() => false),
    104      ]);
    105 
    106      // Close the dropdown with esc key
    107      info("Hitting escape key.");
    108      await EventUtils.synthesizeKey("KEY_Escape");
    109 
    110      let result = await race;
    111      ok(result, "Select closed first");
    112 
    113      await new Promise(resolve => executeSoon(resolve));
    114 
    115      ok(!dialog._isClosing, "Dialog is not closing");
    116      ok(dialog._openedURL, "Dialog is open");
    117    }
    118  );
    119 });