4587 Commits

Author SHA1 Message Date
Tim van der Meij
038ca33f8e
Optimize runtime of the find controller unit tests
The find controller tests consistently show up in the list of slowest
tests reported by Jasmine. Profiling shows that most of the time is
spent waiting for the find results to arrive, even though the find
command itself is quite fast.

It turns out that the slowdown occurs between receiving the `find` event
and actually triggering the search. The find controller has a hardcoded
delay of 250 milliseconds built in, which was introduced for viewer
performance many years ago because otherwise every keystroke would
trigger a search even though the user's query was not complete yet.

For the unit tests we don't need this delay because, contrary to the
viewer use case, we don't have to account for user interaction and
instead dispatch complete `find` events on the event bus ourselves.
However, since the unit tests were introduced well over a year after
the delay was introduced, due to an oversight it was never made
configurable so we could skip it for the unit tests.

This commit fixes the issue, which locally results in the runtime of
`npx gulp unittest --noChrome` dropping from 39.991 seconds before this
patch to 29.116 seconds afterwards, which is a 27% speedup.
2026-05-01 19:31:13 +02:00
calixteman
7ebf3a4d7c
Merge pull request #21196 from calixteman/bug2035530
Fix free highlight on pages without images (bug 2035530)
2026-04-30 19:34:02 +02:00
Jonas Jenwald
3eef724d15 Use a reduced test-case for the "caches image resources at the document/page level as expected (issue 11878)" unit-test 2026-04-30 18:47:42 +02:00
Jonas Jenwald
c5296986fa Improve performance of the "caches image resources at the document/page level as expected (issue 11878)" unit-test
Compare `Uint32Array`s of the image-data, since that's more efficient than comparing the `Uint8ClampedArray`s directly.
2026-04-30 16:09:56 +02:00
calixteman
1ebaa03b25
Merge pull request #21192 from calixteman/colored_logs
Add some colors in the logs in order to easily see failures and add a summary of the failures at the end
2026-04-30 14:50:20 +02:00
Tim van der Meij
55e0f7e97f
Remove obsolete pdfBug: true flag in the image caching unit test
In a previous commit the time-based checks, which were based on
statistics provided by the `pdfBug: true` flag, got replaced by
test-only property checks that don't use said statistics anymore.

Fixes b01eeaf8.
2026-04-30 14:07:39 +02:00
Calixte Denizet
46fd67a191
Add some colors in the logs in order to easily see failures and add a summary of the failures at the end 2026-04-30 14:00:54 +02:00
Tim van der Meij
232506f4e8
Optimize memory usage in the unit tests
This commit fixes a number of missing cleanup steps in the unit tests
that kept state alive for longer than necessary:

- the loading tasks were not all being destroyed;
- the find controllers were not being reset;
- the state set in `beforeAll`/`beforeEach` was not all being nulled in
  the correspoding `afterAll`/`afterEach` blocks.

Combined this resulted in a steady increase in memory usage of the test
process as the tests ran, climbing up to ~1.5 GB. After this patch the
memory usage remains stable at ~800 MB.
2026-04-30 12:35:59 +02:00
calixteman
d92db130da
Merge pull request #21186 from timvandermeij/reorganize-pages-intermittents
Wait for the first page to be ready in the reorganize pages integration tests
2026-04-30 09:01:26 +02:00
Calixte Denizet
e7ec356be0
Fix free highlight on pages without images (bug 2035530) 2026-04-29 19:24:35 +02:00
Calixte Denizet
9a247e51b4
Fix the intermittent test failure 'performs a search in a text containing some Hangul syllables'
The patch cb8055f0a changed the worker source so just set it as it was.
2026-04-29 15:36:22 +02:00
Tim van der Meij
4021d57153
Wait for the first page to be ready in the reorganize pages integration tests
The thumbnails are only available if the first page is ready, and not
awaiting that causes the drag-and-drop action to be performed using
incorrect thumbnail viewer state (see the analysis in #21184 for more
details).

