package windows import ( "testing" "time" ) // TestIsFullscreenRect 验证覆盖判定边界(94%/95%/96%、无交集、跨屏)。 func TestIsFullscreenRect(t *testing.T) { screen := MonitorRect{Left: 0, Top: 0, Right: 1920, Bottom: 1080} cases := []struct { name string win MonitorRect want bool }{ {"完全覆盖", MonitorRect{0, 0, 1920, 1080}, true}, {"无边框全屏", MonitorRect{0, 0, 1920, 1080}, true}, {"任务栏遮挡(94%)", MonitorRect{0, 0, 1920, 1015}, false}, // 1015/1080 ≈ 93.9% {"任务栏遮挡(96%)", MonitorRect{0, 0, 1920, 1040}, true}, // 1040/1080 ≈ 96.3% {"普通窗口", MonitorRect{100, 100, 1200, 800}, false}, {"无交集", MonitorRect{3000, 3000, 4000, 4000}, false}, {"覆盖95%临界", MonitorRect{0, 0, 1920, 1026}, true}, // 1026/1080 = 95.0% } for _, c := range cases { if got := IsFullscreenRect(c.win, screen, 0); got != c.want { t.Errorf("%s: IsFullscreenRect = %v, want %v", c.name, got, c.want) } } } // TestIsFullscreenRectMultiMonitor 验证跨屏窗口按交集最大屏幕判定。 func TestIsFullscreenRectMultiMonitor(t *testing.T) { screen := MonitorRect{Left: 1920, Top: 0, Right: 3840, Bottom: 1080} win := MonitorRect{Left: 1900, Top: 0, Right: 3840, Bottom: 1080} // 几乎全盖副屏 if !IsFullscreenRect(win, screen, 0) { t.Fatal("near-fullscreen on secondary monitor should be true") } } // TestFullscreenWatcherLifecycle 验证轮询器 Start/Stop 幂等与状态可读。 func TestFullscreenWatcherLifecycle(t *testing.T) { w := NewFullscreenWatcher() w.Start() w.Start() // 幂等 time.Sleep(100 * time.Millisecond) _ = w.IsFullscreen() // 可读(值不校验:取决于会话前台窗口) w.Stop() w.Stop() // 幂等 // 重启 w.Start() time.Sleep(50 * time.Millisecond) w.Stop() }