From 65d618635c72172ad9933b4a6da54756f42913e1 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 14 Mar 2024 18:08:46 +0100 Subject: [PATCH] When zooming the scrollbar can disappear and then no scrollend is triggered --- test/integration-boot.mjs | 1 + test/integration/viewer_spec.mjs | 58 ++++++++++++++++++++++++++++++++ web/app.js | 5 +-- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 test/integration/viewer_spec.mjs diff --git a/test/integration-boot.mjs b/test/integration-boot.mjs index d851e1731..11d73addb 100644 --- a/test/integration-boot.mjs +++ b/test/integration-boot.mjs @@ -35,6 +35,7 @@ async function runTests(results) { "scripting_spec.mjs", "stamp_editor_spec.mjs", "text_field_spec.mjs", + "viewer_spec.mjs", ], }); diff --git a/test/integration/viewer_spec.mjs b/test/integration/viewer_spec.mjs new file mode 100644 index 000000000..962d74f10 --- /dev/null +++ b/test/integration/viewer_spec.mjs @@ -0,0 +1,58 @@ +/* Copyright 2024 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { closePages, loadAndWait } from "./test_utils.mjs"; + +describe("PDF viewer", () => { + describe("Zoom with the mouse wheel", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("empty.pdf", ".textLayer .endOfContent", 1000); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that we can zoom with the mouse wheel and pressed control key", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + if (browserName === "firefox") { + // Skip this test for Firefox, as it's not working correctly. + // See https://github.com/puppeteer/puppeteer/issues/12093. + // TODO: Remove this check once the issue is resolved. + return; + } + await page.keyboard.down("Control"); + let zoom = 10; + const zoomGetter = () => + page.evaluate( + () => window.PDFViewerApplication.pdfViewer.currentScale + ); + while (zoom > 0.1) { + await page.mouse.wheel({ deltaY: 100 }); + zoom = await zoomGetter(); + } + while (zoom < 10) { + await page.mouse.wheel({ deltaY: -100 }); + zoom = await zoomGetter(); + } + await page.keyboard.up("Control"); + }) + ); + }); + }); +}); diff --git a/web/app.js b/web/app.js index 77c4b3e1c..2e87b64ce 100644 --- a/web/app.js +++ b/web/app.js @@ -2024,8 +2024,9 @@ const PDFViewerApplication = { }); const scroll = (_boundEvents.mainContainerScroll = () => { if ( - this._lastScrollTop === mainContainer.scrollTop && - this._lastScrollLeft === mainContainer.scrollLeft + this._isCtrlKeyDown || + (this._lastScrollTop === mainContainer.scrollTop && + this._lastScrollLeft === mainContainer.scrollLeft) ) { return; }