Bug 1404359 - Migrate browser_webconsole_bug_586388_select_all.js to the new frontend r?jdescottes
MozReview-Commit-ID: 38FpS7RaSky
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -335,17 +335,16 @@ skip-if = true # Bug 1404832
[browser_webconsole_repeated_messages_accuracy.js]
skip-if = true # Bug 1403450
[browser_webconsole_sandbox_update_after_navigation.js]
[browser_webconsole_script_errordoc_urls.js]
skip-if = true # Bug 1403454
# old console skip-if = e10s # Bug 1042253 - webconsole tests disabled with e10s
[browser_webconsole_scroll.js]
[browser_webconsole_select_all.js]
-skip-if = true # Bug 1404359
[browser_webconsole_show_subresource_security_errors.js]
[browser_webconsole_shows_reqs_in_netmonitor.js]
[browser_webconsole_sourcemap_css.js]
[browser_webconsole_sourcemap_error.js]
[browser_webconsole_sourcemap_invalid.js]
[browser_webconsole_sourcemap_nosource.js]
[browser_webconsole_split.js]
[browser_webconsole_split_escape_key.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_select_all.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_select_all.js
@@ -1,86 +1,80 @@
/* -*- 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 586388.
+// Test that the global Firefox "Select All" functionality (e.g. Edit >
+// Select All) works properly in the Web Console.
+
+/* import-globals-from head.js */
const TEST_URI = "http://example.com/";
-add_task(function* () {
- yield loadTab(TEST_URI);
-
- let hud = yield openConsole();
- yield testSelectionWhenMovingBetweenBoxes(hud);
- performTestsAfterOutput(hud);
+add_task(async function testSelectAll() {
+ let hud = await openNewTabAndConsole(TEST_URI);
+ await testSelectionWhenMovingBetweenBoxes(hud);
+ testBrowserMenuSelectAll(hud);
+ await testContextMenuSelectAll(hud);
});
-var testSelectionWhenMovingBetweenBoxes = Task.async(function* (hud) {
+async function testSelectionWhenMovingBetweenBoxes(hud) {
let jsterm = hud.jsterm;
// Fill the console with some output.
jsterm.clearOutput();
- yield jsterm.execute("1 + 2");
- yield jsterm.execute("3 + 4");
- yield jsterm.execute("5 + 6");
+ await jsterm.execute("1 + 2");
+ await waitFor(() => findMessage(hud, "3"));
+ await jsterm.execute("3 + 4");
+ await waitFor(() => findMessage(hud, "7"));
+ await jsterm.execute("5 + 6");
+ await waitFor(() => findMessage(hud, "11"));
+}
- return waitForMessages({
- webconsole: hud,
- messages: [{
- text: "3",
- category: CATEGORY_OUTPUT,
- },
- {
- text: "7",
- category: CATEGORY_OUTPUT,
- },
- {
- text: "11",
- category: CATEGORY_OUTPUT,
- }],
- });
-});
+function testBrowserMenuSelectAll(hud) {
+ let { ui } = hud;
+ let outputContainer = ui.outputNode.querySelector(".webconsole-output");
-function performTestsAfterOutput(hud) {
- let outputNode = hud.outputNode;
+ is(outputContainer.childNodes.length, 6,
+ "the output node contains the expected number of children");
- ok(outputNode.childNodes.length >= 3, "the output node has children after " +
- "executing some JavaScript");
+ // The focus is on the JsTerm, so we need to blur it for the copy comand to
+ // work.
+ outputContainer.ownerDocument.activeElement.blur();
// Test that the global Firefox "Select All" functionality (e.g. Edit >
// Select All) works properly in the Web Console.
- let commandController = hud.ui._commandController;
- ok(commandController != null, "the window has a command controller object");
-
- commandController.selectAll();
-
- let selectedCount = hud.ui.output.getSelectedMessages().length;
- is(selectedCount, outputNode.childNodes.length,
- "all console messages are selected after performing a regular browser " +
- "select-all operation");
-
- hud.iframeWindow.getSelection().removeAllRanges();
+ goDoCommand("cmd_selectAll");
- // Test the context menu "Select All" (which has a different code path) works
- // properly as well.
- let contextMenuId = hud.ui.outputWrapper.getAttribute("context");
- let contextMenu = hud.ui.document.getElementById(contextMenuId);
- ok(contextMenu != null, "the output node has a context menu");
-
- let selectAllItem = contextMenu.querySelector("*[command='cmd_selectAll']");
- ok(selectAllItem != null,
- "the context menu on the output node has a \"Select All\" item");
-
- outputNode.focus();
-
- selectAllItem.doCommand();
-
- selectedCount = hud.ui.output.getSelectedMessages().length;
- is(selectedCount, outputNode.childNodes.length,
- "all console messages are selected after performing a select-all " +
- "operation from the context menu");
-
+ checkMessagesSelected(outputContainer);
hud.iframeWindow.getSelection().removeAllRanges();
}
+
+// Test the context menu "Select All" (which has a different code path) works
+// properly as well.
+async function testContextMenuSelectAll(hud) {
+ let { ui } = hud;
+ let outputContainer = ui.outputNode.querySelector(".webconsole-output");
+ let contextMenu = await openContextMenu(hud, outputContainer);
+
+ let selectAllItem = contextMenu.querySelector("#console-menu-select");
+ ok(selectAllItem,
+ `the context menu on the output node has a "Select All" item`);
+
+ outputContainer.focus();
+ selectAllItem.click();
+
+ checkMessagesSelected(outputContainer);
+ hud.iframeWindow.getSelection().removeAllRanges();
+}
+
+function checkMessagesSelected(outputContainer) {
+ let selection = outputContainer.ownerDocument.getSelection();
+ let messages = outputContainer.querySelectorAll(".message");
+
+ for (let message of messages) {
+ let selected = selection.containsNode(message);
+ ok(selected, `Node containing text "${message.textContent}" was selected`);
+ }
+}