Bug 1408921 - Split browser_webconsole_autocomplete_keys.js in the new console frontend; r=bgrins.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 25 Oct 2017 11:59:02 +0200
changeset 388442 92273c4c7222f68e6f2360df34b393f14612f1da
parent 388441 6f205bfdd1396f43a814c61728bd85659fad72ba
child 388443 4376bf8afad4255adf7c45451159ee321b2c0322
push id32750
push userarchaeopteryx@coole-files.de
push dateThu, 26 Oct 2017 21:56:27 +0000
treeherdermozilla-central@a6d7be4ac1e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1408921
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1408921 - Split browser_webconsole_autocomplete_keys.js in the new console frontend; r=bgrins. The test was very long and tested different bugs. Splitting it make all the test case clearer. MozReview-Commit-ID: 4z45RE3eJoC
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_array_no_index.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_escape_key.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_inside_text.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_nav_and_tab_key.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key_no_selection.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -191,17 +191,23 @@ skip-if = true # Bug 1406060
 skip-if = true # Bug 1406060
 [browser_console_webconsole_iframe_messages.js]
 skip-if = true # Bug 1406060
 [browser_console_webconsole_private_browsing.js]
 skip-if = true #	Bug 1403188
 # old console skip-if = e10s # Bug 1042253 - webconsole e10s tests
 [browser_jsterm_accessibility.js]
 [browser_jsterm_add_edited_input_to_history.js]
+[browser_jsterm_autocomplete_array_no_index.js]
+[browser_jsterm_autocomplete_escape_key.js]
 [browser_jsterm_autocomplete_helpers.js]
+[browser_jsterm_autocomplete_inside_text.js]
+[browser_jsterm_autocomplete_nav_and_tab_key.js]
+[browser_jsterm_autocomplete_return_key_no_selection.js]
+[browser_jsterm_autocomplete_return_key.js]
 [browser_jsterm_autocomplete-properties-with-non-alphanumeric-names.js]
 [browser_jsterm_copy_command.js]
 [browser_jsterm_dollar.js]
 [browser_jsterm_history_persist.js]
 [browser_jsterm_inspect.js]
 [browser_jsterm_no_autocompletion_on_defined_variables.js]
 [browser_jsterm_no_input_and_tab_key_pressed.js]
 [browser_jsterm_no_input_change_and_tab_key_pressed.js]
@@ -213,18 +219,16 @@ skip-if = true #	Bug 1403452
 [browser_webconsole_autocomplete_and_selfxss.js]
 subsuite = clipboard
 skip-if = true #	Bug 1404850
 # old console skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_webconsole_autocomplete_crossdomain_iframe.js]
 skip-if = true # Bug 1408919
 [browser_webconsole_autocomplete_in_debugger_stackframe.js]
 skip-if = true # Bug 1408920
-[browser_webconsole_autocomplete_keys.js]
-skip-if = true # Bug 1408921
 [browser_webconsole_autocomplete_popup.js]
 skip-if = true # Bug 1408922
 [browser_webconsole_autocomplete_popup_close_on_tab_switch.js]
 skip-if = true # Bug 1408923
 [browser_webconsole_batching.js]
 [browser_webconsole_block_mixedcontent_securityerrors.js]
 tags = mcb
 skip-if = true #	Bug 1403899
