Commit 51357b56 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: shift+arrow keys in console prompt should not move in history

Bug: 749910
Change-Id: Iea25c4b2e102d773273523de10734efc1d688923
Reviewed-on: https://chromium-review.googlesource.com/590960Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Erik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490631}
parent 63f3c7bc
Tests that console prompt keyboard events work.
Adding first message: First
multiline command
Setting prompt text: Second
multiline command
Test that arrow Up stays in the same command
{"startLine":1,"startColumn":0,"endLine":1,"endColumn":0}
Prompt text:Second
multiline command
Test that ArrowUp+shift stays in the same command
{"startLine":0,"startColumn":0,"endLine":0,"endColumn":1}
Prompt text:Second
multiline command
Test that arrow Up from the first line loads previous command
{"startLine":0,"startColumn":0,"endLine":0,"endColumn":0}
Prompt text:First
multiline command
Test that arrow Down stays in the same command
{"startLine":0,"startColumn":0,"endLine":0,"endColumn":0}
Prompt text:First
multiline command
Test that ArrowDown+shift stays in the same command
{"startLine":1,"startColumn":0,"endLine":1,"endColumn":1}
Prompt text:First
multiline command
Test that arrow Down from the first line loads next command
{"startLine":1,"startColumn":0,"endLine":1,"endColumn":0}
Prompt text:Second
multiline command
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult('Tests that console prompt keyboard events work.\n');
await TestRunner.loadModule('console_test_runner');
await TestRunner.loadPanel('console');
await ConsoleTestRunner.waitUntilConsoleEditorLoaded();
var firstCommand = 'First\nmultiline command';
var secondCommand = 'Second\nmultiline command';
TestRunner.addResult('Adding first message: ' + firstCommand);
await ConsoleTestRunner.evaluateInConsolePromise(firstCommand);
TestRunner.addResult('Setting prompt text: ' + secondCommand);
var prompt = Console.ConsoleView.instance()._prompt;
prompt.setText(secondCommand);
TestRunner.addResult('\nTest that arrow Up stays in the same command');
prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(1, 0));
dumpSelection();
sendKeyUpToPrompt();
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.addResult('\nTest that ArrowUp+shift stays in the same command');
prompt._editor.setSelection(new TextUtils.TextRange(0, 0, 0, 1));
dumpSelection();
sendKeyUpToPrompt(true);
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.addResult('\nTest that arrow Up from the first line loads previous command');
prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0, 0));
dumpSelection();
sendKeyUpToPrompt();
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.addResult('\nTest that arrow Down stays in the same command');
prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0, 0));
dumpSelection();
sendKeyDownToPrompt();
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.addResult('\nTest that ArrowDown+shift stays in the same command');
prompt._editor.setSelection(new TextUtils.TextRange(1, 0, 1, 1));
dumpSelection();
sendKeyDownToPrompt(true);
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.addResult('\nTest that arrow Down from the first line loads next command');
prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(1, 0));
dumpSelection();
sendKeyDownToPrompt();
TestRunner.addResult('Prompt text:' + prompt.text());
TestRunner.completeTest();
/**
* @param {boolean} shiftKey
*/
function sendKeyUpToPrompt(shiftKey) {
prompt._editor.element.focus();
if (shiftKey)
eventSender.keyDown('ArrowUp', ['shiftKey']);
else
eventSender.keyDown('ArrowUp');
}
/**
* @param {boolean} shiftKey
*/
function sendKeyDownToPrompt(shiftKey) {
prompt._editor.element.focus();
if (shiftKey)
eventSender.keyDown('ArrowDown', ['shiftKey']);
else
eventSender.keyDown('ArrowDown');
}
function dumpSelection() {
TestRunner.addResult(JSON.stringify(prompt._editor.selection()));
}
})();
......@@ -107,13 +107,13 @@ Console.ConsolePrompt = class extends UI.Widget {
switch (keyboardEvent.keyCode) {
case UI.KeyboardShortcut.Keys.Up.code:
if (this._editor.selection().endLine > 0)
if (keyboardEvent.shiftKey || this._editor.selection().endLine > 0)
break;
newText = this._history.previous(this.text());
isPrevious = true;
break;
case UI.KeyboardShortcut.Keys.Down.code:
if (this._editor.selection().endLine < this._editor.fullRange().endLine)
if (keyboardEvent.shiftKey || this._editor.selection().endLine < this._editor.fullRange().endLine)
break;
newText = this._history.next();
break;
......
......@@ -174,6 +174,15 @@ ConsoleTestRunner.evaluateInConsole = function(code, callback, dontForceMainCont
});
};
/**
* @param {string} code
* @param {boolean=} dontForceMainContext
* @return {!Promise}
*/
ConsoleTestRunner.evaluateInConsolePromise = function(code, dontForceMainContext) {
return new Promise(fulfill => ConsoleTestRunner.evaluateInConsole(code, fulfill, dontForceMainContext));
};
/**
* @param {!Function} override
* @param {boolean=} opt_sticky
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment