Skip to content

Preserve attachment destinations in GoToE outline links - #22001

Open
xjtu-ctgg wants to merge 1 commit into
mozilla:masterfrom
xjtu-ctgg:fix/gotoe-outline-destination
Open

xjtu-ctgg wants to merge 1 commit into
mozilla:masterfrom
xjtu-ctgg:fix/gotoe-outline-destination

Conversation

@xjtu-ctgg

@xjtu-ctgg xjtu-ctgg commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

GoToE outline entries lose attachmentDest when the catalog builds the outline, and the outline viewer does not pass the destination to the download manager. A bookmark targeting a page inside an embedded PDF therefore ignores that destination, opening at the first page on an initial visit, while the equivalent page annotation works.

Preserve the optional destination in outline data and forward it unchanged when opening the attachment. Add a self-contained PDF and regression coverage for explicit and named attachment destinations.

Validation:

  • The PDF-based API regression verifies both explicit and named attachment destinations.
  • Existing outline API expectations were updated for the uniform attachmentDest field.
  • Real viewer integration tests click both outline entries and verify that the embedded PDF opens on page 2 in Chrome and Firefox.
  • gulp generic lib-legacy and gulp lint passed.

Copilot AI lite review requested due to automatic review settings September 21, 2026 15:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread src/core/catalog.js Outdated
Comment on lines +445 to +447
if (data.attachmentDest !== undefined) {
outlineItem.attachmentDest = data.attachmentDest;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why handle this particular case specifically?

Simply adding attachmentDest: data.attachmentDest; just after the attachment-line above seems correct.

Comment thread test/unit/catalog_spec.js Outdated
return new Catalog({ docBaseUrl: null }, xref);
}

describe("documentOutline", function () {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty redundant, given the unit-test using an actual PDF in api_spec.js above.

Comment thread test/unit/catalog_spec.js Outdated
Comment on lines +87 to +92
for (const [description, dest, expected] of [
["explicit", [1, Name.get("Fit")], '[1,{"name":"Fit"}]'],
["string", "second-page", "second-page"],
["name", Name.get("second-page"), "second-page"],
]) {
it(`preserves a GoToE ${description} destination`, function () {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference: Generating test-cases within loops isn't a great pattern to use, despite what your AI might "think".

Comment thread test/unit/pdf_outline_viewer_spec.js Outdated
import { EventBus } from "../../web/event_utils.js";
import { PDFOutlineViewer } from "../../web/pdf_outline_viewer.js";

describe("PDFOutlineViewer", function () {

@Snuffleupagus Snuffleupagus Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems pointless to have a unit-test that stub-out significant parts of the viewer functionality.
If you want to test that code it should really be done using integration-tests instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems pointless to have a unit-test that stub-out significant parts of the viewer functionality. If you want to test that code it should really be done using integration-tests instead.

Thanks for the review.(・ω・)ノ I’ll simplify the assignment, remove the redundant catalog tests, and keep the PDF-based API test. I’ll replace the mocked viewer tests with integration coverage.

@mozilla mozilla deleted a comment from srepollock Sep 22, 2026

@Snuffleupagus Snuffleupagus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread test/integration/viewer_spec.mjs Outdated
Comment on lines +66 to +73
await attachmentPage.waitForFunction(
() => document.querySelector("#pageNumber")?.valueAsNumber === 2
);
const currentPage = await attachmentPage.$eval(
"#pageNumber",
el => el.valueAsNumber
);
expect(currentPage).withContext(`In ${browserName}`).toBe(2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at other integration-tests, why make this so complicated?

Suggested change
await attachmentPage.waitForFunction(
() => document.querySelector("#pageNumber")?.valueAsNumber === 2
);
const currentPage = await attachmentPage.$eval(
"#pageNumber",
el => el.valueAsNumber
);
expect(currentPage).withContext(`In ${browserName}`).toBe(2);
await attachmentPage.waitForFunction(
() => window.PDFViewerApplication.page === 2
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌Thanks for the review.

@xjtu-ctgg

Copy link
Copy Markdown
Contributor Author

Squashed into a single commit and expanded the commit message, as requested.

@calixteman

Copy link
Copy Markdown
Contributor

@xjtu-ctgg can you rebase ?

@xjtu-ctgg
xjtu-ctgg force-pushed the fix/gotoe-outline-destination branch from 5517f96 to 74c3f4d Compare September 30, 2026 05:20
@xjtu-ctgg

Copy link
Copy Markdown
Contributor Author

Rebased onto current master, thanks. The only conflict was in test/pdfs/.gitignore.

@codecov-commenter

codecov-commenter commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.21%. Comparing base (d0295c9) to head (d8fffe3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22001      +/-   ##
==========================================
- Coverage   90.22%   90.21%   -0.01%     
==========================================
  Files         275      275              
  Lines       67837    67837              
==========================================
- Hits        61203    61200       -3     
- Misses       6634     6637       +3     
Flag Coverage Δ
fonttest 8.98% <ø> (ø)
unittest 59.92% <ø> (-0.01%) ⬇️
unittestcli 58.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@calixteman
calixteman force-pushed the fix/gotoe-outline-destination branch from 74c3f4d to b383602 Compare October 4, 2026 12:54
@calixteman

Copy link
Copy Markdown
Contributor

@Snuffleupagus are you ok with this PR ?

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

are you ok with this PR ?

The implementation itself seems OK now, however I've not really checked the integration-test.

Comment thread test/integration/viewer_spec.mjs Outdated
Comment on lines +71 to +77
const text = await attachmentPage.$eval(
textLayer,
el => el.textContent
);
expect(text)
.withContext(`In ${browserName}`)
.toContain("Attachment page TWO");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why you test that stuff.
Even if we're on page 1, this assertion won't fail since page 2 is rendered, so the real test is the waitForFunction just above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the waitForFunction is what checks it. Removed the text check.

);
});

it("opens an attachment at a named destination", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: one it is enough I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but both bookmarks open the same chapter.pdf, and in Firefox the second click doesn't give a new popup while the first one is still open, so the test times out. I kept the two its, but I can close the first popup in between if you'd rather have a single one.

Comment thread test/integration/viewer_spec.mjs Outdated
"#outlinesView .treeItem a",
"page-fit",
null,
{ sidebarViewOnLoad: 2 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it useful ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the PDF has /PageMode /UseOutlines, so the outline opens anyway. Removed.

Keep attachment destinations in outline data and pass them to the
download manager when opening embedded PDFs.

Add API and integration tests for explicit and named destinations.
@xjtu-ctgg
xjtu-ctgg force-pushed the fix/gotoe-outline-destination branch from b383602 to d8fffe3 Compare October 7, 2026 12:59
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Viewer preview

Commit d8fffe3 (build logs).

Viewer Build Preview
Modern (gulp generic) ✅ not published
Legacy (gulp generic-legacy) ✅ not published

🔒 A user with write access must approve this commit with the viewer-preview label to publish the viewers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants