Skip to content

Commit 5666b29

Browse files
committed
test: Try to fix tests for window size
Purely focusing on getting existing tests to pass by assuming that the secondary size will always be 100% (which is how it used to work).
1 parent 01a5dc4 commit 5666b29

File tree

1 file changed

+58
-15
lines changed

1 file changed

+58
-15
lines changed

test/test_extension.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22
import contextlib
3+
import dataclasses
34
import enum
45
import functools
56
import logging.handlers
@@ -90,21 +91,21 @@ def resize_point(frame_rect, window_pos):
9091

9192
def compute_target_rect(size, pos, monitor):
9293
x, y, width, height = monitor.workarea
94+
window_size = WindowSize.get_maximized_size_from_position(size, pos)
9395

9496
round_to = int(monitor.scale)
9597

96-
if pos in [WindowPosition.TOP, WindowPosition.BOTTOM]:
97-
height *= size
98-
height -= height % round_to
98+
height *= window_size.height
99+
height -= height % round_to
99100

100-
if pos == WindowPosition.BOTTOM:
101-
y += monitor.workarea.height - height
102-
else:
103-
width *= size
104-
width -= width % round_to
101+
if pos == WindowPosition.BOTTOM:
102+
y += monitor.workarea.height - height
105103

106-
if pos == WindowPosition.RIGHT:
107-
x += monitor.workarea.width - width
104+
width *= window_size.width
105+
width -= width % round_to
106+
107+
if pos == WindowPosition.RIGHT:
108+
x += monitor.workarea.width - width
108109

109110
return Rect(x, y, width, height)
110111

@@ -139,6 +140,41 @@ def verify_window_geometry(test_interface, size, maximize, pos, monitor):
139140
else:
140141
assert actual_frame_rect == target_rect_unmaximized
141142

143+
@dataclasses.dataclass
144+
class WindowSize:
145+
width: float
146+
height: float
147+
position: WindowPosition
148+
149+
_HORIZONTAL_SIZE_POSITIONS = [WindowPosition.TOP, WindowPosition.BOTTOM]
150+
151+
def get_primary_size(self) -> float:
152+
return self.width if self.position in self._HORIZONTAL_SIZE_POSITIONS else self.height
153+
154+
@classmethod
155+
def get_primary_size_setting(cls, position: WindowPosition) -> str:
156+
return "window-hsize" if position in cls._HORIZONTAL_SIZE_POSITIONS else "window-vsize"
157+
158+
@classmethod
159+
def get_maximized_size_from_position(cls, primary_size: float, position: WindowPosition) -> "WindowSize":
160+
"""
161+
Get window horizontal/vertical size based on the given position.
162+
163+
On top/bottom positions, primary size is horizontal.
164+
On left/right positions, primary size is vertical.
165+
166+
This is a simplified helper to get a secondary size set to 100% for now, until tests
167+
are updated/added to support secondary size as well.
168+
"""
169+
if position in cls._HORIZONTAL_SIZE_POSITIONS:
170+
height = primary_size
171+
width = 1.0
172+
else:
173+
height = 1.0
174+
width = primary_size
175+
176+
return WindowSize(width=width, height=height, position=position)
177+
142178

143179
@contextlib.contextmanager
144180
def wait_move_resize(
@@ -510,7 +546,10 @@ def test_show(self, test_api, monitor_config, window_pos, window_size, window_ma
510546
window_monitor = test_api.layout.resolve_monitor(monitor_config)
511547
prev_maximize = test_api.settings.get('window-maximize')
512548

513-
test_api.settings.set_double('window-size', window_size)
549+
window_size_object = WindowSize.get_maximized_size_from_position(window_size, window_pos)
550+
test_api.settings.set_double('window-hsize', window_size_object.width)
551+
test_api.settings.set_double('window-vsize', window_size_object.height)
552+
514553
test_api.settings.set_string('window-position', window_pos)
515554
test_api.settings.set_string('window-monitor', monitor_config.setting)
516555
test_api.settings.set_boolean(
@@ -622,8 +661,9 @@ def test_mouse_resize(
622661
test_api.mouse_sim.button(False)
623662

624663
with glib_util.SignalWait(test_api.dbus, 'g-signal') as wait3:
664+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
625665
while compute_target_rect(
626-
size=test_api.settings.get('window-size'),
666+
size=test_api.settings.get(window_size_setting),
627667
pos=window_pos,
628668
monitor=monitor
629669
) != target_frame_rect:
@@ -708,7 +748,8 @@ def test_unmaximize_correct_size(
708748
window_pos,
709749
monitor,
710750
) as wait1:
711-
test_api.settings.set_double('window-size', window_size2)
751+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
752+
test_api.settings.set_double(window_size_setting, window_size2)
712753
wait1()
713754

714755
with wait_move_resize(
@@ -756,7 +797,8 @@ def test_unmaximize_on_size_change(
756797
window_pos,
757798
monitor,
758799
) as wait:
759-
test_api.settings.set_double('window-size', window_size2)
800+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
801+
test_api.settings.set_double(window_size_setting, window_size2)
760802
wait()
761803

762804
PARAM_TYPES = {
@@ -820,7 +862,8 @@ def test_dark_mode(self, test_api, container, shell_dbus_api, x11_display):
820862

821863
glib_util.flush_main_loop()
822864

823-
test_api.settings.set_double('window-size', 1)
865+
test_api.settings.set_double('window-hsize', 1)
866+
test_api.settings.set_double('window-vsize', 1)
824867
test_api.settings.set_string('window-position', WindowPosition.TOP)
825868
test_api.settings.set_string('window-monitor', MonitorSetting.PRIMARY)
826869
test_api.settings.set_boolean('window-maximize', True)

0 commit comments

Comments
 (0)