Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
node t12-remote.js
node t13-upload-retry.js
node t14-preview-files.js
node t15-page-view.js

windows:
name: Windows installer
Expand Down
1 change: 1 addition & 0 deletions Source code/server/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ function openPageView(n) {
function closePageView() {
viewPage = 0;
$("pageView").hidden = true;
$("pvStage").innerHTML = "";
}

function renderPageView() {
Expand Down
2 changes: 2 additions & 0 deletions Source code/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ websites (`fake-web.js`) on spare ports, so nothing else needs to be running.
node t13-upload-retry.js "Print this?" screen: a stuck upload is sent again, then shows an error
node t14-preview-files.js the preview library is sent gzipped to browsers that can take it

node t15-page-view.js closing the large page preview frees its image; reopening the same page works

These run on Linux/macOS. The Windows-only parts (the Task Scheduler task,
the installer) are covered by manual checks on Windows and Mac.
t4, t5 and t6 need a real network card: on a machine with only
Expand Down
33 changes: 33 additions & 0 deletions Source code/tests/t15-page-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Closing the large page view releases its image, and the same page can reopen.
const fs = require("fs"), path = require("path"), vm = require("vm"), assert = require("assert");
let n = 0; const ok = (c, m) => { assert(c, m); n++; console.log(" ok -", m); };
const src = fs.readFileSync(path.join(__dirname, "../server/public/app.js"), "utf8");
const code = src.slice(src.indexOf("function openPageView("), src.indexOf("function setupPageView("));
function element() {
return {
children: [], style: {}, hidden: true, clientWidth: 600,
appendChild(child) { this.children.push(child); },
set innerHTML(value) { this.children = []; },
};
}
const ids = Object.fromEntries(["pageView", "pvStage", "pvTitle", "pvChoose", "pvPrev", "pvNext"].map(id => [id, element()]));
const draws = [];
const box = {
viewPage: 0, MAX_THUMBS: 100, $: id => ids[id],
document: { createElement: element }, window: { innerHeight: 800 },
activeEntry: () => ({ pdf: {}, pageCount: 2, pageSizes: {}, chosen: new Set([1]) }),
placeOnPaper: () => ({ ratio: 595 / 842, left: 0, top: 0, width: 1, height: 1 }),
drawPageInto(entry, page, holder) { draws.push(page); holder.appendChild(element()); },
};
vm.runInNewContext(code, box);
for (const page of [1, 1, 2]) {
box.openPageView(page);
ok(!ids.pageView.hidden && box.viewPage === page, "opens page " + page);
ok(ids.pvStage.children.length === 1 && draws.at(-1) === page, "renders the requested page");
box.closePageView();
ok(ids.pageView.hidden && box.viewPage === 0, "hides and resets the view");
ok(ids.pvStage.children.length === 0, "releases the large preview subtree");
}
box.closePageView();
ok(ids.pvStage.children.length === 0, "closing an already closed view is harmless");
console.log(n + " checks passed");
Loading