返回 DeepSeek-Reasonix
webview2_startup_test.go
根目录 / desktop / webview2_startup_test.go
1 package main
2
3 import (
4 "context"
5 "testing"
6 "time"
7 )
8
9 func TestWindowsWebView2StartupFallbackScope(t *testing.T) {
10 tests := []struct {
11 name string
12 goos string
13 remoteWindow bool
14 want bool
15 }{
16 {name: "primary Windows window", goos: "windows", want: true},
17 {name: "remote Windows window", goos: "windows", remoteWindow: true, want: false},
18 {name: "non-Windows primary window", goos: "darwin", want: false},
19 }
20 for _, tt := range tests {
21 t.Run(tt.name, func(t *testing.T) {
22 if got := shouldStartWindowsWebView2StartupFallback(tt.goos, tt.remoteWindow); got != tt.want {
23 t.Fatalf("shouldStartWindowsWebView2StartupFallback(%q, %v) = %v, want %v", tt.goos, tt.remoteWindow, got, tt.want)
24 }
25 })
26 }
27 }
28
29 func TestAwaitStartupFallbackFiresWhenDOMIsNotReady(t *testing.T) {
30 timeout := make(chan time.Time, 1)
31 timeout <- time.Now()
32 if !awaitStartupFallback(context.Background(), timeout, func() bool { return false }) {
33 t.Fatal("startup fallback did not fire after timeout")
34 }
35 }
36
37 func TestAwaitStartupFallbackSkipsReadyWindow(t *testing.T) {
38 timeout := make(chan time.Time, 1)
39 timeout <- time.Now()
40 if awaitStartupFallback(context.Background(), timeout, func() bool { return true }) {
41 t.Fatal("startup fallback fired after domReady")
42 }
43 }
44
45 func TestAwaitStartupFallbackStopsWithApplication(t *testing.T) {
46 ctx, cancel := context.WithCancel(context.Background())
47 cancel()
48 if awaitStartupFallback(ctx, make(chan time.Time), func() bool { return false }) {
49 t.Fatal("startup fallback fired after application shutdown")
50 }
51 }
52
52 lines GO