sendEvent for key events generates inconsistent DOM key events #11094
Description
ljouann...@gmail.com commented:
Which version of PhantomJS are you using? 1.8.1
What steps will reproduce the problem?
- git clone https://github.com/laurentj/slimerjs.git
- go into the test directory
- run phantomjs phantomjs-test-keyevent.js
What is the expected output?
All tests should pass
What do you see instead?
Many tests are failing
Which operating system are you using?
Linux (Kubuntu 12.10) / Azerty keyboard
Did you use binary PhantomJS or did you compile it from source?
Binary
Please provide any additional information below.
Here are tests that are launched :
- https://github.com/laurentj/slimerjs/blob/master/test/test-webpage-keyevent.js
- https://github.com/laurentj/slimerjs/blob/master/test/test-webpage-keyevent2.js
(92 specs, hundreds 'expect' tests)
These tests files launch tests on webpage.sendEvent with various values on parameters, to send key events on the webpage. To summarize issues, many of failed tests show that we don't have the same behavior as in a "real" browser (Firefox, Chrome..): we don't receive same DOM events in the webpage as if we were in a real browser.
Here are these issues:
- calling sendEvent("keydown") with webpage.event.key.A, generates a DOM keydown event, but also a DOM keypress event. This DOM keypress event should not be generated. Same issue if we give a string like "a" or "é".
- calling sendEvent("keypress") with webpage.event.key.A, generates a DOM keypress event, but also a DOM keydown event and a DOM keyup event. We should not have these two last events. It is inconsistent IMHO, because it means that we don't have an easy way to simulate only a DOM keypress event. Or if for you it is consistent, then I think the "keypress" keyword is not a good choice for the phantomjs API. Same issue if we give a string like "a" or "é".
- worse issue : calling sendEvent("keypress") with webpage.event.key.A AND ctrl modifier, does NOT generate a DOM keypress event at all, but it still generates the unexpected DOM keydown and DOM keyup events. Probably ctrl+A has a specific meaning in QT/Webkit and then it "eats" the event. But it means that we cannot simulate a real CTRL+A (whereas it works well in a real browser, we receive the keypress event). We have the same issue with "keypress" + a printable character that does not correspond to a DOM keycode (like webpage.event.key.Ocircumflex), or + a non printable key (like webpage.event.key.Delete), or + a string with a single char
- calling sendEvent("keydown") with webpage.event.key.Delete, generates a DOM keydown event, but not a DOM keypress event. from my point of view, it is ok, but it is inconsistent with the first issue I list. So depending on what we send with keydown, we don't have the same behavior in terms of DOM key event. Worse, this call erase a character in the input target, although it should not since the resulting action of a key in a browser is down during a DOM keypress event (if it is not canceled by the webpage).
- We have almost the same issue when calling sendEvent("keydown") with a string longer than one character. We receive only one DOM keydown event. This is consistent, since it does not make sense to receive a DOM keydown event for each character without their keypress and keyup events. The issue here, is that we receive one keypress event, and the <input> target is filled with the entire given string. It means that character are taken account without corresponding DOM key events!
Note that we don't have this issue with the ctrl modifier. And <input> content is ok with alt modifier and shift+ctrl modifier (but we have still the keypress event in these two cases)
- we have also minor issues with sendEvent("keydown") with a string longer than one character
For details, see comments in test files.
Bonus, activate the file test-webpage-keyevent-phantom.js instead of the two test files, in phantomjs-test-keyevent.js. and you then have same tests but against results as generated by phantomjs 1.8.1. Tests succeeded with this file (but results are not good of course). Feel free to integrate these tests into your own tests suite.
The origin of some of these issues comes probably from QTwebkit, or even Webkit. Perhaps also something is missing in the use of the QT API in phantomjs. I'm not familiar enough with QT to say who is the responsible :-)
Laurent
Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #1094.
🌟 3 people had starred this issue at the time of migration.