michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/" + michael@0: "test/test-console.html?_date=" + Date.now(); michael@0: const COMMAND_NAME = "consoleCmd_copyURL"; michael@0: const CONTEXT_MENU_ID = "#menu_copyURL"; michael@0: michael@0: let HUD = null; michael@0: let output = null; michael@0: let menu = null; michael@0: michael@0: function test() { michael@0: let originalNetPref = Services.prefs.getBoolPref("devtools.webconsole.filter.networkinfo"); michael@0: registerCleanupFunction(() => { michael@0: Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", originalNetPref); michael@0: HUD = output = menu = null; michael@0: }); michael@0: michael@0: Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true); michael@0: michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: michael@0: openConsole(null, function (aHud) { michael@0: HUD = aHud; michael@0: output = aHud.outputNode; michael@0: menu = HUD.iframeWindow.document.getElementById("output-contextmenu"); michael@0: michael@0: executeSoon(testWithoutNetActivity); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: // Return whether "Copy Link Location" command is enabled or not. michael@0: function isEnabled() { michael@0: let controller = top.document.commandDispatcher michael@0: .getControllerForCommand(COMMAND_NAME); michael@0: return controller && controller.isCommandEnabled(COMMAND_NAME); michael@0: } michael@0: michael@0: function testWithoutNetActivity() { michael@0: HUD.jsterm.clearOutput(); michael@0: content.console.log("bug 638949"); michael@0: michael@0: // Test that the "Copy Link Location" command is disabled for non-network michael@0: // messages. michael@0: waitForMessages({ michael@0: webconsole: HUD, michael@0: messages: [{ michael@0: text: "bug 638949", michael@0: category: CATEGORY_WEBDEV, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(onConsoleMessage); michael@0: } michael@0: michael@0: function onConsoleMessage(aResults) { michael@0: output.focus(); michael@0: let message = [...aResults[0].matched][0]; michael@0: michael@0: goUpdateCommand(COMMAND_NAME); michael@0: ok(!isEnabled(), COMMAND_NAME + "is disabled"); michael@0: michael@0: // Test that the "Copy Link Location" menu item is hidden for non-network michael@0: // messages. michael@0: message.scrollIntoView(); michael@0: waitForContextMenu(menu, message, () => { michael@0: let isHidden = menu.querySelector(CONTEXT_MENU_ID).hidden; michael@0: ok(isHidden, CONTEXT_MENU_ID + " is hidden"); michael@0: }, testWithNetActivity); michael@0: } michael@0: michael@0: function testWithNetActivity() { michael@0: HUD.jsterm.clearOutput(); michael@0: content.location.reload(); // Reloading will produce network logging michael@0: michael@0: // Test that the "Copy Link Location" command is enabled and works michael@0: // as expected for any network-related message. michael@0: // This command should copy only the URL. michael@0: waitForMessages({ michael@0: webconsole: HUD, michael@0: messages: [{ michael@0: text: "test-console.html", michael@0: category: CATEGORY_NETWORK, michael@0: severity: SEVERITY_LOG, michael@0: }], michael@0: }).then(onNetworkMessage); michael@0: } michael@0: michael@0: function onNetworkMessage(aResults) { michael@0: output.focus(); michael@0: let message = [...aResults[0].matched][0]; michael@0: HUD.ui.output.selectMessage(message); michael@0: michael@0: goUpdateCommand(COMMAND_NAME); michael@0: ok(isEnabled(), COMMAND_NAME + " is enabled"); michael@0: michael@0: info("expected clipboard value: " + message.url); michael@0: michael@0: waitForClipboard((aData) => { return aData.trim() == message.url; }, michael@0: () => { goDoCommand(COMMAND_NAME) }, michael@0: testMenuWithNetActivity, testMenuWithNetActivity); michael@0: michael@0: function testMenuWithNetActivity() { michael@0: // Test that the "Copy Link Location" menu item is visible for network-related michael@0: // messages. michael@0: message.scrollIntoView(); michael@0: waitForContextMenu(menu, message, () => { michael@0: let isVisible = !menu.querySelector(CONTEXT_MENU_ID).hidden; michael@0: ok(isVisible, CONTEXT_MENU_ID + " is visible"); michael@0: }, finishTest); michael@0: } michael@0: } michael@0: