capture_workspace_e2e_test.go RawHistoryFolder
1package core_test
2
3import (
4 "testing"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9// configureOf returns the next ConfigureWindow of id, skipping other commands.
10func (r *captureRig) configureOf(t *testing.T, id ports.WindowID) ports.ConfigureWindow {
11 t.Helper()
12 for {
13 if v, ok := receive(t, r.commands).(ports.ConfigureWindow); ok && v.ID == id {
14 return v
15 }
16 }
17}
18
19// A session keeps capturing a workspace that leaves the screen: the state
20// stays active, the scene carries a sibling CaptureScene, and the window is
21// configured Captured (sized, physically invisible) until the session stops.
22func TestCaptureSessionSurvivesWorkspaceSwitch(t *testing.T) {
23 r := captureCore(t)
24 r.client <- ports.WindowMapped{ID: 1}
25 scene(t, r.scenes)
26 // Mapping the window adds a spare workspace: wait for the inventory that lists it.
27 var ws []ports.WorkspaceInfo
28 for len(ws) < 2 {
29 ws = receive(t, r.workspaces).Outputs[0].Workspaces
30 }
31 r.client <- ports.CaptureSessionOpen{ID: 1, Workspace: ws[0].ID}
32 if st := r.state(t); !st.Active {
33 t.Fatalf("state %+v", st)
34 }
35 on := r.sceneWith(t, true)
36 if on.CaptureScene != nil {
37 t.Fatalf("a workspace on screen needs no capture scene: %+v", on.CaptureScene)
38 }
39 // The window is shown and not Captured until its workspace leaves.
40 for len(r.commands) > 0 {
41 if v, ok := (<-r.commands).(ports.ConfigureWindow); ok && v.ID == 1 && (!v.Visible || v.Captured) {
42 t.Fatalf("shown window %+v", v)
43 }
44 }
45
46 r.client <- ports.WorkspaceActivate{IDs: []uint64{ws[1].ID}}
47 var off ports.Scene
48 for {
49 off = scene(t, r.scenes)
50 if off.CaptureScene != nil {
51 break
52 }
53 }
54 if off.Capture.Workspace != ws[0].ID {
55 t.Fatalf("capture %+v", off.Capture)
56 }
57 c := off.CaptureScene
58 if c.Capture != nil || c.CaptureScene != nil || len(c.Layers) != 0 || c.Seq != off.Seq || c.OutputWidth != 100 || c.OutputHeight != 80 {
59 t.Fatalf("capture scene %+v (root seq %d)", c, off.Seq)
60 }
61 if len(c.Windows) != 1 || c.Windows[0].ID != 1 || c.Windows[0].Hidden || c.Windows[0].Rect.W <= 0 {
62 t.Fatalf("capture windows %+v", c.Windows)
63 }
64 for _, w := range off.Windows {
65 if w.ID == 1 && !w.Hidden {
66 t.Fatalf("captured window drawn on screen: %+v", w)
67 }
68 }
69 hid := r.configureOf(t, 1)
70 if hid.Visible || hid.Activated || !hid.Captured || hid.Width <= 0 {
71 t.Fatalf("captured hidden window %+v", hid)
72 }
73
74 // Stopping the session hides the window for real again.
75 r.client <- ports.CaptureSessionClose{ID: 1}
76 var after ports.Scene
77 for {
78 if after = scene(t, r.scenes); after.Capture == nil {
79 break
80 }
81 }
82 end := r.configureOf(t, 1)
83 if end.Captured || end.Visible || end.Width != hid.Width {
84 t.Fatalf("released window %+v", end)
85 }
86}