fix: close iCloud mail tabs after verification success

This commit is contained in:
QLHazyCoder
2026-04-25 15:14:35 +08:00
parent 84e2f9bd8b
commit 672c593271
5 changed files with 127 additions and 1 deletions
@@ -35,3 +35,28 @@ test('navigation utils support codex2api mode and url normalization', () => {
assert.equal(utils.getPanelMode({ panelMode: 'codex2api' }), 'codex2api');
assert.equal(utils.getPanelModeLabel('codex2api'), 'Codex2API');
});
test('navigation utils recognize the iCloud mail tab family on both supported hosts', () => {
const source = fs.readFileSync('background/navigation-utils.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundNavigationUtils;`)(globalScope);
const utils = api.createNavigationUtils({
DEFAULT_CODEX2API_URL: 'http://localhost:8080/admin/accounts',
DEFAULT_SUB2API_URL: 'https://sub.example.com/admin/accounts',
normalizeLocalCpaStep9Mode: (value) => value,
});
assert.equal(
utils.matchesSourceUrlFamily('icloud-mail', 'https://www.icloud.com/mail/', 'https://www.icloud.com/mail/'),
true
);
assert.equal(
utils.matchesSourceUrlFamily('icloud-mail', 'https://www.icloud.com.cn/mail/', 'https://www.icloud.com.cn/mail/'),
true
);
assert.equal(
utils.matchesSourceUrlFamily('icloud-mail', 'https://mail.google.com/mail/u/0/#inbox', 'https://www.icloud.com/mail/'),
false
);
});
+71
View File
@@ -280,6 +280,77 @@ test('verification flow skips 2925 mailbox preclear when using a fixed signup ma
assert.deepStrictEqual(mailMessages, ['POLL_EMAIL', 'DELETE_ALL_EMAILS']);
});
test('verification flow closes the tracked iCloud mail tab after a successful verification submit', async () => {
const removedTabIds = [];
const logMessages = [];
const helpers = api.createVerificationFlowHelpers({
addLog: async (message) => {
logMessages.push(message);
},
chrome: {
tabs: {
update: async () => {},
remove: async (tabId) => {
removedTabIds.push(tabId);
},
},
},
closeConflictingTabsForSource: async () => {
throw new Error('should not use family cleanup when tracked tab exists');
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeStepFromBackground: async () => {},
confirmCustomVerificationStepBypassRequest: async () => ({ confirmed: true }),
getHotmailVerificationPollConfig: () => ({}),
getHotmailVerificationRequestTimestamp: () => 0,
getState: async () => ({}),
getTabId: async (source) => (source === 'icloud-mail' ? 91 : 1),
HOTMAIL_PROVIDER: 'hotmail-api',
isStopError: () => false,
LUCKMAIL_PROVIDER: 'luckmail-api',
MAIL_2925_VERIFICATION_INTERVAL_MS: 15000,
MAIL_2925_VERIFICATION_MAX_ATTEMPTS: 15,
pollCloudflareTempEmailVerificationCode: async () => ({}),
pollHotmailVerificationCode: async () => ({}),
pollLuckmailVerificationCode: async () => ({}),
sendToContentScript: async (_source, message) => {
if (message.type === 'FILL_CODE') {
return {};
}
return {};
},
sendToMailContentScriptResilient: async () => ({
code: '654321',
emailTimestamp: 123,
}),
setState: async () => {},
setStepStatus: async () => {},
sleepWithStop: async () => {},
throwIfStopped: () => {},
VERIFICATION_POLL_MAX_ROUNDS: 5,
});
await helpers.resolveVerificationStep(
4,
{
email: 'user@example.com',
lastSignupCode: null,
},
{
source: 'icloud-mail',
url: 'https://www.icloud.com/mail/',
label: 'iCloud 邮箱',
},
{}
);
await new Promise((resolve) => setTimeout(resolve, 0));
assert.deepStrictEqual(removedTabIds, [91]);
assert.ok(logMessages.some((message) => message.includes('已关闭 iCloud 邮箱标签页')));
});
test('verification flow completes step 8 and flags phone verification when add-phone appears after login code submit', async () => {
const events = [];