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

[JS] Use beforeinput event to trigger a keystroke event in the sandbox #14430

Merged
merged 1 commit into from Jan 23, 2022

Conversation

calixteman
Copy link
Contributor

@calixteman calixteman commented Jan 8, 2022

  • it aims to fix issue Fix AForm Validation for fields with non-digit characters #14307;
  • this event has been added recently in Firefox and we can now use it;
  • fix few bugs in aform.js or in annotation_layer.js;
  • add some integration tests to test keystroke events (see AFSpecial_Keystroke);
  • make dispatchEvent in the quickjs sandbox async.

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2022

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/1fcbc73bff57fe0/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2022

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/fb1d6a2ea91bd76/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2022

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/1fcbc73bff57fe0/output.txt

Total script time: 4.94 mins

  • Integration Tests: FAILED

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2022

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/fb1d6a2ea91bd76/output.txt

Total script time: 6.98 mins

  • Integration Tests: FAILED

@marco-c marco-c linked an issue Jan 10, 2022 that may be closed by this pull request
@Snuffleupagus
Copy link
Collaborator

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/da1f3d0d2f08a99/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/1952160057b40c5/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/da1f3d0d2f08a99/output.txt

Total script time: 4.83 mins

  • Integration Tests: FAILED

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/1952160057b40c5/output.txt

Total script time: 6.01 mins

  • Integration Tests: Passed

@calixteman
Copy link
Contributor Author

There is definitely something wrong on linux. I wrote the tests under windows...
I'll investigate.

@calixteman
Copy link
Contributor Author

And of course I can't reproduce the issue locally on debian...

@calixteman calixteman force-pushed the beforeinput branch 2 times, most recently from c5c539d to b3ad48c Compare January 15, 2022 18:11
@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/68d25f9889a1b82/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/6a641ac014484ae/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/68d25f9889a1b82/output.txt

Total script time: 3.95 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/6a641ac014484ae/output.txt

Total script time: 6.21 mins

  • Integration Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/2d21e467c69e720/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/da1d48865993413/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/da1d48865993413/output.txt

Total script time: 3.94 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/2d21e467c69e720/output.txt

Total script time: 4.27 mins

  • Integration Tests: FAILED

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/94f044bd3bc0128/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/f7e81367f97af77/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/94f044bd3bc0128/output.txt

Total script time: 4.03 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/f1bad878264b381/output.txt

Total script time: 6.61 mins

  • Integration Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/f836e3a1eb57785/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/34d3a4f209a3eb1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/f836e3a1eb57785/output.txt

Total script time: 3.89 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/34d3a4f209a3eb1/output.txt

Total script time: 6.73 mins

  • Integration Tests: FAILED

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

r=me, with one final comment/question addressed; thank you!

@@ -56,7 +56,7 @@ class GenericScripting {

async dispatchEventInSandbox(event) {
const sandbox = await this._ready;
sandbox.dispatchEvent(event);
setTimeout(() => sandbox.dispatchEvent(event), 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, that was just a bit surprising since naively I'd have assumed that the previous line (where we await a Promise) already introduces asynchronicity in the event dispatching.

Anyway, if we're adding this additional "delay" to the event dispatching there's potentially a slightly larger risk than before that we're now attempting to dispatch an event after destruction have started.
Given all the various dispatchEventInSandbox call-sites it's difficult to easily tell what an error could lead to, so how about also changing

this.support.callSandboxFunction("dispatchEvent", event);

into the following to prevent any future errors elsewhere:

this.support?.callSandboxFunction("dispatchEvent", event); 

@calixteman
Copy link
Contributor Author

When entering 123A in the second field in the test file, when entering the A, I get (in Chrome):

BEFOREINPUT 123
dispatchEventInSandbox
<<< alert >>>
VALUE 123 (field value is set from the sandbox)
INPUT 123A (input event which should come after the above BEFOREINPUT)

and in Firefox:

BEFOREINPUT 123
INPUT 123A
dispatchEventInSandbox
<<< alert >>>
VALUE 123

When adding the setTimeout, in Chrome, the INPUT event is triggered before the alert.
I think when I release the key for A then a beforeinput is triggered (but the A is not added yet in the field), ...etc and once the sandbox stuff is done + alert... then the A is finally added to the field and input is triggered. So the setTimeout likely helps to let the input stuff be done before triggering an event in the sandbox.

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/1048d0bbcb832f1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/6e5f1496d99f3b8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/1048d0bbcb832f1/output.txt

Total script time: 4.86 mins

  • Integration Tests: FAILED

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/6e5f1496d99f3b8/output.txt

Total script time: 5.68 mins

  • Integration Tests: Passed

 - it aims to fix issue mozilla#14307;
 - this event has been added recently in Firefox and we can now use it;
 - fix few bugs in aform.js or in annotation_layer.js;
 - add some integration tests to test keystroke events (see `AFSpecial_Keystroke`);
 - make dispatchEvent in the quickjs sandbox async.
@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/3c60402e66e9e4f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/46ae0a192453b60/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/3c60402e66e9e4f/output.txt

Total script time: 3.92 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/46ae0a192453b60/output.txt

Total script time: 6.66 mins

  • Integration Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/8f38bba25094c54/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/000ddaae2924129/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/8f38bba25094c54/output.txt

Total script time: 3.99 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/000ddaae2924129/output.txt

Total script time: 6.62 mins

  • Integration Tests: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AForm validation rejects valid fields
3 participants