Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit add5cee

Browse files
committed
Bug 1531826 Part 4 - Add tests for console/inspector links to eval sources.
--HG-- extra : rebase_source : b67e3713f0839c257f5b3d5ba4715ce158e28286
1 parent 1940354 commit add5cee

File tree

5 files changed

+100
-12
lines changed

5 files changed

+100
-12
lines changed

devtools/client/inspector/markup/test/browser.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ subsuite = clipboard
236236
[browser_markup_toggle_04.js]
237237
[browser_markup_toggle_closing_tag_line.js]
238238
[browser_markup_update-on-navigtion.js]
239+
[browser_markup_view-source.js]
239240
[browser_markup_void_elements_html.js]
240241
[browser_markup_void_elements_xhtml.js]
241242
[browser_markup_whitespace.js]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2+
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
3+
/* Any copyright is dedicated to the Public Domain.
4+
* http://creativecommons.org/publicdomain/zero/1.0/ */
5+
6+
"use strict";
7+
8+
const DOCUMENT_SRC = `
9+
<body>
10+
<button id="foo">Button</button>
11+
<script>
12+
var script = \`
13+
function foo() {
14+
console.log('handler');
15+
}
16+
\`;
17+
eval(script);
18+
19+
var button = document.getElementById("foo");
20+
button.addEventListener("click", foo, false);
21+
</script>
22+
</body>`;
23+
24+
const TEST_URI = "data:text/html;charset=utf-8," + DOCUMENT_SRC;
25+
26+
add_task(async function() {
27+
// Test that event handler links go to the right debugger source when it
28+
// came from an eval().
29+
const { inspector, toolbox } = await openInspectorForURL(TEST_URI);
30+
31+
const target = await TargetFactory.forTab(gBrowser.selectedTab);
32+
33+
const nodeFront = await getNodeFront("#foo", inspector);
34+
const container = getContainerForNodeFront(nodeFront, inspector);
35+
36+
const evHolder = container.elt.querySelector(
37+
".inspector-badge.interactive[data-event]");
38+
39+
evHolder.scrollIntoView();
40+
EventUtils.synthesizeMouseAtCenter(evHolder, {},
41+
inspector.markup.doc.defaultView);
42+
43+
const tooltip = inspector.markup.eventDetailsTooltip;
44+
await tooltip.once("shown");
45+
46+
const debuggerIcon = tooltip.panel.querySelector(".event-tooltip-debugger-icon");
47+
EventUtils.synthesizeMouse(debuggerIcon, 2, 2, {}, debuggerIcon.ownerGlobal);
48+
49+
await gDevTools.showToolbox(target, "jsdebugger");
50+
const dbg = toolbox.getPanel("jsdebugger");
51+
52+
let source;
53+
await BrowserTestUtils.waitForCondition(() => {
54+
source = dbg._selectors.getSelectedSource(dbg._getState());
55+
return !!source;
56+
}, "loaded source", 100, 20);
57+
58+
is(
59+
source.url,
60+
null,
61+
"expected no url for eval source"
62+
);
63+
});

devtools/client/webconsole/test/mochitest/browser_webconsole_eval_sources.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
99
"test/mochitest/test-eval-sources.html";
1010

11-
async function clickFirstStackElement(hud, message) {
12-
const button = message.querySelector(".collapse-button");
13-
ok(button, "has button");
14-
15-
button.click();
11+
async function clickFirstStackElement(hud, message, needsExpansion) {
12+
if (needsExpansion) {
13+
const button = message.querySelector(".collapse-button");
14+
ok(button, "has button");
15+
button.click();
16+
}
1617

1718
let frame;
1819
await waitUntil(() => {
@@ -33,8 +34,8 @@ add_task(async function() {
3334
const target = await TargetFactory.forTab(gBrowser.selectedTab);
3435
const toolbox = gDevTools.getToolbox(target);
3536

36-
const messageNode = await waitFor(() => findMessage(hud, "BAR"));
37-
await clickFirstStackElement(hud, messageNode);
37+
let messageNode = await waitFor(() => findMessage(hud, "BAR"));
38+
await clickFirstStackElement(hud, messageNode, true);
3839

3940
const dbg = toolbox.getPanel("jsdebugger");
4041

@@ -46,4 +47,18 @@ add_task(async function() {
4647

4748
await testOpenInDebugger(hud, toolbox, "FOO", false);
4849
await testOpenInDebugger(hud, toolbox, "BAR", false);
50+
51+
// Test that links in the API work when the eval source has a sourceURL property
52+
// which is not considered to be a valid URL.
53+
await testOpenInDebugger(hud, toolbox, "BAZ", false);
54+
55+
// Test that stacks in console.trace() calls work.
56+
messageNode = await waitFor(() => findMessage(hud, "TRACE"));
57+
await clickFirstStackElement(hud, messageNode, false);
58+
59+
is(
60+
/my-foo.js/.test(dbg._selectors.getSelectedSource(dbg._getState()).url),
61+
true,
62+
"expected source url"
63+
);
4964
});

devtools/client/webconsole/test/mochitest/head.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,12 @@ async function checkClickOnNode(hud, toolbox, frameLinkNode, expectUrl) {
377377
return !!dbg._selectors.getSelectedSource(dbg._getState());
378378
});
379379

380-
is(
381-
dbg._selectors.getSelectedSource(dbg._getState()).url,
382-
expectUrl ? url : null,
383-
"expected source url"
384-
);
380+
if (expectUrl) {
381+
is(
382+
dbg._selectors.getSelectedSource(dbg._getState()).url, url,
383+
"expected source url"
384+
);
385+
}
385386
}
386387

387388
/**

devtools/client/webconsole/test/mochitest/test-eval-sources.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
/* eslint-disable */
55
eval("window.foo = function() { console.log('FOO'); }");
66
eval("window.bar = function() { throw new Error('BAR') };");
7+
eval(`window.baz = function() {
8+
console.log('BAZ');
9+
console.trace('TRACE');
10+
}
11+
//# sourceURL=my-foo.js`);
12+
713
foo();
14+
baz();
815
bar();
16+
917
</script>

0 commit comments

Comments
 (0)