Commit Graph

3262 Commits

Author SHA1 Message Date
Tim van der Meij
ede65e11c6
Fix the protocol timeout configuration for Puppeteer
The default protocol timeout is 180 seconds according to the
documentation at https://pptr.dev/api/puppeteer.browserconnectoptions,
but the Jasmine timeout we configure in the individual boot files is 30
seconds. The consequence of this is that if a protocol (CDP) error
occurs after 30 seconds Jasmine will fail the test, but the actual
protocol error from Puppeteer is raised much later in the context of
another test, which causes unrelated failures or tracebacks.

This commit fixes the problem by configuring Puppeteer to always use a
lower protocol timeout than the Jasmine timeout so that protocol errors
are always raised in the context of the test that actually triggered it.
2023-10-08 18:22:02 +02:00
Tim van der Meij
2c1d95b153
Activate the selector check for the autoprint integration test as soon as possible
The Windows bot is usually slower than the Linux bot, and therefore
text layer rendering is as well. However, the `autoprint` test awaited
text layer rendering to complete before activating the selector check,
which makes it timing-sensitive and causes it to never resolve because
the page is already printed (and the printed page div removed) by then.

This commit should fix the issue by activating the selector check as
soon as possible, namely as soon as the viewer appears, which should
ensure we're always registering the selector check in time because we're
doing it even before rendering is starting.
2023-10-07 19:27:34 +02:00
Tim van der Meij
bab4c7f617
Merge pull request #17055 from Snuffleupagus/output-modules
[api-major] Output JavaScript modules in the builds (issue 10317)
2023-10-07 15:02:59 +02:00
Tim van der Meij
89d8c639fa
Merge pull request #17077 from Snuffleupagus/css-rm-unneeded-alpha
Remove unnecessary alpha-value from CSS `rgb` colors
2023-10-07 12:33:48 +02:00
Jonas Jenwald
927e50f5d4 [api-major] Output JavaScript modules in the builds (issue 10317)
At this point in time all browsers, and also Node.js, support standard `import`/`export` statements and we can now finally consider outputting modern JavaScript modules in the builds.[1]

In order for this to work we can *only* use proper `import`/`export` statements throughout the main code-base, and (as expected) our Node.js support made this much more complicated since both the official builds and the GitHub Actions-based tests must keep working.[2]
One remaining issue is that the `pdf.scripting.js` file cannot be built as a JavaScript module, since doing so breaks PDF scripting.

Note that my initial goal was to try and split these changes into a couple of commits, however that unfortunately didn't really work since it turned out to be difficult for smaller patches to work correctly and pass (all) tests that way.[3]
This is a classic case of every change requiring a couple of other changes, with each of those changes requiring further changes in turn and the size/scope quickly increasing as a result.

One possible "issue" with these changes is that we'll now only output JavaScript modules in the builds, which could perhaps be a problem with older tools. However it unfortunately seems far too complicated/time-consuming for us to attempt to support both the old and modern module formats, hence the alternative would be to do "nothing" here and just keep our "old" builds.[4]

---
[1] The final blocker was module support in workers in Firefox, which was implemented in Firefox 114; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility

[2] It's probably possible to further improve/simplify especially the Node.js-specific code, but it does appear to work as-is.

[3] Having partially "broken" patches, that fail tests, as part of the commit history is *really not* a good idea in general.

