mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1753626 - [devtools] Repurpose browser_dbg-reload.js to test breakpoints on reload when source content changes r=ochameau
This repurposes browser_dbg-reload.js which tested breakpoints resync after reload when the source content changes. This renamed test (browser_dbg-breakpoints-reloading-with-source-changes.js) covers the expected behaviour after breakpoint shifting is removed. The sceanarios covered are :- - When new content is added and the breakpoint points to a different source code - When the content changes and the breakpoint is on a non-breakable line - When the content changes and the line for the breakpoint has been removed. Currently we use IS_BREAKPOINT_SHIFTING_ENABLED to make the test pass with all the issues. Also removing old example files that are no longer used. Differential Revision: https://phabricator.services.mozilla.com/D136720
This commit is contained in:
parent
dbc7289949
commit
67566267d9
@ -57,6 +57,7 @@ skip-if = !e10s || verify # This test is only valid in e10s
|
||||
[browser_dbg-continue-to-here.js]
|
||||
[browser_dbg-continue-to-here-click.js]
|
||||
skip-if = os == "win"
|
||||
[browser_dbg-breakpoints-reloading-with-source-changes.js]
|
||||
[browser_dbg-breakpoints-reloading.js]
|
||||
[browser_dbg-breakpoint-skipping.js]
|
||||
[browser_dbg-breakpoint-skipping-console.js]
|
||||
@ -155,7 +156,6 @@ skip-if = os == "win"
|
||||
skip-if = os == "win"
|
||||
[browser_dbg-react-jsx.js]
|
||||
[browser_dbg-returnvalues.js]
|
||||
[browser_dbg-reload.js]
|
||||
[browser_dbg-reloading.js]
|
||||
skip-if = true
|
||||
[browser_dbg-pause-points.js]
|
||||
|
@ -0,0 +1,163 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
|
||||
// This tests breakpoints resyncing when source content changes
|
||||
// after reload.
|
||||
// IMPORTANT NOTE: This test currently test scenarios with breakpoint shifting
|
||||
// feature enabled and disabled. The breakpoint shifting feature is broken and
|
||||
// causes failures for the expected behaviours. This feature is going to be
|
||||
// removed in which case the correct behaviours should begin to pass. To see the
|
||||
// failures with breakpoints shifting make flag IS_BREAKPOINT_SHIFTING_ENABLED = false
|
||||
|
||||
const IS_BREAKPOINT_SHIFTING_ENABLED = true;
|
||||
|
||||
const httpServer = createTestHTTPServer();
|
||||
httpServer.registerContentType("html", "text/html");
|
||||
httpServer.registerContentType("js", "application/javascript");
|
||||
|
||||
httpServer.registerPathHandler("/doc-breakpoint-reload.html", (request, response) => {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.write(`<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/script.js"></script>
|
||||
</head>
|
||||
</html>
|
||||
`);
|
||||
});
|
||||
|
||||
let views = 0;
|
||||
httpServer.registerPathHandler("/script.js", (request, response) => {
|
||||
response.setHeader("Content-Type", "application/javascript");
|
||||
// The script contents to serve on reload of script.js. Each relaod
|
||||
// cycles through the script content.
|
||||
const content = [
|
||||
// CONTENT 1: Source content with 1 function
|
||||
// The breakpoint will be set on line 3 (i.e with the `return` statement)
|
||||
`function bar() {
|
||||
const prefix = "long";
|
||||
return prefix + "bar";
|
||||
}
|
||||
console.log(bar());`,
|
||||
|
||||
// CONTENT 2: Source content with 2 functions, where the breakpoint is now in a
|
||||
// different function though the line does not change.
|
||||
`function foo() {
|
||||
const prefix = "long";
|
||||
return prefix + "foo";
|
||||
}
|
||||
|
||||
function bar() {
|
||||
const prefix = "long";
|
||||
return prefix + "bar";
|
||||
}
|
||||
console.log(bar(), foo());`,
|
||||
|
||||
// CONTENT 3: Source content with comments and 1 function, where the breakpoint is
|
||||
// is now at a line with comments (non-breakable line).
|
||||
`// This is a random comment which is here
|
||||
// to move the function a couple of lines
|
||||
// down, making sure the breakpoint is on
|
||||
// a non-breakable line.
|
||||
function bar() {
|
||||
const prefix = "long";
|
||||
return prefix + "bar";
|
||||
}
|
||||
console.log(bar());`,
|
||||
|
||||
// CONTENT 4: Source content with just a comment where the line which the breakpoint
|
||||
// is supposed to be on no longer exists.
|
||||
`// one line comment`,
|
||||
];
|
||||
|
||||
response.write(content[views % content.length]);
|
||||
views++;
|
||||
});
|
||||
|
||||
const BASE_URL = `http://localhost:${httpServer.identity.primaryPort}/`;
|
||||
|
||||
add_task(async function testBreakpointInFunctionRelocation() {
|
||||
info("Start test for relocation of breakpoint set in a function");
|
||||
const dbg = await initDebuggerWithAbsoluteURL(BASE_URL + "doc-breakpoint-reload.html", "script.js");
|
||||
|
||||
let source = findSource(dbg, "script.js");
|
||||
await selectSource(dbg, source.url);
|
||||
|
||||
info("Add breakpoint in bar()")
|
||||
await addBreakpoint(dbg, source.url, 3);
|
||||
|
||||
info("Assert the text content on line 3 to make sure the breakpoint was set in bar()");
|
||||
assertTextContentOnLine(dbg, 3, 'return prefix + "bar";');
|
||||
|
||||
info("Reload should change the source content to CONTENT 2 i.e 2 functions foo() and bar()");
|
||||
await reload(dbg);
|
||||
await waitForPaused(dbg);
|
||||
|
||||
source = findSource(dbg, "script.js");
|
||||
|
||||
|
||||
info("Assert that the breakpoint pauses on line 3");
|
||||
assertPausedAtSourceAndLine(dbg, source.id, 3);
|
||||
|
||||
if (IS_BREAKPOINT_SHIFTING_ENABLED) {
|
||||
// This is one of the bugs we see, the debugger pauses
|
||||
// on line 3 while the breakpoint has move to line 8
|
||||
info("Assert that the breakpoint is visible on line 8");
|
||||
await assertBreakpoint(dbg, 8);
|
||||
} else {
|
||||
info("Assert that the breakpoint is visible on line 3");
|
||||
await assertBreakpoint(dbg, 3);
|
||||
}
|
||||
|
||||
info("Assert the text content on line 3 to make sure we are paused in foo()");
|
||||
assertTextContentOnLine(dbg, 3, 'return prefix + "foo";');
|
||||
|
||||
info("Check that only one breakpoint currently exists");
|
||||
is(dbg.selectors.getBreakpointCount(), 1, "One breakpoint exists");
|
||||
|
||||
await resume(dbg);
|
||||
|
||||
info("Reload should change the source content to CONTENT 3 i.e comments and 1 function bar()")
|
||||
await reload(dbg);
|
||||
await waitForSelectedSource(dbg, "script.js");
|
||||
|
||||
if (IS_BREAKPOINT_SHIFTING_ENABLED) {
|
||||
// Another bug here is that this should be paused as the
|
||||
// breakpoint shifted to line 7 which is a breakble line
|
||||
await assertNotPaused(dbg);
|
||||
|
||||
info("Assert that the breakpoint is visible on line 7");
|
||||
await assertBreakpoint(dbg, 7);
|
||||
} else {
|
||||
await assertNotPaused(dbg);
|
||||
|
||||
info("Assert that the breakpoint is still visible on line 3 which is a non-breakable line");
|
||||
await assertBreakpoint(dbg, 3);
|
||||
}
|
||||
|
||||
info("Assert the text content on line 3 to make sure the breakpoint is set line 3 of the comment");
|
||||
assertTextContentOnLine(dbg, 3, '// down, making sure the breakpoint is on');
|
||||
|
||||
info("Check that only one breakpoint still exists");
|
||||
is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
|
||||
|
||||
info("Reload should change the source content to CONTENT 4 which is just a one comment line")
|
||||
await reload(dbg);
|
||||
await waitForSelectedSource(dbg, "script.js");
|
||||
|
||||
await assertNotPaused(dbg);
|
||||
|
||||
info("Assert that the source content is one comment line");
|
||||
assertTextContentOnLine(dbg, 1, "// one line comment");
|
||||
|
||||
info("Check that the breakpoint has been removed");
|
||||
is(dbg.selectors.getBreakpointCount(), 0, "No breakpoint exists");
|
||||
});
|
||||
|
||||
function assertTextContentOnLine(dbg, line, expectedTextContent) {
|
||||
const lineInfo = getCM(dbg).lineInfo(line - 1);
|
||||
const textContent = lineInfo.text.trim();
|
||||
is(textContent, expectedTextContent, `Expected text content on line ${line}`);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
/*
|
||||
* Test reloading:
|
||||
* 1. reload the source
|
||||
* 2. re-sync breakpoints
|
||||
*/
|
||||
|
||||
add_task(async function() {
|
||||
const dbg = await initDebugger("reload/doc-reload.html");
|
||||
|
||||
await waitForSource(dbg, "sjs_code_reload");
|
||||
await selectSource(dbg, "sjs_code_reload");
|
||||
await addBreakpoint(dbg, "sjs_code_reload", 2);
|
||||
|
||||
await waitForRequestsToSettle(dbg);
|
||||
await reload(dbg, "sjs_code_reload.sjs");
|
||||
await waitForSelectedSource(dbg, "sjs_code_reload.sjs");
|
||||
|
||||
const source = findSource(dbg, "sjs_code_reload");
|
||||
const location = { sourceId: source.id, line: 6, column: 2 };
|
||||
|
||||
await waitForBreakpoint(dbg, location);
|
||||
|
||||
const breakpointList = dbg.selectors.getBreakpointsList();
|
||||
const breakpoint = breakpointList[0];
|
||||
|
||||
is(breakpointList.length, 1);
|
||||
is(breakpoint.location.line, 6);
|
||||
await waitForRequestsToSettle(dbg);
|
||||
});
|
||||
|
||||
async function waitForBreakpoint(dbg, location) {
|
||||
return waitForState(
|
||||
dbg,
|
||||
state => {
|
||||
return dbg.selectors.getBreakpoint(location);
|
||||
},
|
||||
"Waiting for breakpoint"
|
||||
);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
/*
|
||||
* comments
|
||||
*/
|
||||
|
||||
function foo() {
|
||||
console.log("YO")
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<script src="sjs_code_reload.sjs"></script>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Empty test page 1</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,32 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/* globals getState, setState */
|
||||
/* exported handleRequest */
|
||||
|
||||
"use strict";
|
||||
|
||||
function _getUrl(request, counter) {
|
||||
const { scheme, host, path } = request;
|
||||
|
||||
const newPath = path.substr(0, path.lastIndexOf("/") + 1);
|
||||
const index = counter == 1 ? 1 : 2;
|
||||
const url = `${scheme}://${host}${newPath}/code_reload_${index}.js`;
|
||||
return url
|
||||
}
|
||||
|
||||
function handleRequest(request, response) {
|
||||
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setHeader("Expires", "0");
|
||||
response.setHeader("Access-Control-Allow-Origin", "*", false);
|
||||
response.setHeader("Content-Type", "text/javascript", false);
|
||||
|
||||
// Redirect to a different file each time.
|
||||
let counter = 1 + (+getState("counter") % 4);
|
||||
const newUrl = _getUrl(request, counter);
|
||||
|
||||
response.setStatusLine(request.httpVersion, 302, "Found");
|
||||
response.setHeader("Location", newUrl);
|
||||
setState("counter", "" + counter);
|
||||
}
|
@ -826,10 +826,26 @@ async function reload(dbg, ...sources) {
|
||||
* @static
|
||||
*/
|
||||
async function navigate(dbg, url, ...sources) {
|
||||
await navigateTo(EXAMPLE_URL + url);
|
||||
return navigateToAbsoluteURL(dbg, EXAMPLE_URL + url, ...sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates the debuggee to another absolute url.
|
||||
*
|
||||
* @memberof mochitest/actions
|
||||
* @param {Object} dbg
|
||||
* @param {String} url
|
||||
* @param {Array} sources
|
||||
* @return {Promise}
|
||||
* @static
|
||||
*/
|
||||
async function navigateToAbsoluteURL(dbg, url, ...sources) {
|
||||
await navigateTo(url);
|
||||
return waitForSources(dbg, ...sources);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getFirstBreakpointColumn(dbg, { line, sourceId }) {
|
||||
const { getSource, getFirstBreakpointPosition } = dbg.selectors;
|
||||
const source = getSource(sourceId);
|
||||
|
Loading…
Reference in New Issue
Block a user