Fixes #21184.
Supersedes #20902.
Unblocks #21173.
2026-04-29 14:22:10 +02:00
Calixte Denizet
47f0bdc6a5
Use Istanbul instrumentation for unittestcli code coverage 2026-04-29 11:02:51 +02:00
Tim van der Meij
a5382249db
Merge pull request #21178 from calixteman/unittest-coverage-lib
Collect worker-side coverage for browser unit tests
2026-04-28 15:25:14 +02:00
Calixte Denizet
cb8055f0a9
Collect worker-side coverage for browser unit tests 2026-04-28 14:53:14 +02:00
Calixte Denizet
dc3c07b3e3 Allow free-highlighting on top of image placeholders (bug 2034980)
The `textLayerImagePlaceholder` canvas added in #20626 covers scanned
pages and was not recognized as a valid pointerdown target by
`#textLayerPointerDown`, so free highlights couldn't start.
2026-04-27 20:13:39 +02:00
Calixte Denizet
c9a7ff0506 Fix merging PDFs with conflicting AcroForm /DR (bug 2035197) 2026-04-27 18:54:52 +02:00
Calixte Denizet
64b25a8f47
Fix merging a PDF after a page deletion (bug 2034804)
When pages carry explicit pageIndices (e.g. after a delete),
resolve insertAfter against that layout instead of the empty
base sequence. Also reject partial pageIndices combined with
insertAfter, which would race against the extraction's auto-fill.
2026-04-26 22:37:22 +02:00
Jonas Jenwald
fc9d9e49de Improve unit-testing for the PDFDocumentProxy.prototype.getPageIndex method
Given the existing worker-thread caching it doesn't seem, based on the coverage report, that all of the `getPageIndex` code is being tested.
2026-04-26 13:38:08 +02:00
Tim van der Meij
2674a9f3e4
Merge pull request #21137 from calixteman/bug2022700
Don't decode name of the checkboxes exported values (bug 2022700)
2026-04-26 12:00:58 +02:00
Jonas Jenwald
1591ddfa8d
Merge pull request #21157 from Snuffleupagus/eslint-radix
Enable the `radix` ESLint rule
2026-04-25 22:27:21 +02:00
Jonas Jenwald
e6dba6ee34 Enable the radix ESLint rule
Many `parseInt` call-sites already provide the `radix` argument, and this rule helps improve consistency in the code-base; see https://eslint.org/docs/latest/rules/radix

*Please note:* The rule is disabled in `src/scripting_api/util.js` for now, since it's not obvious at a glance (at least to me) what the correct `radix` argument should be there.
2026-04-25 12:13:12 +02:00
calixteman
30d060c77a
Merge pull request #21151 from calixteman/bug2034568
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
2026-04-25 08:20:25 +02:00
Tim van der Meij
f41c60ab7e
Merge pull request #21147 from Snuffleupagus/unittestcli-download-PDFs
Download linked PDFs when running `gulp unittestcli`
2026-04-24 20:29:14 +02:00
Tim van der Meij
7dc4812643
Merge pull request #21138 from calixteman/bug2034111
Fix status label mismatch after merging with a pre-existing selection (bug 2034111)
2026-04-24 20:07:50 +02:00
calixteman
2d896faa1e
Merge pull request #21142 from calixteman/input_color_alpha
[Ink] Replace the opacity slider with an alpha-enabled color input
2026-04-24 15:46:46 +02:00
Calixte Denizet
39eb691252
Fix status label mismatch after merging with a pre-existing selection (bug 2034111) 2026-04-24 14:13:53 +02:00
calixteman
a6382ac97d
Merge pull request #21145 from calixteman/bug2034461
Prompt the user for saving a merged pdf (bug 2034461)
2026-04-24 14:11:36 +02:00
calixteman
c05d87a63f
Merge pull request #21149 from calixteman/switch_quickjs_wasm
Switch to a wasm file for the quickjs sandbox
2026-04-24 14:10:47 +02:00
Calixte Denizet
b669fdfc70
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
Screen readers like NVDA fire synthetic click events on the <img> child of the button rather than on the
thumbnailImageContainer element itself, so the strict classList.contains check silently failed.
2026-04-24 10:10:59 +02:00
Calixte Denizet
987edbb646
Switch to a wasm file for the quickjs sandbox 2026-04-23 22:34:48 +02:00
calixteman
25204d359a
Merge pull request #21136 from calixteman/bug2033908
Avoid to add outlines having a deleted page which leads to clone a useless page (bug 2033908)
2026-04-23 22:24:58 +02:00
Jonas Jenwald
4e08d00466 Download linked PDFs when running gulp unittestcli
Currently a fair number of unit-tests are disabled in Node.js not because of missing functionality, but only because they use linked PDFs.
2026-04-23 21:52:08 +02:00
Calixte Denizet
f266c4d8b8
[Ink] Replace the opacity slider with an alpha-enabled color input
The alpha feature is available in Firefox nightly (with the pref `dom.forms.html_color_picker.enabled` set to `true`).
It's available in Safari but not in Chrome.
2026-04-23 21:37:37 +02:00
Tim van der Meij
14743eef45
Introduce a GitHub Actions workflow for running the unit tests
Note that we no longer create an empty file if the download fails because
we don't want to leave traces of incorrect file contents on disk. This
has never been particularly useful because it'd require a manual user
action to remove the empty file to be able to retry in case of e.g. a
timed out connection, but especially in the context of GitHub Actions
where we cache the PDFs directory we don't want to cache invalid files
to make sure that a next run will automatically retry to fetch any
previously missed PDF files and update the cache.
2026-04-23 21:12:01 +02:00
Calixte Denizet
302bc5f4d9
Prompt the user for saving a merged pdf (bug 2034461) 2026-04-23 18:37:56 +02:00
Jonas Jenwald
a6988582d2 [api-minor] Replace the CCITT and JBig2 fallback decoders with a JS version of the PDFium decoder
*Note:* This is similar to PR 19525, which did the same thing for the OpenJPEG decoder.

