browser/devtools/webconsole/test/browser_bug_638949_copy_link_location.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/" +
michael@0 7 "test/test-console.html?_date=" + Date.now();
michael@0 8 const COMMAND_NAME = "consoleCmd_copyURL";
michael@0 9 const CONTEXT_MENU_ID = "#menu_copyURL";
michael@0 10
michael@0 11 let HUD = null;
michael@0 12 let output = null;
michael@0 13 let menu = null;
michael@0 14
michael@0 15 function test() {
michael@0 16 let originalNetPref = Services.prefs.getBoolPref("devtools.webconsole.filter.networkinfo");
michael@0 17 registerCleanupFunction(() => {
michael@0 18 Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", originalNetPref);
michael@0 19 HUD = output = menu = null;
michael@0 20 });
michael@0 21
michael@0 22 Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true);
michael@0 23
michael@0 24 addTab(TEST_URI);
michael@0 25 browser.addEventListener("load", function onLoad() {
michael@0 26 browser.removeEventListener("load", onLoad, true);
michael@0 27
michael@0 28 openConsole(null, function (aHud) {
michael@0 29 HUD = aHud;
michael@0 30 output = aHud.outputNode;
michael@0 31 menu = HUD.iframeWindow.document.getElementById("output-contextmenu");
michael@0 32
michael@0 33 executeSoon(testWithoutNetActivity);
michael@0 34 });
michael@0 35 }, true);
michael@0 36 }
michael@0 37
michael@0 38 // Return whether "Copy Link Location" command is enabled or not.
michael@0 39 function isEnabled() {
michael@0 40 let controller = top.document.commandDispatcher
michael@0 41 .getControllerForCommand(COMMAND_NAME);
michael@0 42 return controller && controller.isCommandEnabled(COMMAND_NAME);
michael@0 43 }
michael@0 44
michael@0 45 function testWithoutNetActivity() {
michael@0 46 HUD.jsterm.clearOutput();
michael@0 47 content.console.log("bug 638949");
michael@0 48
michael@0 49 // Test that the "Copy Link Location" command is disabled for non-network
michael@0 50 // messages.
michael@0 51 waitForMessages({
michael@0 52 webconsole: HUD,
michael@0 53 messages: [{
michael@0 54 text: "bug 638949",
michael@0 55 category: CATEGORY_WEBDEV,
michael@0 56 severity: SEVERITY_LOG,
michael@0 57 }],
michael@0 58 }).then(onConsoleMessage);
michael@0 59 }
michael@0 60
michael@0 61 function onConsoleMessage(aResults) {
michael@0 62 output.focus();
michael@0 63 let message = [...aResults[0].matched][0];
michael@0 64
michael@0 65 goUpdateCommand(COMMAND_NAME);
michael@0 66 ok(!isEnabled(), COMMAND_NAME + "is disabled");
michael@0 67
michael@0 68 // Test that the "Copy Link Location" menu item is hidden for non-network
michael@0 69 // messages.
michael@0 70 message.scrollIntoView();
michael@0 71 waitForContextMenu(menu, message, () => {
michael@0 72 let isHidden = menu.querySelector(CONTEXT_MENU_ID).hidden;
michael@0 73 ok(isHidden, CONTEXT_MENU_ID + " is hidden");
michael@0 74 }, testWithNetActivity);
michael@0 75 }
michael@0 76
michael@0 77 function testWithNetActivity() {
michael@0 78 HUD.jsterm.clearOutput();
michael@0 79 content.location.reload(); // Reloading will produce network logging
michael@0 80
michael@0 81 // Test that the "Copy Link Location" command is enabled and works
michael@0 82 // as expected for any network-related message.
michael@0 83 // This command should copy only the URL.
michael@0 84 waitForMessages({
michael@0 85 webconsole: HUD,
michael@0 86 messages: [{
michael@0 87 text: "test-console.html",
michael@0 88 category: CATEGORY_NETWORK,
michael@0 89 severity: SEVERITY_LOG,
michael@0 90 }],
michael@0 91 }).then(onNetworkMessage);
michael@0 92 }
michael@0 93
michael@0 94 function onNetworkMessage(aResults) {
michael@0 95 output.focus();
michael@0 96 let message = [...aResults[0].matched][0];
michael@0 97 HUD.ui.output.selectMessage(message);
michael@0 98
michael@0 99 goUpdateCommand(COMMAND_NAME);
michael@0 100 ok(isEnabled(), COMMAND_NAME + " is enabled");
michael@0 101
michael@0 102 info("expected clipboard value: " + message.url);
michael@0 103
michael@0 104 waitForClipboard((aData) => { return aData.trim() == message.url; },
michael@0 105 () => { goDoCommand(COMMAND_NAME) },
michael@0 106 testMenuWithNetActivity, testMenuWithNetActivity);
michael@0 107
michael@0 108 function testMenuWithNetActivity() {
michael@0 109 // Test that the "Copy Link Location" menu item is visible for network-related
michael@0 110 // messages.
michael@0 111 message.scrollIntoView();
michael@0 112 waitForContextMenu(menu, message, () => {
michael@0 113 let isVisible = !menu.querySelector(CONTEXT_MENU_ID).hidden;
michael@0 114 ok(isVisible, CONTEXT_MENU_ID + " is visible");
michael@0 115 }, finishTest);
michael@0 116 }
michael@0 117 }
michael@0 118

mercurial