mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
test: keep Traffic interception off workers and restore screenshot windows
This commit is contained in:
1 parent
116f28a525
commit
168d491038
6 files changed
+230
-27
No files matched your search
+56
-1
@@ -1,6 +1,10 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { MACOS_CHROME, chromeExecutablePath } from '../scripts/qa-chrome.mjs';
|
||||
import {
|
||||
MACOS_CHROME,
|
||||
chromeExecutablePath,
|
||||
captureQaScreenshot,
|
||||
} from '../scripts/qa-chrome.mjs';
|
||||
|
||||
test('gates keep macOS Chrome where it is installed', () => {
|
||||
assert.equal(
|
||||
@@ -25,3 +29,54 @@ test('an explicit executable path wins', () => {
|
||||
'C:\\Chrome\\chrome.exe',
|
||||
);
|
||||
});
|
||||
|
||||
test('screenshots restore minimized test windows before capture and detach their session', async () => {
|
||||
const calls = [];
|
||||
const session = {
|
||||
send: async (method, params) => {
|
||||
calls.push([method, params]);
|
||||
return { windowId: 7, bounds: { windowState: 'minimized' } };
|
||||
},
|
||||
detach: async () => calls.push(['detach']),
|
||||
};
|
||||
const page = {
|
||||
createCDPSession: async () => session,
|
||||
bringToFront: async () => calls.push(['front']),
|
||||
screenshot: async (options) => {
|
||||
calls.push(['capture', options]);
|
||||
return 'pixels';
|
||||
},
|
||||
};
|
||||
assert.equal(
|
||||
await captureQaScreenshot(page, { path: 'proof.png' }),
|
||||
'pixels',
|
||||
);
|
||||
assert.deepEqual(
|
||||
calls.map((c) => c[0]),
|
||||
[
|
||||
'Browser.getWindowForTarget',
|
||||
'Browser.setWindowBounds',
|
||||
'front',
|
||||
'detach',
|
||||
'capture',
|
||||
],
|
||||
);
|
||||
assert.deepEqual(calls[1][1], {
|
||||
windowId: 7,
|
||||
bounds: { windowState: 'normal' },
|
||||
});
|
||||
});
|
||||
|
||||
test('headless capture does not manipulate a native window', async () => {
|
||||
const options = { path: 'proof.png' };
|
||||
const page = {
|
||||
screenshot: async (supplied) => {
|
||||
assert.equal(supplied, options);
|
||||
return 'pixels';
|
||||
},
|
||||
};
|
||||
assert.equal(
|
||||
await captureQaScreenshot(page, options, { headful: false }),
|
||||
'pixels',
|
||||
);
|
||||
});
|
||||
@@ -90,3 +90,81 @@ test('flat terrain fixture decodes through Cesium and advertises no network chil
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
||||
test('fixture interception targets provider URLs and leaves app workers alone', async () => {
|
||||
const { installTrafficRoutes } =
|
||||
await import('../../scripts/traffic-fixtures.mjs');
|
||||
const sent = [];
|
||||
let paused;
|
||||
const session = {
|
||||
on: (_, handler) => {
|
||||
paused = handler;
|
||||
},
|
||||
send: async (name, args) => {
|
||||
sent.push({ name, args });
|
||||
},
|
||||
};
|
||||
await installTrafficRoutes(
|
||||
{ createCDPSession: async () => session, isClosed: () => false },
|
||||
{ origin: 'http://localhost:4173', fixtures: true },
|
||||
);
|
||||
const patterns = sent[0].args.patterns.map((p) => p.urlPattern);
|
||||
assert.deepEqual(patterns, [
|
||||
'http://localhost:4173/api/tomtom/status*',
|
||||
'http://localhost:4173/api/tomtom/flow/*',
|
||||
'https://tiles.openfreemap.org/*',
|
||||
'https://terrain.reearth.land/*',
|
||||
]);
|
||||
await paused({
|
||||
requestId: 'terrain',
|
||||
request: { url: 'https://terrain.reearth.land/layer.json' },
|
||||
});
|
||||
const reply = sent.at(-1);
|
||||
assert.equal(reply.name, 'Fetch.fulfillRequest');
|
||||
assert.equal(
|
||||
JSON.parse(Buffer.from(reply.args.body, 'base64')).format,
|
||||
'heightmap-1.0',
|
||||
);
|
||||
assert.ok(
|
||||
reply.args.responseHeaders.some(
|
||||
(h) => h.name === 'access-control-allow-origin' && h.value === '*',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('keyless interception refuses and records unexpected flow requests', async () => {
|
||||
const { installTrafficRoutes } =
|
||||
await import('../../scripts/traffic-fixtures.mjs');
|
||||
const sent = [],
|
||||
flows = [];
|
||||
let paused;
|
||||
const session = {
|
||||
on: (_, handler) => {
|
||||
paused = handler;
|
||||
},
|
||||
send: async (name, args) => {
|
||||
sent.push({ name, args });
|
||||
},
|
||||
};
|
||||
await installTrafficRoutes(
|
||||
{ createCDPSession: async () => session, isClosed: () => false },
|
||||
{
|
||||
origin: 'http://localhost:4173',
|
||||
keyless: true,
|
||||
onFlow: (url) => flows.push(url),
|
||||
},
|
||||
);
|
||||
await paused({
|
||||
requestId: 'status',
|
||||
request: { url: 'http://localhost:4173/api/tomtom/status' },
|
||||
});
|
||||
assert.deepEqual(JSON.parse(Buffer.from(sent.at(-1).args.body, 'base64')), {
|
||||
hasKey: false,
|
||||
});
|
||||
await paused({
|
||||
requestId: 'flow',
|
||||
request: { url: 'http://localhost:4173/api/tomtom/flow/12/1/1.pbf' },
|
||||
});
|
||||
assert.equal(sent.at(-1).args.responseCode, 503);
|
||||
assert.equal(flows.length, 1);
|
||||
});
|
||||
Reference in new issue
Block a user