Merge pull request #18129 from nicolo-ribaudo/test-css-only-zoom
Add test for drawing delay with CSS-only zoom
This commit is contained in:
commit
2ad4601d04
@ -13,7 +13,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { closePages, loadAndWait } from "./test_utils.mjs";
|
import {
|
||||||
|
awaitPromise,
|
||||||
|
closePages,
|
||||||
|
createPromise,
|
||||||
|
loadAndWait,
|
||||||
|
} from "./test_utils.mjs";
|
||||||
|
|
||||||
describe("PDF viewer", () => {
|
describe("PDF viewer", () => {
|
||||||
describe("Zoom with the mouse wheel", () => {
|
describe("Zoom with the mouse wheel", () => {
|
||||||
@ -87,4 +92,87 @@ describe("PDF viewer", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("CSS-only zoom", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait(
|
||||||
|
"tracemonkey.pdf",
|
||||||
|
".textLayer .endOfContent",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
maxCanvasPixels: 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
function createPromiseForFirstPageRendered(page) {
|
||||||
|
return createPromise(page, (resolve, reject) => {
|
||||||
|
const controller = new AbortController();
|
||||||
|
window.PDFViewerApplication.eventBus.on(
|
||||||
|
"pagerendered",
|
||||||
|
({ pageNumber, timestamp }) => {
|
||||||
|
if (pageNumber === 1) {
|
||||||
|
resolve(timestamp);
|
||||||
|
controller.abort();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ signal: controller.signal }
|
||||||
|
);
|
||||||
|
setTimeout(reject, 1000, new Error("Timeout"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it("respects drawing delay when zooming out", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
const promise = await createPromiseForFirstPageRendered(page);
|
||||||
|
|
||||||
|
const start = await page.evaluate(() => {
|
||||||
|
const startTime = performance.now();
|
||||||
|
window.PDFViewerApplication.pdfViewer.decreaseScale({
|
||||||
|
drawingDelay: 100,
|
||||||
|
scaleFactor: 0.9,
|
||||||
|
});
|
||||||
|
return startTime;
|
||||||
|
});
|
||||||
|
|
||||||
|
const end = await awaitPromise(promise);
|
||||||
|
|
||||||
|
expect(end - start)
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toBeGreaterThanOrEqual(100);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("respects drawing delay when zooming in", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
const promise = await createPromiseForFirstPageRendered(page);
|
||||||
|
|
||||||
|
const start = await page.evaluate(() => {
|
||||||
|
const startTime = performance.now();
|
||||||
|
window.PDFViewerApplication.pdfViewer.increaseScale({
|
||||||
|
drawingDelay: 100,
|
||||||
|
scaleFactor: 1.1,
|
||||||
|
});
|
||||||
|
return startTime;
|
||||||
|
});
|
||||||
|
|
||||||
|
const end = await awaitPromise(promise);
|
||||||
|
|
||||||
|
expect(end - start)
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toBeGreaterThanOrEqual(100);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -359,6 +359,12 @@ const PDFViewerApplication = {
|
|||||||
params.get("highlighteditorcolors")
|
params.get("highlighteditorcolors")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (params.has("maxcanvaspixels")) {
|
||||||
|
AppOptions.set(
|
||||||
|
"maxCanvasPixels",
|
||||||
|
Number(params.get("maxcanvaspixels"))
|
||||||
|
);
|
||||||
|
}
|
||||||
if (params.has("supportscaretbrowsingmode")) {
|
if (params.has("supportscaretbrowsingmode")) {
|
||||||
AppOptions.set(
|
AppOptions.set(
|
||||||
"supportsCaretBrowsingMode",
|
"supportsCaretBrowsingMode",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user