feat(mail2925): 修复登陆跳转问题

This commit is contained in:
QLHazyCoder
2026-04-23 02:55:49 +08:00
parent 05225c4e7f
commit 2989609954
5 changed files with 166 additions and 13 deletions
@@ -267,6 +267,91 @@ test('ensureMail2925MailboxSession logs in when login page is detected and accou
assert.equal(result.result.loggedIn, true);
});
test('ensureMail2925MailboxSession recovers after login-page navigation reload breaks the old content-script channel', async () => {
let currentState = {
autoRunning: false,
mail2925Accounts: mail2925Utils.normalizeMail2925Accounts([
{ id: 'acc-1', email: 'acc1@2925.com', password: 'p1', enabled: true, lastUsedAt: 10 },
]),
currentMail2925AccountId: 'acc-1',
};
let tabUrl = 'https://2925.com/login/';
const events = {
logs: [],
readyCalls: 0,
sendCalls: 0,
waitCompleteCalls: 0,
};
const manager = api.createMail2925SessionManager({
addLog: async (message, level = 'info') => {
events.logs.push({ message, level });
},
broadcastDataUpdate: () => {},
chrome: {
tabs: {
get: async () => ({ id: 9, url: tabUrl, status: tabUrl.includes('/#/mailList') ? 'complete' : 'loading' }),
},
cookies: {
getAll: async () => [],
remove: async () => ({ ok: true }),
},
browsingData: {
removeCookies: async () => {},
},
},
ensureContentScriptReadyOnTab: async () => {
events.readyCalls += 1;
},
findMail2925Account: mail2925Utils.findMail2925Account,
getMail2925AccountStatus: mail2925Utils.getMail2925AccountStatus,
getState: async () => currentState,
isAutoRunLockedState: () => false,
isMail2925AccountAvailable: mail2925Utils.isMail2925AccountAvailable,
MAIL2925_LIMIT_COOLDOWN_MS: mail2925Utils.MAIL2925_LIMIT_COOLDOWN_MS,
normalizeMail2925Account: mail2925Utils.normalizeMail2925Account,
normalizeMail2925Accounts: mail2925Utils.normalizeMail2925Accounts,
pickMail2925AccountForRun: mail2925Utils.pickMail2925AccountForRun,
reuseOrCreateTab: async () => 9,
sendToContentScriptResilient: async () => {
events.sendCalls += 1;
if (events.sendCalls === 1) {
throw new Error('Could not establish connection. Receiving end does not exist.');
}
return { loggedIn: true, currentView: 'mailbox', mailboxEmail: 'acc1@2925.com' };
},
setPersistentSettings: async (payload) => {
currentState = { ...currentState, ...payload };
},
setState: async (updates) => {
currentState = { ...currentState, ...updates };
},
throwIfStopped: () => {},
upsertMail2925AccountInList: mail2925Utils.upsertMail2925AccountInList,
waitForTabComplete: async () => {
events.waitCompleteCalls += 1;
tabUrl = 'https://2925.com/#/mailList';
return { id: 9, url: tabUrl, status: 'complete' };
},
});
const result = await manager.ensureMail2925MailboxSession({
accountId: 'acc-1',
forceRelogin: false,
allowLoginWhenOnLoginPage: true,
actionLabel: '步骤 4:确认 2925 邮箱登录态',
});
assert.equal(events.sendCalls, 2);
assert.equal(events.readyCalls, 2);
assert.equal(events.waitCompleteCalls, 1);
assert.equal(result.result.loggedIn, true);
const combinedLogs = events.logs.map(({ message }) => message).join('\n');
assert.match(combinedLogs, /登录提交后页面发生跳转或重载/);
assert.match(combinedLogs, /登录跳转恢复后当前标签地址:https:\/\/2925\.com\/#\/mailList/);
assert.match(combinedLogs, /页面恢复完成,正在重新确认登录态/);
});
test('ensureMail2925MailboxSession relogs with selected account when mailbox page email mismatches and pool is on', async () => {
let currentState = {
autoRunning: false,