The advantages of doing this are:
 - The same JBig2 decoder is used regardless of WASM being supported or not, which means consistent rendering.
 - The old `Jbig2Image` implementation has various bugs and missing features.
 - Less code that needs to be maintained in the PDF.js project, since both the CCITT and the JBig2 decoder is replaced.

The disadvantage of doing this is:
 - Slightly larger bundle size, however the effect is limited since a fair amount of PDF.js code can be removed. For the `gulp mozcentral` target the size increase is approximately 54 kilo-bytes (which is small compared to the 452 kilo-bytes for the JS version of the OpenJPEG decoder).
2026-04-22 23:24:26 +02:00
Calixte Denizet
42ccca7ee8
Don't decode name of the checkboxes exported values (bug 2022700) 2026-04-22 18:30:43 +02:00
Calixte Denizet
a52c8334f5 Avoid to add outlines having a deleted page which leads to clone a useless page (bug 2033908) 2026-04-21 22:23:28 +02:00
Tim van der Meij
e070944ff0
Merge pull request #21131 from Snuffleupagus/fix-CopyLocalImage-unittests
Improve the "CopyLocalImage" unit-tests
2026-04-21 20:18:40 +02:00
calixteman
56d730e975
Merge pull request #21125 from calixteman/reftest_coverage
Add code coverage support for browser/ref tests
2026-04-21 15:00:48 +02:00
Nicolò Ribaudo
f7725254f3
Fix unit test for dependency tracking
Follow up to PR #21102
2026-04-21 11:48:18 +02:00
Jonas Jenwald
b01eeaf8e1 Improve the "CopyLocalImage" unit-tests
Rather than relying on the time it takes to parse/render the pages, which leads to intermittent failures, add a test-only property and use it to check if the "CopyLocalImage" code-path was exercised.
2026-04-21 11:43:08 +02:00
calixteman
3aab546524 Add code coverage support for browser/ref tests
Instrument JS files on-the-fly via babel-plugin-istanbul when --coverage
or --coverage-per-test is passed, producing an aggregate lcov/HTML report
at the end of the run. A persistent PDFWorker accumulates worker-thread
coverage alongside the main-thread coverage, collected via a new
GetWorkerCoverage message handler.

With --coverage-per-test, an inverted index
(build/coverage/per-test-index.json) is also built as tests run, mapping
each hit source line and function name to the numeric IDs of the tests
that exercised it, keeping the output compact. The new
`gulp test_search --code=file::line_or_function` tool queries the index,
and passing --code to browsertest pre-filters the test run to only those
tests.

Coverage output formats are selectable via --coverage-formats (default:
info; also accepts html, json, text, cobertura, clover).
2026-04-20 21:46:18 +02:00
Tim van der Meij
ab85b7f0ff
Merge pull request #21128 from calixteman/bug2025109
Remove user and password from URLs (bug 2025109)
2026-04-20 21:21:29 +02:00
Calixte Denizet
8ddbeda4a0
Remove user and password from URLs (bug 2025109) 2026-04-20 20:53:24 +02:00
Calixte Denizet
db89d3a0e6 Correctly compute the bbox when simplifying the path construction
It fixes #21126.
2026-04-20 18:42:09 +02:00
Tim van der Meij
801236f8c4
Fix the gets text content, with correct properties (issue 8276) unit test
This unit test failed consistently in Firefox both locally and on GitHub
Actions (but not in Chrome or on the bots), which suggests a timing issue.

Since all other unit tests that rely on `commonObjs` actually render the
page, most likely to make sure that `commonObjs` is fully populated at
the time of the check, this commit mirrors that approach to this test,
which indeed fixes the issue.
2026-04-19 19:09:43 +02:00
Calixte Denizet
7810cee005
Improve reftest runner memory usage and load balancing
Replace manifest slicing with a dynamic task queue: drivers request tasks
on demand via WebSocket so parallel sessions self-balance naturally.

Start reading reference PNGs from disk as soon as a task is dispatched
(prefetchRefPngs) to overlap I/O with rendering. Release snapshot
buffers and task entries immediately after comparison, and copy WS
frame slices via Buffer.from() so the original frame buffer can be
GC'd.

Bump --max-old-space-size to 8192 MB as a workaround for a
Puppeteer/BiDi memory leak where data: URL strings accumulate in
BrowsingContext.#requests indefinitely:
  https://github.com/puppeteer/puppeteer/issues/14876
2026-04-18 22:33:31 +02:00
Jonas Jenwald
c155a86733 Store the Type1 program privateData in a Map, rather than an Object
This is nicer when checking if fields exist in `Type1Font.prototype.wrap`, and a couple of loops in that method are also "modernized" slightly.
2026-04-18 12:32:22 +02:00