Files
Reims-Go/internal/host/fullscreen_hotkey_windows_test.go
T

91 lines
3.0 KiB
Go

package host
import (
"testing"
"time"
)
func TestFullscreenHotkeyDispatchAfterInputServiceCloses(t *testing.T) {
input := NewInputService(nil)
input.Close()
service := &FullscreenHotkeyService{}
t.Cleanup(service.Close)
target := IMETarget{VMName: "mac", PID: 1234}
hotkey, _, _ := ParseFullscreenHotkey("F8")
received := make(chan fullscreenHotkeyEvent, 1)
service.Sync(true, hotkey, []IMETarget{target}, func(target IMETarget, hwnd uintptr) {
received <- fullscreenHotkeyEvent{target: target, hwnd: hwnd}
})
if !service.HookActive() {
t.Fatal("fullscreen hook did not start after closing the input service")
}
service.hook.triggers <- fullscreenHotkeyEvent{target: target, hotkey: hotkey, hwnd: 42}
select {
case got := <-received:
if got.target != target || got.hwnd != 42 {
t.Fatalf("dispatched event = %+v", got)
}
case <-time.After(time.Second):
t.Fatal("fullscreen event did not reach the callback")
}
}
func TestFullscreenHotkeyResetClearsPhysicalAndSuppressedKeys(t *testing.T) {
hotkey, _, _ := ParseFullscreenHotkey("Ctrl+F8")
h := fullscreenHotkeyHook{matcher: FullscreenHotkeyMatcher{Hotkey: hotkey}}
h.physical.handle(vkLCtrl, true, false)
if consume, trigger := h.matcher.Handle(hotkey.VK, true, true, h.physical.mods()); !consume || !trigger {
t.Fatalf("initial chord = (%t, %t)", consume, trigger)
}
h.resetKeys()
if h.matcher.suppressedVK != 0 || h.physical.mods() != (FullscreenHotkeyMods{}) {
t.Fatal("reset left held keys behind")
}
if consume, trigger := h.matcher.Handle(hotkey.VK, false, true, h.physical.mods()); consume || trigger {
t.Fatalf("release after reset = (%t, %t)", consume, trigger)
}
}
func TestFullscreenHotkeyKeepsSwallowedModifiersInVM(t *testing.T) {
hotkey, _, _ := ParseFullscreenHotkey(DefaultFullscreenHotkey)
h := fullscreenHotkeyHook{matcher: FullscreenHotkeyMatcher{Hotkey: hotkey}}
// No key is physically held here, which matches a modifier swallowed by SDL3.
h.physical.handle(vkRCtrl, true, false)
h.reconcilePhysical(true)
if !h.physical.mods().Ctrl {
t.Fatal("held Ctrl was dropped while the VM window was focused")
}
h.reconcilePhysical(false)
if h.physical.mods().Ctrl {
t.Fatal("stale Ctrl survived after the VM window lost focus")
}
}
func TestFullscreenHotkeyPromotesOnFocusAndRecapture(t *testing.T) {
var h fullscreenHotkeyHook
if h.needsPromotion(0, "") {
t.Fatal("promoted without a VM window")
}
if !h.needsPromotion(1, "mac") {
t.Fatal("focusing a VM window did not promote the hook")
}
settled := 0
for range fullscreenHotkeySettleTicks * 2 {
if h.needsPromotion(1, "mac") {
settled++
}
}
if settled != 1 {
t.Fatalf("settled promotions = %d, want 1", settled)
}
if !h.needsPromotion(1, "mac (captured)") {
t.Fatal("recapturing the keyboard did not promote the hook")
}
if h.needsPromotion(0, "") {
t.Fatal("promoted after the VM window lost focus")
}
if !h.needsPromotion(1, "mac (captured)") {
t.Fatal("refocusing the VM window did not promote the hook")
}
}