Add a new helper, in the viewer, to close everything during testing

This has two advantages, as far as I'm concerned:
 - The tests don't need to manually invoke multiple functions to properly clean-up, which reduces the risk of missing something.
 - By collecting all the relevant clean-up in one method, rather than spreading it out, we get a much better overview of exactly what is being reset.
This commit is contained in:
Jonas Jenwald 2024-06-19 07:45:34 +02:00
parent c53f71a7d2
commit c771ac81cd
2 changed files with 16 additions and 12 deletions

View file

@ -80,10 +80,7 @@ function closePages(pages) {
pages.map(async ([_, page]) => { pages.map(async ([_, page]) => {
// Avoid to keep something from a previous test. // Avoid to keep something from a previous test.
await page.evaluate(async () => { await page.evaluate(async () => {
const viewer = window.PDFViewerApplication; await window.PDFViewerApplication.testingClose();
viewer.unbindWindowEvents();
viewer.unbindEvents();
await viewer.close();
window.localStorage.clear(); window.localStorage.clear();
}); });
await page.close({ runBeforeUnload: false }); await page.close({ runBeforeUnload: false });

View file

@ -2105,14 +2105,21 @@ const PDFViewerApplication = {
unbindWindowEvents() { unbindWindowEvents() {
this._windowAbortController?.abort(); this._windowAbortController?.abort();
this._windowAbortController = null; this._windowAbortController = null;
if ( },
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) ||
AppOptions.get("isInAutomation") /**
) { * @ignore
this._globalAbortController?.abort(); */
this._globalAbortController = null; async testingClose() {
this.l10n?.pause(); this.l10n?.pause();
}
this.unbindEvents();
this.unbindWindowEvents();
this._globalAbortController?.abort();
this._globalAbortController = null;
await this.close();
}, },
_accumulateTicks(ticks, prop) { _accumulateTicks(ticks, prop) {