summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_webconsole_multiline_input.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/webconsole/test/browser_webconsole_multiline_input.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/webconsole/test/browser_webconsole_multiline_input.js')
-rw-r--r--devtools/client/webconsole/test/browser_webconsole_multiline_input.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser_webconsole_multiline_input.js b/devtools/client/webconsole/test/browser_webconsole_multiline_input.js
new file mode 100644
index 000000000..7285c2127
--- /dev/null
+++ b/devtools/client/webconsole/test/browser_webconsole_multiline_input.js
@@ -0,0 +1,70 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Tests that the console waits for more input instead of evaluating
+// when valid, but incomplete, statements are present upon pressing enter
+// -or- when the user ends a line with shift + enter.
+
+"use strict";
+
+const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
+ "test/test-console.html";
+
+let SHOULD_ENTER_MULTILINE = [
+ {input: "function foo() {" },
+ {input: "var a = 1," },
+ {input: "var a = 1;", shiftKey: true },
+ {input: "function foo() { }", shiftKey: true },
+ {input: "function" },
+ {input: "(x) =>" },
+ {input: "let b = {" },
+ {input: "let a = [" },
+ {input: "{" },
+ {input: "{ bob: 3343," },
+ {input: "function x(y=" },
+ {input: "Array.from(" },
+ // shift + enter creates a new line despite parse errors
+ {input: "{2,}", shiftKey: true },
+];
+let SHOULD_EXECUTE = [
+ {input: "function foo() { }" },
+ {input: "var a = 1;" },
+ {input: "function foo() { var a = 1; }" },
+ {input: '"asdf"' },
+ {input: "99 + 3" },
+ {input: "1, 2, 3" },
+ // errors
+ {input: "function f(x) { let y = 1, }" },
+ {input: "function f(x=,) {" },
+ {input: "{2,}" },
+];
+
+add_task(function* () {
+ let { tab, browser } = yield loadTab(TEST_URI);
+ let hud = yield openConsole();
+ let inputNode = hud.jsterm.inputNode;
+
+ for (let test of SHOULD_ENTER_MULTILINE) {
+ hud.jsterm.setInputValue(test.input);
+ EventUtils.synthesizeKey("VK_RETURN", { shiftKey: test.shiftKey });
+ let inputValue = hud.jsterm.getInputValue();
+ is(inputNode.selectionStart, inputNode.selectionEnd,
+ "selection is collapsed");
+ is(inputNode.selectionStart, inputValue.length,
+ "caret at end of multiline input");
+ let inputWithNewline = test.input + "\n";
+ is(inputValue, inputWithNewline, "Input value is correct");
+ }
+
+ for (let test of SHOULD_EXECUTE) {
+ hud.jsterm.setInputValue(test.input);
+ EventUtils.synthesizeKey("VK_RETURN", { shiftKey: test.shiftKey });
+ let inputValue = hud.jsterm.getInputValue();
+ is(inputNode.selectionStart, 0, "selection starts/ends at 0");
+ is(inputNode.selectionEnd, 0, "selection starts/ends at 0");
+ is(inputValue, "", "Input value is cleared");
+ }
+
+});