magpie rewrites the extension's folder when an older one connects, but Chrome runs what it loaded until the extension is reloaded on chrome://extensions or the browser starts again, so a user who never does either stays on the old code. Now that is said: - Library → Magpie Browser: under "Connected to your browser · 0.1.8" a line says "Magpie Browser 0.1.9 is ready: reload Magpie Browser on chrome://extensions (edge://extensions in Edge)." Looked at from another computer (the zip install), it says to download it again, unzip it over the old folder and reload it. /api/library/browser has outdated. - The agent: the first browser answer on such a connection starts with a line telling it to have the user reload it (or download it again, for one connected with a gateway key). Once a connection. The extension still isn't made to reload itself: an unpacked one that calls chrome.runtime.reload() doesn't come back (the finding in browser.go's hello). The fake extension in the gateway's tests now says magpie's own version (it said 0.1.0, which every test would now be told about). Run (on mote): - internal/gateway TestBrowser* (new TestBrowserSaysTheExtensionIsOlder, TestBrowserSaysNothingOfACurrentExtension), ok. - internal/gui TestBrowser* (new TestBrowserStateOutdated), ok. - GUI: library-browser-setup, library-browser-away, library-browser-ask, browser-access, i18n-keys in Chromium and WebKit, every language, at 1100 and 420 wide: 127 of 128. The red is i18n-keys "a plugin's words are its own" for three keys this change doesn't touch, red on main and filed (#5332, #5482, #5426). - go vet for darwin, linux (nogui) and windows; gofmt -l clean. Broken by hand: - the once-a-connection check removed: TestBrowserSaysTheExtensionIsOlder red ("s1's next answer" has the note again). - the sheet's line never shown: library-browser-setup red, 20 of 20. - Outdated without Connected: TestBrowserStateOutdated red. Not tried: the whole GUI suite before this push (run next), and a real Chrome with an older extension loaded by hand.
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/browserext"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// The sheet says to reload the extension when the connected one is older
|
|
// than this magpie's (the browser runs what it loaded until then), and not
|
|
// when it is as new, or when none is connected.
|
|
func TestBrowserStateOutdated(t *testing.T) {
|
|
sandboxHome(t)
|
|
var st map[string]any
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != gateway.BrowserStatusPath {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
json.NewEncoder(w).Encode(st)
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
t.Setenv("MAGPIE_ADDR", strings.TrimPrefix(srv.URL, "http://"))
|
|
if gateway.URL() != srv.URL {
|
|
t.Fatalf("the gateway is at %s, not %s", gateway.URL(), srv.URL)
|
|
}
|
|
v := browserext.Version()
|
|
for _, c := range []struct {
|
|
connected bool
|
|
ext string
|
|
want bool
|
|
}{{true, "0.0.1", true}, {true, v, false}, {true, v + ".1", false}, {false, "0.0.1", false}, {true, "", false}} {
|
|
st = map[string]any{"connected": c.connected, "extension": c.ext}
|
|
if got := browserState(context.Background()); got.Outdated != c.want || got.Extension != c.ext && c.connected {
|
|
t.Errorf("connected %v, extension %q: %+v", c.connected, c.ext, got)
|
|
}
|
|
}
|
|
}
|