Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to check that the compression is ok when saving an annotation #16559

Merged
merged 1 commit into from
Jun 16, 2023
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 test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,4 @@
!issue16538.pdf
!freetexts.pdf
!issue16553.pdf
!empty.pdf
Binary file added test/pdfs/empty.pdf
Binary file not shown.
43 changes: 43 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,49 @@ describe("api", function () {
await loadingTask.destroy();
});

it("write a new annotation, save the pdf and check that the text content is correct", async function () {
// This test helps to check that the text stream is correctly compressed
// when saving.
const manifesto = `
The Mozilla Manifesto Addendum
Pledge for a Healthy Internet

The open, global internet is the most powerful communication and collaboration resource we have ever seen.
It embodies some of our deepest hopes for human progress.
It enables new opportunities for learning, building a sense of shared humanity, and solving the pressing problems
facing people everywhere.

Over the last decade we have seen this promise fulfilled in many ways.
We have also seen the power of the internet used to magnify divisiveness,
incite violence, promote hatred, and intentionally manipulate fact and reality.
We have learned that we should more explicitly set out our aspirations for the human experience of the internet.
We do so now.
`.repeat(100);
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise;
pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", {
annotationType: AnnotationEditorType.FREETEXT,
rect: [10, 10, 500, 500],
rotation: 0,
fontSize: 1,
color: [0, 0, 0],
value: manifesto,
pageIndex: 0,
});

const data = await pdfDoc.saveDocument();
await loadingTask.destroy();

loadingTask = getDocument(data);
pdfDoc = await loadingTask.promise;
const page = await pdfDoc.getPage(1);
const annotations = await page.getAnnotations();

expect(annotations[0].contentsObj.str).toEqual(manifesto);

await loadingTask.destroy();
});

describe("Cross-origin", function () {
let loadingTask;
function _checkCanLoad(expectSuccess, filename, options) {
Expand Down