修复 Step 5 导航交棒后的完成收尾
This commit is contained in:
@@ -201,3 +201,59 @@ return {
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test('step 5 recovers from bfcache transport close when tab already reached chatgpt', async () => {
|
||||
const api = new Function(`
|
||||
const logs = [];
|
||||
let waitCalls = 0;
|
||||
|
||||
async function getTabId(source) {
|
||||
return source === 'openai-auth' ? 42 : null;
|
||||
}
|
||||
|
||||
async function waitForTabStableComplete(tabId) {
|
||||
waitCalls += 1;
|
||||
if (tabId !== 42) throw new Error('unexpected tab id');
|
||||
return { url: 'https://chatgpt.com/' };
|
||||
}
|
||||
|
||||
async function addLog(message, level, meta) {
|
||||
logs.push({ message, level, meta });
|
||||
}
|
||||
|
||||
function getErrorMessage(error) {
|
||||
return String(error?.message || error || '');
|
||||
}
|
||||
|
||||
${extractFunction('parseUrlSafely')}
|
||||
${extractFunction('isSignupEntryHost')}
|
||||
${extractFunction('isLikelyLoggedInChatgptHomeUrl')}
|
||||
${extractFunction('isStep5CompletionChatgptUrl')}
|
||||
${extractFunction('completeStep5FromTabUrlAfterTransportError')}
|
||||
|
||||
return {
|
||||
async run() {
|
||||
return completeStep5FromTabUrlAfterTransportError(new Error('The page keeping the extension port is moved into back/forward cache, so the message channel is closed.'));
|
||||
},
|
||||
snapshot() {
|
||||
return { logs, waitCalls };
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run();
|
||||
const snapshot = api.snapshot();
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
recoveredFromTransportError: true,
|
||||
});
|
||||
assert.equal(snapshot.waitCalls, 1);
|
||||
assert.equal(
|
||||
snapshot.logs.some(({ message }) => /通信中断,但后台确认标签页已进入 chatgpt\.com/.test(message)),
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1109,7 +1109,7 @@ return {
|
||||
assert.equal(api.isCompletion('https://chatgpt.com/add-phone'), false);
|
||||
});
|
||||
|
||||
test('step 5 navigation reporter does not complete on beforeunload alone', () => {
|
||||
test('step 5 navigation reporter hands off to background on beforeunload', () => {
|
||||
const api = new Function(`
|
||||
const events = [];
|
||||
const listeners = new Map();
|
||||
@@ -1147,22 +1147,31 @@ ${extractFunction('installStep5NavigationCompletionReporter')}
|
||||
|
||||
return {
|
||||
run() {
|
||||
let completionCount = 0;
|
||||
const cleanup = installStep5NavigationCompletionReporter(() => {
|
||||
completionCount += 1;
|
||||
events.push({ type: 'complete' });
|
||||
const cleanup = installStep5NavigationCompletionReporter((payload) => {
|
||||
events.push({ type: 'complete', payload });
|
||||
});
|
||||
const beforeUnload = listeners.get('beforeunload');
|
||||
if (beforeUnload) {
|
||||
beforeUnload({ type: 'beforeunload' });
|
||||
}
|
||||
cleanup();
|
||||
return { completionCount, events };
|
||||
return { events };
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = api.run();
|
||||
assert.equal(result.completionCount, 0);
|
||||
assert.deepStrictEqual(
|
||||
result.events.filter((entry) => entry.type === 'complete'),
|
||||
[
|
||||
{
|
||||
type: 'complete',
|
||||
payload: {
|
||||
navigationStarted: true,
|
||||
navigationEventType: 'beforeunload',
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
assert.equal(result.events.some((entry) => entry.type === 'log' && /检测到页面开始导航/.test(entry.message)), true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user