From f4053c2b3e84fce7090451042193bdc01a18da87 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Jun 2024 12:37:43 +0200 Subject: [PATCH] Close the page in the text layer caret selection integration test This integration test is currently the only one that spawns a separate browser instance. However, while it closes the browser once it's done, it doesn't close the page (and therefore doesn't call the `testingClose` method) like the other integration tests do. This commit fixes this difference by closing the page before closing the browser, thereby ensuring all regular cleanup logic gets called and we avoid (intermittent) shutdown tracebacks in the logs. This allows upcoming integration tests that spawn a separate browser instance to reuse this pattern to cleanly end the test. Given that we integrate the `closeSinglePage` code from #17962 for this patch, @calixteman is credited as the co-author. Co-authored-by: Calixte Denizet --- test/integration/test_utils.mjs | 21 +++++++++++---------- test/integration/text_layer_spec.mjs | 8 +++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index 85c715acdb20f..65c7f29141ae3 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -81,16 +81,16 @@ function awaitPromise(promise) { } function closePages(pages) { - return Promise.all( - pages.map(async ([_, page]) => { - // Avoid to keep something from a previous test. - await page.evaluate(async () => { - await window.PDFViewerApplication.testingClose(); - window.localStorage.clear(); - }); - await page.close({ runBeforeUnload: false }); - }) - ); + return Promise.all(pages.map(([_, page]) => closeSinglePage(page))); +} + +async function closeSinglePage(page) { + // Avoid to keep something from a previous test. + await page.evaluate(async () => { + await window.PDFViewerApplication.testingClose(); + window.localStorage.clear(); + }); + await page.close({ runBeforeUnload: false }); } async function waitForSandboxTrip(page) { @@ -634,6 +634,7 @@ export { awaitPromise, clearInput, closePages, + closeSinglePage, createPromise, dragAndDropAnnotation, firstPageOnTop, diff --git a/test/integration/text_layer_spec.mjs b/test/integration/text_layer_spec.mjs index 1fd8296b808ba..d34b519c6853e 100644 --- a/test/integration/text_layer_spec.mjs +++ b/test/integration/text_layer_spec.mjs @@ -13,7 +13,12 @@ * limitations under the License. */ -import { closePages, getSpanRectFromText, loadAndWait } from "./test_utils.mjs"; +import { + closePages, + closeSinglePage, + getSpanRectFromText, + loadAndWait, +} from "./test_utils.mjs"; import { startBrowser } from "../test.mjs"; describe("Text layer", () => { @@ -227,6 +232,7 @@ describe("Text layer", () => { ); }); afterAll(async () => { + await closeSinglePage(page); await browser.close(); });