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

// Test that hitting Ctrl + B does toggle the editor mode.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1519105

"use strict";

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Test editor mode toggle keyboard shortcut";
const EDITOR_PREF = "devtools.webconsole.input.editor";

// See Bug 1631529
requestLongerTimeout(2);

add_task(async function () {
  // Start with the editor turned off
  await pushPref(EDITOR_PREF, false);
  let hud = await openNewTabAndConsole(TEST_URI);

  const INPUT_VALUE = "`hello`";
  setInputValue(hud, INPUT_VALUE);

  is(isEditorModeEnabled(hud), false, "The console isn't in editor mode");

  info("Enable the editor mode");
  await toggleLayout(hud);
  is(isEditorModeEnabled(hud), true, "Editor mode is enabled");
  is(getInputValue(hud), INPUT_VALUE, "The input value wasn't cleared");

  info("Close the console and reopen it");
  // Wait for eager evaluation result so we don't have a pending call to the server.
  await waitForEagerEvaluationResult(hud, `"hello"`);
  await closeConsole();
  hud = await openConsole();
  is(isEditorModeEnabled(hud), true, "Editor mode is still enabled");
  setInputValue(hud, INPUT_VALUE);

  info("Disable the editor mode");
  await toggleLayout(hud);
  is(isEditorModeEnabled(hud), false, "Editor was disabled");
  is(getInputValue(hud), INPUT_VALUE, "The input value wasn't cleared");

  info("Enable the editor mode again");
  await toggleLayout(hud);
  is(isEditorModeEnabled(hud), true, "Editor mode was enabled again");
  is(getInputValue(hud), INPUT_VALUE, "The input value wasn't cleared");

  info("Close popup on switching editor modes");
  const popup = hud.jsterm.autocompletePopup;
  await setInputValueForAutocompletion(hud, "a");
  ok(popup.isOpen, "Auto complete popup is shown");
  const onPopupClosed = popup.once("popup-closed");
  await toggleLayout(hud);
  await onPopupClosed;
  ok(!popup.isOpen, "Auto complete popup is hidden on switching editor modes.");

  // Wait for eager evaluation result so we don't have a pending call to the server.
  await waitForEagerEvaluationResult(hud, /ReferenceError/);

  Services.prefs.clearUserPref(EDITOR_PREF);
});