tor-browser

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

browser_jsterm_autocomplete_getters_confirm.js (4566B)


      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 accessing properties with getters displays the confirm dialog to invoke them,
      7 // and then displays the autocomplete popup with the results.
      8 
      9 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
     10 <head>
     11  <script>
     12    /* Create a prototype-less object so popup does not contain native
     13     * Object prototype properties.
     14     */
     15    var obj = props => Object.create(null, Object.getOwnPropertyDescriptors(props));
     16    let sideEffect;
     17    var foo = obj({
     18      get bar() {
     19        sideEffect = "bar";
     20        return obj({
     21          get baz() {
     22            sideEffect = "baz";
     23            return obj({
     24              hello: 1,
     25              world: "",
     26            });
     27          },
     28          bloop: true,
     29        })
     30      },
     31      get rab() {
     32        sideEffect = "rab";
     33        return "";
     34      }
     35    });
     36  </script>
     37 </head>
     38 <body>Autocomplete popup - invoke getter usage test</body>`;
     39 
     40 add_task(async function () {
     41  const hud = await openNewTabAndConsole(TEST_URI);
     42  const { jsterm } = hud;
     43  const { autocompletePopup } = jsterm;
     44  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     45 
     46  let tooltip = await setInputValueForGetterConfirmDialog(
     47    toolbox,
     48    hud,
     49    "foo.bar."
     50  );
     51  let labelEl = tooltip.querySelector(".confirm-label");
     52  is(
     53    labelEl.textContent,
     54    "Invoke getter foo.bar to retrieve the property list?",
     55    "Dialog has expected text content"
     56  );
     57 
     58  info(
     59    "Check that hitting Tab does invoke the getter and return its properties"
     60  );
     61  let onPopUpOpen = autocompletePopup.once("popup-opened");
     62  EventUtils.synthesizeKey("KEY_Tab");
     63  await onPopUpOpen;
     64  ok(autocompletePopup.isOpen, "popup is open after Tab");
     65  ok(
     66    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
     67    "popup has expected items"
     68  );
     69  checkInputValueAndCursorPosition(hud, "foo.bar.|");
     70  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");
     71 
     72  let onPopUpClose = autocompletePopup.once("popup-closed");
     73  EventUtils.synthesizeKey("KEY_Tab");
     74  await onPopUpClose;
     75  checkInputValueAndCursorPosition(hud, "foo.bar.baz|");
     76 
     77  info(
     78    "Check that the invoke tooltip is displayed when performing an element access"
     79  );
     80  EventUtils.sendString("[");
     81  await waitFor(() => isConfirmDialogOpened(toolbox));
     82 
     83  tooltip = getConfirmDialog(toolbox);
     84  labelEl = tooltip.querySelector(".confirm-label");
     85  is(
     86    labelEl.textContent,
     87    "Invoke getter foo.bar.baz to retrieve the property list?",
     88    "Dialog has expected text content"
     89  );
     90 
     91  info(
     92    "Check that hitting Tab does invoke the getter and return its properties"
     93  );
     94  onPopUpOpen = autocompletePopup.once("popup-opened");
     95  EventUtils.synthesizeKey("KEY_Tab");
     96  await onPopUpOpen;
     97  ok(autocompletePopup.isOpen, "popup is open after Tab");
     98  ok(
     99    hasExactPopupLabels(autocompletePopup, [`"hello"`, `"world"`]),
    100    "popup has expected items"
    101  );
    102  checkInputValueAndCursorPosition(hud, "foo.bar.baz[|]");
    103  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");
    104 
    105  onPopUpClose = autocompletePopup.once("popup-closed");
    106  EventUtils.synthesizeKey("KEY_Tab");
    107  await onPopUpClose;
    108  checkInputValueAndCursorPosition(hud, `foo.bar.baz["hello"]|`);
    109 
    110  info("Check that autocompletion work on a getter result");
    111  onPopUpOpen = autocompletePopup.once("popup-opened");
    112  EventUtils.sendString(".");
    113  await onPopUpOpen;
    114  ok(autocompletePopup.isOpen, "got items of getter result");
    115  ok(
    116    hasPopupLabel(autocompletePopup, "toExponential"),
    117    "popup has expected items"
    118  );
    119 
    120  tooltip = await setInputValueForGetterConfirmDialog(toolbox, hud, "foo.rab.");
    121  labelEl = tooltip.querySelector(".confirm-label");
    122  is(
    123    labelEl.textContent,
    124    "Invoke getter foo.rab to retrieve the property list?",
    125    "Dialog has expected text content"
    126  );
    127 
    128  info(
    129    "Check clicking the confirm button invokes the getter and return its properties"
    130  );
    131  onPopUpOpen = autocompletePopup.once("popup-opened");
    132  tooltip.querySelector(".confirm-button").click();
    133  await onPopUpOpen;
    134  ok(
    135    autocompletePopup.isOpen,
    136    "popup is open after clicking on the confirm button"
    137  );
    138  ok(
    139    hasPopupLabel(autocompletePopup, "startsWith"),
    140    "popup has expected items"
    141  );
    142  checkInputValueAndCursorPosition(hud, "foo.rab.|");
    143  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");
    144 
    145  info("Close autocomplete popup");
    146  await closeAutocompletePopup(hud);
    147 });