-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwindow_chrome_test.go
More file actions
202 lines (183 loc) · 5.54 KB
/
Copy pathwindow_chrome_test.go
File metadata and controls
202 lines (183 loc) · 5.54 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2026 The gogpu Authors
// SPDX-License-Identifier: MIT
package gpucontext
import "testing"
func TestNullWindowChrome_Defaults(t *testing.T) {
var wc WindowChrome = NullWindowChrome{}
if wc.IsFrameless() {
t.Error("IsFrameless() should return false")
}
if wc.IsMaximized() {
t.Error("IsMaximized() should return false")
}
if wc.IsFullscreen() {
t.Error("IsFullscreen() should return false")
}
}
func TestNullWindowChrome_Actions(t *testing.T) {
var wc WindowChrome = NullWindowChrome{}
// All actions should succeed without panic
wc.SetFrameless(true)
wc.SetFrameless(false)
wc.SetHitTestCallback(func(x, y float64) HitTestResult { return HitTestClient })
wc.SetHitTestCallback(nil)
wc.Minimize()
wc.Maximize()
wc.SetFullscreen(true)
wc.SetFullscreen(false)
wc.Close()
}
func TestHitTestResult_String(t *testing.T) {
tests := []struct {
result HitTestResult
want string
}{
{HitTestClient, "Client"},
{HitTestCaption, "Caption"},
{HitTestClose, "Close"},
{HitTestMaximize, "Maximize"},
{HitTestMinimize, "Minimize"},
{HitTestResizeN, "ResizeN"},
{HitTestResizeS, "ResizeS"},
{HitTestResizeW, "ResizeW"},
{HitTestResizeE, "ResizeE"},
{HitTestResizeNW, "ResizeNW"},
{HitTestResizeNE, "ResizeNE"},
{HitTestResizeSW, "ResizeSW"},
{HitTestResizeSE, "ResizeSE"},
{HitTestResult(99), "Unknown"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.result.String(); got != tt.want {
t.Errorf("HitTestResult(%d).String() = %q, want %q", tt.result, got, tt.want)
}
})
}
}
func TestHitTestResult_Values(t *testing.T) {
// Verify hit test result constants are sequential starting from 0
if HitTestClient != 0 {
t.Errorf("HitTestClient = %d, want 0", HitTestClient)
}
if HitTestCaption != 1 {
t.Errorf("HitTestCaption = %d, want 1", HitTestCaption)
}
if HitTestClose != 2 {
t.Errorf("HitTestClose = %d, want 2", HitTestClose)
}
if HitTestMaximize != 3 {
t.Errorf("HitTestMaximize = %d, want 3", HitTestMaximize)
}
if HitTestMinimize != 4 {
t.Errorf("HitTestMinimize = %d, want 4", HitTestMinimize)
}
if HitTestResizeN != 5 {
t.Errorf("HitTestResizeN = %d, want 5", HitTestResizeN)
}
if HitTestResizeS != 6 {
t.Errorf("HitTestResizeS = %d, want 6", HitTestResizeS)
}
if HitTestResizeW != 7 {
t.Errorf("HitTestResizeW = %d, want 7", HitTestResizeW)
}
if HitTestResizeE != 8 {
t.Errorf("HitTestResizeE = %d, want 8", HitTestResizeE)
}
if HitTestResizeNW != 9 {
t.Errorf("HitTestResizeNW = %d, want 9", HitTestResizeNW)
}
if HitTestResizeNE != 10 {
t.Errorf("HitTestResizeNE = %d, want 10", HitTestResizeNE)
}
if HitTestResizeSW != 11 {
t.Errorf("HitTestResizeSW = %d, want 11", HitTestResizeSW)
}
if HitTestResizeSE != 12 {
t.Errorf("HitTestResizeSE = %d, want 12", HitTestResizeSE)
}
}
// mockWindowChrome verifies the interface can be implemented by custom types.
type mockWindowChrome struct {
frameless bool
maximized bool
fullscreen bool
closed bool
minimized bool
callback HitTestCallback
}
func (m *mockWindowChrome) SetFrameless(frameless bool) { m.frameless = frameless }
func (m *mockWindowChrome) IsFrameless() bool { return m.frameless }
func (m *mockWindowChrome) SetHitTestCallback(cb HitTestCallback) { m.callback = cb }
func (m *mockWindowChrome) Minimize() { m.minimized = true }
func (m *mockWindowChrome) Maximize() { m.maximized = !m.maximized }
func (m *mockWindowChrome) IsMaximized() bool { return m.maximized }
func (m *mockWindowChrome) SetFullscreen(fullscreen bool) { m.fullscreen = fullscreen }
func (m *mockWindowChrome) IsFullscreen() bool { return m.fullscreen }
func (m *mockWindowChrome) Close() { m.closed = true }
// Ensure mockWindowChrome implements WindowChrome.
var _ WindowChrome = &mockWindowChrome{}
func TestWindowChrome_CustomImplementation(t *testing.T) {
mock := &mockWindowChrome{}
var wc WindowChrome = mock
// Test frameless mode
wc.SetFrameless(true)
if !wc.IsFrameless() {
t.Error("IsFrameless() should return true after SetFrameless(true)")
}
wc.SetFrameless(false)
if wc.IsFrameless() {
t.Error("IsFrameless() should return false after SetFrameless(false)")
}
// Test hit test callback
called := false
wc.SetHitTestCallback(func(x, y float64) HitTestResult {
called = true
if x > 100 {
return HitTestClient
}
return HitTestCaption
})
if mock.callback == nil {
t.Fatal("callback should be set")
}
result := mock.callback(50, 10)
if !called {
t.Error("callback should have been called")
}
if result != HitTestCaption {
t.Errorf("callback(50, 10) = %v, want Caption", result)
}
result = mock.callback(150, 10)
if result != HitTestClient {
t.Errorf("callback(150, 10) = %v, want Client", result)
}
// Test minimize
wc.Minimize()
if !mock.minimized {
t.Error("Minimize() should set minimized to true")
}
// Test maximize toggle
wc.Maximize()
if !wc.IsMaximized() {
t.Error("IsMaximized() should return true after first Maximize()")
}
wc.Maximize()
if wc.IsMaximized() {
t.Error("IsMaximized() should return false after second Maximize()")
}
// Test fullscreen
wc.SetFullscreen(true)
if !wc.IsFullscreen() {
t.Error("IsFullscreen() should return true after SetFullscreen(true)")
}
wc.SetFullscreen(false)
if wc.IsFullscreen() {
t.Error("IsFullscreen() should return false after SetFullscreen(false)")
}
// Test close
wc.Close()
if !mock.closed {
t.Error("Close() should set closed to true")
}
}