Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 5784733

Browse files
committed
Revert "Revert "Fix previewing a file w/ no functions (#5390)""
This reverts commit cc1a9eb.
1 parent 8681189 commit 5784733

File tree

6 files changed

+70
-43
lines changed

6 files changed

+70
-43
lines changed

src/test/mochitest/browser.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ support-files =
100100
examples/doc-minified.html
101101
examples/big-sourcemap.html
102102
examples/doc-minified2.html
103+
examples/doc-on-load.html
103104
examples/doc-sourcemaps.html
104105
examples/doc-sourcemaps2.html
105106
examples/doc-sourcemaps3.html
@@ -116,6 +117,7 @@ support-files =
116117
examples/long.js
117118
examples/math.min.js
118119
examples/nested/nested-source.js
120+
examples/top-level.js
119121
examples/opts.js
120122
examples/output.js
121123
examples/simple1.js
@@ -173,6 +175,8 @@ skip-if = os == "win"
173175
[browser_dbg-pretty-print-paused.js]
174176
[browser_dbg-preview.js]
175177
skip-if = os == "win"
178+
[browser_dbg-preview-module.js]
179+
skip-if = os == "win"
176180
[browser_dbg-preview-source-maps.js]
177181
skip-if = os == "win"
178182
[browser_dbg-returnvalues.js]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
// Test hovering in a script that is paused on load
5+
// and doesn't have functions.
6+
add_task(async function() {
7+
const dbg = await initDebugger("doc-scripts.html");
8+
const { selectors: { getSelectedSource }, getState } = dbg;
9+
10+
navigate(dbg, "doc-on-load.html");
11+
12+
// wait for `top-level.js` to load and to pause at a debugger statement
13+
await waitForSelectedSource(dbg);
14+
await waitForPaused(dbg);
15+
16+
const popupPreviewed = waitForDispatch(dbg, "SET_PREVIEW");
17+
hoverAtPos(dbg, { line: 1, ch: 6 });
18+
await popupPreviewed;
19+
await assertPreviewPopup(dbg, {
20+
field: "foo",
21+
value: "1",
22+
expression: "obj"
23+
});
24+
await assertPreviewPopup(dbg, {
25+
field: "bar",
26+
value: "2",
27+
expression: "obj"
28+
});
29+
30+
// hover over an empty position so that the popup closes
31+
hoverAtPos(dbg, { line: 1, ch: 40 });
32+
33+
const tooltipPreviewed = waitForDispatch(dbg, "SET_PREVIEW");
34+
hoverAtPos(dbg, { line: 2, ch: 7 });
35+
await tooltipPreviewed;
36+
await assertPreviewTooltip(dbg, { result: "3", expression: "func" });
37+
});

src/test/mochitest/browser_dbg-preview-source-maps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function hoverAtPos(dbg, { line, ch }) {
2121
return previewed;
2222
}
2323

24-
function assertTooltip(dbg, { result, expression }) {
24+
function assertPreviewTooltip(dbg, { result, expression }) {
2525
const previewEl = findElement(dbg, "tooltip");
2626
is(previewEl.innerText, result, "Preview text shown to user");
2727

@@ -31,7 +31,7 @@ function assertTooltip(dbg, { result, expression }) {
3131
is(preview.expression, expression, "Preview.expression");
3232
}
3333

34-
function assertPopup(dbg, { field, value, expression }) {
34+
function assertPreviewPopup(dbg, { field, value, expression }) {
3535
const previewEl = findElement(dbg, "popup");
3636
is(previewEl.innerText, "", "Preview text shown to user");
3737

src/test/mochitest/browser_dbg-preview.js

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
/* Any copyright is dedicated to the Public Domain.
22
* http://creativecommons.org/publicdomain/zero/1.0/ */
33

4-
function getCoordsFromPosition(cm, { line, ch }) {
5-
return cm.charCoords({ line: ~~line, ch: ~~ch });
6-
}
7-
8-
function hoverAtPos(dbg, { line, ch }) {
9-
const cm = getCM(dbg);
10-
const coords = getCoordsFromPosition(cm, { line: line - 1, ch });
11-
const tokenEl = dbg.win.document.elementFromPoint(coords.left, coords.top);
12-
tokenEl.dispatchEvent(
13-
new MouseEvent("mouseover", {
14-
bubbles: true,
15-
cancelable: true,
16-
view: dbg.win
17-
})
18-
);
19-
}
20-
21-
async function assertTooltip(dbg, { result, expression }) {
22-
const previewEl = await waitForElement(dbg, "tooltip");
23-
is(previewEl.innerText, result, "Preview text shown to user");
24-
25-
const preview = dbg.selectors.getPreview(dbg.getState());
26-
is(`${preview.result}`, result, "Preview.result");
27-
is(preview.updating, false, "Preview.updating");
28-
is(preview.expression, expression, "Preview.expression");
29-
}
30-
31-
async function assertPreviewPopup(dbg, { field, value, expression }) {
32-
const previewEl = await waitForElement(dbg, "popup");
33-
const preview = dbg.selectors.getPreview(dbg.getState());
34-
35-
is(
36-
`${preview.result.preview.ownProperties[field].value}`,
37-
value,
38-
"Preview.result"
39-
);
40-
is(preview.updating, false, "Preview.updating");
41-
is(preview.expression, expression, "Preview.expression");
42-
}
43-
4+
// Test hovering on an object, which will show a popup and on a
5+
// simple value, which will show a tooltip.
446
add_task(async function() {
457
const dbg = await initDebugger("doc-scripts.html");
468
const { selectors: { getSelectedSource }, getState } = dbg;
@@ -56,7 +18,7 @@ add_task(async function() {
5618
const tooltipPreviewed = waitForDispatch(dbg, "SET_PREVIEW");
5719
hoverAtPos(dbg, { line: 5, ch: 12 });
5820
await tooltipPreviewed;
59-
await assertTooltip(dbg, { result: "3", expression: "result" });
21+
await assertPreviewTooltip(dbg, { result: "3", expression: "result" });
6022

6123
const popupPreviewed = waitForDispatch(dbg, "SET_PREVIEW");
6224
hoverAtPos(dbg, { line: 2, ch: 10 });
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
2+
- License, v. 2.0. If a copy of the MPL was not distributed with this
3+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
4+
<!DOCTYPE html>
5+
<html>
6+
<head>
7+
<meta charset="utf-8"/>
8+
<title>Debugger test page</title>
9+
</head>
10+
11+
<body>
12+
13+
<script src="top-level.js"></script>
14+
<script>
15+
// This inline script allows this HTML page to show up as a
16+
// source. It also needs to introduce a new global variable so
17+
// it's not immediately garbage collected.
18+
inline_script = function () { var x = 5; };
19+
</script>
20+
</body>
21+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var obj = { foo: 1, bar: 2 };
2+
var func = 3;
3+
debugger;

0 commit comments

Comments
 (0)