The owner, 10-21: "要默认关闭「轻量模式」,不然太卡了". With it on, the window is made again and its page loaded again on every opening, which is slow.28bec1507had made it on for a user who never chose, against a hidden webview growing ~20 MB a minute on Windows (#2515); that user now gets the kept window again. A user who turned it on or off keeps their choice: only an unset value changes meaning (LightweightOn, Settings › General's row). Run on origin/mainb855cfee9+ this commit, macOS, playwright 1.62.0: - go test ./internal/settings/ -run Lightweight ok; red with the old LightweightOn. - lightweight.test.cjs, segs-glide, segs-press-redraw, settings-general: 89/90 in chromium and webkit, every language; the red was segs-press-redraw chromium en 440px while a full GUI suite ran beside it, and the file passes 42/42 alone. lightweight.test.cjs goes 4 of 8 red with app.js's old `!== false`. - gofmt -l clean; GOOS=linux go vet -tags nogui and GOOS=windows go vet of internal/settings and internal/gui. Shipped at the owner's word (10-21, "赶紧上线") before the full GUI suite finished: it was stopped at ~2,040 passing tests (about a quarter of the files, onb855cfee9+ the dialog change), with two reds, desktop-longest chromium zh 640px and gateway-key-groups chromium en, both under load at ~100. On origin/mainc79400556+ both commits (rebased after ontoe68a0b1db, which adds only internal/sessions): desktop-longest, gateway-key-groups, modal-morph, lightweight, segs-glide, segs-press-redraw and settings-general 108/108 in chromium and webkit; go test ./internal/settings/ ok; go test ./internal/gui/ -run 'Budget|Lightweight' ok; gofmt -l clean; GOOS=linux go vet -tags nogui and GOOS=windows go vet of internal/settings and internal/gui. Not run: the rest of the GUI suite.
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
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})
|
|
if !from.WindowMaximised || len(from.Window) != 2 {
|
|
t.Fatalf("KeepOwn dropped it: %v %v", from.Window, from.WindowMaximised)
|
|
}
|
|
from = Settings{Window: []int{1200, 800}, WindowMaximised: true}
|
|
from.KeepOwn(Settings{})
|
|
if from.WindowMaximised || from.Window != nil {
|
|
t.Fatalf("another computer's window here: %v %v", from.Window, from.WindowMaximised)
|
|
}
|
|
}
|
|
|
|
// 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")
|
|
}
|
|
}
|