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

test: Follow ASCII chart instead of browser's keycodes #19442

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

skobyda
Copy link
Contributor

@skobyda skobyda commented Oct 5, 2023

Until now, we were mapping values of characters to their browser's keycodes values [1]. This however is incorrect, since to get a value of character, we use Python's 'ord' function, which returns character's Unicode value.

In some cases, these values are different. For example, a value for newline key has keycode '13' in browser [1], but Python's 'ord' will give us value of '10' [2].

[1] https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
[2] https://python-reference.readthedocs.io/en/latest/docs/str/ASCII.html

@skobyda
Copy link
Contributor Author

skobyda commented Oct 5, 2023

This causes a failure in PR cockpit-project/cockpit-machines#1150, where I try to input a text with newline into a textarea using "set_input_text", but it fails because our testlib._key_press_firefox expects newline to have value of 13 (as is browser's keycode for newline character), but instead a value of 10 is provided (as that's the value a Python's ord('/n') returns)

# testCreateCloudBaseImage (__main__.TestMachinesCreate.testCreateCloudBaseImage)
error: Failed to define network from /etc/libvirt/qemu/networks/default.xml
error: operation failed: network 'default' already exists with uuid 4f111cf5-ec75-4185-9a1b-5885a5374676
..+.+...+..+.......+..+...+............+..........+......+...+..+++++++++++++++++++++++++++++++++++++++++++++*...+...+......+.....+..........+......+...+...+.....+..........+.....+.......+..+.+..+............+....+++++++++++++++++++++++++++++++++++++++++++++*.+.........+......+.+.....+.+...............+...+..+...+....+..+.+....................+...................+...........+....+........+......................+........+..........+...+........+.+.....+.+.....+++++
.+...+.+..+.......+.....+.............+...+...........+.....................+.........+...+..........+..+....+..+.........+...+...+.......+.....+...+...+....+.....................+.....+......+.+..+......+.......+..+.......+...+......+..+...+.......+..+++++++++++++++++++++++++++++++++++++++++++++*..+...+..+...+.+..+............+......+..........+...............+..+......................+..+.+...+..+.......+..+.+.........+++++++++++++++++++++++++++++++++++++++++++++*............+..+...+...+..........+...+..+...............+.............+..+...+....+...+..+............+...+...............+..........+..+......+.........+....+...............+..+.........+...+.+.....+.......+........+.+.....+...+.+.................+.......+.....+...+.............+............+........................+...+...+.....+....+.............................................+.....+.........+...................+.....+......+++++
-----
restorecon: SELinux: Could not get canonical path for /tmp/tmp3tynbnei/.mozilla/firefox/* restorecon: No such file or directory.
*** You are running in headless mode.
Warning no default label for /tmp/tmp3tynbnei/.mozilla/firefox/5hp74fd1.blank
Warning no default label for /tmp/tmp3tynbnei/.mozilla/firefox/profiles.ini
*** You are running in headless mode.
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.246978) [GFX1-]: glxtest: Unable to open a connection to the X server
WebDriver BiDi listening on ws://127.0.0.1:9351
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.246978) |[1][GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt (t=0.905018) [GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
DevTools listening on ws://127.0.0.1:9351/devtools/browser/fa701b9a-4176-4eb2-95f7-ae050b560866
CDP: {"source":"other","level":"error","text":"The resource from “http://localhost:9090/cockpit/@localhost/*/po.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).","timestamp":1696414511539,"url":"http://localhost:9090/machines","lineNumber":0}
CDP: {"source":"other","level":"error","text":"The resource from “http://localhost:9090/cockpit/@localhost/*/po.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).","timestamp":1696414511709,"url":"http://localhost:9090/machines","lineNumber":0}
CDP: {"source":"other","level":"warning","text":"Loading failed for the <script> with source “http://localhost:9090/cockpit/@localhost/*/po.js”.","timestamp":1696414511710,"url":"http://localhost:9090/machines","lineNumber":12}
> error: Scrollbar test exception: TypeError: document.body is null
> log: PackageKit went away from D-Bus
> warning: Server did not accept the resize request: Invalid screen layout
Traceback (most recent call last):
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 311, in testCreateCloudBaseImage
    runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 1886, in createCloudBaseImageTest
    .fill() \
     ^^^^^^
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 1304, in fill
    b.set_input_text(f"#create-vm-dialog-ssh-key-{idx} textarea", key, value_check=False, blur=False)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 537, in set_input_text
    self.key_press(val)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 472, in key_press
    self._key_press_firefox(keys, modifiers, use_ord)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 508, in _key_press_firefox
    args["key"] = keyMap[ord(key)]
                  ~~~~~~^^^^^^^^^^
KeyError: 10

Wrote screenshot to TestMachinesCreate-testCreateCloudBaseImage-fedora-39-localhost-22-FAIL.png
Wrote HTML dump to TestMachinesCreate-testCreateCloudBaseImage-fedora-39-localhost-22-FAIL.html
Wrote JS log to TestMachinesCreate-testCreateCloudBaseImage-fedora-39-localhost-22-FAIL.js.log
Journal extracted to TestMachinesCreate-testCreateCloudBaseImage-fedora-39-localhost-22-FAIL.log.gz
Warning: Stopping virtstoraged.service, but it can still be activated by:
  virtstoraged-admin.socket
  virtstoraged-ro.socket
  virtstoraged.socket
Warning: Stopping virtnetworkd.service, but it can still be activated by:
  virtnetworkd-ro.socket
  virtnetworkd.socket
  virtnetworkd-admin.socket
Warning: Stopping virtqemud.service, but it can still be activated by:
  virtqemud.socket
  virtqemud-admin.socket
  virtqemud-ro.socket
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Traceback (most recent call last):
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 311, in testCreateCloudBaseImage
    runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 1886, in createCloudBaseImageTest
    .fill() \
     ^^^^^^
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/check-machines-create", line 1304, in fill
    b.set_input_text(f"#create-vm-dialog-ssh-key-{idx} textarea", key, value_check=False, blur=False)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 537, in set_input_text
    self.key_press(val)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 472, in key_press
    self._key_press_firefox(keys, modifiers, use_ord)
  File "/var/ARTIFACTS/work-basicrxuv7x4x/plans/all/basic/discover/default-0/tests/test/common/testlib.py", line 508, in _key_press_firefox
    args["key"] = keyMap[ord(key)]
                  ~~~~~~^^^^^^^^^^
KeyError: 10

@skobyda
Copy link
Contributor Author

skobyda commented Oct 5, 2023

Note that this is an issue only for firefox

@skobyda skobyda requested a review from jelly October 5, 2023 08:30
13: "Enter", # Enter key
10: "Enter", # Enter key
Copy link
Member

Choose a reason for hiding this comment

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

13 is carriage return (enter key)
10 is not enter, but linefeed

The issue is the handling of CRLF.

See cockpit-project/cockpit-machines#1150 (comment)

Until now, we were mapping values of characters to their browser's
keycodes values [1]. This however is incorrect, since to get a value of
character, we use Python's 'ord' function, which returns character's
Unicode value.

In some cases, these values are different. For example, a value for
Enter has keycode '13' in browser [1], but Python's 'ord' will give us
value of '10' for a line feed character. [2]

[1] https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
[2] https://python-reference.readthedocs.io/en/latest/docs/str/ASCII.html
@martinpitt
Copy link
Member

Thanks! LGTM, but I'd really like to get a CI run -- and with that being down, we'll have to wait until tomorrow-ish I'm afraid 😢

@martinpitt martinpitt merged commit fffd442 into cockpit-project:main Oct 5, 2023
98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants