fix: a slow answer to an approval still reaches the site (closes #540)
Chrome stopped the background worker about six minutes after a site's request even with the approval window open, and the approval and the site's waiting request went with it. Every approval is now added through addPendingApproval(), which starts a timer in the worker that calls runtime.getPlatformInfo() every 20 seconds while any approval is pending; Chrome counts each call as activity. tests/e2e/slowApproval.js, run by make test-e2e, leaves a transaction and a signature approval open for seven minutes in minimized windows and requires the site to receive both results. It drives Chromium over the DevTools pipe because Playwright keeps DevTools attached to the worker. Its loopback dApp server, shared with the Firefox suite, moves to tests/e2e/dapp.js. Model: opus-5-5
This commit is contained in:
@@ -264,6 +264,7 @@ function loadBackground(options) {
|
||||
connectListener = fn;
|
||||
},
|
||||
},
|
||||
getPlatformInfo: jest.fn((cb) => cb({ os: "linux" })),
|
||||
lastError: null,
|
||||
},
|
||||
windows: {
|
||||
@@ -878,6 +879,45 @@ describe("one transaction approval at a time", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Chrome stops an idle worker, and the approvals in it go with it
|
||||
// (https://git.eeqj.de/sneak/AutistMask/issues/540). tests/e2e/slowApproval.js
|
||||
// shows the worker kept running in Chrome; this shows the calls stop once the
|
||||
// approval is answered, so the worker can stop again. Every kind of approval is
|
||||
// added through addPendingApproval(), which starts the calls, so a transaction
|
||||
// approval stands for all of them.
|
||||
describe("the worker keeps running while an approval is pending", () => {
|
||||
test("an extension call every 20 seconds until the approval is answered", async () => {
|
||||
const startTimer = jest
|
||||
.spyOn(global, "setInterval")
|
||||
.mockImplementation(() => 1);
|
||||
const stopTimer = jest
|
||||
.spyOn(global, "clearInterval")
|
||||
.mockImplementation(() => {});
|
||||
try {
|
||||
const bg = loadBackground();
|
||||
const calls = global.chrome.runtime.getPlatformInfo;
|
||||
bg.requestTx();
|
||||
await settle();
|
||||
expect(startTimer).toHaveBeenCalledTimes(1);
|
||||
expect(startTimer.mock.calls[0][1]).toBe(20000);
|
||||
const tick = startTimer.mock.calls[0][0];
|
||||
|
||||
tick();
|
||||
expect(calls).toHaveBeenCalledTimes(1);
|
||||
|
||||
// The user closes the approval window, which rejects it.
|
||||
bg.closeWindow(1);
|
||||
await settle();
|
||||
tick();
|
||||
expect(calls).toHaveBeenCalledTimes(1);
|
||||
expect(stopTimer).toHaveBeenCalledWith(1);
|
||||
} finally {
|
||||
startTimer.mockRestore();
|
||||
stopTimer.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// A page that asks again before the user has answered its last connection or
|
||||
// signature request is refused, instead of opening one more window per call.
|
||||
describe("one connection and one signature approval per site at a time", () => {
|
||||
|
||||
Reference in New Issue
Block a user