[4] Outputting JavaScript modules was first requested almost five years ago, see issue 10317, and nowadays there *should* be much better support for JavaScript modules in various tools.
2023-10-07 09:31:08 +02:00
calixteman
905ad1fe68
Merge pull request #16761 from calixteman/editor_add_new_with_keyboard
[Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
2023-10-06 11:44:07 +02:00
Jonas Jenwald
4ebddcb092 Remove unnecessary alpha-value from CSS rgb colors
Setting the alpha-value explicitly to `1` in `rgb` colors is unnecessary, since that's the default value, and this way we ever so slightly reduce the size of our CSS files.
Unfortunately I've not found a Stylelint rule to enforce this automatically, and the patch was generated using search and replace.
2023-10-06 09:50:03 +02:00
Calixte Denizet
ea5eafa265 [Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
When an editing button is disabled, focused and the user press Enter (or space), an
editor is automatically added at the center of the current page.
Next creations can be done in using the same keys within the focused page.
2023-10-05 22:49:15 +02:00
Jonas Jenwald
4277205d78 Enable some Stylelint color-related rules to slightly reduce file sizes
- Use a consistent format for all alpha-values (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/alpha-value-notation
 - Use modern and slightly shorter color notation, since [according to MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#browser_compatibility) that should be supported "everywhere" nowadays; see https://stylelint.io/user-guide/rules/color-function-notation/
 - Use "short" hexadecimal colors whenever possible; see https://stylelint.io/user-guide/rules/color-hex-length/
 - Help avoid adding broken hexadecimal colors (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/color-no-invalid-hex/
2023-10-05 17:51:21 +02:00
Calixte Denizet
40b1d92044 Update the noHTML flag to take into account the hasOwnCanvas one (fixes #17069)
When an element has the hasOwnCanvas flag we must have an HTML container to attach
the canvas where the element will be rendered.
So the noHTML flag must take this information into account:
 - in some cases the noHTML flag is resetted depending on the hasOwnCanvas value;
 - in some others, the hasOwnCanvas flag is set depending on the value of noHTML.
2023-10-04 18:06:21 +02:00
calixteman
40d6b0e1bf
Merge pull request #17062 from calixteman/resize_keyboard
[Editor] Support resizing editors with the keyboard (bug 1854340)
2023-10-04 13:55:04 +02:00
Calixte Denizet
05ca3fd99b [Editor] Support resizing editors with the keyboard (bug 1854340) 2023-10-04 12:57:37 +02:00
Jonas Jenwald
bf9c33e60f Add support for "GoToE" actions with destinations (issue 17056)
This shouldn't be very common in practice, since "GoToE" actions themselves seem quite uncommon; see PR 15537.
2023-10-04 11:14:23 +02:00
Calixte Denizet
1be9bbd2e1 Compute correctly the bounding box of a transformed rectangle (fixes #17065) 2023-10-03 23:50:59 +02:00
Jonas Jenwald
f113320bd5 Ensure that readonly TextWidget-annotations are rendered when forms are disabled (issue 17064)
To reduced the risk of regressing something else, given that the issue only applies to a (for the default viewer) non-default configuration, this patch is purposely limited to only TextWidget-annotations in the display layer.
2023-10-03 21:26:08 +02:00
Jonas Jenwald
426209c6e6
Merge pull request #16699 from Snuffleupagus/rm-svg
[api-major] Remove the SVG back-end (PR 15173 follow-up)
2023-10-03 15:13:14 +02:00
calixteman
0cc8c6671c
Merge pull request #17059 from calixteman/fix_copy_paste_integration_test
Remove timeouts from the copy_paste integration test
2023-10-03 13:27:13 +02:00
Calixte Denizet
bb59f445a9 Remove timeouts from the copy_paste integration test 2023-10-03 11:55:18 +02:00
Calixte Denizet
e3fbe2908a [Editor] Use the alt text to descibe the canvas used to display the image 2023-10-02 23:28:11 +02:00
Calixte Denizet
eebd251552 [Editor] Don't show the alt-text button when the alt-text dialog is visible
This way, the button doens't cover the image.
2023-10-02 20:34:30 +02:00
calixteman
f5367f01ca
Merge pull request #17051 from calixteman/test_stamp_svg
Fix new intermittent failures with ink and stamp tests
2023-10-02 18:10:00 +02:00
Calixte Denizet
077d239b96 Fix new intermittent failures with ink and stamp tests
It happens only on windows with chrome.
For any reason, click event isn't correctly triggered and it seems work correctly
with pointerup.
And it seems that when drawing a svg on an OffscreenCanvas we need to wait
a little in order to be able to transfer it: it's why this patch adds
a check on the canvas content.
2023-10-02 15:04:44 +02:00
Jonas Jenwald
3ced0dec1b [api-major] Remove the SVG back-end (PR 15173 follow-up)
This has been deprecated since version `2.15.349`, which is a year ago.
Removing this will also simplify some upcoming changes, specifically outputting of JavaScript modules in the builds.
2023-10-01 23:14:29 +02:00
Jonas Jenwald
9624505f0f Use a standard export statement in the web/pdfjs.js file
This removes the only remaining old and non-standard handling of exports in the `web/`-folder, since some initial attempts at outputting JavaScript modules in the builds have identified this file as a potential problem.
While this uses a hard-coded list, for overall simplicity, I don't believe that that's a big problem since:
 - Generating this file automatically would require a bunch more parsing *every single time* that the library is built.
 - The official API-surface doesn't change often enough for this to really impede development in any significant way.
 - The added unit-test helps ensure that this list cannot accidentally become outdated.
2023-09-30 12:10:02 +02:00
calixteman
3ca63c68ea
Merge pull request #17050 from calixteman/editor_delete_invisible
[Editor] Make a deleted (when it was invisible) editor undoable
2023-09-29 18:06:55 +02:00
calixteman
7d7a7a46a0
Merge pull request #17049 from calixteman/fix_stamp_tests
Remove the timeouts from the stampEditor integration tests
2023-09-29 17:02:10 +02:00
Calixte Denizet
b65b079ceb [Editor] Make a deleted (when it was invisible) editor undoable
When the editor is invisible (because on a non-rendered page) its parent is null.
But when we undo its deletion, we need to have a parent to attach it.
2023-09-29 16:19:11 +02:00
Calixte Denizet
b8c118db22 Remove the timeouts from the stampEditor integration tests 2023-09-29 15:57:16 +02:00
Calixte Denizet
627249f889 Remove the timeouts from the inkEditor integration tests 2023-09-29 15:01:52 +02:00
Calixte Denizet
55e5af2d01 [Editor] Remove almost all the waitForTimeout from the freetext integration tests 2023-09-29 11:14:21 +02:00
Calixte Denizet
f2196f7803 StructParents entry isn't required on pages with no tagged contents (bug 1855641) 2023-09-28 14:23:10 +02:00
Calixte Denizet
3ee5268a23 [Editor] Don't try to add data to the struct tree when there is no accessibilityData (bug 1855157) 2023-09-26 11:02:14 +02:00
Tim van der Meij
ce87167432
Merge pull request #17022 from timvandermeij/fix-intermittent-us
Fix integration test "Interaction in issue14307.pdf (1) must check input for US zip format"
2023-09-24 18:47:18 +02:00
Tim van der Meij
6e584adfc5
Use realistic typing delays for the scripting integration tests
In the scripting integration tests we use a few different typing
delays, mostly 100 or 200 milliseconds. According to for example
https://www.typingpal.com/en/documentation/school-edition/pedagogical-resources/typing-speed,
a fast typing speed is around 300 characters per minute, which is 5
characters per second and therefore a delay of 200 milliseconds between
each keystroke. Note that this is already above average, so in practice
the delay will be even larger. Therefore the 100 milliseconds variant
is unrealistically fast and therefore not suitable for the integration
tests which aim to simulate the average user behavior.

On top of that, the quick typing speeds are problematic for the tests
that involve validation alert dialogs appearing during typing. In those
tests a handler is registered to close the dialog once it pops up, but
it takes time for Puppeteer to notice the dialog, trigger the handler
and close it. If the typing delay, which is the delay between the key
down and key up events according to the Puppeteer source code at
https://github.com/puppeteer/puppeteer/blob/master/packages/puppeteer-core/src/cdp/Input.ts#L209-L215,
is too short, the key up event will be fired before the dialog is
closed. In that time the text box we're typing in is not focused, so
when the dialog is closed the `page.type()` call on the text box will
never resolve because the key up event never reached the text box.

This commit aims to fix the issues by converting all 100 millisecond
delays to 200 milliseconds. For instance the "must check input for US
zip format" failed pretty consistently locally before and hasn't failed
anymore with a 200 millisecond delay.
2023-09-24 15:47:21 +02:00
calixteman
48d75599d3
Merge pull request #17018 from calixteman/alt_text_test
[Editor] Add an integration test for the new alt-text flow
2023-09-24 14:34:58 +02:00
Calixte Denizet
de553456ce [Editor] Add an integration test for the new alt-text flow 2023-09-24 13:39:18 +02:00
Tim van der Meij
9b464047bc
Merge pull request #17021 from timvandermeij/fix-intermittent-autoprint
Fix integration test "Interaction in autoprint.pdf must check if printing is triggered when the document is open"
2023-09-24 13:37:18 +02:00
Tim van der Meij
b41bca7da9
Don't wait for scripting to be ready in the autoprint integration test
This integration test fails often because we wait for scripting to be
ready before we check the printed page, but most of the time the PDF
is already done printing before scripting is reported to be ready.

This happens because the print trigger is on the `Open` event, which is
one of the first events to be dispatched and, most notably, before
scripting is marked as ready; please see
https://github.com/mozilla/pdf.js/blob/master/web/pdf_scripting_manager.js#L176-L191.
Given that the PDF document is only one page, printing it is usually
finished between triggering the `Open` event and scripting reported
to be ready. If this happens the printed page is already destroyed
before we get to our actual test, which will then timeout because it
will never find the printed page in the DOM.

This commit fixes the problem by not awaiting scripting to be ready
because the fact that the printed page appears is already enough to know
that autoprint was triggered (after all, there is no other user
interaction involved here). While we're here we also switch to the
shorter `page.waitForSelector` function.
2023-09-24 12:48:58 +02:00
Calixte Denizet
57caa4601c [Editor] The ::before containter containing the border of a selected editor mustn't catch mouse events (bug 1854818) 2023-09-23 23:53:19 +02:00
Jonas Jenwald
1df31c0284 Use one noContextMenu function in both the src/- and web/-folders
Currently we duplicate this event handler function in multiple places, which seems unnecessary.
2023-09-23 15:37:13 +02:00
Tim van der Meij
a09b7228fb
Merge pull request #16970 from timvandermeij/fix-intermittent-border
Fix integration test "Interaction in issue15053.pdf must check that a button and text field with a border are hidden"
2023-09-23 14:35:07 +02:00
Tim van der Meij
f9eda5b30e
Merge pull request #16967 from timvandermeij/fix-intermittent-freetext
Fix integration test "FreeText Editor FreeText (edit existing in double clicking on it) must move an annotation"
2023-09-23 14:34:43 +02:00
Calixte Denizet
6545551e76 [Editor] Avoid to darken the current editor when opening the alt-text dialog 2023-09-21 20:44:53 +02:00
Jonas Jenwald
e2b7896826 [GeckoView] Avoid bundling the AltTextManager class, since it's unused 2023-09-21 12:51:34 +02:00
Jonas Jenwald
0ac8f33e13 Ignore optional content with missing /Type-entries
In the rare situation that an optional content dictionary lacks a /Type-entry we currently throw, which may prevent e.g. Form XObjects from rendering completely.

Fixes https://bugs.ghostscript.com/show_bug.cgi?id=707147
2023-09-19 14:11:03 +02:00
calixteman
3afb717eed
Merge pull request #16938 from calixteman/update_struct_tree
[Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
2023-09-18 13:04:52 +02:00
Tim van der Meij
01428f1e23
Wait for visibility change in the issue15053 integration test
Especially on slower bots there is some time between clicking the
element and the actual visibility change, but we didn't await this and
checked the visibility state immediately after clicking. This can be
reproduced 100% of the time by introducing a delay in the `display` and
`hidden` handlers of the `_commonActions` shadow call.

This commit fixes the problem by waiting until the first visibility
change actually happened before continuing with the assertions.
2023-09-17 19:48:14 +02:00
Tim van der Meij
1b3ccf1321
Wait for selector instead of timeout in the freetext double click move integration test
This integration test currently fails intermittently on the bots because
of the fixed timeout in the test, which is sometimes too low on slower
systems. The issue can be reproduced 100% of the time by introducing a
delay just before dispatching the `switchannotationeditormode` event.

Puppeteer also discourages this and instead recommends waiting for a
selector instead, which we now do here. This ensures that the test only
continues if the element under test is available and therefore prevents
any timing problems.
2023-09-17 18:49:11 +02:00
Tim van der Meij
306cca930f
Fix off-by-one errors in the "FreeText must move several annotations" integration test
The x/y-coordinates are floats instead of integers like one might
expect. The current approach rounds both the old and the new
coordinates in order to do integer comparison. However, rounding each
coordinate individually causes too much loss of precision because,
depending on the decimal value, they are either rounded up or down
which causes intermittent off-by-one errors.

This commit fixes the problem by comparing coordinate differences
instead of the coordinates themselves. The precision loss is avoided
by subtracting the old from the new coordinate as-is and only rounding
the final result.
2023-09-17 15:56:51 +02:00
Tim van der Meij
0d3fbc1818
Wait for selector instead of timeout in the bug1844576 integration test
This integration test currently fails intermittently on the bots because
of the fixed timeout in the test, which is sometimes too low on slower
systems. The issue can be reproduced 100% of the time by introducing a
delay in the `WidgetAnnotationElement.showElementAndHideCanvas` method.

Puppeteer also discourages this and instead recommends waiting for a
selector instead, which we now do here. This ensures that the test only
continues if the element under test is available and therefore prevents
any timing problems.
2023-09-17 13:15:53 +02:00