Skip to content

Commit

Permalink
Backed out changeset 232f3a99301c (bug 1408933) for build bustage due…
Browse files Browse the repository at this point in the history
… to not removing reference to renamed test. r=backout on a CLOSED TREE

--HG--
rename : devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_ctrl_key_nav.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_ctrl_key_nav.js
  • Loading branch information
nbeleuzu committed Dec 8, 2017
1 parent d6368e6 commit 446b415
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ skip-if = true # Bug 1403188
[browser_jsterm_autocomplete-properties-with-non-alphanumeric-names.js]
[browser_jsterm_completion.js]
[browser_jsterm_copy_command.js]
[browser_jsterm_ctrl_key_nav.js]
skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only
[browser_jsterm_dollar.js]
[browser_jsterm_history.js]
[browser_jsterm_history_persist.js]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,46 @@

// Test navigation of webconsole contents via ctrl-a, ctrl-e, ctrl-p, ctrl-n
// see https://bugzilla.mozilla.org/show_bug.cgi?id=804845
//
// The shortcuts tested here have platform limitations:
// - ctrl-e does not work on windows,
// - ctrl-a, ctrl-p and ctrl-n only work on OSX
"use strict";

const TEST_URI = "data:text/html;charset=utf-8,Web Console test for " +
"bug 804845 and bug 619598";

add_task(async function () {
const {jsterm} = await openNewTabAndConsole(TEST_URI);
var jsterm, inputNode;

add_task(function* () {
yield loadTab(TEST_URI);

let hud = yield openConsole();

doTests(hud);

jsterm = inputNode = null;
});

function doTests(HUD) {
jsterm = HUD.jsterm;
inputNode = jsterm.inputNode;
ok(!jsterm.getInputValue(), "jsterm.getInputValue() is empty");
is(jsterm.inputNode.selectionStart, 0);
is(jsterm.inputNode.selectionEnd, 0);

testSingleLineInputNavNoHistory(jsterm);
testMultiLineInputNavNoHistory(jsterm);
testNavWithHistory(jsterm);
});
testSingleLineInputNavNoHistory();
testMultiLineInputNavNoHistory();
testNavWithHistory();
}

