Repository navigation
Expand file tree
/
Copy pathstartup_window_gate_test.go
More file actions
95 lines (85 loc) · 2.45 KB
/
Copy pathstartup_window_gate_test.go
File metadata and controls
95 lines (85 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"sync/atomic"
"testing"
"time"
)
func TestShouldShowStartupWindow(t *testing.T) {
t.Parallel()
tests := []struct {
name string
iconReady bool
frontendReady bool
timedOut bool
showBound bool
want bool
}{
{name: "frontend without icon stays hidden", frontendReady: true, showBound: true},
{name: "icon without paint stays hidden", iconReady: true, showBound: true},
{name: "unbound show stays hidden", iconReady: true, frontendReady: true},
{name: "icon and frontend present", iconReady: true, frontendReady: true, showBound: true, want: true},
{name: "timeout presents after icon", iconReady: true, timedOut: true, showBound: true, want: true},
{name: "timeout without icon stays hidden", timedOut: true, showBound: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := shouldShowStartupWindow(tt.iconReady, tt.frontendReady, tt.timedOut, tt.showBound)
if got != tt.want {
t.Fatalf("shouldShow = %v, want %v", got, tt.want)
}
})
}
}
func TestStartupWindowGateWaitsForFrontendPaint(t *testing.T) {
t.Parallel()
var shown atomic.Int32
gate := newStartupWindowGate()
gate.markFrontendReady()
gate.bindShow(func() { shown.Add(1) })
if got := shown.Load(); got != 0 {
t.Fatalf("presented before icon ready: %d", got)
}
gate.markIconReady()
if got := shown.Load(); got != 1 {
t.Fatalf("first presentation = %d, want 1", got)
}
gate.markFrontendReady()
gate.markTimedOut()
if got := shown.Load(); got != 1 {
t.Fatalf("repeat presentation = %d, want 1", got)
}
}
func TestStartupWindowGateTimeoutPresentsAfterIcon(t *testing.T) {
t.Parallel()
var shown atomic.Int32
gate := newStartupWindowGate()
gate.bindShow(func() { shown.Add(1) })
gate.markIconReady()
if got := shown.Load(); got != 0 {
t.Fatalf("presented before timeout: %d", got)
}
gate.markTimedOut()
if got := shown.Load(); got != 1 {
t.Fatalf("timeout presentation = %d, want 1", got)
}
}
func TestStartupWindowGateFallbackTimer(t *testing.T) {
t.Parallel()
var shown atomic.Int32
gate := newStartupWindowGate()
gate.bindShow(func() { shown.Add(1) })
gate.markIconReady()
done := make(chan struct{})
gate.startFallback(time.Millisecond, func() {
gate.markTimedOut()
close(done)
})
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("fallback timer did not fire")
}
if got := shown.Load(); got != 1 {
t.Fatalf("fallback presentation = %d, want 1", got)
}
}