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

Add scaling tests #140

Merged
merged 19 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mir-ci/mir_ci/tests/robot/platforms/wayland/WaylandHid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def __init__(self) -> None:
display_name = os.environ.get("WAYLAND_DISPLAY", "wayland-0")
super().__init__(display_name)

@keyword
async def set_output_scale(self, output_scale: float) -> None:
self.output_scale = output_scale

@keyword
async def move_pointer_to_absolute(self, x: int, y: int) -> None:
await self.connect()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions mir-ci/mir_ci/tests/robot/suites/scale/scale.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*** Settings ***
Resource ${KVM_RESOURCE}

Suite Setup Suite Setup
Test Setup Set Output Scale ${SCALE}


*** Variables ***
${T} ${CURDIR}
${SCREENSHOT} ${T}/${SCALE}-gtk4-demo-screenshot.png
${DEMO-APP-TITLE} ${T}/${SCALE}-gtk4-demo-title-main.png
${DEMO-APP-TITLE-HALF} ${T}/${SCALE}-gtk4-demo-title-main-half.png
${BUTTON} ${T}/${SCALE}-gtk4-demo-button.png
${TITLE} ${T}/${SCALE}-gtk4-demo-title.png


*** Test Cases ***
Ensure Scaling Is Visually Correct
Move Pointer To Proportional (1.0, 1.0)

Match ${SCREENSHOT}

Click Button With Scaling Enabled
Walk Pointer To ${BUTTON}
Click LEFT Button

Match ${TITLE}


*** Keywords ***
Suite Setup
Set Output Scale ${SCALE}
# Work around https://github.com/canonical/mir/issues/3553
${aligned}= Run Keyword And Return Status
... Walk Pointer To ${DEMO-APP-TITLE}
IF ${aligned} == False Walk Pointer To ${DEMO-APP-TITLE-HALF}
Click LEFT Button
Click LEFT Button
85 changes: 85 additions & 0 deletions mir-ci/mir_ci/tests/test_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import itertools
from pathlib import Path
from textwrap import dedent
from typing import Collection

import pytest
from mir_ci import VARIANT
from mir_ci.fixtures.servers import ServerCap, servers
from mir_ci.program.app import App, AppType
from mir_ci.program.display_server import DisplayServer

TESTS_PATH = Path(__file__).parent
APP_PATH = "gtk4-demo"
ROBOT_PATH = TESTS_PATH / "robot"


def collect_asset(asset: Path, variant):
variants = reversed((variant, *variant.parents[:-1]))
return itertools.chain(
asset.glob("*"),
*((asset / "variants" / v).glob("*") for v in variants),
)


def collect_assets(platform: str, resources: Collection[str], suite: str, variant: Path = VARIANT):
return {
p.name: p
for p in itertools.chain(
collect_asset(ROBOT_PATH / "platforms" / platform, variant),
*(collect_asset(ROBOT_PATH / "resources" / resource, variant) for resource in resources),
collect_asset(ROBOT_PATH / "suites" / suite, variant),
)
if p.is_file()
}


@pytest.mark.xdg(
XDG_CONFIG_HOME={
"glib-2.0/settings/keyfile": dedent(
"""\
[org/gnome/desktop/interface]
color-scheme='prefer-light'
gtk-theme='Adwaita'
icon-theme='Adwaita'
font-name='Ubuntu 11'
cursor-theme='Adwaita'
cursor-size=24
font-antialiasing='grayscale'
"""
),
},
)
@pytest.mark.env(GSETTINGS_BACKEND="keyfile")
@pytest.mark.parametrize("server", servers(ServerCap.DISPLAY_CONFIG))
@pytest.mark.parametrize("scale", [1.0, 1.5, 2.0])
@pytest.mark.deps(
debs=("gtk-4-examples",),
pip_pkgs=(
("pygobject", "gi"),
("robotframework~=6.1.1", "robot"),
("rpaframework", "RPA"),
("rpaframework-recognition", "RPA.recognition"),
),
)
class TestScale:
async def test_scale(self, robot_log, server, scale, tmp_path) -> None:
extensions = ("all",) # TODO no need to enable all extension

server_instance = DisplayServer(
server,
add_extensions=extensions,
env={"MIR_SERVER_X11_OUTPUT": "1024x768", "MIR_SERVER_DISPLAY_SCALE": str(scale)},
)

assets = collect_assets("wayland", ["kvm"], "scale")

async with server_instance, server_instance.program(App(APP_PATH, AppType.deb)):
tuple((tmp_path / k).symlink_to(v) for k, v in assets.items())

robot = server_instance.program(
App(("robot", "-d", tmp_path, "--log", robot_log, "--variable", f"SCALE:{scale}", tmp_path))
)

async with robot:
await robot.wait(120)
8 changes: 5 additions & 3 deletions mir-ci/mir_ci/wayland/virtual_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class VirtualPointer(WaylandClient):
required_extensions = (ZwlrVirtualPointerManagerV1.name, ZxdgOutputManagerV1.name)

def __init__(self, display_name: str) -> None:
def __init__(self, display_name: str, output_scale=1.0) -> None:
super().__init__(display_name)
self.pointer_manager: Optional[ZwlrVirtualPointerManagerV1Proxy] = None
self.pointer: Optional[ZwlrVirtualPointerV1Proxy] = None
Expand All @@ -29,6 +29,7 @@
self.xdg_outputs: List[ZxdgOutputV1Proxy] = []
self.output_width = 0
self.output_height = 0
self.output_scale = output_scale

Check warning on line 32 in mir-ci/mir_ci/wayland/virtual_pointer.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/wayland/virtual_pointer.py#L32

Added line #L32 was not covered by tests

def registry_global(self, registry, id_num: int, iface_name: str, version: int) -> None:
if iface_name == ZwlrVirtualPointerManagerV1.name:
Expand All @@ -53,9 +54,10 @@
pass

def xdg_output_logical_size(self, xdg_output, width: int, height: int) -> None:
# Whenever the logical size changes, we update the cached physical size
Saviq marked this conversation as resolved.
Show resolved Hide resolved
if xdg_output == self.xdg_outputs[0]:
self.output_width = width
self.output_height = height
self.output_width = int(width * self.output_scale)
self.output_height = int(height * self.output_scale)

Check warning on line 60 in mir-ci/mir_ci/wayland/virtual_pointer.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/wayland/virtual_pointer.py#L59-L60

Added lines #L59 - L60 were not covered by tests

def move_to_absolute(self, x: float, y: float) -> None:
assert self.output_width > 0, "Output width must be greater than 0"
Expand Down
Loading