mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Use the waitForEvent
helper function in the text layer integration tests
The `waitForClick` helper function is functionality-wise mostly a reduced copy of the more generic `waitForEvent` helper function that we use for other integration tests, so we can safely replace it to reduce the amount of code. Moreover, the `waitForClick` code is prone to intermittent failures given recent assertion failures we have seen on the bots (one of them is linked in #18396) while `waitForEvent` has recently been fixed to avoid intermittent failures, so usiong it should also get rid of the flakiness for these integration tests.
This commit is contained in:
parent
c60c0d1c6d
commit
356d54175b
1 changed files with 23 additions and 47 deletions
|
@ -14,11 +14,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
awaitPromise,
|
|
||||||
closePages,
|
closePages,
|
||||||
closeSinglePage,
|
closeSinglePage,
|
||||||
getSpanRectFromText,
|
getSpanRectFromText,
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
|
waitForEvent,
|
||||||
} from "./test_utils.mjs";
|
} from "./test_utils.mjs";
|
||||||
import { startBrowser } from "../test.mjs";
|
import { startBrowser } from "../test.mjs";
|
||||||
|
|
||||||
|
@ -228,34 +228,6 @@ describe("Text layer", () => {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
function waitForClick(page, selector, timeout) {
|
|
||||||
return page.evaluateHandle(
|
|
||||||
(sel, timeoutDelay) => {
|
|
||||||
const element = document.querySelector(sel);
|
|
||||||
const timeoutSignal = AbortSignal.timeout(timeoutDelay);
|
|
||||||
return [
|
|
||||||
new Promise(resolve => {
|
|
||||||
timeoutSignal.addEventListener(
|
|
||||||
"abort",
|
|
||||||
() => resolve(false),
|
|
||||||
{ once: true }
|
|
||||||
);
|
|
||||||
element.addEventListener(
|
|
||||||
"click",
|
|
||||||
e => {
|
|
||||||
e.preventDefault();
|
|
||||||
resolve(true);
|
|
||||||
},
|
|
||||||
{ once: true, signal: timeoutSignal }
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
selector,
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
it("allows selecting within the link", async () => {
|
it("allows selecting within the link", async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pages.map(async ([browserName, page]) => {
|
pages.map(async ([browserName, page]) => {
|
||||||
|
@ -315,16 +287,18 @@ describe("Text layer", () => {
|
||||||
await moveInSteps(page, positionStart, positionEnd, 20);
|
await moveInSteps(page, positionStart, positionEnd, 20);
|
||||||
await page.mouse.up();
|
await page.mouse.up();
|
||||||
|
|
||||||
const clickPromiseHandle = await waitForClick(
|
await waitForEvent({
|
||||||
page,
|
page,
|
||||||
"#pdfjs_internal_id_8R",
|
eventName: "click",
|
||||||
1000
|
action: () => page.mouse.click(positionEnd.x, positionEnd.y),
|
||||||
);
|
selector: "#pdfjs_internal_id_8R",
|
||||||
|
validator: e => {
|
||||||
await page.mouse.click(positionEnd.x, positionEnd.y);
|
// Don't navigate to the link destination: the `click` event
|
||||||
|
// firing is enough validation that the link can be clicked.
|
||||||
const clicked = await awaitPromise(clickPromiseHandle);
|
e.preventDefault();
|
||||||
expect(clicked).toBeTrue();
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -348,16 +322,18 @@ describe("Text layer", () => {
|
||||||
await page.keyboard.press("ArrowRight");
|
await page.keyboard.press("ArrowRight");
|
||||||
await page.keyboard.up("Shift");
|
await page.keyboard.up("Shift");
|
||||||
|
|
||||||
const clickPromiseHandle = await waitForClick(
|
await waitForEvent({
|
||||||
page,
|
page,
|
||||||
"#pdfjs_internal_id_8R",
|
eventName: "click",
|
||||||
1000
|
action: () => page.mouse.click(positionEnd.x, positionEnd.y),
|
||||||
);
|
selector: "#pdfjs_internal_id_8R",
|
||||||
|
validator: e => {
|
||||||
await page.mouse.click(positionEnd.x, positionEnd.y);
|
// Don't navigate to the link destination: the `click` event
|
||||||
|
// firing is enough validation that the link can be clicked.
|
||||||
const clicked = await awaitPromise(clickPromiseHandle);
|
e.preventDefault();
|
||||||
expect(clicked).toBeTrue();
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue