Bug 1639716 - [devtools performance] Change a few test helpers so that the window can be specified r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D134338
This commit is contained in:
Julien Wajsberg 2022-01-26 17:26:23 +00:00
Родитель 220542aa8c
Коммит 66e3718376
3 изменённых файлов: 21 добавлений и 11 удалений

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

@ -29,6 +29,7 @@ add_task(async function test() {
// First check for the "Media" preset which will have no "view" query
// string because it opens our traditional "full" view.
await openPopupAndAssertUrlForPreset({
window,
preset: "Media",
expectedUrl: FRONTEND_BASE_URL,
});
@ -36,14 +37,16 @@ add_task(async function test() {
// Now, let's check for "web-developer" preset. This will open up the frontend
// with "active-tab" view query string. Frontend will understand and open the active tab view for it.
await openPopupAndAssertUrlForPreset({
window,
preset: "Web Developer",
expectedUrl: FRONTEND_BASE_URL + "?view=active-tab&implementation=js",
});
});
async function openPopupAndAssertUrlForPreset({ preset, expectedUrl }) {
async function openPopupAndAssertUrlForPreset({ window, preset, expectedUrl }) {
// Let's capture a profile and assert newly created tab's url.
await openPopupAndEnsureCloses(window, async () => {
const { document } = window;
{
// Select the preset in the popup
const presetsInPopup = document.getElementById(

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

@ -77,7 +77,7 @@ add_task(async function click_dropmarker() {
ok(!dropmarker.hasAttribute("open"), "should start with the panel closed");
ok(!isActive(), "should start with the profiler inactive");
const popupShownPromise = waitForProfilerPopupEvent("popupshown");
const popupShownPromise = waitForProfilerPopupEvent(window, "popupshown");
dropmarker.click();
await popupShownPromise;
@ -87,7 +87,7 @@ add_task(async function click_dropmarker() {
await getElementByLabel(document, "Start Recording");
info("Press Escape to close the panel.");
const popupHiddenPromise = waitForProfilerPopupEvent("popuphidden");
const popupHiddenPromise = waitForProfilerPopupEvent(window, "popuphidden");
EventUtils.synthesizeKey("KEY_Escape");
await popupHiddenPromise;
ok(!dropmarker.hasAttribute("open"), "panel should be closed");

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

@ -197,10 +197,11 @@ async function makeSureProfilerPopupIsEnabled() {
* any type of popup in the browser. This function waits for one of those events, and
* checks that the viewId of the popup is PanelUI-profiler
*
* @param {Window} window
* @param {"popupshown" | "popuphidden"} eventName
* @returns {Promise<void>}
*/
function waitForProfilerPopupEvent(eventName) {
function waitForProfilerPopupEvent(window, eventName) {
return new Promise(resolve => {
function handleEvent(event) {
if (event.target.getAttribute("viewId") === "PanelUI-profiler") {
@ -218,13 +219,14 @@ function waitForProfilerPopupEvent(eventName) {
*
* This function toggles the profiler menu button, and then uses user gestures
* to click it open. It waits a tick to make sure it has a chance to initialize.
* @param {Window} window
* @return {Promise<void>}
*/
async function _toggleOpenProfilerPopup(window) {
info("Toggle open the profiler popup.");
info("> Find the profiler menu button.");
const profilerDropmarker = document.getElementById(
const profilerDropmarker = window.document.getElementById(
"profiler-button-dropmarker"
);
if (!profilerDropmarker) {
@ -233,10 +235,10 @@ async function _toggleOpenProfilerPopup(window) {
);
}
const popupShown = waitForProfilerPopupEvent("popupshown");
const popupShown = waitForProfilerPopupEvent(window, "popupshown");
info("> Trigger a click on the profiler button dropmarker.");
await EventUtils.synthesizeMouseAtCenter(profilerDropmarker, {});
await EventUtils.synthesizeMouseAtCenter(profilerDropmarker, {}, window);
if (profilerDropmarker.getAttribute("open") !== "true") {
throw new Error(
@ -255,10 +257,11 @@ async function _toggleOpenProfilerPopup(window) {
* Do not use this directly in a test. Prefer withPopupOpen.
*
* This function uses a keyboard shortcut to close the profiler popup.
* @param {Window} window
* @return {Promise<void>}
*/
async function _closePopup(window) {
const popupHiddenPromise = waitForProfilerPopupEvent("popuphidden");
const popupHiddenPromise = waitForProfilerPopupEvent(window, "popuphidden");
info("> Trigger an escape key to hide the popup");
EventUtils.synthesizeKey("KEY_Escape");
@ -292,7 +295,7 @@ async function withPopupOpen(window, callback) {
async function openPopupAndEnsureCloses(window, callback) {
await _toggleOpenProfilerPopup(window);
// We want to ensure the popup gets closed by the test, during the callback.
const popupHiddenPromise = waitForProfilerPopupEvent("popuphidden");
const popupHiddenPromise = waitForProfilerPopupEvent(window, "popuphidden");
await callback();
info("> Verifying that the popup was closed by the test.");
await popupHiddenPromise;
@ -465,14 +468,18 @@ function withAboutProfiling(callback) {
* devtools panel's document, the
* second parameter is the opened tab's
* document.
* @param {Window} [aWindow] The browser's window object we target
* @returns {Promise<void>}
*/
async function withDevToolsPanel(url, callback) {
if (typeof url !== "string" && !callback) {
async function withDevToolsPanel(url, callback, aWindow = window) {
if (typeof url === "function") {
aWindow = callback ?? window;
callback = url;
url = "about:blank";
}
const { gBrowser } = aWindow;
SpecialPowers.pushPrefEnv({
set: [["devtools.performance.new-panel-enabled", "true"]],
});