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.

This gets rid of the recent TestHostSwitching mouse move hack (reverts
commit b5b8c6d), and we can also run `TestPages.testPageStatus`
again (reverts commit 529e334).
  • Loading branch information
martinpitt committed Dec 10, 2024
1 parent 54e5094 commit 18e9f45
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
4 changes: 2 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
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
8 changes: 0 additions & 8 deletions test/verify/check-shell-host-switching
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,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")

b.click("#hosts-sel button")
Expand Down

0 comments on commit 18e9f45

Please sign in to comment.