Skip to content

Commit

Permalink
test: Use real mouse events with Chromium in the shell
Browse files Browse the repository at this point in the history
BiDi mouse events work fine on the top-level document (i.e. not in
frames). So let's use them to test the shell.

Generalize the "move mouse position to a harmless place" hack from
commit b5b8c6d, so that we make the pixel snapshots without
focusing a random element on the page.

We can also run `TestPages.testPageStatus` again (reverts commit
529e334).

This just needs one little tweak in TestHostSwitching.testBasic's pixel
test. Our current reference does not expect any dialog item to be
highlighted (when the mouse is over it), so move the mouse out of the
dialog.
  • Loading branch information
martinpitt committed Dec 11, 2024
1 parent ac435cd commit 7ba1bd2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
12 changes: 10 additions & 2 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ def mouse(
# HACK: Chromium clicks don't work with iframes; use our old "synthesize MouseEvent" approach
# https://issues.chromium.org/issues/359616812
# TODO: x and y are not currently implemented: webdriver (0, 0) is the element's center, not top left corner
if self.browser == "chromium" or x != 0 or y != 0:
if (self.browser == "chromium" and not self.driver.in_top_context()) or x != 0 or y != 0:
self.call_js_func('ph_mouse', selector, event, x, y, btn, ctrlKey, shiftKey, altKey, metaKey)
return

# For Firefox and regular clicks, use the BiDi API, which is more realistic -- it doesn't
# For Firefox and top frame with Chromium, use the BiDi API, which is more realistic -- it doesn't
# sidestep the browser
element = self.call_js_func('ph_find_scroll_into_view' if scrollVisible else 'ph_find', selector)

Expand Down Expand Up @@ -1479,6 +1479,14 @@ def assert_pixels(
if "pf-v5-c-page__main" in classes:
self.set_attr("main.pf-v5-c-page__main", "class", f"{classes} pixel-test")

# move the mouse to a harmless place where it doesn't accidentally focus anything (as that changes UI)
self.bidi("input.performActions", context=self.driver.context, actions=[{
"id": "move-away",
"type": "pointer",
"parameters": {"pointerType": "mouse"},
"actions": [{"type": "pointerMove", "x": 2000, "y": 0, "origin": "viewport"}]
}])

if self.current_layout:
previous_layout = self.current_layout["name"]
for layout in self.layouts:
Expand Down
3 changes: 3 additions & 0 deletions test/common/webdriver_bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def switch_to_top(self) -> None:
self.context = self.top_context
log_command.info("← switch_to_top")

def in_top_context(self) -> bool:
return self.context == self.top_context

@contextlib.contextmanager
def restore_context(self) -> Iterator[None]:
saved = self.context
Expand Down
1 change: 0 additions & 1 deletion test/verify/check-pages
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ OnCalendar=daily
with b.wait_timeout(60):
b.wait_js_func("ph_plot_data_plateau", "pmcd", mem_avail * 0.85, mem_avail * 1.15, 15, "mem")

@testlib.skipBrowser("Headless chromium is missing the synthetic mouseenter", "chromium")
def testPageStatus(self):
b = self.browser

Expand Down
10 changes: 2 additions & 8 deletions test/verify/check-shell-host-switching
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers):
b.wait_not_present("#nav-system.interact")
b.set_layout("desktop")

# this looks different (focused) when the mouse is inside (default 0,0 possition), so move it away
# chromium is stubborn here, we *have* to move the real mouse, not just do this with synthetic MouseEvents
b.bidi("input.performActions", context=b.driver.context, actions=[{
"id": "move-away",
"type": "pointer",
"parameters": {"pointerType": "mouse"},
"actions": [{"type": "pointerMove", "x": 200, "y": 200, "origin": "viewport"}]
}])
b.assert_pixels("#hosts-sel", "hosts-sel-closed")

self.open_host_switcher()
Expand Down Expand Up @@ -237,6 +229,8 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers):
b.wait_in_text('#hosts_setup_server_dialog', "Unable to contact the given host 10.111.113.2:4321. Make sure it has ssh running on port 4321, or specify another port in the address.")
# Now do it right
b.set_input_text('#add-machine-address', "10.111.113.2")
# move the mouse away to avoid highlighting any UI element (pixel ref does not expect that)
b.mouse("#hosts-sel", "mouseenter")
b.assert_pixels("#hosts_setup_server_dialog", "host-add-dialog")
b.click('#hosts_setup_server_dialog .pf-m-primary:contains("Add")')
b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.2 for the first time")
Expand Down

0 comments on commit 7ba1bd2

Please sign in to comment.