Bug 1810979 - [devtools] Fix source tab names for sources with no urls r=nchevobbe

Found a bug where we just showing `SOURCE` in the tab for sources without urls,
instead of the actual source ids. e.g `SOURCE` instead of `SOURCEsource39`
This patch fixes the issue to show
- The source id ie. `(source39)`
- No need for the duplicate `SOURCE`

Differential Revision: https://phabricator.services.mozilla.com/D168245
This commit is contained in:
Hubert Boma Manilla 2023-01-31 17:16:48 +00:00
Родитель 83f86a9fce
Коммит a8c20b3cc0
2 изменённых файлов: 23 добавлений и 21 удалений

Просмотреть файл

@ -189,9 +189,7 @@ function resolveFileURL(
}
export function getFormattedSourceId(id) {
const firstIndex = id.indexOf("/");
const secondIndex = id.indexOf("/", firstIndex);
return `SOURCE${id.slice(firstIndex, secondIndex)}`;
return id.substring(id.lastIndexOf("/") + 1);
}
/**

Просмотреть файл

@ -2,8 +2,8 @@
* 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 that URL-less sources have tabs added to the UI but
// do not persist upon reload
// Test that URL-less sources have tabs added to the UI, are named correctly
// and do not persist upon reload
"use strict";
@ -15,28 +15,32 @@ add_task(async function() {
);
await selectSource(dbg, "simple1.js");
await selectSource(dbg, "simple2.js");
is(countTabs(dbg), 2);
is(countTabs(dbg), 1, "Only the `simple.js` source tab exists");
invokeInTab("doEval");
await waitForPaused(dbg);
await resume(dbg);
is(countTabs(dbg), 3);
invokeInTab("doEval");
await waitForPaused(dbg);
is(countTabs(dbg), 2, "The new eval tab is now added");
info("Assert that the eval source the tab source name correctly");
ok(
/source\d+/g.test(getTabContent(dbg, 0)),
"The tab name pattern is correct"
);
await resume(dbg);
is(countTabs(dbg), 4);
// Test reloading the debugger
await reload(dbg, "simple1.js", "simple2.js");
is(countTabs(dbg), 2);
// TODO: This is here to make this test less flakey because otherwise the
// test will end while the files are still loading, which will stop all
// in-progress requests causing uncaught rejections when querying
// 'getBreakpointPositionsCompressed'.
await selectSource(dbg, "simple1.js");
await selectSource(dbg, "simple2.js");
is(countTabs(dbg), 1, "The eval source tab is no longer available");
});
/*
* Get the tab content for the specific tab
*
* @param {Number} index - index of the tab to get the source content
*/
function getTabContent(dbg, index) {
const tabs = findElement(dbg, "sourceTabs").children;
return tabs[index]?.innerText || "";
}