summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_getters_cancel.js
blob: dcb1ce774e94098231cb8d8c7483fb1d99288d76 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the confirm dialog can be closed with different actions.

const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
<head>
  <script>
    let sideEffect;
    window.foo = {
      get rab() {
        sideEffect = "getRab";
        return "rab";
      }
    };
  </script>
</head>
<body>Autocomplete popup - invoke getter - close dialog test</body>`;

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

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

  info("Check that Escape closes the confirm tooltip");
  EventUtils.synthesizeKey("KEY_Escape");
  await waitFor(() => !isConfirmDialogOpened(toolbox));

  info("Check that typing a letter won't show the tooltip");
  const onAutocompleteUpdate = jsterm.once("autocomplete-updated");
  EventUtils.sendString("t");
  await onAutocompleteUpdate;
  is(isConfirmDialogOpened(toolbox), false, "The confirm dialog is not open");

  info("Check that Ctrl+space show the confirm tooltip again");
  EventUtils.synthesizeKey(" ", { ctrlKey: true });
  await waitFor(() => isConfirmDialogOpened(toolbox));
  tooltip = getConfirmDialog(toolbox);
  labelEl = tooltip.querySelector(".confirm-label");
  is(
    labelEl.textContent,
    "Invoke getter foo.rab to retrieve the property list?",
    "Dialog has expected text content"
  );

  info("Check that clicking on the close button closes the tooltip");
  const closeButtonEl = tooltip.querySelector(".close-confirm-dialog-button");
  is(closeButtonEl.title, "Close (Esc)", "Close button has the expected title");
  closeButtonEl.click();
  await waitFor(() => !isConfirmDialogOpened(toolbox));
  ok(true, "Clicking the close button does close the tooltip");

  info(
    "Check that the tooltip closes when there's no more reason to display it"
  );
  // Open the tooltip again
  EventUtils.synthesizeKey(" ", { ctrlKey: true });
  await waitFor(() => isConfirmDialogOpened(toolbox));

  // Adding a space will make the input `foo.rab.t `, which we shouldn't try to
  // autocomplete.
  EventUtils.sendString(" ");
  await waitFor(() => !isConfirmDialogOpened(toolbox));
  ok(
    true,
    "The tooltip is now closed since the input doesn't match a getter name"
  );
  info("Check that evaluating the expression closes the tooltip");
  tooltip = await setInputValueForGetterConfirmDialog(toolbox, hud, "foo.rab.");
  EventUtils.sendString("length");
  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(() => !isConfirmDialogOpened(toolbox));
  await waitFor(() => findEvaluationResultMessage(hud, "3"));
  ok("Expression was evaluated and tooltip was closed");
});