Merge pull request #17051 from calixteman/test_stamp_svg

Fix new intermittent failures with ink and stamp tests
This commit is contained in:
calixteman 2023-10-02 18:10:00 +02:00 committed by GitHub
commit f5367f01ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 9 deletions

View File

@ -20,11 +20,11 @@ const {
waitForStorageEntries, waitForStorageEntries,
} = require("./test_utils.js"); } = require("./test_utils.js");
const waitForClick = async page => const waitForPointerUp = page =>
page.evaluate( page.evaluate(
() => () =>
new Promise(resolve => { new Promise(resolve => {
window.addEventListener("click", resolve, { once: true }); window.addEventListener("pointerup", resolve, { once: true });
}) })
); );
@ -77,7 +77,7 @@ describe("Ink Editor", () => {
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
const x = rect.x + 100 + i * 100; const x = rect.x + 100 + i * 100;
const y = rect.y + 100 + i * 100; const y = rect.y + 100 + i * 100;
const promise = waitForClick(page); const promise = waitForPointerUp(page);
await page.mouse.move(x, y); await page.mouse.move(x, y);
await page.mouse.down(); await page.mouse.down();
await page.mouse.move(x + 50, y + 50); await page.mouse.move(x + 50, y + 50);
@ -115,7 +115,7 @@ describe("Ink Editor", () => {
const xStart = rect.x + 300; const xStart = rect.x + 300;
const yStart = rect.y + 300; const yStart = rect.y + 300;
const clickPromise = waitForClick(page); const clickPromise = waitForPointerUp(page);
await page.mouse.move(xStart, yStart); await page.mouse.move(xStart, yStart);
await page.mouse.down(); await page.mouse.down();
await page.mouse.move(xStart + 50, yStart + 50); await page.mouse.move(xStart + 50, yStart + 50);
@ -185,7 +185,7 @@ describe("Ink Editor", () => {
const x = rect.x + 20; const x = rect.x + 20;
const y = rect.y + 20; const y = rect.y + 20;
const clickPromise = waitForClick(page); const clickPromise = waitForPointerUp(page);
await page.mouse.move(x, y); await page.mouse.move(x, y);
await page.mouse.down(); await page.mouse.down();
await page.mouse.move(x + 50, y + 50); await page.mouse.move(x + 50, y + 50);

View File

@ -43,6 +43,22 @@ const clearAll = async page => {
await waitForStorageEntries(page, 0); await waitForStorageEntries(page, 0);
}; };
const waitForImage = async (page, selector) => {
await page.waitForSelector(`${selector} canvas`);
await page.waitForFunction(
sel => {
const canvas = document.querySelector(sel);
const data = canvas
.getContext("2d")
.getImageData(0, 0, canvas.width, canvas.height);
return data.data.some(x => x !== 0);
},
{},
`${selector} canvas`
);
await page.waitForSelector(`${selector} .altText`);
};
describe("Stamp Editor", () => { describe("Stamp Editor", () => {
describe("Basic operations", () => { describe("Basic operations", () => {
let pages; let pages;
@ -70,7 +86,7 @@ describe("Stamp Editor", () => {
await input.uploadFile( await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}` `${path.join(__dirname, "../images/firefox_logo.png")}`
); );
await page.waitForSelector(`${getEditorSelector(0)} .altText`); await waitForImage(page, getEditorSelector(0));
const { width } = await getEditorDimensions(page, 0); const { width } = await getEditorDimensions(page, 0);
@ -100,7 +116,7 @@ describe("Stamp Editor", () => {
await input.uploadFile( await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.svg")}` `${path.join(__dirname, "../images/firefox_logo.svg")}`
); );
await page.waitForSelector(`${getEditorSelector(1)} .altText`); await waitForImage(page, getEditorSelector(1));
const { width } = await getEditorDimensions(page, 1); const { width } = await getEditorDimensions(page, 1);
@ -153,6 +169,7 @@ describe("Stamp Editor", () => {
await input.uploadFile( await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}` `${path.join(__dirname, "../images/firefox_logo.png")}`
); );
await waitForImage(page, getEditorSelector(i));
await page.waitForSelector(`${getEditorSelector(i)} .altText`); await page.waitForSelector(`${getEditorSelector(i)} .altText`);
for (let j = 0; j < 4; j++) { for (let j = 0; j < 4; j++) {
@ -236,8 +253,10 @@ describe("Stamp Editor", () => {
await page.keyboard.press("v"); await page.keyboard.press("v");
await page.keyboard.up("Control"); await page.keyboard.up("Control");
await waitForImage(page, getEditorSelector(0));
// Wait for the alt-text button to be visible. // Wait for the alt-text button to be visible.
const buttonSelector = "#pdfjs_internal_editor_0 button.altText"; const buttonSelector = `${getEditorSelector(0)} button.altText`;
await page.waitForSelector(buttonSelector); await page.waitForSelector(buttonSelector);
// Click on the alt-text button. // Click on the alt-text button.

View File

@ -207,7 +207,18 @@ function getEditorDimensions(page, id) {
} }
exports.getEditorDimensions = getEditorDimensions; exports.getEditorDimensions = getEditorDimensions;
function serializeBitmapDimensions(page) { async function serializeBitmapDimensions(page) {
await page.waitForFunction(() => {
try {
const map =
window.PDFViewerApplication.pdfDocument.annotationStorage.serializable
.map;
return !!map;
} catch {
return false;
}
});
return page.evaluate(() => { return page.evaluate(() => {
const { map } = const { map } =
window.PDFViewerApplication.pdfDocument.annotationStorage.serializable; window.PDFViewerApplication.pdfDocument.annotationStorage.serializable;