|
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/. */ |
|
5 |
|
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"; |
|
10 |
|
11 let HUD = null; |
|
12 let output = null; |
|
13 let menu = null; |
|
14 |
|
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 }); |
|
21 |
|
22 Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true); |
|
23 |
|
24 addTab(TEST_URI); |
|
25 browser.addEventListener("load", function onLoad() { |
|
26 browser.removeEventListener("load", onLoad, true); |
|
27 |
|
28 openConsole(null, function (aHud) { |
|
29 HUD = aHud; |
|
30 output = aHud.outputNode; |
|
31 menu = HUD.iframeWindow.document.getElementById("output-contextmenu"); |
|
32 |
|
33 executeSoon(testWithoutNetActivity); |
|
34 }); |
|
35 }, true); |
|
36 } |
|
37 |
|
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 } |
|
44 |
|
45 function testWithoutNetActivity() { |
|
46 HUD.jsterm.clearOutput(); |
|
47 content.console.log("bug 638949"); |
|
48 |
|
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 } |
|
60 |
|
61 function onConsoleMessage(aResults) { |
|
62 output.focus(); |
|
63 let message = [...aResults[0].matched][0]; |
|
64 |
|
65 goUpdateCommand(COMMAND_NAME); |
|
66 ok(!isEnabled(), COMMAND_NAME + "is disabled"); |
|
67 |
|
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 } |
|
76 |
|
77 function testWithNetActivity() { |
|
78 HUD.jsterm.clearOutput(); |
|
79 content.location.reload(); // Reloading will produce network logging |
|
80 |
|
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 } |
|
93 |
|
94 function onNetworkMessage(aResults) { |
|
95 output.focus(); |
|
96 let message = [...aResults[0].matched][0]; |
|
97 HUD.ui.output.selectMessage(message); |
|
98 |
|
99 goUpdateCommand(COMMAND_NAME); |
|
100 ok(isEnabled(), COMMAND_NAME + " is enabled"); |
|
101 |
|
102 info("expected clipboard value: " + message.url); |
|
103 |
|
104 waitForClipboard((aData) => { return aData.trim() == message.url; }, |
|
105 () => { goDoCommand(COMMAND_NAME) }, |
|
106 testMenuWithNetActivity, testMenuWithNetActivity); |
|
107 |
|
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 } |
|
118 |