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

// Test that user input is not cleared when 'devtools.webconsole.input.editor'
// is set to true.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1519313

"use strict";

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for bug 1519313";

add_task(async function () {
  await pushPref("devtools.webconsole.input.editor", true);
  const hud = await openNewTabAndConsole(TEST_URI);

  const testExpressions = [
    "`Mozilla 😍 Firefox`",
    "`Firefox Devtools are awesome`",
    "`2 + 2 = 5?`",
    "`I'm running out of ideas...`",
    "`🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘`",
    "`🌪🌪 🐄 🐄 🏠 🐄 🐄 ⛈`",
    "`🌈 🌈 🌈 🦄 🦄 🌈 🌈 🌈`",
    "`Time to perform the test 🤪`",
  ];

  info("Executing a bunch of non-sense JS expression");
  for (const expression of testExpressions) {
    // Wait until we get the result of the command.
    await executeAndWaitForResultMessage(hud, expression, "");
    ok(true, `JS expression executed successfully: ${expression} `);
  }

  info("Test that pressing ArrowUp does nothing");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), "", "Good! There is no text in the JS Editor");

  info("Test that pressing multiple times ArrowUp does nothing");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), "", "Good! Again, there is no text in the JS Editor");

  info(
    "Move somewhere in the middle of the history using the navigation buttons and test again"
  );
  const prevHistoryButton = getEditorToolbar(hud).querySelector(
    ".webconsole-editor-toolbar-history-prevExpressionButton"
  );
  info("Pressing 3 times the previous history button");
  prevHistoryButton.click();
  prevHistoryButton.click();
  prevHistoryButton.click();
  const jsExpression = testExpressions[testExpressions.length - 3];
  is(
    getInputValue(hud),
    jsExpression,
    "Sweet! We are in the right position of the history"
  );

  info("Test again that pressing ArrowUp does nothing");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(
    getInputValue(hud),
    jsExpression,
    "OMG! We have some cows in the JS Editor!"
  );

  info("Test again that pressing multiple times ArrowUp does nothing");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(
    getInputValue(hud),
    jsExpression,
    "Awesome! The cows are still there in the JS Editor!"
  );

  info("Test that pressing ArrowDown does nothing");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(
    getInputValue(hud),
    jsExpression,
    "Super! We still have the cows in the JS Editor!"
  );

  info("Test that pressing multiple times ArrowDown does nothing");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(getInputValue(hud), jsExpression, "And the cows are still there...");
});

function getEditorToolbar(hud) {
  return hud.ui.outputNode.querySelector(".webconsole-editor-toolbar");
}