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

// Test that user input that is not submitted in the command line input is not
// lost after navigating in history.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=817834

"use strict";

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

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  ok(!getInputValue(hud), "console input is empty");
  checkInputCursorPosition(hud, 0, "Cursor is at expected position");

  setInputValue(hud, '"first item"');
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), '"first item"', "null test history up");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(getInputValue(hud), '"first item"', "null test history down");

  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(() => findEvaluationResultMessage(hud, "first item"));
  is(getInputValue(hud), "", "cleared input line after submit");

  setInputValue(hud, '"editing input 1"');
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), '"first item"', "test history up");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(
    getInputValue(hud),
    '"editing input 1"',
    "test history down restores in-progress input"
  );

  setInputValue(hud, '"second item"');
  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(() => findEvaluationResultMessage(hud, "second item"));

  setInputValue(hud, '"editing input 2"');
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), '"second item"', "test history up");
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(getInputValue(hud), '"first item"', "test history up");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(getInputValue(hud), '"second item"', "test history down");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  is(
    getInputValue(hud),
    '"editing input 2"',
    "test history down restores new in-progress input again"
  );

  // Appending the same value again should not impact the history.
  // Let's also use some spaces around to check that the input value
  // is properly trimmed.
  setInputValue(hud, '"second item"');
  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(
    () => findEvaluationResultMessages(hud, "second item").length == 2
  );

  setInputValue(hud, '"second item"    ');
  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(
    () => findEvaluationResultMessages(hud, "second item").length == 3
  );

  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(
    getInputValue(hud),
    '"second item"',
    "test history up reaches duplicated entry just once"
  );
  EventUtils.synthesizeKey("KEY_ArrowUp");
  is(
    getInputValue(hud),
    '"first item"',
    "test history up reaches the previous value"
  );
});