tor-browser

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

browser_jsterm_autocomplete_getters_cache.js (4201B)


      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 invoke getter authorizations are cleared when expected.
      7 
      8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
      9 <head>
     10  <script>
     11    /* Create a prototype-less object so popup does not contain native
     12     * Object prototype properties.
     13     */
     14    var obj = props => Object.create(null, Object.getOwnPropertyDescriptors(props));
     15    let sideEffectVar;
     16    var foo = obj({
     17      get bar() {
     18        sideEffectVar = "from bar";
     19        return obj({
     20          get baz() {
     21            sideEffectVar = "from baz";
     22            return obj({
     23              hello: 1,
     24              world: "",
     25            });
     26          },
     27          bloop: true,
     28        })
     29      }
     30    });
     31  </script>
     32 </head>
     33 <body>Autocomplete popup - invoke getter cache test</body>`;
     34 
     35 add_task(async function () {
     36  const hud = await openNewTabAndConsole(TEST_URI);
     37  const { jsterm } = hud;
     38  const { autocompletePopup } = jsterm;
     39  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     40 
     41  let tooltip = await setInputValueForGetterConfirmDialog(
     42    toolbox,
     43    hud,
     44    "foo.bar."
     45  );
     46  let labelEl = tooltip.querySelector(".confirm-label");
     47  is(
     48    labelEl.textContent,
     49    "Invoke getter foo.bar to retrieve the property list?",
     50    "Dialog has expected text content"
     51  );
     52 
     53  info(
     54    "Check that hitting Tab does invoke the getter and return its properties"
     55  );
     56  let onAutocompleteUpdated = jsterm.once("autocomplete-updated");
     57  EventUtils.synthesizeKey("KEY_Tab");
     58  await onAutocompleteUpdated;
     59  ok(autocompletePopup.isOpen, "popup is open after Tab");
     60  ok(
     61    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
     62    "popup has expected items"
     63  );
     64  checkInputValueAndCursorPosition(hud, "foo.bar.|");
     65  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");
     66 
     67  info("Close autocomplete popup");
     68  let onPopupClose = autocompletePopup.once("popup-closed");
     69  EventUtils.synthesizeKey("KEY_Escape");
     70  await onPopupClose;
     71 
     72  info(
     73    "Ctrl+Space again to ensure the autocomplete is shown, not the confirm dialog"
     74  );
     75  onAutocompleteUpdated = jsterm.once("autocomplete-updated");
     76  EventUtils.synthesizeKey(" ", { ctrlKey: true });
     77  await onAutocompleteUpdated;
     78  ok(autocompletePopup.isOpen, "popup is open after Ctrl + Space");
     79  ok(
     80    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
     81    "popup has expected items"
     82  );
     83  checkInputValueAndCursorPosition(hud, "foo.bar.|");
     84  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is not open");
     85 
     86  info(
     87    "Type a space, then backspace and ensure the autocomplete popup is displayed"
     88  );
     89  onAutocompleteUpdated = jsterm.once("autocomplete-updated");
     90  EventUtils.synthesizeKey(" ");
     91  await onAutocompleteUpdated;
     92  is(autocompletePopup.isOpen, true, "Autocomplete popup is still opened");
     93  ok(
     94    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
     95    "popup has expected items"
     96  );
     97 
     98  onAutocompleteUpdated = jsterm.once("autocomplete-updated");
     99  EventUtils.synthesizeKey("KEY_Backspace");
    100  await onAutocompleteUpdated;
    101  is(autocompletePopup.isOpen, true, "Autocomplete popup is still opened");
    102  ok(
    103    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
    104    "popup has expected items"
    105  );
    106 
    107  info(
    108    "Reload the page to ensure asking for autocomplete again show the confirm dialog"
    109  );
    110  onPopupClose = autocompletePopup.once("popup-closed");
    111  await reloadBrowser();
    112  info("tab reloaded, waiting for the popup to close");
    113  await onPopupClose;
    114 
    115  info("Press Ctrl+Space to open the confirm dialog again");
    116  EventUtils.synthesizeKey(" ", { ctrlKey: true });
    117  await waitFor(() => isConfirmDialogOpened(toolbox));
    118  ok(true, "Confirm Dialog is shown after tab navigation");
    119  tooltip = getConfirmDialog(toolbox);
    120  labelEl = tooltip.querySelector(".confirm-label");
    121  is(
    122    labelEl.textContent,
    123    "Invoke getter foo.bar to retrieve the property list?",
    124    "Dialog has expected text content"
    125  );
    126 
    127  info("Close tooltip");
    128  EventUtils.synthesizeKey("KEY_Escape");
    129  await waitFor(() => !isConfirmDialogOpened(toolbox));
    130 });