Files
MyGoNavi/internal/app/window_zoom_other_test.go
Syngnat 2580e4d6f3 🐛 fix(window): 直接调 WebView2 zoom factor 零感知修复 Windows 字体异常
- 新增 ResetWebViewZoom RPC:从 ctx 反射拿 Wails 内部 *edge.Chromium,调 PutZoomFactor(1.0) 强制 WebView2 重算 D2D/DirectWrite 字体度量,完全不动窗口零动画
- 自动路径:maximised + restore + drift 时直接调 backend reset,告别 9848b8b2 之后字体偶发变大的取舍
- 手动路径:保留 Ctrl+Shift+0 快捷键作为兜底(优先 WebView2 reset,失败回退 toggle)
- 撤回上一版 CSS zoom nudge:实测在 WebView2 上不能修字体度量(度量缓存在 D2D 层不在 Chromium layout 层)
- 反射做了 3 层签名校验(frontend value / chromium 字段 / PutZoomFactor 方法签名),wails 升级破坏接口时返回 error 不让进程崩溃
- 新增 windows-only 反射逻辑测试 4 个、跨平台 RPC 行为测试 2 个、Ctrl+Shift+0 快捷键注册测试
2026-05-15 16:01:18 +08:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build !windows
package app
import (
"context"
"strings"
"testing"
)
// 非 Windows 平台WebView2 不存在resetWebViewZoomFactor 必须明确返回 error
// 让前端 fallback 到 toggle 路径而不是误以为修复成功。
func TestResetWebViewZoomFactorReturnsErrorOnNonWindows(t *testing.T) {
err := resetWebViewZoomFactor(context.Background(), 1.0)
if err == nil {
t.Fatal("expected error on non-Windows platform, got nil")
}
if !strings.Contains(strings.ToLower(err.Error()), "windows") {
t.Fatalf("expected error to mention Windows-only, got %v", err)
}
}
// App.ResetWebViewZoom RPC 在 darwin/linux 上返回 success=false让前端不至于
// 调用后误以为成功而跳过 fallback 路径。
func TestAppResetWebViewZoomRPCReportsFailureOnNonWindows(t *testing.T) {
app := &App{ctx: context.Background()}
res := app.ResetWebViewZoom()
if res.Success {
t.Fatal("expected RPC to report failure on non-Windows platform")
}
if strings.TrimSpace(res.Message) == "" {
t.Fatal("expected failure message to explain why")
}
}