tor-browser

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

browser_jsterm_autocomplete_getters_cancel.js (3073B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the confirm dialog can be closed with different actions.
      7 
      8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
      9 <head>
     10  <script>
     11    let sideEffect;
     12    window.foo = {
     13      get rab() {
     14        sideEffect = "getRab";
     15        return "rab";
     16      }
     17    };
     18  </script>
     19 </head>
     20 <body>Autocomplete popup - invoke getter - close dialog test</body>`;
     21 
     22 add_task(async function () {
     23  const hud = await openNewTabAndConsole(TEST_URI);
     24  const { jsterm } = hud;
     25  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     26 
     27  let tooltip = await setInputValueForGetterConfirmDialog(
     28    toolbox,
     29    hud,
     30    "foo.rab."
     31  );
     32  let labelEl = tooltip.querySelector(".confirm-label");
     33  is(
     34    labelEl.textContent,
     35    "Invoke getter foo.rab to retrieve the property list?",
     36    "Dialog has expected text content"
     37  );
     38 
     39  info("Check that Escape closes the confirm tooltip");
     40  EventUtils.synthesizeKey("KEY_Escape");
     41  await waitFor(() => !isConfirmDialogOpened(toolbox));
     42 
     43  info("Check that typing a letter won't show the tooltip");
     44  const onAutocompleteUpdate = jsterm.once("autocomplete-updated");
     45  EventUtils.sendString("t");
     46  await onAutocompleteUpdate;
     47  is(isConfirmDialogOpened(toolbox), false, "The confirm dialog is not open");
     48 
     49  info("Check that Ctrl+space show the confirm tooltip again");
     50  EventUtils.synthesizeKey(" ", { ctrlKey: true });
     51  await waitFor(() => isConfirmDialogOpened(toolbox));
     52  tooltip = getConfirmDialog(toolbox);
     53  labelEl = tooltip.querySelector(".confirm-label");
     54  is(
     55    labelEl.textContent,
     56    "Invoke getter foo.rab to retrieve the property list?",
     57    "Dialog has expected text content"
     58  );
     59 
     60  info("Check that clicking on the close button closes the tooltip");
     61  const closeButtonEl = tooltip.querySelector(".close-confirm-dialog-button");
     62  is(closeButtonEl.title, "Close (Esc)", "Close button has the expected title");
     63  closeButtonEl.click();
     64  await waitFor(() => !isConfirmDialogOpened(toolbox));
     65  ok(true, "Clicking the close button does close the tooltip");
     66 
     67  info(
     68    "Check that the tooltip closes when there's no more reason to display it"
     69  );
     70  // Open the tooltip again
     71  EventUtils.synthesizeKey(" ", { ctrlKey: true });
     72  await waitFor(() => isConfirmDialogOpened(toolbox));
     73 
     74  // Adding a space will make the input `foo.rab.t `, which we shouldn't try to
     75  // autocomplete.
     76  EventUtils.sendString(" ");
     77  await waitFor(() => !isConfirmDialogOpened(toolbox));
     78  ok(
     79    true,
     80    "The tooltip is now closed since the input doesn't match a getter name"
     81  );
     82  info("Check that evaluating the expression closes the tooltip");
     83  tooltip = await setInputValueForGetterConfirmDialog(toolbox, hud, "foo.rab.");
     84  EventUtils.sendString("length");
     85  EventUtils.synthesizeKey("KEY_Enter");
     86  await waitFor(() => !isConfirmDialogOpened(toolbox));
     87  await waitFor(() => findEvaluationResultMessage(hud, "3"));
     88  ok("Expression was evaluated and tooltip was closed");
     89 });