test_gnome.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. """GNOME on Wayland via the Shell extension: desktop window, per monitor pause, desktop menu, extension removal."""
  2. import time
  3. from pathlib import Path
  4. import pytest
  5. from conftest import REPO, changed_fraction
  6. from desktops.runner import terminate
  7. UUID = "linux-wallpaperengine@wallpaperenginelover.github.io"
  8. WALLPAPER = "global.get_window_actors().map(a => a.meta_window).find(w => w.get_wm_class() === 'linux-wallpaperengine')"
  9. POINTER = ("const C = imports.gi.Clutter, G = imports.gi.GLib;"
  10. "if (!global._lweLabPointer) global._lweLabPointer = C.get_default_backend().get_default_seat()"
  11. ".create_virtual_device(C.InputDeviceType.POINTER_DEVICE);"
  12. "const pointer = global._lweLabPointer, now = () => G.get_monotonic_time();")
  13. CLICK_PROBE = REPO / "tests/desktops/fixtures/clickprobe"
  14. def _engine(desktop, engine, log, *extra, wallpaper=None):
  15. return desktop.client([engine["binary"], "--assets-dir", engine["assets"], "--screen-root",
  16. desktop.output_names()[0], "--silent", "--fps", "30", *extra,
  17. str(wallpaper or engine["wallpaper"])],
  18. log=log, env={"LWE_FRAME_STATS": "1", "LWE_SCRIPT_LOG": "1"})
  19. def _point(desktop, x, y):
  20. """moves the lab's virtual pointer, again until the Shell has it (it sometimes keeps an older position)"""
  21. # the hot corner at the start position opens the overview
  22. desktop.eval(POINTER + f"pointer.notify_absolute_motion(now(), {x}, {y}); 1")
  23. time.sleep(0.5)
  24. desktop.eval("Main.overview.hide(); 1")
  25. time.sleep(0.5)
  26. for _ in range(20):
  27. desktop.eval(POINTER + f"pointer.notify_absolute_motion(now(), {x}, {y}); 1")
  28. time.sleep(0.25)
  29. if desktop.eval("global.get_pointer().slice(0, 2).join(',')") == f'"{x},{y}"':
  30. return
  31. raise AssertionError(f"the virtual pointer never got to {x},{y}")
  32. def _click(desktop, button=1):
  33. desktop.eval(POINTER + f"pointer.notify_button(now(), {button}, C.ButtonState.PRESSED); 1")
  34. time.sleep(0.3)
  35. desktop.eval(POINTER + f"pointer.notify_button(now(), {button}, C.ButtonState.RELEASED); 1")
  36. def _frame_lines(log):
  37. return Path(log).read_text(errors="replace").count("FRAME-STATS")
  38. def _window(desktop, mode, name=None):
  39. """a GTK probe window, focused like a user would: Mutter maps it without the focus when the session never saw
  40. any input (focus stealing prevention), and WE counts only the focused window as fullscreen"""
  41. process = desktop.spawn(name or f"{mode}-probe", ["python3", str(REPO / "tools/desktops/wayland_window.py"), mode])
  42. title = f"lwe-{mode}-probe"
  43. for _ in range(40):
  44. time.sleep(0.25)
  45. if desktop.eval(f"const w = global.display.list_all_windows().find(w => w.get_title() === '{title}');"
  46. "if (w) w.activate(global.display.get_current_time_roundtrip()); !!w") == "true":
  47. break
  48. return process
  49. def _renders(log, seconds=5):
  50. before = _frame_lines(log)
  51. time.sleep(seconds)
  52. return _frame_lines(log) > before
  53. # 49/50: Meta.Window.set_type, 46-48: helper's Meta.WaylandClient, 45: bottom normal-layer window
  54. @pytest.fixture(params=["gnome", "gnome49", "gnome48", "gnome47", "gnome46", "gnome45"])
  55. def gnome(request, desktop_factory):
  56. return desktop_factory(request.param)
  57. def test_wallpaper_is_a_desktop_window(gnome, engine, tmp_path):
  58. process = _engine(gnome, engine, tmp_path / "engine.log")
  59. try:
  60. time.sleep(8)
  61. assert process.poll() is None, (tmp_path / "engine.log").read_text()[-1500:]
  62. state = gnome.eval(f"const w = {WALLPAPER}; const r = w.get_frame_rect();"
  63. "[w.get_window_type(), w.skip_taskbar, w.is_fullscreen(), r.width, r.height].join(',')")
  64. width, height = gnome.size
  65. if gnome.name == "gnome45":
  66. # 45: normal window hidden from the window lists, kept in the work area
  67. window_type, skip, fullscreen, frame_width, frame_height = state.strip('"').split(",")
  68. assert (window_type, skip, fullscreen, frame_width) == ("0", "true", "false", str(width))
  69. assert int(frame_height) >= height - 64
  70. else:
  71. # Meta.WindowType.DESKTOP
  72. assert state == f'"1,true,false,{width},{height}"'
  73. assert gnome.eval("global.display.get_monitor_in_fullscreen(0)") == "false"
  74. assert gnome.eval("Shell.AppSystem.get_default().get_running().length") == "0"
  75. finally:
  76. process.terminate()
  77. process.wait(10)
  78. @pytest.mark.parametrize("mode", ["maximized", "fullscreen"])
  79. def test_covering_window_pauses_rendering(gnome, engine, tmp_path, mode):
  80. log = tmp_path / "engine.log"
  81. process = _engine(gnome, engine, log)
  82. probe = None
  83. try:
  84. time.sleep(8)
  85. assert _renders(log), "the engine does not render on GNOME"
  86. probe = _window(gnome, mode)
  87. time.sleep(4)
  88. assert not _renders(log), f"still rendering under a {mode} window"
  89. terminate([probe.pid])
  90. probe = None
  91. time.sleep(4)
  92. assert _renders(log), f"rendering did not resume after the {mode} window"
  93. normal = _window(gnome, "normal")
  94. try:
  95. time.sleep(4)
  96. assert _renders(log), "a plain window paused the wallpaper"
  97. finally:
  98. terminate([normal.pid])
  99. finally:
  100. if probe is not None:
  101. terminate([probe.pid])
  102. process.terminate()
  103. process.wait(10)
  104. def test_desktop_menu_opens_over_the_wallpaper(gnome, engine, tmp_path):
  105. process = _engine(gnome, engine, tmp_path / "engine.log")
  106. try:
  107. width, height = gnome.size
  108. gnome.eval(POINTER + f"pointer.notify_absolute_motion(now(), {width // 2}, {height // 2}); 1")
  109. time.sleep(0.5)
  110. gnome.eval("Main.overview.hide(); 1")
  111. time.sleep(8)
  112. # the lab pointer sometimes lags, resend until the Shell has it
  113. target = f"{width // 2},{height // 2}"
  114. for _ in range(20):
  115. gnome.eval(POINTER + f"pointer.notify_absolute_motion(now(), {width // 2}, {height // 2}); 1")
  116. time.sleep(0.25)
  117. if gnome.eval("global.get_pointer().slice(0, 2).join(',')") == f'"{target}"':
  118. break
  119. gnome.shot(tmp_path / "before.png")
  120. gnome.eval(POINTER + "pointer.notify_button(now(), 3, C.ButtonState.PRESSED);"
  121. "pointer.notify_button(now() + 20000, 3, C.ButtonState.RELEASED); 1")
  122. time.sleep(2)
  123. opened = gnome.eval("Main.layoutManager._bgManagers.some(m => m.backgroundActor._backgroundMenu?.isOpen)")
  124. gnome.shot(tmp_path / "after.png")
  125. gnome.eval("Main.layoutManager._bgManagers.forEach(m => m.backgroundActor._backgroundMenu?.close()); 1")
  126. assert opened == "true", "a right click on the wallpaper did not reach GNOME's desktop menu"
  127. assert changed_fraction(tmp_path / "before.png", tmp_path / "after.png") > 0.01
  128. finally:
  129. process.terminate()
  130. process.wait(10)
  131. def test_engine_stops_without_the_extension(gnome, engine, tmp_path):
  132. log = tmp_path / "engine.log"
  133. process = _engine(gnome, engine, log)
  134. try:
  135. time.sleep(6)
  136. assert process.poll() is None
  137. gnome.run(["gnome-extensions", "disable", UUID])
  138. process.wait(10)
  139. assert "GNOME Shell extension went away" in log.read_text(errors="replace")
  140. deadline = time.monotonic() + 10
  141. while gnome.eval(f"!!{WALLPAPER}") != "false" and time.monotonic() < deadline:
  142. time.sleep(0.5)
  143. assert gnome.eval(f"!!{WALLPAPER}") == "false", "the wallpaper window outlived the extension"
  144. refused = _engine(gnome, engine, tmp_path / "refused.log")
  145. code = refused.wait(20)
  146. # a signal exit (abort) fails too
  147. assert 0 < code < 128, f"the engine exited with {code} instead of an error"
  148. assert "without the GNOME Shell extension" in (tmp_path / "refused.log").read_text(errors="replace")
  149. finally:
  150. gnome.run(["gnome-extensions", "enable", UUID])
  151. if process.poll() is None:
  152. process.terminate()
  153. process.wait(10)
  154. def test_wallpaper_survives_a_close_request(gnome, engine, tmp_path):
  155. """Alt+F4 on a focused wallpaper (45 keeps it a normal window) must not remove it"""
  156. log = tmp_path / "engine.log"
  157. process = _engine(gnome, engine, log)
  158. try:
  159. time.sleep(8)
  160. assert _renders(log), "the engine does not render on GNOME"
  161. gnome.eval(f"{WALLPAPER}.delete(global.display.get_current_time_roundtrip()); 1")
  162. time.sleep(2)
  163. assert process.poll() is None, "the engine stopped on a close request"
  164. assert gnome.eval(f"!!{WALLPAPER}") == "true", "the wallpaper window is gone"
  165. assert _renders(log), "the wallpaper stopped rendering after a close request"
  166. finally:
  167. process.terminate()
  168. process.wait(10)
  169. def test_overview_shows_the_live_wallpaper(gnome, engine, tmp_path):
  170. log = tmp_path / "engine.log"
  171. gnome.eval("Main.overview.show(); 1")
  172. time.sleep(3)
  173. gnome.shot(tmp_path / "bare.png")
  174. gnome.eval("Main.overview.hide(); 1")
  175. time.sleep(2)
  176. process = _engine(gnome, engine, log)
  177. try:
  178. time.sleep(8)
  179. gnome.eval("Main.overview.show(); 1")
  180. time.sleep(3)
  181. gnome.shot(tmp_path / "overview.png")
  182. # only the clones keep frame callbacks coming in the overview
  183. assert _renders(log), "the wallpaper stopped rendering in the overview"
  184. assert changed_fraction(tmp_path / "bare.png", tmp_path / "overview.png") > 0.2, \
  185. "the overview still shows GNOME's own background"
  186. finally:
  187. gnome.eval("Main.overview.hide(); 1")
  188. process.terminate()
  189. process.wait(10)
  190. def test_focused_window_pauses_with_pause_on_focus(gnome, engine, tmp_path):
  191. log = tmp_path / "engine.log"
  192. process = _engine(gnome, engine, log, "--pause-on-focus")
  193. probe = None
  194. try:
  195. time.sleep(8)
  196. assert _renders(log), "the engine does not render on GNOME"
  197. probe = _window(gnome, "normal", "focus-probe")
  198. time.sleep(4)
  199. assert not _renders(log), "--pause-on-focus kept rendering while another application had the focus"
  200. terminate([probe.pid])
  201. probe = None
  202. time.sleep(4)
  203. assert _renders(log), "rendering did not resume once the focused window was gone"
  204. finally:
  205. if probe is not None:
  206. terminate([probe.pid])
  207. process.terminate()
  208. process.wait(10)
  209. # DING: own desktop window on GNOME 50, bottom-layer normal one on Ubuntu 46
  210. @pytest.fixture(params=["gnome-ding", "gnome46-ding", "gnome45-ding"])
  211. def ding(request, desktop_factory):
  212. return desktop_factory(request.param)
  213. def test_wallpaper_stays_under_desktop_icons(ding, engine, tmp_path):
  214. log = tmp_path / "engine.log"
  215. process = _engine(ding, engine, log, "--pause-on-focus", wallpaper=CLICK_PROBE)
  216. try:
  217. time.sleep(8)
  218. order = ding.eval("global.display.sort_windows_by_stacking(global.display.list_all_windows())"
  219. ".map(w => w.get_gtk_application_id() || w.get_wm_class()).join('|')").strip('"').split("|")
  220. icons = order.index("com.rastersoft.ding")
  221. wallpaper = order.index("linux-wallpaperengine")
  222. assert wallpaper < icons, f"the wallpaper is above the desktop icons: {order}"
  223. # WE counts the icon view as the desktop: clicks reach the wallpaper, focusing it isn't another app
  224. width, height = ding.size
  225. _point(ding, width // 2, height // 2)
  226. _click(ding)
  227. time.sleep(1.5)
  228. text = log.read_text(errors="replace")
  229. assert "LWE-CLICK down" in text and "LWE-CLICK up" in text, "the click on the desktop never reached the wallpaper"
  230. assert ding.eval("global.display.focus_window?.get_gtk_application_id() ?? ''") == '"com.rastersoft.ding"'
  231. assert _renders(log), "focusing the desktop icons paused the wallpaper"
  232. finally:
  233. process.terminate()
  234. process.wait(10)