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