Merge pull request #20054 from calixteman/bug1974863
Don't focus the viewer at startup (bug 1974863)
This commit is contained in:
commit
54c0d56ccf
@ -543,6 +543,14 @@ async function dragAndDrop(page, selector, translations, steps = 1) {
|
||||
await page.waitForSelector("#viewer:not(.noUserSelect)");
|
||||
}
|
||||
|
||||
function waitForPageChanging(page) {
|
||||
return createPromise(page, resolve => {
|
||||
window.PDFViewerApplication.eventBus.on("pagechanging", resolve, {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForAnnotationEditorLayer(page) {
|
||||
return createPromise(page, resolve => {
|
||||
window.PDFViewerApplication.eventBus.on(
|
||||
@ -944,6 +952,7 @@ export {
|
||||
waitForEntryInStorage,
|
||||
waitForEvent,
|
||||
waitForNoElement,
|
||||
waitForPageChanging,
|
||||
waitForPageRendered,
|
||||
waitForPointerUp,
|
||||
waitForSandboxTrip,
|
||||
|
||||
@ -20,6 +20,7 @@ import {
|
||||
getSpanRectFromText,
|
||||
loadAndWait,
|
||||
scrollIntoView,
|
||||
waitForPageChanging,
|
||||
waitForPageRendered,
|
||||
} from "./test_utils.mjs";
|
||||
import { PNG } from "pngjs";
|
||||
@ -1273,4 +1274,48 @@ describe("PDF viewer", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Keyboard scrolling on startup (bug 843653)", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that keyboard scrolling works without having to give the focus to the viewer", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const pdfViewer = await page.evaluateHandle(
|
||||
() => window.PDFViewerApplication.pdfViewer
|
||||
);
|
||||
|
||||
// The viewer should not have the focus.
|
||||
const hasFocus = await pdfViewer.evaluate(viewer =>
|
||||
viewer.container.contains(document.activeElement)
|
||||
);
|
||||
expect(hasFocus).withContext(`In ${browserName}`).toBeFalse();
|
||||
|
||||
let currentPageNumber = await pdfViewer.evaluate(
|
||||
viewer => viewer.currentPageNumber
|
||||
);
|
||||
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(1);
|
||||
|
||||
// Press the 'PageDown' key to check that it works.
|
||||
const handle = await waitForPageChanging(page);
|
||||
await page.keyboard.press("PageDown");
|
||||
await awaitPromise(handle);
|
||||
|
||||
// The second page should be displayed.
|
||||
currentPageNumber = await pdfViewer.evaluate(
|
||||
viewer => viewer.currentPageNumber
|
||||
);
|
||||
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(2);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1455,11 +1455,6 @@ const PDFViewerApplication = {
|
||||
spreadMode,
|
||||
});
|
||||
this.eventBus.dispatch("documentinit", { source: this });
|
||||
// Make all navigation keys work on document load,
|
||||
// unless the viewer is embedded in a web page.
|
||||
if (!this.isViewerEmbedded) {
|
||||
pdfViewer.focus();
|
||||
}
|
||||
|
||||
// For documents with different page sizes, once all pages are
|
||||
// resolved, ensure that the correct location becomes visible on load.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user