Skip to content

Commit 62df5a5

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 62df5a5

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

test/test_extension.py

Lines changed: 62 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

@@ -140,6 +141,45 @@ def verify_window_geometry(test_interface, size, maximize, pos, monitor):
140141
assert actual_frame_rect == target_rect_unmaximized
141142

142143

144+
@dataclasses.dataclass
145+
class WindowSize:
146+
width: float
147+
height: float
148+
position: WindowPosition
149+
150+
_HORIZONTAL_SIZE_POSITIONS = [WindowPosition.TOP, WindowPosition.BOTTOM]
151+
152+
def get_primary_size(self) -> float:
153+
return self.width if self.position in self._HORIZONTAL_SIZE_POSITIONS else self.height
154+
155+
@classmethod
156+
def get_primary_size_setting(cls, position: WindowPosition) -> str:
157+
return "window-hsize" if position in cls._HORIZONTAL_SIZE_POSITIONS else "window-vsize"
158+
159+
@classmethod
160+
def get_maximized_size_from_position(
161+
cls,
162+
primary_size: float,
163+
position: WindowPosition) -> "WindowSize":
164+
"""
165+
Get window horizontal/vertical size based on the given position.
166+
167+
On top/bottom positions, primary size is horizontal.
168+
On left/right positions, primary size is vertical.
169+
170+
This is a simplified helper to get a secondary size set to 100% for now, until tests
171+
are updated/added to support secondary size as well.
172+
"""
173+
if position in cls._HORIZONTAL_SIZE_POSITIONS:
174+
height = primary_size
175+
width = 1.0
176+
else:
177+
height = 1.0
178+
width = primary_size
179+
180+
return WindowSize(width=width, height=height, position=position)
181+
182+
143183
@contextlib.contextmanager
144184
def wait_move_resize(
145185
test_interface,
@@ -510,7 +550,10 @@ def test_show(self, test_api, monitor_config, window_pos, window_size, window_ma
510550
window_monitor = test_api.layout.resolve_monitor(monitor_config)
511551
prev_maximize = test_api.settings.get('window-maximize')
512552

513-
test_api.settings.set_double('window-size', window_size)
553+
window_size_object = WindowSize.get_maximized_size_from_position(window_size, window_pos)
554+
test_api.settings.set_double('window-hsize', window_size_object.width)
555+
test_api.settings.set_double('window-vsize', window_size_object.height)
556+
514557
test_api.settings.set_string('window-position', window_pos)
515558
test_api.settings.set_string('window-monitor', monitor_config.setting)
516559
test_api.settings.set_boolean(
@@ -622,8 +665,9 @@ def test_mouse_resize(
622665
test_api.mouse_sim.button(False)
623666

624667
with glib_util.SignalWait(test_api.dbus, 'g-signal') as wait3:
668+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
625669
while compute_target_rect(
626-
size=test_api.settings.get('window-size'),
670+
size=test_api.settings.get(window_size_setting),
627671
pos=window_pos,
628672
monitor=monitor
629673
) != target_frame_rect:
@@ -708,7 +752,8 @@ def test_unmaximize_correct_size(
708752
window_pos,
709753
monitor,
710754
) as wait1:
711-
test_api.settings.set_double('window-size', window_size2)
755+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
756+
test_api.settings.set_double(window_size_setting, window_size2)
712757
wait1()
713758

714759
with wait_move_resize(
@@ -756,7 +801,8 @@ def test_unmaximize_on_size_change(
756801
window_pos,
757802
monitor,
758803
) as wait:
759-
test_api.settings.set_double('window-size', window_size2)
804+
window_size_setting = WindowSize.get_primary_size_setting(window_pos)
805+
test_api.settings.set_double(window_size_setting, window_size2)
760806
wait()
761807

762808
PARAM_TYPES = {
@@ -820,7 +866,8 @@ def test_dark_mode(self, test_api, container, shell_dbus_api, x11_display):
820866

821867
glib_util.flush_main_loop()
822868

823-
test_api.settings.set_double('window-size', 1)
869+
test_api.settings.set_double('window-hsize', 1)
870+
test_api.settings.set_double('window-vsize', 1)
824871
test_api.settings.set_string('window-position', WindowPosition.TOP)
825872
test_api.settings.set_string('window-monitor', MonitorSetting.PRIMARY)
826873
test_api.settings.set_boolean('window-maximize', True)

0 commit comments

Comments
 (0)