Skip to content

Commit

Permalink
Avoid wrong scrolling when calling zoomReset
Browse files Browse the repository at this point in the history
The goal of this patch is to fix the test:
https://searchfox.org/mozilla-central/source/toolkit/components/pdfjs/test/browser_pdfjs_zoom.js

It's a regression due to #17790.
  • Loading branch information
calixteman committed Mar 21, 2024
1 parent ae60221 commit 8c53c25
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/integration/viewer_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,36 @@ describe("PDF viewer", () => {
);
});
});

describe("Zoom commands", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
});

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]) => {
for (let i = 0; i < 10; i++) {
await page.evaluate(() => window.PDFViewerApplication.zoomIn());
await page.evaluate(() => window.PDFViewerApplication.zoomReset());
await page.waitForSelector(
`.page[data-page-number="1"] .textLayer .endOfContent`
);
const scrollTop = await page.evaluate(
() => document.getElementById("viewerContainer").scrollTop
);
expect(scrollTop < 100)
.withContext(`In ${browserName}`)
.toBe(true);
}
})
);
});
});
});
5 changes: 5 additions & 0 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ class PDFPageView {

#addLayer(div, name) {
const pos = LAYERS_ORDER.get(name);
const oldDiv = this.#layers[pos];
this.#layers[pos] = div;
if (oldDiv) {
oldDiv.replaceWith(div);
return;
}
for (let i = pos - 1; i >= 0; i--) {
const layer = this.#layers[i];
if (layer) {
Expand Down

0 comments on commit 8c53c25

Please sign in to comment.