Show PDF pages in one column that scrolls
The PDF tab shows all pages in one column. The wheel, Page Up, and Page Down scroll. They do not change the page, and they draw nothing again at the start or the end of the document. - The zoom percent is a field. A typed percent sets the zoom. Ctrl and the wheel also change the zoom. - The toolbar, the status line, and the password form are opaque, so a background image does not hide them. - Ctrl+Tab and Ctrl+Shift+Tab give keyboard focus to the new plugin tab. Cards: 9b7b246e, 59ff5dc1, 2e425cbc, 7bd092d2, 2142ca04, c0900ae8.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// The native PDF Viewer: the file tree marks PDF files without the module, the first PDF tab loads it, and each tab
|
||||
// renders a page with selectable text, page controls, zoom, rotation, Page Up and Page Down, and Reload.
|
||||
// renders its pages in one column with selectable text, page controls, zoom, a typed zoom, rotation, scrolling by wheel and
|
||||
// keyboard, and Reload. It also checks the opaque toolbar and the focus after Ctrl+Tab.
|
||||
// It also checks two tabs, one worker for each open tab, a protected PDF, a damaged file, Off and On, no network request,
|
||||
// no text read of a PDF, the owner ID of a tab transfer, a saved tab after a reload, both themes, and a narrow toolbar.
|
||||
// It replaces tests/browser.mjs of the PDF Viewer plugin.
|
||||
@@ -78,8 +79,13 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
await rendered("Page 1 of 2");
|
||||
assert.equal(await loaded(), true, "The first PDF tab loads the module");
|
||||
await active.getByRole("img", { name: "PDF page 1", exact: true }).waitFor();
|
||||
assert.match(await active.locator(".textLayer").innerText(), /Page one text selection/);
|
||||
assert.ok(await active.locator("canvas").evaluate(canvas => {
|
||||
const sheet = number => active.locator(`.sheet[data-page="${number}"]`);
|
||||
const scroll = active.locator(".scroll");
|
||||
const scrollTop = () => scroll.evaluate(node => node.scrollTop);
|
||||
await sheet(1).locator(".textLayer span").first().waitFor();
|
||||
assert.match(await sheet(1).locator(".textLayer").innerText(), /Page one text selection/);
|
||||
assert.equal(await active.locator(".sheet").count(), 2, "Each page has a sheet in the column");
|
||||
assert.ok(await sheet(1).locator("canvas").evaluate(canvas => {
|
||||
const data = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height).data;
|
||||
let colored = 0;
|
||||
for (let index = 0; index < data.length; index += 4) if (data[index] < 200 && data[index + 2] > 100) colored++;
|
||||
@@ -89,6 +95,10 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
assert.equal(await button("Fit width").getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await button("Previous page").isDisabled(), true);
|
||||
assert.equal(await workers(), 1);
|
||||
// The toolbar and the status line are opaque, so a background image does not show through them.
|
||||
for (const selector of [".toolbar", ".status"]) {
|
||||
assert.match(await active.locator(selector).evaluate(node => getComputedStyle(node).backgroundColor), /^rgb\(/, `${selector} has an opaque fill`);
|
||||
}
|
||||
|
||||
// Both themes. The page stays white paper.
|
||||
for (const theme of ["dark", "light"]) {
|
||||
@@ -119,7 +129,8 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
await rendered("Page 2 of 2");
|
||||
await active.getByRole("img", { name: "PDF page 2", exact: true }).waitFor();
|
||||
assert.equal(await button("Next page").isDisabled(), true);
|
||||
const zoomText = () => active.locator(".zoom").innerText();
|
||||
const zoomField = active.getByRole("textbox", { name: "Zoom percent", exact: true });
|
||||
const zoomText = () => zoomField.inputValue();
|
||||
const before = await zoomText();
|
||||
await button("Zoom in").click();
|
||||
await rendered("Page 2 of 2");
|
||||
@@ -127,13 +138,70 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
assert.equal(await button("Fit width").getAttribute("aria-pressed"), "false");
|
||||
await button("Rotate clockwise").click();
|
||||
await rendered("Page 2 of 2");
|
||||
assert.ok(await active.locator("canvas").evaluate(canvas => canvas.width > canvas.height), "A rotated page is wider than high");
|
||||
await active.locator(".scroll").focus();
|
||||
assert.ok(await sheet(2).locator("canvas").evaluate(canvas => canvas.width > canvas.height), "A rotated page is wider than high");
|
||||
for (let turn = 0; turn < 3; turn++) await button("Rotate clockwise").click();
|
||||
// A typed zoom.
|
||||
await zoomField.fill("137");
|
||||
await zoomField.press("Enter");
|
||||
assert.equal(await zoomText(), "137%");
|
||||
await zoomField.fill("text");
|
||||
await zoomField.press("Enter");
|
||||
assert.equal(await zoomText(), "137%", "Text that is not a number keeps the zoom");
|
||||
await zoomField.fill("9000");
|
||||
await zoomField.press("Enter");
|
||||
assert.equal(await zoomText(), "400%", "A typed zoom stays in the limits");
|
||||
const unfitted = button("Fit width").and(page.locator('[aria-pressed="false"]'));
|
||||
await unfitted.waitFor();
|
||||
const fitted = button("Fit width").and(page.locator('[aria-pressed="true"]'));
|
||||
const input = active.getByRole("spinbutton", { name: "Page number", exact: true });
|
||||
await input.fill("1");
|
||||
await input.press("Enter");
|
||||
await rendered("Page 1 of 2");
|
||||
// Page Down and Page Up scroll. At 400%, a page is higher than the tab. They do not jump to the next page, and they do not draw a page again at the ends.
|
||||
assert.equal(await scrollTop(), 0);
|
||||
await scroll.focus();
|
||||
const keepCanvas = number => sheet(number).locator("canvas").evaluate(canvas => { window.__PDF_CANVAS__ = canvas; });
|
||||
const sameCanvas = number => sheet(number).locator("canvas").evaluate(canvas => window.__PDF_CANVAS__ === canvas);
|
||||
await keepCanvas(1);
|
||||
await page.keyboard.press("PageUp");
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await scrollTop(), 0);
|
||||
assert.equal(await sameCanvas(1), true, "Page Up at the start does not draw the page again");
|
||||
await rendered("Page 1 of 2");
|
||||
await page.keyboard.press("PageDown");
|
||||
await page.waitForFunction(() => document.activeElement.scrollTop > 0);
|
||||
await page.waitForTimeout(400);
|
||||
assert.ok(await scrollTop() < await sheet(2).evaluate(node => node.offsetTop - node.previousElementSibling.offsetTop), "Page Down scrolls less than one page");
|
||||
await rendered("Page 1 of 2");
|
||||
assert.equal(await input.inputValue(), "1");
|
||||
await page.keyboard.press("End");
|
||||
await rendered("Page 2 of 2");
|
||||
assert.equal(await input.inputValue(), "2", "The page field follows the scroll position");
|
||||
await page.waitForTimeout(400);
|
||||
const end = await scrollTop();
|
||||
await keepCanvas(2);
|
||||
await page.keyboard.press("PageDown");
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await scrollTop(), end);
|
||||
assert.equal(await sameCanvas(2), true, "Page Down at the end does not draw the page again");
|
||||
await rendered("Page 2 of 2");
|
||||
// The wheel shows the other pages.
|
||||
await page.keyboard.press("Home");
|
||||
await rendered("Page 1 of 2");
|
||||
await scroll.hover();
|
||||
await page.mouse.wheel(0, 5000);
|
||||
await rendered("Page 2 of 2");
|
||||
await active.getByRole("img", { name: "PDF page 2", exact: true }).waitFor();
|
||||
// Ctrl and the wheel change the zoom.
|
||||
await button("Fit width").click();
|
||||
await fitted.waitFor();
|
||||
await scroll.hover();
|
||||
await page.keyboard.down("Control");
|
||||
await page.mouse.wheel(0, -100);
|
||||
await page.keyboard.up("Control");
|
||||
await unfitted.waitFor();
|
||||
await button("Fit width").click();
|
||||
await rendered("Page 2 of 2");
|
||||
const input = active.getByRole("spinbutton", { name: "Page number", exact: true });
|
||||
await input.fill("1");
|
||||
await input.press("Enter");
|
||||
await rendered("Page 1 of 2");
|
||||
@@ -148,6 +216,24 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
assert.equal(await workers(), 2);
|
||||
await row("Other.PDF").click();
|
||||
assert.equal(await tab("Other").count(), 1, "A second open selects the same tab");
|
||||
// The tabs are New tab, Sample, and Other. Ctrl+Tab and Ctrl+Shift+Tab give the keyboard to the page area of the PDF tab.
|
||||
const focused = () => page.waitForFunction(() => document.activeElement?.matches(".pdf-viewer .scroll") && document.activeElement.offsetParent !== null);
|
||||
await page.keyboard.press("Control+Shift+Tab");
|
||||
await focused();
|
||||
assert.equal(await tab("Sample").getAttribute("aria-selected"), "true");
|
||||
await input.fill("1");
|
||||
await input.press("Enter");
|
||||
await rendered("Page 1 of 2");
|
||||
await page.keyboard.press("Control+Tab");
|
||||
await focused();
|
||||
await page.keyboard.press("Control+Shift+Tab");
|
||||
await focused();
|
||||
assert.equal(await tab("Sample").getAttribute("aria-selected"), "true");
|
||||
await page.keyboard.press("PageDown");
|
||||
await page.waitForFunction(() => document.activeElement.scrollTop > 0);
|
||||
await page.keyboard.press("Control+Tab");
|
||||
await rendered("Page 1 of 2");
|
||||
assert.equal(await tab("Other").getAttribute("aria-selected"), "true");
|
||||
await page.getByRole("button", { name: "Close Other", exact: true }).click();
|
||||
await tab("Other").waitFor({ state: "detached" });
|
||||
await page.waitForFunction(() => window.__PDF_WORKERS__.size === 1);
|
||||
@@ -182,6 +268,8 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
|
||||
// Reload keeps the page and replaces the worker.
|
||||
await tab("Sample").click();
|
||||
await input.fill("2");
|
||||
await input.press("Enter");
|
||||
await rendered("Page 2 of 2");
|
||||
await button("Reload PDF").click();
|
||||
await rendered("Page 2 of 2");
|
||||
@@ -225,5 +313,5 @@ await runSmoke("features/pdf", async ({ page }) => {
|
||||
assert.equal(await tab("Sample").count(), 1);
|
||||
|
||||
assert.deepEqual(requests, [], "No network request leaves the app");
|
||||
console.log("PASS: PDF Viewer loads at first need, renders text and pages, zooms, rotates, reloads, unlocks, reports a damaged file, keeps one worker per tab, restores its tab, and Off removes it");
|
||||
console.log("PASS: PDF Viewer loads at first need, renders text and pages, scrolls, zooms, rotates, reloads, unlocks, reports a damaged file, keeps one worker per tab, restores its tab, and Off removes it");
|
||||
}, { timeout: 60000, viewport: { width: 1440, height: 1000 } });
|
||||
|
||||
Reference in New Issue
Block a user