fix(tabs): stop fallback outside locked window
This commit is contained in:
@@ -44,6 +44,8 @@ ${coreSource}
|
||||
return {
|
||||
applyExitRegionExpectation,
|
||||
buildIpProxyPacScript,
|
||||
chrome,
|
||||
createAutomationScopedTab,
|
||||
buildIpProxyRoutingStatePatch,
|
||||
applyTargetReachabilityExpectation,
|
||||
getAccountModeProxyPoolFromState,
|
||||
@@ -51,6 +53,7 @@ return {
|
||||
normalizeProxyPoolEntries,
|
||||
parseProxyExitProbePayload,
|
||||
parseIpProxyLine,
|
||||
queryAutomationScopedTabs,
|
||||
resolveExitProbeEndpoints,
|
||||
resolveIpProxyAutoSwitchThreshold,
|
||||
resolveTargetReachabilityEndpoints,
|
||||
@@ -135,6 +138,46 @@ test('IP proxy routing state patch keeps exit probe endpoint for diagnostics', (
|
||||
assert.equal(patch.ipProxyAppliedExitEndpoint, 'https://ipinfo.io/json');
|
||||
});
|
||||
|
||||
test('IP proxy page probes do not fall back to other windows when the locked window is unavailable', async () => {
|
||||
const api = loadIpProxyCore();
|
||||
const created = [];
|
||||
const queries = [];
|
||||
api.chrome.tabs = {
|
||||
create: async (payload) => {
|
||||
created.push(payload);
|
||||
if (payload.windowId === 77) {
|
||||
throw new Error('No window with id: 77');
|
||||
}
|
||||
return { id: 12, windowId: payload.windowId, url: payload.url };
|
||||
},
|
||||
query: async (queryInfo) => {
|
||||
queries.push(queryInfo);
|
||||
if (queryInfo.windowId === 77) {
|
||||
throw new Error('No window with id: 77');
|
||||
}
|
||||
return [{ id: 99, windowId: 1, url: 'https://ipinfo.io/json' }];
|
||||
},
|
||||
};
|
||||
|
||||
await assert.rejects(
|
||||
() => api.createAutomationScopedTab(
|
||||
{ url: 'https://ipinfo.io/json', active: false },
|
||||
{ state: { automationWindowId: 77 } }
|
||||
),
|
||||
/自动任务窗口已不可用/
|
||||
);
|
||||
await assert.rejects(
|
||||
() => api.queryAutomationScopedTabs(
|
||||
{ url: 'https://ipinfo.io/*' },
|
||||
{ state: { automationWindowId: 77 } }
|
||||
),
|
||||
/自动任务窗口已不可用/
|
||||
);
|
||||
|
||||
assert.deepEqual(created, [{ url: 'https://ipinfo.io/json', active: false, windowId: 77 }]);
|
||||
assert.deepEqual(queries, [{ url: 'https://ipinfo.io/*', windowId: 77 }]);
|
||||
});
|
||||
|
||||
test('711 fixed-account mode applies region and sticky session parameters', () => {
|
||||
const api = loadIpProxyCore();
|
||||
const pool = api.getAccountModeProxyPoolFromState({
|
||||
|
||||
@@ -260,3 +260,82 @@ test('tab runtime scopes tab queries to the locked automation window', async ()
|
||||
|
||||
assert.deepEqual(queries[0], { active: true, windowId: 22 });
|
||||
});
|
||||
|
||||
test('tab runtime does not create tabs outside an unavailable locked window', async () => {
|
||||
const source = fs.readFileSync('background/tab-runtime.js', 'utf8');
|
||||
const globalScope = {};
|
||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundTabRuntime;`)(globalScope);
|
||||
const created = [];
|
||||
const runtime = api.createTabRuntime({
|
||||
LOG_PREFIX: '[test]',
|
||||
addLog: async () => {},
|
||||
chrome: {
|
||||
tabs: {
|
||||
create: async (payload) => {
|
||||
created.push(payload);
|
||||
if (payload.windowId === 44) {
|
||||
throw new Error('No window with id: 44');
|
||||
}
|
||||
return { id: 99, windowId: payload.windowId, url: payload.url };
|
||||
},
|
||||
get: async () => ({ id: 1, windowId: 44, url: 'https://example.com' }),
|
||||
query: async () => [],
|
||||
},
|
||||
},
|
||||
getSourceLabel: (sourceName) => sourceName || 'unknown',
|
||||
getState: async () => ({
|
||||
automationWindowId: 44,
|
||||
tabRegistry: {},
|
||||
sourceLastUrls: {},
|
||||
}),
|
||||
matchesSourceUrlFamily: () => false,
|
||||
setState: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
() => runtime.createAutomationTab({ url: 'https://example.com', active: true }),
|
||||
/自动任务窗口已不可用/
|
||||
);
|
||||
|
||||
assert.deepEqual(created, [{ url: 'https://example.com', active: true, windowId: 44 }]);
|
||||
});
|
||||
|
||||
test('tab runtime does not query all windows when the locked window is unavailable', async () => {
|
||||
const source = fs.readFileSync('background/tab-runtime.js', 'utf8');
|
||||
const globalScope = {};
|
||||
const api = new Function('self', `${source}; return self.MultiPageBackgroundTabRuntime;`)(globalScope);
|
||||
const queries = [];
|
||||
const runtime = api.createTabRuntime({
|
||||
LOG_PREFIX: '[test]',
|
||||
addLog: async () => {},
|
||||
chrome: {
|
||||
tabs: {
|
||||
get: async () => ({ id: 1, windowId: 55, url: 'https://example.com' }),
|
||||
query: async (queryInfo) => {
|
||||
queries.push(queryInfo);
|
||||
if (queryInfo.windowId === 55) {
|
||||
throw new Error('No window with id: 55');
|
||||
}
|
||||
return [{ id: 7, windowId: 1, url: 'https://other.example/' }];
|
||||
},
|
||||
},
|
||||
},
|
||||
getSourceLabel: (sourceName) => sourceName || 'unknown',
|
||||
getState: async () => ({
|
||||
automationWindowId: 55,
|
||||
tabRegistry: {},
|
||||
sourceLastUrls: {},
|
||||
}),
|
||||
matchesSourceUrlFamily: () => false,
|
||||
setState: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
() => runtime.queryTabsInAutomationWindow({ active: true }),
|
||||
/自动任务窗口已不可用/
|
||||
);
|
||||
|
||||
assert.deepEqual(queries, [{ active: true, windowId: 55 }]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user