feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
+132
@@ -0,0 +1,132 @@
|
||||
//go:build !js
|
||||
|
||||
package mygo
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/internal/fake"
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
const blockAds = `[{"trigger":{"url-filter":"ads"},"action":{"type":"block"}}]`
|
||||
|
||||
func compileRules(t *testing.T, id, rules string) *ContentRules {
|
||||
t.Helper()
|
||||
r, err := CompileContentRules(id, rules)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func lists(fw *fake.Window) []string {
|
||||
var out []string
|
||||
for _, l := range fw.ContentRules() {
|
||||
out = append(out, l.Identifier)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestContentRules(t *testing.T) {
|
||||
ads := compileRules(t, "ads", blockAds)
|
||||
hide := compileRules(t, "hide", `[{"trigger":{"url-filter":".*"},"action":{"type":"css-display-none","selector":".ad"}}]`)
|
||||
if ads.ID() != "ads" {
|
||||
t.Errorf("ID = %q", ads.ID())
|
||||
}
|
||||
adsList := platform.ContentRulesIdentifier("ads", blockAds)
|
||||
|
||||
w, fw := testWindow(t, WindowOptions{URL: "https://example.com/", Page: PageOptions{ContentRules: []*ContentRules{ads}}})
|
||||
if got := lists(fw); !slices.Equal(got, []string{adsList}) {
|
||||
t.Fatalf("a window's lists = %v, want PageOptions.ContentRules", got)
|
||||
}
|
||||
w.Page().SetContentRules(hide, nil, ads)
|
||||
if got := lists(fw); len(got) != 2 || got[1] != adsList || !strings.HasPrefix(got[0], "hide-") {
|
||||
t.Errorf("lists after SetContentRules = %v", got)
|
||||
}
|
||||
w.Page().SetContentRules()
|
||||
if got := lists(fw); len(got) != 0 {
|
||||
t.Errorf("SetContentRules() left %v", got)
|
||||
}
|
||||
|
||||
// A window without rules is left alone until it gets some.
|
||||
_, plain := testWindow(t, WindowOptions{})
|
||||
if n := onMainValue(func() int { return plain.ContentRuleUpdates }); n != 0 {
|
||||
t.Errorf("a window without rules had them set %d times", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentRulesWebView(t *testing.T) {
|
||||
ads := compileRules(t, "ads", blockAds)
|
||||
w, _, s := contentWindow(t, func(c *ui.Context) {})
|
||||
v, err := w.NewWebView(WebViewOptions{Page: PageOptions{ContentRules: []*ContentRules{ads}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fv := s.WebViews()[0]
|
||||
if got := lists(fv.Window); len(got) != 1 {
|
||||
t.Fatalf("a web view's lists = %v, want PageOptions.ContentRules", got)
|
||||
}
|
||||
v.Page().SetContentRules()
|
||||
if got := lists(fv.Window); len(got) != 0 {
|
||||
t.Errorf("the web view kept %v", got)
|
||||
}
|
||||
if w.Page() != nil {
|
||||
t.Fatal("a window of native UI has a page")
|
||||
}
|
||||
}
|
||||
|
||||
// The same rules load what was compiled; other rules of the same id
|
||||
// compile again and replace the earlier list.
|
||||
func TestContentRulesKept(t *testing.T) {
|
||||
before := onMainValue(func() int { return fb.ContentRuleCompiles })
|
||||
compileRules(t, "kept", blockAds)
|
||||
compileRules(t, "kept", blockAds)
|
||||
if n := onMainValue(func() int { return fb.ContentRuleCompiles }) - before; n != 1 {
|
||||
t.Errorf("the same rules compiled %d times, want once", n)
|
||||
}
|
||||
other := `[{"trigger":{"url-filter":"trackers"},"action":{"type":"block"}}]`
|
||||
compileRules(t, "kept", other)
|
||||
compileRules(t, "kept-more", blockAds)
|
||||
var kept []string
|
||||
for _, name := range fb.ContentRuleLists() {
|
||||
if strings.HasPrefix(name, "kept-") {
|
||||
kept = append(kept, name)
|
||||
}
|
||||
}
|
||||
slices.Sort(kept)
|
||||
want := []string{platform.ContentRulesIdentifier("kept", other), platform.ContentRulesIdentifier("kept-more", blockAds)}
|
||||
slices.Sort(want)
|
||||
if !slices.Equal(kept, want) {
|
||||
t.Errorf("lists kept = %v, want %v", kept, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentRulesErrors(t *testing.T) {
|
||||
for _, id := range []string{"", "a/b", "spaced id", strings.Repeat("x", 65)} {
|
||||
if _, err := CompileContentRules(id, blockAds); err == nil {
|
||||
t.Errorf("id %q was taken", id)
|
||||
}
|
||||
}
|
||||
if _, err := CompileContentRules("bad", `{"trigger":{}}`); err == nil || !strings.Contains(err.Error(), "content rules bad") {
|
||||
t.Errorf("rules that are not an array: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStaleContentRules(t *testing.T) {
|
||||
current := platform.ContentRulesIdentifier("ads", "[1]")
|
||||
for name, want := range map[string]bool{
|
||||
platform.ContentRulesIdentifier("ads", "[2]"): true,
|
||||
current: false,
|
||||
platform.ContentRulesIdentifier("ads-more", "[2]"): false,
|
||||
"ads-notahash0000000": false,
|
||||
"ads": false,
|
||||
} {
|
||||
if got := platform.StaleContentRules("ads", current, name); got != want {
|
||||
t.Errorf("StaleContentRules(%q) = %v, want %v", name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user