统一服务默认端口为 59188,完善 Windows 服务权限与 macOS LaunchAgent 管理。 实现 Windows 与 macOS 托盘状态机、服务启停等待、单实例保护、日志目录入口和退出前清理后台服务。 统一 Linux、Windows、macOS 与 Docker 的 Playwright Chromium runtime 构建流程,增加缓存、架构校验和 Linux 原生 runner,避免 QEMU。 完善 Windows、macOS、Linux 安装包及签名打包脚本,修正 Chromium 嵌入、服务注册和安装卸载流程。 同步 README、AGENTS、官网首页、Wiki 与前端开发文档,统一端口、初始化、服务、日志、托盘和安装说明。
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
type fakeWindowsServiceController struct {
|
|
states []uint32
|
|
actions []string
|
|
}
|
|
|
|
func (controller *fakeWindowsServiceController) state() (uint32, error) {
|
|
if len(controller.states) == 0 {
|
|
return 0, fmt.Errorf("测试状态序列为空")
|
|
}
|
|
state := controller.states[0]
|
|
if len(controller.states) > 1 {
|
|
controller.states = controller.states[1:]
|
|
}
|
|
return state, nil
|
|
}
|
|
|
|
func (controller *fakeWindowsServiceController) start() error {
|
|
controller.actions = append(controller.actions, "start")
|
|
return nil
|
|
}
|
|
|
|
func (controller *fakeWindowsServiceController) stop() error {
|
|
controller.actions = append(controller.actions, "stop")
|
|
return nil
|
|
}
|
|
|
|
func (controller *fakeWindowsServiceController) close() {}
|
|
|
|
func TestWindowsRestartWaitsForStoppedBeforeStarting(t *testing.T) {
|
|
controller := &fakeWindowsServiceController{
|
|
states: []uint32{
|
|
windows.SERVICE_RUNNING,
|
|
windows.SERVICE_STOP_PENDING,
|
|
windows.SERVICE_STOPPED,
|
|
windows.SERVICE_STOPPED,
|
|
windows.SERVICE_START_PENDING,
|
|
windows.SERVICE_RUNNING,
|
|
},
|
|
}
|
|
if err := controlWindowsService(controller, "restart", time.Second, time.Millisecond); err != nil {
|
|
t.Fatalf("restart Windows service: %v", err)
|
|
}
|
|
if want := []string{"stop", "start"}; !reflect.DeepEqual(controller.actions, want) {
|
|
t.Fatalf("actions = %v, want %v", controller.actions, want)
|
|
}
|
|
}
|
|
|
|
func TestWindowsStartWaitsForPreviousStop(t *testing.T) {
|
|
controller := &fakeWindowsServiceController{
|
|
states: []uint32{
|
|
windows.SERVICE_STOP_PENDING,
|
|
windows.SERVICE_STOPPED,
|
|
windows.SERVICE_START_PENDING,
|
|
windows.SERVICE_RUNNING,
|
|
},
|
|
}
|
|
if err := controlWindowsService(controller, "start", time.Second, time.Millisecond); err != nil {
|
|
t.Fatalf("start Windows service: %v", err)
|
|
}
|
|
if want := []string{"start"}; !reflect.DeepEqual(controller.actions, want) {
|
|
t.Fatalf("actions = %v, want %v", controller.actions, want)
|
|
}
|
|
}
|
|
|
|
func TestWindowsServiceAccessIsLimitedToStatusStartStop(t *testing.T) {
|
|
want := uint32(windows.SERVICE_QUERY_STATUS | windows.SERVICE_START | windows.SERVICE_STOP)
|
|
if windowsServiceAccess != want {
|
|
t.Fatalf("service access = %#x, want %#x", windowsServiceAccess, want)
|
|
}
|
|
}
|