Repository navigation
Expand file tree
/
Copy pathlightweight_test.go
More file actions
104 lines (99 loc) · 3.23 KB
/
Copy pathlightweight_test.go
File metadata and controls
104 lines (99 loc) · 3.23 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
package settings
import "testing"
// Lightweight mode (#580) is off for a user who never chose (the owner,
// 10-21: too slow to have by default), on for one who turned it on, and
// kept off for one who turned it off; it is saved and read back, and is
// this computer's own: a sync or a restored backup keeps it as it is here.
func TestLightweightKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().LightweightOn() {
t.Fatal("on for a user who never chose")
}
off, on := false, true
s := Load()
s.Lightweight = &on
if err := Save(s); err != nil {
t.Fatal(err)
}
if !Load().LightweightOn() {
t.Fatal("turned on, but read back off")
}
s.Lightweight = &off
if err := Save(s); err != nil {
t.Fatal(err)
}
if Load().LightweightOn() {
t.Fatal("turned off, but read back on")
}
s.Theme = "dark" // another setting saved keeps it off
if err := Save(s); err != nil {
t.Fatal(err)
}
if Load().LightweightOn() {
t.Fatal("another setting's save turned it on")
}
from := Settings{Theme: "dark", Lightweight: &on}
from.KeepOwn(Load())
if from.LightweightOn() || from.Theme != "dark" {
t.Fatalf("KeepOwn: %+v", from)
}
from = Settings{Lightweight: &off}
from.KeepOwn(Settings{})
if from.Lightweight != nil {
t.Fatal("another computer's choice taken here")
}
}
// Keep awake (xiao_wang24004 on X) is off by default, saved, and this
// computer's own.
func TestKeepAwakeKeptAndOwn(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if Load().KeepAwake {
t.Fatal("on by default")
}
s := Load()
s.KeepAwake, s.KeepAwakeDisplay = true, true
if err := Save(s); err != nil {
t.Fatal(err)
}
if l := Load(); !l.KeepAwake || !l.KeepAwakeDisplay {
t.Fatal("not kept")
}
from := Settings{}
from.KeepOwn(Load())
if !from.KeepAwake || !from.KeepAwakeDisplay {
t.Fatal("KeepOwn dropped it")
}
from = Settings{KeepAwake: true, KeepAwakeDisplay: true}
from.KeepOwn(Settings{})
if from.KeepAwake || from.KeepAwakeDisplay {
t.Fatal("another computer's turned on here")
}
}
// Whether the main window was maximised is this computer's, like its size:
// a synced or restored bundle doesn't bring another's.
func TestWindowMaximisedKeptAndOwn(t *testing.T) {
from := Settings{}
from.KeepOwn(Settings{Window: []int{900, 700}, WindowMaximised: true, WindowAt: []int{40, 60}})
if !from.WindowMaximised || len(from.Window) != 2 || len(from.WindowAt) != 2 {
t.Fatalf("KeepOwn dropped it: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
}
from = Settings{Window: []int{1200, 800}, WindowMaximised: true, WindowAt: []int{2560, 0}}
from.KeepOwn(Settings{})
if from.WindowMaximised || from.Window != nil || from.WindowAt != nil {
t.Fatalf("another computer's window here: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
}
}
// Detect agents in WSL (#1264) is this computer's own: a sync from a Mac or
// a restored backup leaves it as it is on this Windows box.
func TestNoWSLAgentsOwn(t *testing.T) {
from := Settings{Theme: "dark"}
from.KeepOwn(Settings{NoWSLAgents: true})
if !from.NoWSLAgents || from.Theme != "dark" {
t.Fatalf("KeepOwn: %+v", from)
}
from = Settings{NoWSLAgents: true}
from.KeepOwn(Settings{})
if from.NoWSLAgents {
t.Fatal("another computer's turned off here")
}
}