1package cef
2
3import "testing"
4
5func TestAdaptiveFrameRateForRefresh(t *testing.T) {
6 tests := []struct {
7 name string
8 refreshMilliHz int
9 fallbackFPS int32
10 maxFPS int32
11 want int32
12 }{
13 {name: "fallback unknown", refreshMilliHz: 0, fallbackFPS: 60, maxFPS: 240, want: 60},
14 {name: "uses monitor refresh", refreshMilliHz: 144000, fallbackFPS: 60, maxFPS: 240, want: 144},
15 {name: "uses lower refresh monitor", refreshMilliHz: 50000, fallbackFPS: 60, maxFPS: 240, want: 50},
16 {name: "floors very low refresh monitor", refreshMilliHz: 24000, fallbackFPS: 60, maxFPS: 240, want: 30},
17 {name: "hard caps extreme monitor", refreshMilliHz: 500000, fallbackFPS: 60, maxFPS: 240, want: 240},
18 }
19
20 for _, tt := range tests {
21 t.Run(tt.name, func(t *testing.T) {
22 got := adaptiveFrameRateForRefresh(tt.refreshMilliHz, tt.fallbackFPS, tt.maxFPS)
23 if got != tt.want {
24 t.Fatalf("adaptiveFrameRateForRefresh() = %d, want %d", got, tt.want)
25 }
26 })
27 }
28}
29
30func TestIsWaylandDisplayName(t *testing.T) {
31 tests := []struct {
32 name string
33 input string
34 want bool
35 }{
36 {name: "exact lowercase", input: "wayland", want: true},
37 {name: "exact uppercase", input: "WAYLAND", want: true},
38 {name: "mixed case", input: "WayLand", want: true},
39 {name: "numeric suffix", input: "wayland-1", want: true},
40 {name: "punctuation suffix", input: "wayland:0", want: true},
41 {name: "leading whitespace", input: " wayland ", want: true},
42 {name: "substring", input: "mywayland-display", want: true},
43 {name: "x11", input: "x11", want: false},
44 {name: "empty", input: "", want: false},
45 {name: "whitespace", input: " ", want: false},
46 }
47 for _, tt := range tests {
48 t.Run(tt.name, func(t *testing.T) {
49 if got := isWaylandDisplayName(tt.input); got != tt.want {
50 t.Fatalf("isWaylandDisplayName(%q) = %v, want %v", tt.input, got, tt.want)
51 }
52 })
53 }
54}