diff --git a/background/mail-2925-session.js b/background/mail-2925-session.js index 410fa97..4db55db 100644 --- a/background/mail-2925-session.js +++ b/background/mail-2925-session.js @@ -584,6 +584,18 @@ await failMailboxSession(`2925:${actionLabel}失败,登录后仍未进入收件箱。`); } + if (!account) { + await addLog('2925:未触发自动登录,继续复用当前已登录会话。', 'info'); + return { + account: null, + mail: getMail2925MailConfig(), + result: { + ...result, + usedExistingSession: true, + }, + }; + } + await patchMail2925Account(account.id, { lastLoginAt: Date.now(), lastError: '', diff --git a/tests/background-mail2925-entry-behavior.test.js b/tests/background-mail2925-entry-behavior.test.js index cd9cc07..ec75def 100644 --- a/tests/background-mail2925-entry-behavior.test.js +++ b/tests/background-mail2925-entry-behavior.test.js @@ -426,3 +426,69 @@ test('ensureMail2925MailboxSession stops when mailbox page email mismatches and assert.equal(stopCalls.length, 1); assert.match(stopCalls[0].logMessage, /与目标账号 target@2925\.com 不一致/); }); + +test('ensureMail2925MailboxSession does not crash when mailbox page is reused but top email cannot be detected', async () => { + let currentState = { + autoRunning: false, + mail2925UseAccountPool: false, + mail2925Accounts: [], + currentMail2925AccountId: null, + }; + let sendCalls = 0; + + const manager = api.createMail2925SessionManager({ + addLog: async () => {}, + broadcastDataUpdate: () => {}, + chrome: { + tabs: { + get: async () => ({ id: 9, url: 'https://2925.com/#/mailList' }), + }, + cookies: { + getAll: async () => [], + remove: async () => ({ ok: true }), + }, + browsingData: { + removeCookies: async () => {}, + }, + }, + ensureContentScriptReadyOnTab: async () => {}, + 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, + sendToMailContentScriptResilient: async () => { + sendCalls += 1; + return { + loggedIn: true, + currentView: 'mailbox', + mailboxEmail: '', + }; + }, + setPersistentSettings: async (payload) => { + currentState = { ...currentState, ...payload }; + }, + setState: async (updates) => { + currentState = { ...currentState, ...updates }; + }, + throwIfStopped: () => {}, + upsertMail2925AccountInList: mail2925Utils.upsertMail2925AccountInList, + }); + + const result = await manager.ensureMail2925MailboxSession({ + accountId: null, + forceRelogin: false, + allowLoginWhenOnLoginPage: false, + expectedMailboxEmail: 'target@2925.com', + actionLabel: '步骤 4:确认 2925 邮箱登录态', + }); + + assert.equal(sendCalls, 1); + assert.equal(result.account, null); + assert.equal(result.result.usedExistingSession, true); +}); diff --git a/tests/sidepanel-mail2925-base-email.test.js b/tests/sidepanel-mail2925-base-email.test.js index 8b17251..f27d503 100644 --- a/tests/sidepanel-mail2925-base-email.test.js +++ b/tests/sidepanel-mail2925-base-email.test.js @@ -186,6 +186,7 @@ const inputTempEmailBaseUrl = { value: '' }; const inputTempEmailAdminAuth = { value: '' }; const inputTempEmailCustomAuth = { value: '' }; const inputTempEmailReceiveMailbox = { value: '' }; +const inputTempEmailUseRandomSubdomain = { checked: false }; const inputAutoSkipFailures = { checked: false }; const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' }; const inputAutoDelayEnabled = { checked: false };