e2e: the tooltip's vertical offset is computed by Firefox's own rule (kDefaultTooltipOffset scaled by the system cursor size on Windows), not typed as 21
This commit is contained in:
1 parent
c39a976a44
commit
3259840c7c
1 file changed
+30
-6
@@ -14,8 +14,11 @@ with the same box at (40, 40) of its document. For each of the two boxes:
|
||||
(after ``ui.tooltip.delay_ms``); the chrome window is focused first, because ``showTooltip`` shows nothing in a window that has no focus;
|
||||
* from chrome, the popup's real screen rectangle (``getOuterScreenRect()``) and the REAL screen position of the pointer are read, in CSS pixels of the chrome: the content-area
|
||||
rectangle of the ``<browser>`` plus the point in the page, converted with the chrome window's ``windowUtils.toScreenRectInCSSUnits`` (the widget as it really is);
|
||||
* Firefox opens an unanchored tooltip with its left at the pointer and its top ``LookAndFeel::TooltipOffsetVertical`` below it (``nsMenuPopupFrame::GetMargin``: 21 CSS pixels,
|
||||
more only if the system cursor size is not the default 32, which a CI runner has): the popup's left less the pointer's x is 0 and its top less the pointer's y is 21, each
|
||||
* Firefox opens an unanchored tooltip with its left at the pointer and its top ``LookAndFeel::TooltipOffsetVertical`` below it (``nsMenuPopupFrame::GetMargin``,
|
||||
layout/xul/nsMenuPopupFrame.cpp:2249). The offset is ``LookAndFeel::kDefaultTooltipOffset`` = 21 CSS pixels (widget/LookAndFeel.h:349); on Windows
|
||||
``GetTooltipOffsetVertical`` (widget/windows/nsLookAndFeel.cpp:43-51) makes it ceil(21 * cursor size / 32) when the system cursor size (SPI_GETCURSORSIZE, 0x2028) is
|
||||
not 32. The expected offset is computed from that rule (``tooltip_offset()``), so it holds for any cursor size: the popup's left less the pointer's x is 0 and its top
|
||||
less the pointer's y is that offset, each
|
||||
within two device pixels (the point is a device pixel and the popup's position is rounded once more), in the top document and in the frame alike.
|
||||
|
||||
RED WITHOUT THE TOOLTIP MAP. With the declared point opened as it is, the popup is at the pointer plus (declared window origin - real window origin) (and, in the frame, plus the
|
||||
@@ -27,6 +30,8 @@ The engine that answers these values is not released yet: this test is red on an
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import sys
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
import pytest
|
||||
@@ -36,8 +41,26 @@ from _window_origin import CASES, DEADLINE_S, launch_case, wait_for
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
MARIONETTE_ARGS = ["-marionette", "-remote-allow-system-access"]
|
||||
#: ``LookAndFeel::kDefaultTooltipOffset``: how far below the pointer an unanchored tooltip opens, CSS pixels.
|
||||
TOOLTIP_OFFSET = 21
|
||||
#: ``LookAndFeel::kDefaultTooltipOffset`` (widget/LookAndFeel.h:349): how far below the pointer an unanchored tooltip opens, CSS pixels, at the default cursor size.
|
||||
DEFAULT_TOOLTIP_OFFSET = 21
|
||||
#: ``kDefaultCursorSize`` of ``GetTooltipOffsetVertical`` (widget/windows/nsLookAndFeel.cpp:44).
|
||||
DEFAULT_CURSOR_SIZE = 32
|
||||
#: ``MOZ_SPI_CURSORSIZE`` (widget/windows/nsLookAndFeel.h:44).
|
||||
SPI_GETCURSORSIZE = 0x2028
|
||||
|
||||
|
||||
def tooltip_offset() -> int:
|
||||
"""The vertical tooltip offset Firefox computes on this host, by its own rule (widget/windows/nsLookAndFeel.cpp:43-51 on Windows; the default elsewhere)."""
|
||||
if sys.platform != "win32":
|
||||
return DEFAULT_TOOLTIP_OFFSET
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
size = wintypes.DWORD(DEFAULT_CURSOR_SIZE)
|
||||
if not ctypes.windll.user32.SystemParametersInfoW(SPI_GETCURSORSIZE, 0, ctypes.byref(size), 0):
|
||||
size = wintypes.DWORD(DEFAULT_CURSOR_SIZE)
|
||||
if size.value == DEFAULT_CURSOR_SIZE:
|
||||
return DEFAULT_TOOLTIP_OFFSET
|
||||
return math.ceil(DEFAULT_TOOLTIP_OFFSET * size.value / DEFAULT_CURSOR_SIZE)
|
||||
#: The box that has the title: 120x40 at (40, 40) of its document.
|
||||
BOX = (40, 40, 120, 40)
|
||||
#: Where the mouse waits before it comes onto the box, in the top document.
|
||||
@@ -146,10 +169,11 @@ def test_a_tooltip_opens_at_the_pointer(firefox_binary, monkeypatch, case):
|
||||
if marionette is not None:
|
||||
marionette.close()
|
||||
|
||||
offset = tooltip_offset()
|
||||
for name, read in reads.items():
|
||||
tolerance = 2.0 / read["dpr"] + 0.01
|
||||
dx, dy = _offset(read)
|
||||
assert abs(dx) <= tolerance and abs(dy - TOOLTIP_OFFSET) <= tolerance, (
|
||||
assert abs(dx) <= tolerance and abs(dy - offset) <= tolerance, (
|
||||
"%s, %s document: the tooltip opened at (left %r, top %r) on the real screen and the real pointer is at (%r, %r): it is (%r, %r) from the pointer, Firefox opens it at (0, %d), "
|
||||
"each within %r CSS pixels of the chrome (popup %r)"
|
||||
% (case, name, read["popup"]["left"], read["popup"]["top"], read["pointer"]["x"], read["pointer"]["y"], dx, dy, TOOLTIP_OFFSET, tolerance, read["popup"]))
|
||||
% (case, name, read["popup"]["left"], read["popup"]["top"], read["pointer"]["x"], read["pointer"]["y"], dx, dy, offset, tolerance, read["popup"]))
|
||||
Reference in new issue
Block a user