AtlatestRepositorysigil-ui

sigil-ui / tree / test / waylandservices.sgl

1;;; Protocol-only host services: private compositor, no desktop or clipboard.
2(import (sigil test) (sigil process) (sigil io) (sigil fs)
3 (sigil path) (sigil time) (sigil ui window) (sigil ui wayland))
4
5(define server (or (getenv "SIGIL_UI_CONFIGURE_SERVER") (error "Run scripts/test-wayland-configure.sgl")))
6(define folder (or (getenv "SIGIL_UI_CONFIGURE_ROOT") (error "Private fixture root is required")))
7(define sequence 0)
8(define (now) (/ (current-jiffy) (jiffies-per-second)))
9
10(define (with-window mode thunk)
11 (set! sequence (+ sequence 1))
12 (let* ((work (path-join folder (string-append "services-" (number->string sequence))))
13 (child #f) (window #f))
14 (make-directory work)
15 (process-output->string "chmod" "700" work)
16 (dynamic-wind
17 (lambda () #f)
18 (lambda ()
19 (set! child (process-spawn "env" "-u" "WAYLAND_DISPLAY" "-u" "DISPLAY"
20 (string-append "XDG_RUNTIME_DIR=" work) server mode
21 die-with-parent: #t err: (path-join work "server.log")))
22 (assert-equal "READY" (read-line (process-stdout child)))
23 (set! window (open-window display: (path-join work "configure-test")))
24 (window-dispatch window 0)
25 (thunk window))
26 (lambda ()
27 (when window (window-close! window))
28 (when child
29 (when (process-alive? child) (process-kill! child))
30 (process-wait child))))))
32(define (wait-terminal window)
33 (let loop ((events '()))
34 (if (eq? 'pending (window-fullscreen-status window))
35 (loop (append events (window-dispatch window #f)))
36 events)))
38(test "portable title accepts repeated UTF-8 metadata and unavailable clipboard refuses"
39 (with-window "services-grant"
40 (lambda (window)
41 (assert-true (window-set-title! window "Window — λ"))
42 (assert-true (window-set-title! window "Window — λ"))
43 (assert-false (wayland-set-title! window "Window — λ"))
44 (assert-error (window-set-title! window 42))
45 (assert-false (window-clipboard-read window))
46 (assert-false (window-clipboard-set! window ""))
47 (assert-equal 'idle (window-fullscreen-status window))
48 (assert-false (window-fullscreen? window)))))
50(test "fullscreen acknowledges enter and exit and preserves event-time status"
51 (with-window "services-grant"
52 (lambda (window)
53 (assert-true (window-set-fullscreen! window #t))
54 (assert-false (window-fullscreen? window))
55 (assert-equal 'pending (window-fullscreen-status window))
56 (assert-equal '((fullscreen #f pending) (fullscreen #t granted)) (wait-terminal window))
57 (assert-true (window-fullscreen? window))
58 (assert-true (window-set-fullscreen! window #f))
59 (assert-true (window-fullscreen? window))
60 (assert-equal '((fullscreen #t pending) (fullscreen #f granted)) (wait-terminal window))
61 (assert-false (window-fullscreen? window)))))
63(test "superseded replies do not grant the wrong requested state"
64 (with-window "services-grant"
65 (lambda (window)
66 (assert-true (window-set-fullscreen! window #t))
67 (assert-true (window-set-fullscreen! window #f))
68 (assert-equal '((fullscreen #f pending) (fullscreen #f pending)
69 (fullscreen #t pending) (fullscreen #f granted))
70 (wait-terminal window))
71 (assert-equal 'granted (window-fullscreen-status window)))))
73(test "an identical-state request still awaits an acknowledgment"
74 (with-window "services-grant"
75 (lambda (window)
76 (assert-true (window-set-fullscreen! window #f))
77 (assert-equal 'pending (window-fullscreen-status window))
78 (assert-equal '((fullscreen #f pending) (fullscreen #f granted)) (wait-terminal window)))))
80(for-each
81 (lambda (mode)
82 (test (string-append mode " wakes an indefinite dispatch with refusal at the original deadline")
83 (with-window mode
84 (lambda (window)
85 (let ((start (now)))
86 (assert-true (window-set-fullscreen! window #t))
87 (assert-equal '((fullscreen #f pending) (fullscreen #f refused)) (wait-terminal window))
88 (assert-true (>= (- (now) start) 4.8))
89 (assert-true (< (- (now) start) 6.5))
90 (assert-false (window-fullscreen? window))
91 (assert-equal 'refused (window-fullscreen-status window)))))))
92 '("services-refuse" "services-silent"))
94(test "all portable services fail cleanly after close while legacy errors remain"
95 (with-window "services-grant"
96 (lambda (window)
97 (window-close! window)
98 (assert-false (window-set-title! window "Closed"))
99 (assert-false (window-clipboard-read window))
100 (assert-false (window-clipboard-set! window ""))
101 (assert-false (window-fullscreen? window))
102 (assert-false (window-set-fullscreen! window #t))
103 (assert-equal 'refused (window-fullscreen-status window))
104 (assert-error (wayland-set-title! window "Closed")))))