Bug 1463674 - Add a missing test for hitting arrow keys when autocomplete popup is displayed; r=Honza. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 05 Jul 2018 16:48:01 +0200
changeset 817791 d847f4b73e71d1c0f4ce4419fd30f4403a8aae50
parent 817790 c4b9a1f22d76cd0ee0d039b3f888096fad3e09d8
child 817792 8eda1d9ad069a3d2f77180afe40d10d84fbd87a0
push id116163
push userbmo:nchevobbe@mozilla.com
push dateFri, 13 Jul 2018 13:10:25 +0000
reviewersHonza
bugs1463674
milestone63.0a1
Bug 1463674 - Add a missing test for hitting arrow keys when autocomplete popup is displayed; r=Honza. When migrating the old code to codeMirror, I saw that two defined behaviors were not tested: - ArrowLeft when popup is displayed should hide the popup and the autocompletion test - ArrowRight when popup is displayed should complete the input with the selected element. This patch add a test for those two cases. MozReview-Commit-ID: HZYtHssfB55
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -179,16 +179,17 @@ skip-if = (verify && debug && (os == 'ma
 skip-if = verify
 [browser_console_webconsole_console_api_calls.js]
 [browser_console_webconsole_ctrlw_close_tab.js]
 [browser_console_webconsole_iframe_messages.js]
 [browser_console_webconsole_private_browsing.js]
 [browser_jsterm_accessibility.js]
 [browser_jsterm_add_edited_input_to_history.js]
 [browser_jsterm_autocomplete_array_no_index.js]
+[browser_jsterm_autocomplete_arrow_keys.js]
 [browser_jsterm_autocomplete_cached_results.js]
 [browser_jsterm_autocomplete_crossdomain_iframe.js]
 [browser_jsterm_autocomplete_escape_key.js]
 [browser_jsterm_autocomplete_extraneous_closing_brackets.js]
 [browser_jsterm_autocomplete_helpers.js]
 [browser_jsterm_autocomplete_in_chrome_tab.js]
 [browser_jsterm_autocomplete_in_debugger_stackframe.js]
 [browser_jsterm_autocomplete_inside_text.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
@@ -0,0 +1,68 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TEST_URI = `data:text/html;charset=utf-8,<head><script>
+    /* Create a prototype-less object so popup does not contain native
+     * Object prototype properties.
+     */
+    window.foo = Object.create(null, Object.getOwnPropertyDescriptors({
+      aa: "a",
+      bb: "b",
+    }));
+  </script></head><body>Autocomplete text navigation key usage test</body>`;
+
+add_task(async function() {
+  // Run test with legacy JsTerm
+  await performTests();
+  // And then run it with the CodeMirror-powered one.
+  await pushPref("devtools.webconsole.jsterm.codeMirror", true);
+  await performTests();
+});
+
+async function performTests() {
+  const { jsterm } = await openNewTabAndConsole(TEST_URI);
+  const { autocompletePopup: popup } = jsterm;
+
+  const checkInput = (expected, assertionInfo) =>
+    checkJsTermValueAndCursor(jsterm, expected, assertionInfo);
+
+  let onPopUpOpen = popup.once("popup-opened");
+  jsterm.setInputValue("window.foo");
+  EventUtils.sendString(".");
+  await onPopUpOpen;
+
+  info("Trigger autocomplete popup opening");
+  checkInput("window.foo.|");
+  is(popup.isOpen, true, "popup is open");
+  checkJsTermCompletionValue(jsterm, "           aa", "completeNode has expected value");
+
+  info("Test that arrow left closes the popup and clear complete node");
+  let onPopUpClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("KEY_ArrowLeft");
+  await onPopUpClose;
+  checkInput("window.foo|.");
+  is(popup.isOpen, false, "popup is closed");
+  checkJsTermCompletionValue(jsterm, "", "completeNode is empty");
+
+  info("Trigger autocomplete popup opening again");
+  onPopUpOpen = popup.once("popup-opened");
+  jsterm.setInputValue("window.foo");
+  EventUtils.sendString(".");
+  await onPopUpOpen;
+
+  checkInput("window.foo.|");
+  is(popup.isOpen, true, "popup is open");
+  checkJsTermCompletionValue(jsterm, "           aa", "completeNode has expected value");
+
+  info("Test that arrow right selects selected autocomplete item");
+  onPopUpClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("KEY_ArrowRight");
+  await onPopUpClose;
+  checkInput("window.foo.aa|");
+  is(popup.isOpen, false, "popup is closed");
+  checkJsTermCompletionValue(jsterm, "", "completeNode is empty");
+}