rename from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
rename to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_array_no_index.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_array_no_index.js
@@ -2,368 +2,48 @@
 /* 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";
 
 // See Bug 585991.
 
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
-
-// We should turn off auto-multiline editing during these tests
-const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
-
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
-
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
+const TEST_URI = `data:text/html;charset=utf-8,
+<head>
+  <script>
+    window.foo = [1,2,3];
+  </script>
+</head>
+<body>bug 585991 - Autocomplete popup on array</body>`;
 
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
-  info("web console opened");
-
-  jsterm = HUD.jsterm;
-
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
-
-  ok(!popup.isOpen, "popup is not open");
-
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
-
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
+add_task(async function () {
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
 
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
-
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    let currentSelectionIndex = popup.selectedIndex;
-
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
-
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
-
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
-
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
+  let onPopUpOpen = popup.once("popup-opened");
 
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("window.foobarBug585991");
+  info("wait for popup to show");
+  jsterm.setInputValue("foo");
   EventUtils.synthesizeKey(".", {});
 
-  return deferred.promise;
-});
-
-function popupHideAfterTab() {
-  let deferred = defer();
-
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
-     "completion was successful after VK_TAB");
-
-  ok(!completeNode.value, "completeNode is empty");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
+  await onPopUpOpen;
 
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
-
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
+  let popupItems = popup.getItems().map(e => e.label);
+  is(popupItems.includes("0"), false, "Completing on an array doesn't show numbers.");
 
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
-
-  info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
-
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
-
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
+  info("press Escape to close the popup");
+  const onPopupClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("VK_ESCAPE", {});
 
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
-  ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-  is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
-  is(completeNode.value, "", "completeNode is empty");
-  is(jsterm.history[jsterm.history.length - 1], "window.testBug",
-     "jsterm history is correct");
-
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
+  await onPopupClose;
 
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+});
copy from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
copy to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_escape_key.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_escape_key.js
@@ -2,368 +2,60 @@
 /* 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";
 
 // See Bug 585991.
 
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
-
-// We should turn off auto-multiline editing during these tests
-const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
+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.assign(window.foo, {
+      item0: "value0",
+      item1: "value1",
+    });
+  </script>
+</head>
+<body>bug 585991 - autocomplete popup escape key usage test</body>`;
 
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
-
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
-
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
+add_task(async function () {
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
   info("web console opened");
 
-  jsterm = HUD.jsterm;
-
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
-
-  ok(!popup.isOpen, "popup is not open");
-
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
-
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
-
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
-    let currentSelectionIndex = popup.selectedIndex;
-
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
-
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
-
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
-
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
+  let onPopUpOpen = popup.once("popup-opened");
 
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
-
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("window.foobarBug585991");
+  info("wait for completion: window.foo.");
+  jsterm.setInputValue("window.foo");
   EventUtils.synthesizeKey(".", {});
 
-  return deferred.promise;
-});
+  await onPopUpOpen;
 
-function popupHideAfterTab() {
-  let deferred = defer();
+  ok(popup.isOpen, "popup is open");
+  ok(popup.itemCount, "popup has items");
 
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
+  info("press Escape to close the popup");
+  const onPopupClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("VK_ESCAPE", {});
 
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
-     "completion was successful after VK_TAB");
+  await onPopupClose;
 
+  ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
+  is(jsterm.getInputValue(), "window.foo.", "completion was cancelled");
   ok(!completeNode.value, "completeNode is empty");
 
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
-
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
-
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
-
-  info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
-
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
-
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
-
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
-  ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-  is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
-  is(completeNode.value, "", "completeNode is empty");
-  is(jsterm.history[jsterm.history.length - 1], "window.testBug",
-     "jsterm history is correct");
-
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
-
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+});
copy from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
copy to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_inside_text.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_inside_text.js
@@ -1,369 +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";
 
-// See Bug 585991.
-
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
-
-// We should turn off auto-multiline editing during these tests
-const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
+// See Bug 812618.
 
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
+const TEST_URI = `data:text/html;charset=utf-8,
+<head>
+  <script>
+    window.testBugA = "hello world";
+    window.testBugB = "hello world 2";
+  </script>
+</head>
+<body>bug 812618 - test completion inside text</body>`;
 
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
-
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
+add_task(async function () {
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
   info("web console opened");
 
-  jsterm = HUD.jsterm;
-
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
-
-  ok(!popup.isOpen, "popup is not open");
-
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
-
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
+  const onPopUpOpen = popup.once("popup-opened");
+
+  const dumpString = "dump(window.testBu)";
+  jsterm.setInputValue(dumpString);
+  inputNode.selectionStart = inputNode.selectionEnd = dumpString.indexOf(")");
+  EventUtils.synthesizeKey("g", {});
 
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
+  await onPopUpOpen;
 
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
+  ok(popup.isOpen, "popup is open");
+  is(popup.itemCount, 2, "popup.itemCount is correct");
 
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    let currentSelectionIndex = popup.selectedIndex;
-
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
+  EventUtils.synthesizeKey("VK_DOWN", {});
+  is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
+  ok(!completeNode.value, "completeNode.value is empty");
 
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
-
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
-
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
-
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
-
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
+  let items = popup.getItems().map(e => e.label);
+  let expectedItems = ["testBugB", "testBugA"];
+  is(items.join("-"), expectedItems.join("-"), "getItems returns the items we expect");
 
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
+  info("press Tab and wait for popup to hide");
+  const onPopupClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("VK_TAB", {});
 
-  jsterm.setInputValue("window.foobarBug585991");
-  EventUtils.synthesizeKey(".", {});
-
-  return deferred.promise;
-});
-
-function popupHideAfterTab() {
-  let deferred = defer();
+  await onPopupClose;
 
   // At this point the completion suggestion should be accepted.
   ok(!popup.isOpen, "popup is not open");
-
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
-     "completion was successful after VK_TAB");
-
+  const expectedInput = "dump(window.testBugB)";
+  is(jsterm.getInputValue(), expectedInput, "completion was successful after VK_TAB");
+  is(inputNode.selectionStart, expectedInput.length - 1, "cursor location is correct");
+  is(inputNode.selectionStart, inputNode.selectionEnd, "cursor location (confirmed)");
   ok(!completeNode.value, "completeNode is empty");
 
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
-
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
-
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
-
-  info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
-
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
-
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
-
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
-  ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-  is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
-  is(completeNode.value, "", "completeNode is empty");
-  is(jsterm.history[jsterm.history.length - 1], "window.testBug",
-     "jsterm history is correct");
-
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
-
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+});
copy from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
copy to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_nav_and_tab_key.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_nav_and_tab_key.js
@@ -2,368 +2,114 @@
 /* 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";
 
 // See Bug 585991.
 
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
-
-// We should turn off auto-multiline editing during these tests
-const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
+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.assign(window.foo, {
+      item0: "value0",
+      item1: "value1",
+      item2: "value2",
+      item3: "value3",
+    });
+  </script>
+</head>
+<body>bug 585991 - autocomplete popup navigation and tab key usage test</body>`;
 
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
-
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
-
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
+add_task(async function () {
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
   info("web console opened");
 
-  jsterm = HUD.jsterm;
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
   ok(!popup.isOpen, "popup is not open");
 
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
+  const onPopUpOpen = popup.once("popup-opened");
+  jsterm.setInputValue("window.foo");
 
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
+  // Shows the popup
+  EventUtils.synthesizeKey(".", {});
+  await onPopUpOpen;
 
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
+  ok(popup.isOpen, "popup is open");
 
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
+  const popupItems = popup.getItems().map(e => e.label);
+  const expectedPopupItems = [
+    "item3",
+    "item2",
+    "item1",
+    "item0",
+  ];
 
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
+  is(popup.itemCount, expectedPopupItems.length, "popup.itemCount is correct");
+  is(popupItems.join("-"), expectedPopupItems.join("-"),
+    "getItems returns the items we expect");
+  is(popup.selectedIndex, expectedPopupItems.length - 1,
+      "Index of the first item from bottom is selected.");
 
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
+  EventUtils.synthesizeKey("VK_DOWN", {});
 
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
+  let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
+  is(popup.selectedIndex, 0, "index 0 is selected");
+  is(popup.selectedItem.label, "item3", "item3 is selected");
+  is(completeNode.value, prefix + "item3", "completeNode.value holds item3");
+
+  EventUtils.synthesizeKey("VK_DOWN", {});
 
-    EventUtils.synthesizeKey("VK_DOWN", {});
+  is(popup.selectedIndex, 1, "index 1 is selected");
+  is(popup.selectedItem.label, "item2", "item2 is selected");
+  is(completeNode.value, prefix + "item2", "completeNode.value holds item2");
 
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
+  EventUtils.synthesizeKey("VK_UP", {});
 
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    let currentSelectionIndex = popup.selectedIndex;
+  is(popup.selectedIndex, 0, "index 0 is selected");
+  is(popup.selectedItem.label, "item3", "item3 is selected");
+  is(completeNode.value, prefix + "item3", "completeNode.value holds item3");
 
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
+  let currentSelectionIndex = popup.selectedIndex;
 
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
+  EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
 
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
+  ok(popup.selectedIndex > currentSelectionIndex, "Index is greater after PGDN");
 
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
+  currentSelectionIndex = popup.selectedIndex;
+  EventUtils.synthesizeKey("VK_PAGE_UP", {});
 
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
+  ok(popup.selectedIndex < currentSelectionIndex, "Index is less after Page UP");
 
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
+  EventUtils.synthesizeKey("VK_END", {});
+  is(popup.selectedIndex, expectedPopupItems.length - 1, "index is last after End");
 
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
+  EventUtils.synthesizeKey("VK_HOME", {});
+  is(popup.selectedIndex, 0, "index is first after Home");
 
-  jsterm.setInputValue("window.foobarBug585991");
-  EventUtils.synthesizeKey(".", {});
+  info("press Tab and wait for popup to hide");
+  const onPopupClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("VK_TAB", {});
 
-  return deferred.promise;
-});
-
-function popupHideAfterTab() {
-  let deferred = defer();
+  await onPopupClose;
 
   // At this point the completion suggestion should be accepted.
   ok(!popup.isOpen, "popup is not open");
-
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
+  is(jsterm.getInputValue(), "window.foo.item3",
      "completion was successful after VK_TAB");
-
   ok(!completeNode.value, "completeNode is empty");
 
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
-
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
-
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
-
-  info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
-
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
-
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
-
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
-  ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-  is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
-  is(completeNode.value, "", "completeNode is empty");
-  is(jsterm.history[jsterm.history.length - 1], "window.testBug",
-     "jsterm history is correct");
-
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
-
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+});
copy from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
copy to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key.js
@@ -2,368 +2,85 @@
 /* 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";
 
 // See Bug 585991.
 
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
+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.foobar = Object.create(null);
+    Object.assign(window.foobar, {
+      item0: "value0",
+      item1: "value1",
+      item2: "value2",
+      item3: "value3",
+    });
+  </script>
+</head>
+<body>bug 585991 - test pressing return with open popup</body>`;
 
 // We should turn off auto-multiline editing during these tests
 const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
 
-add_task(function* () {
+add_task(async function () {
   Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
-
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
-
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
-
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
-  info("web console opened");
-
-  jsterm = HUD.jsterm;
 
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
-
-  ok(!popup.isOpen, "popup is not open");
-
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
-
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
-
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    let currentSelectionIndex = popup.selectedIndex;
-
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
-
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
+  let onPopUpOpen = popup.once("popup-opened");
 
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
-
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
-
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
+  info("wait for completion suggestions: window.foobar.");
 
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("window.foobarBug585991");
+  jsterm.setInputValue("window.fooba");
+  EventUtils.synthesizeKey("r", {});
   EventUtils.synthesizeKey(".", {});
 
-  return deferred.promise;
-});
+  await onPopUpOpen;
+
+  ok(popup.isOpen, "popup is open");
 
-function popupHideAfterTab() {
-  let deferred = defer();
+  const expectedPopupItems = [
+    "item3",
+    "item2",
+    "item1",
+    "item0",
+  ];
+  is(popup.itemCount, expectedPopupItems.length, "popup.itemCount is correct");
+  is(popup.selectedIndex, expectedPopupItems.length - 1,
+    "First index from bottom is selected");
 
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
+  EventUtils.synthesizeKey("VK_DOWN", {});
+
+  is(popup.selectedIndex, 0, "index 0 is selected");
+  is(popup.selectedItem.label, "item3", "item3 is selected");
+  let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
+  is(completeNode.value, prefix + "item3", "completeNode.value holds item3");
 
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
-     "completion was successful after VK_TAB");
+  info("press Return to accept suggestion. wait for popup to hide");
+  const onPopupClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("VK_RETURN", {});
 
+  await onPopupClose;
+
+  ok(!popup.isOpen, "popup is not open after VK_RETURN");
+  is(jsterm.getInputValue(), "window.foobar.item3",
+    "completion was successful after VK_RETURN");
   ok(!completeNode.value, "completeNode is empty");
 
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
-
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
-
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
-
-  info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
-
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
-
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
-
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
-  ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-  is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
-  is(completeNode.value, "", "completeNode is empty");
-  is(jsterm.history[jsterm.history.length - 1], "window.testBug",
-     "jsterm history is correct");
-
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
-
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+  Services.prefs.clearUserPref(PREF_AUTO_MULTILINE);
+});
copy from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
copy to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key_no_selection.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_keys.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_return_key_no_selection.js
@@ -1,369 +1,55 @@
 /* -*- 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";
 
-// See Bug 585991.
-
-const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete " +
-                 "popup keyboard usage test";
-
-// We should turn off auto-multiline editing during these tests
-const PREF_AUTO_MULTILINE = "devtools.webconsole.autoMultiline";
-var HUD, popup, jsterm, inputNode, completeNode;
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, false);
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
-
-  yield consoleOpened(hud);
-  yield popupHideAfterTab();
-  yield testReturnKey();
-  yield dontShowArrayNumbers();
-  yield testReturnWithNoSelection();
-  yield popupHideAfterReturnWithNoSelection();
-  yield testCompletionInText();
-  yield popupHideAfterCompletionInText();
-
-  HUD = popup = jsterm = inputNode = completeNode = null;
-  Services.prefs.setBoolPref(PREF_AUTO_MULTILINE, true);
-});
-
-var consoleOpened = Task.async(function* (hud) {
-  let deferred = defer();
-  HUD = hud;
-  info("web console opened");
-
-  jsterm = HUD.jsterm;
-
-  yield jsterm.execute("window.foobarBug585991={" +
-    "'item0': 'value0'," +
-    "'item1': 'value1'," +
-    "'item2': 'value2'," +
-    "'item3': 'value3'" +
-  "}");
-  yield jsterm.execute("window.testBug873250a = 'hello world';"
-    + "window.testBug873250b = 'hello world 2';");
-  popup = jsterm.autocompletePopup;
-  completeNode = jsterm.completeNode;
-  inputNode = jsterm.inputNode;
-
-  ok(!popup.isOpen, "popup is not open");
-
-  popup.once("popup-opened", () => {
-    ok(popup.isOpen, "popup is open");
-
-    // 4 values, and the following properties:
-    // __defineGetter__  __defineSetter__ __lookupGetter__ __lookupSetter__
-    // __proto__ hasOwnProperty isPrototypeOf propertyIsEnumerable
-    // toLocaleString toString toSource unwatch valueOf watch constructor.
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    let sameItems = popup.getItems().reverse().map(function (e) {
-      return e.label;
-    });
+// See Bug 873250.
 
-    ok(sameItems.every(function (prop, index) {
-      return [
-        "__defineGetter__",
-        "__defineSetter__",
-        "__lookupGetter__",
-        "__lookupSetter__",
-        "__proto__",
-        "constructor",
-        "hasOwnProperty",
-        "isPrototypeOf",
-        "item0",
-        "item1",
-        "item2",
-        "item3",
-        "propertyIsEnumerable",
-        "toLocaleString",
-        "toSource",
-        "toString",
-        "unwatch",
-        "valueOf",
-        "watch",
-      ][index] === prop;
-    }), "getItems returns the items we expect");
-
-    is(popup.selectedIndex, 18,
-       "Index of the first item from bottom is selected.");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-        "completeNode.value holds valueOf");
-
-    EventUtils.synthesizeKey("VK_UP", {});
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    let currentSelectionIndex = popup.selectedIndex;
-
-    EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
-
-    ok(popup.selectedIndex > currentSelectionIndex,
-      "Index is greater after PGDN");
-
-    currentSelectionIndex = popup.selectedIndex;
-    EventUtils.synthesizeKey("VK_PAGE_UP", {});
-
-    ok(popup.selectedIndex < currentSelectionIndex,
-       "Index is less after Page UP");
-
-    EventUtils.synthesizeKey("VK_END", {});
-    is(popup.selectedIndex, 18, "index is last after End");
-
-    EventUtils.synthesizeKey("VK_HOME", {});
-    is(popup.selectedIndex, 0, "index is first after Home");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", () => {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
+const TEST_URI = `data:text/html;charset=utf-8,
+<head>
+  <script>
+    window.testBugA = "hello world";
+    window.testBugB = "hello world 2";
+  </script>
+</head>
+<body>bug 873250 - test pressing return with open popup, but no selection</body>`;
 
-  jsterm.setInputValue("window.foobarBug585991");
-  EventUtils.synthesizeKey(".", {});
-
-  return deferred.promise;
-});
-
-function popupHideAfterTab() {
-  let deferred = defer();
-
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-
-  is(jsterm.getInputValue(), "window.foobarBug585991.watch",
-     "completion was successful after VK_TAB");
-
-  ok(!completeNode.value, "completeNode is empty");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
-
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.",
-         "completion was cancelled");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Escape to close the popup");
-    executeSoon(function () {
-      EventUtils.synthesizeKey("VK_ESCAPE", {});
-    });
-  }, false);
-
-  info("wait for completion: window.foobarBug585991.");
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function testReturnKey() {
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-
-    is(popup.itemCount, 19, "popup.itemCount is correct");
+add_task(async function () {
+  let { jsterm } = await openNewTabAndConsole(TEST_URI);
+  // Clearing history that might have been set in previous tests.
+  await jsterm.clearHistory();
 
-    is(popup.selectedIndex, 18, "First index from bottom is selected");
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    let prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
-
-    is(popup.selectedIndex, 0, "index 0 is selected");
-    is(popup.selectedItem.label, "watch", "watch is selected");
-    is(completeNode.value, prefix + "watch",
-        "completeNode.value holds watch");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-
-    is(popup.selectedIndex, 1, "index 1 is selected");
-    is(popup.selectedItem.label, "valueOf", "valueOf is selected");
-    is(completeNode.value, prefix + "valueOf",
-       "completeNode.value holds valueOf");
-
-    popup.once("popup-closed", function onHidden() {
-      ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
-      is(jsterm.getInputValue(), "window.foobarBug585991.valueOf",
-         "completion was successful after VK_RETURN");
-
-      ok(!completeNode.value, "completeNode is empty");
-
-      deferred.resolve();
-    }, false);
-
-    info("press Return to accept suggestion. wait for popup to hide");
-
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  }, false);
-
-  info("wait for completion suggestions: window.foobarBug585991.");
+  const {
+    autocompletePopup: popup,
+    completeNode,
+    inputNode,
+  } = jsterm;
 
-  executeSoon(function () {
-    jsterm.setInputValue("window.foobarBug58599");
-    EventUtils.synthesizeKey("1", {});
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
-
-function* dontShowArrayNumbers() {
-  let deferred = defer();
-
-  info("dontShowArrayNumbers");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"];
-  });
-
-  jsterm = HUD.jsterm;
-  popup = jsterm.autocompletePopup;
-
-  popup.once("popup-opened", function onShown() {
-    let sameItems = popup.getItems().map(function (e) {
-      return e.label;
-    });
-    ok(!sameItems.some(function (prop) {
-      prop === "0";
-    }), "Completing on an array doesn't show numbers.");
-
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    }, false);
-
-    info("wait for popup to hide");
-    executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {}));
-  }, false);
+  const onPopUpOpen = popup.once("popup-opened");
 
   info("wait for popup to show");
-  executeSoon(() => {
-    jsterm.setInputValue("window.foobarBug585991");
-    EventUtils.synthesizeKey(".", {});
-  });
-
-  return deferred.promise;
-}
+  jsterm.setInputValue("window.testBu");
+  EventUtils.synthesizeKey("g", {});
 
-function testReturnWithNoSelection() {
-  let deferred = defer();
-
-  info("test pressing return with open popup, but no selection, see bug 873250");
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-    isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
+  await onPopUpOpen;
 
-    info("press Return and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
-  });
+  ok(popup.isOpen, "popup is open");
+  is(popup.itemCount, 2, "popup.itemCount is correct");
+  isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct");
 
-  executeSoon(() => {
-    info("wait for popup to show");
-    jsterm.setInputValue("window.testBu");
-    EventUtils.synthesizeKey("g", {});
-  });
+  info("press Return and wait for popup to hide");
+  const onPopUpClose = popup.once("popup-closed");
+  executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {}));
+  await onPopUpClose;
 
-  return deferred.promise;
-}
-
-function popupHideAfterReturnWithNoSelection() {
   ok(!popup.isOpen, "popup is not open after VK_RETURN");
-
   is(jsterm.getInputValue(), "", "inputNode is empty after VK_RETURN");
   is(completeNode.value, "", "completeNode is empty");
   is(jsterm.history[jsterm.history.length - 1], "window.testBug",
      "jsterm history is correct");
 
-  return promise.resolve();
-}
-
-function testCompletionInText() {
-  info("test that completion works inside text, see bug 812618");
-
-  let deferred = defer();
-
-  popup.once("popup-opened", function onShown() {
-    ok(popup.isOpen, "popup is open");
-    is(popup.itemCount, 2, "popup.itemCount is correct");
-
-    EventUtils.synthesizeKey("VK_DOWN", {});
-    is(popup.selectedIndex, 0, "popup.selectedIndex is correct");
-    ok(!completeNode.value, "completeNode.value is empty");
-
-    let items = popup.getItems().reverse().map(e => e.label);
-    let sameItems = items.every((prop, index) =>
-      ["testBug873250a", "testBug873250b"][index] === prop);
-    ok(sameItems, "getItems returns the items we expect");
-
-    info("press Tab and wait for popup to hide");
-    popup.once("popup-closed", function popupHidden() {
-      deferred.resolve();
-    });
-    EventUtils.synthesizeKey("VK_TAB", {});
-  });
-
-  jsterm.setInputValue("dump(window.testBu)");
-  inputNode.selectionStart = inputNode.selectionEnd = 18;
-  EventUtils.synthesizeKey("g", {});
-  return deferred.promise;
-}
-
-function popupHideAfterCompletionInText() {
-  // At this point the completion suggestion should be accepted.
-  ok(!popup.isOpen, "popup is not open");
-  is(jsterm.getInputValue(), "dump(window.testBug873250b)",
-     "completion was successful after VK_TAB");
-  is(inputNode.selectionStart, 26, "cursor location is correct");
-  is(inputNode.selectionStart, inputNode.selectionEnd,
-     "cursor location (confirmed)");
-  ok(!completeNode.value, "completeNode is empty");
-
-  return promise.resolve();
-}
+  // Cleaning history.
+  await jsterm.clearHistory();
+});