// Click pause, load second request and make sure they don't show up.
EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
await waitForPauseButtonToChange(document, true);
ok(noRequest, "There should be no activity when paused.");
assertRequestCount(store, 1);
// Click pause again to resume monitoring. Load a third request // and make sure they will show up.
EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
await waitForPauseButtonToChange(document, false);
ok(!noRequest, "There should be activity when resumed.");
assertRequestCount(store, 2);
// Click pause, reload the page and check that there are // some requests.
EventUtils.sendMouseEvent({ type: "click" }, pauseButton);
await waitForPauseButtonToChange(document, true);
ok(!noRequest, "There should be activity when resumed.");
return teardown(monitor);
});
/** * Wait until a request is visible in the request list
*/ function waitForRequest(doc, url) { return waitUntil(() =>
[...doc.querySelectorAll(".request-list-item .requests-list-file")].some(
columns => columns.title.includes(url)
)
);
}
/** * Waits for the state of the paused/resume button to change.
*/
async function waitForPauseButtonToChange(doc, isPaused) {
await waitUntil(
() =>
!!doc.querySelector(
`.requests-list-pause-button[aria-pressed="${
isPaused ? "true" : "false"
}"]`
)
);
ok( true,
`The pause button is correctly in the ${
isPaused ? "paused" : "resumed"
} state`
);
}
/** * Asserts the number of requests in the network monitor.
*/ function assertRequestCount(store, count) {
is(
store.getState().requests.requests.length,
count, "There should be correct number of requests"
);
}
/** * Execute simple GET request and wait till it's done.
*/
async function performRequestAndWait(tab, monitor, requestURL) { const wait = waitForRequest(monitor.panelWin.document, requestURL);
await SpecialPowers.spawn(
tab.linkedBrowser,
[requestURL],
async function (url) {
await content.wrappedJSObject.performRequests(url);
}
);
await wait;
}
/** * Execute simple GET request, and uses a one time listener to * know when the resource is available.
*/
async function performPausedRequest(tab, monitor, toolbox) { const { onResource: waitForEventWhenPaused } =
await toolbox.resourceCommand.waitForNextResource(
toolbox.resourceCommand.TYPES.NETWORK_EVENT,
{
ignoreExistingResources: true,
}
);
await SpecialPowers.spawn(
tab.linkedBrowser,
[SIMPLE_URL],
async function (url) {
await content.wrappedJSObject.performRequests(url);
}
); // Wait for NETWORK_EVENT resources to be fetched, in order to ensure // that there is no pending request related to their processing.
await waitForEventWhenPaused;
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.