summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_getters_confirm.js
blob: e7ac63b3e00e6839d38d565923c445b3a0843f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that accessing properties with getters displays the confirm dialog to invoke them,
// and then displays the autocomplete popup with the results.

const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
<head>
  <script>
    /* Create a prototype-less object so popup does not contain native
     * Object prototype properties.
     */
    var obj = props => Object.create(null, Object.getOwnPropertyDescriptors(props));
    let sideEffect;
    var foo = obj({
      get bar() {
        sideEffect = "bar";
        return obj({
          get baz() {
            sideEffect = "baz";
            return obj({
              hello: 1,
              world: "",
            });
          },
          bloop: true,
        })
      },
      get rab() {
        sideEffect = "rab";
        return "";
      }
    });
  </script>
</head>
<body>Autocomplete popup - invoke getter usage test</body>`;

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const { jsterm } = hud;
  const { autocompletePopup } = jsterm;
  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);

  let tooltip = await setInputValueForGetterConfirmDialog(
    toolbox,
    hud,
    "foo.bar."
  );
  let labelEl = tooltip.querySelector(".confirm-label");
  is(
    labelEl.textContent,
    "Invoke getter foo.bar to retrieve the property list?",
    "Dialog has expected text content"
  );

  info(
    "Check that hitting Tab does invoke the getter and return its properties"
  );
  let onPopUpOpen = autocompletePopup.once("popup-opened");
  EventUtils.synthesizeKey("KEY_Tab");
  await onPopUpOpen;
  ok(autocompletePopup.isOpen, "popup is open after Tab");
  ok(
    hasExactPopupLabels(autocompletePopup, ["baz", "bloop"]),
    "popup has expected items"
  );
  checkInputValueAndCursorPosition(hud, "foo.bar.|");
  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");

  let onPopUpClose = autocompletePopup.once("popup-closed");
  EventUtils.synthesizeKey("KEY_Tab");
  await onPopUpClose;
  checkInputValueAndCursorPosition(hud, "foo.bar.baz|");

  info(
    "Check that the invoke tooltip is displayed when performing an element access"
  );
  EventUtils.sendString("[");
  await waitFor(() => isConfirmDialogOpened(toolbox));

  tooltip = getConfirmDialog(toolbox);
  labelEl = tooltip.querySelector(".confirm-label");
  is(
    labelEl.textContent,
    "Invoke getter foo.bar.baz to retrieve the property list?",
    "Dialog has expected text content"
  );

  info(
    "Check that hitting Tab does invoke the getter and return its properties"
  );
  onPopUpOpen = autocompletePopup.once("popup-opened");
  EventUtils.synthesizeKey("KEY_Tab");
  await onPopUpOpen;
  ok(autocompletePopup.isOpen, "popup is open after Tab");
  ok(
    hasExactPopupLabels(autocompletePopup, [`"hello"`, `"world"`]),
    "popup has expected items"
  );
  checkInputValueAndCursorPosition(hud, "foo.bar.baz[|]");
  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");

  onPopUpClose = autocompletePopup.once("popup-closed");
  EventUtils.synthesizeKey("KEY_Tab");
  await onPopUpClose;
  checkInputValueAndCursorPosition(hud, `foo.bar.baz["hello"]|`);

  info("Check that autocompletion work on a getter result");
  onPopUpOpen = autocompletePopup.once("popup-opened");
  EventUtils.sendString(".");
  await onPopUpOpen;
  ok(autocompletePopup.isOpen, "got items of getter result");
  ok(
    hasPopupLabel(autocompletePopup, "toExponential"),
    "popup has expected items"
  );

  tooltip = await setInputValueForGetterConfirmDialog(toolbox, hud, "foo.rab.");
  labelEl = tooltip.querySelector(".confirm-label");
  is(
    labelEl.textContent,
    "Invoke getter foo.rab to retrieve the property list?",
    "Dialog has expected text content"
  );

  info(
    "Check clicking the confirm button invokes the getter and return its properties"
  );
  onPopUpOpen = autocompletePopup.once("popup-opened");
  tooltip.querySelector(".confirm-button").click();
  await onPopUpOpen;
  ok(
    autocompletePopup.isOpen,
    "popup is open after clicking on the confirm button"
  );
  ok(
    hasPopupLabel(autocompletePopup, "startsWith"),
    "popup has expected items"
  );
  checkInputValueAndCursorPosition(hud, "foo.rab.|");
  is(isConfirmDialogOpened(toolbox), false, "confirm tooltip is now closed");

  info("Close autocomplete popup");
  await closeAutocompletePopup(hud);
});