function testSingleLineInputNavNoHistory(jsterm) {
let inputNode = jsterm.inputNode;
function testSingleLineInputNavNoHistory() {
// Single char input
EventUtils.synthesizeKey("1", {});
is(inputNode.selectionStart, 1, "caret location after single char input");

// nav to start/end with ctrl-a and ctrl-e;
synthesizeLineStartKey();
EventUtils.synthesizeKey("a", { ctrlKey: true });
is(inputNode.selectionStart, 0,
"caret location after single char input and ctrl-a");

synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
is(inputNode.selectionStart, 1,
"caret location after single char input and ctrl-e");

Expand All @@ -51,35 +58,34 @@ function testSingleLineInputNavNoHistory(jsterm) {
is(inputNode.selectionStart, 2,
"caret location after two char input and VK_DOWN");

synthesizeLineStartKey();
EventUtils.synthesizeKey("a", { ctrlKey: true });
is(inputNode.selectionStart, 0,
"move caret to beginning of 2 char input with ctrl-a");
synthesizeLineStartKey();
EventUtils.synthesizeKey("a", { ctrlKey: true });
is(inputNode.selectionStart, 0,
"no change of caret location on repeat ctrl-a");
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(inputNode.selectionStart, 0,
"no change of caret location on ctrl-p from beginning of line");

synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
is(inputNode.selectionStart, 2,
"move caret to end of 2 char input with ctrl-e");
synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
is(inputNode.selectionStart, 2,
"no change of caret location on repeat ctrl-e");
synthesizeLineDownKey();
EventUtils.synthesizeKey("n", { ctrlKey: true });
is(inputNode.selectionStart, 2,
"no change of caret location on ctrl-n from end of line");

synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(inputNode.selectionStart, 0, "ctrl-p moves to start of line");

synthesizeLineDownKey();
EventUtils.synthesizeKey("n", { ctrlKey: true });
is(inputNode.selectionStart, 2, "ctrl-n moves to end of line");
}

function testMultiLineInputNavNoHistory(jsterm) {
let inputNode = jsterm.inputNode;
function testMultiLineInputNavNoHistory() {
let lineValues = ["one", "2", "something longer", "", "", "three!"];
jsterm.setInputValue("");
// simulate shift-return
Expand Down Expand Up @@ -107,69 +113,65 @@ function testMultiLineInputNavNoHistory(jsterm) {
"down arrow from within multiline");

// navigate up through input lines
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(jsterm.getInputValue().slice(inputNode.selectionStart), expectedStringAfterCarat,
"ctrl-p from end of multiline");

for (let i = 4; i >= 0; i--) {
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
expectedStringAfterCarat = lineValues[i] + newlineString +
expectedStringAfterCarat;
is(jsterm.getInputValue().slice(inputNode.selectionStart),
expectedStringAfterCarat, "ctrl-p from within line " + i +
" of multiline input");
}
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(inputNode.selectionStart, 0, "reached start of input");
is(jsterm.getInputValue(), inputValue,
"no change to multiline input on ctrl-p from beginning of multiline");

// navigate to end of first line
synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
let caretPos = inputNode.selectionStart;
let expectedStringBeforeCarat = lineValues[0];
is(jsterm.getInputValue().slice(0, caretPos), expectedStringBeforeCarat,
"ctrl-e into multiline input");
synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
is(inputNode.selectionStart, caretPos,
"repeat ctrl-e doesn't change caret position in multiline input");

// navigate down one line; ctrl-a to the beginning; ctrl-e to end
for (let i = 1; i < lineValues.length; i++) {
synthesizeLineDownKey();
synthesizeLineStartKey();
EventUtils.synthesizeKey("n", { ctrlKey: true });
EventUtils.synthesizeKey("a", { ctrlKey: true });
caretPos = inputNode.selectionStart;
expectedStringBeforeCarat += newlineString;
is(jsterm.getInputValue().slice(0, caretPos), expectedStringBeforeCarat,
"ctrl-a to beginning of line " + (i + 1) + " in multiline input");

synthesizeLineEndKey();
EventUtils.synthesizeKey("e", { ctrlKey: true });
caretPos = inputNode.selectionStart;
expectedStringBeforeCarat += lineValues[i];
is(jsterm.getInputValue().slice(0, caretPos), expectedStringBeforeCarat,
"ctrl-e to end of line " + (i + 1) + "in multiline input");
}
}

function testNavWithHistory(jsterm) {
let inputNode = jsterm.inputNode;

function testNavWithHistory() {
// NOTE: Tests does NOT currently define behaviour for ctrl-p/ctrl-n with
// caret placed _within_ single line input
let values = [
'"single line input"',
'"a longer single-line input to check caret repositioning"',
'"multi-line"\n"input"\n"here!"',
];

let values = ['"single line input"',
'"a longer single-line input to check caret repositioning"',
['"multi-line"', '"input"', '"here!"'].join("\n"),
];
// submit to history
for (let i = 0; i < values.length; i++) {
jsterm.setInputValue(values[i]);
jsterm.execute();
}
is(inputNode.selectionStart, 0, "caret location at start of empty line");

synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(inputNode.selectionStart, values[values.length - 1].length,
"caret location correct at end of last history input");

Expand All @@ -178,21 +180,20 @@ function testNavWithHistory(jsterm) {
let match = values[i].match(/(\n)/g);
if (match) {
// multi-line inputs won't update from history unless caret at beginning
synthesizeLineStartKey();
EventUtils.synthesizeKey("a", { ctrlKey: true });
for (let j = 0; j < match.length; j++) {
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
}
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
} else {
// single-line inputs will update from history from end of line
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
}
is(jsterm.getInputValue(), values[i - 1],
"ctrl-p updates inputNode from backwards history values[" + i - 1 + "]");
}

let inputValue = jsterm.getInputValue();
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(inputNode.selectionStart, 0,
"ctrl-p at beginning of history moves caret location to beginning " +
"of line");
Expand All @@ -201,42 +202,26 @@ function testNavWithHistory(jsterm) {

// Navigate forwards history with ctrl-n
for (let i = 1; i < values.length; i++) {
synthesizeLineDownKey();
EventUtils.synthesizeKey("n", { ctrlKey: true });
is(jsterm.getInputValue(), values[i],
"ctrl-n updates inputNode from forwards history values[" + i + "]");
is(inputNode.selectionStart, values[i].length,
"caret location correct at end of history input for values[" + i + "]");
}
synthesizeLineDownKey();
EventUtils.synthesizeKey("n", { ctrlKey: true });
ok(!jsterm.getInputValue(), "ctrl-n at end of history updates to empty input");

// Simulate editing multi-line
inputValue = "one\nlinebreak";
jsterm.setInputValue(inputValue);

// Attempt nav within input
synthesizeLineUpKey();
EventUtils.synthesizeKey("p", { ctrlKey: true });
is(jsterm.getInputValue(), inputValue,
"ctrl-p from end of multi-line does not trigger history");

synthesizeLineStartKey();
synthesizeLineUpKey();
is(jsterm.getInputValue(), values[values.length - 1],
"ctrl-p from start of multi-line triggers history");
}

function synthesizeLineStartKey() {
EventUtils.synthesizeKey("a", { ctrlKey: true });
}

function synthesizeLineEndKey() {
EventUtils.synthesizeKey("e", { ctrlKey: true });
}

function synthesizeLineUpKey() {
EventUtils.synthesizeKey("p", { ctrlKey: true });
}

function synthesizeLineDownKey() {
EventUtils.synthesizeKey("n", { ctrlKey: true });
is(jsterm.getInputValue(), values[values.length - 1],
"ctrl-p from start of multi-line triggers history");
}

0 comments on commit 446b415

Please sign in to comment.