Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
test: fix and re-enable Network.getResponseBody test (electron#33227)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored and khalwa committed Feb 22, 2023
1 parent cf62710 commit 2e404d6
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions spec-main/api-debugger-spec.ts
Expand Up @@ -133,39 +133,26 @@ describe('debugger module', () => {
w.webContents.debugger.detach();
});

// TODO(deepak1556): Fix and enable with upgrade
it.skip('handles valid unicode characters in message', (done) => {
try {
w.webContents.debugger.attach();
} catch (err) {
done(`unexpected error : ${err}`);
}

let requestId : number;
w.webContents.debugger.on('message', (event, method, params) => {
if (method === 'Network.responseReceived' &&
params.response.url.startsWith('http://127.0.0.1')) {
requestId = params.requestId;
} else if (method === 'Network.loadingFinished' &&
params.requestId === requestId) {
w.webContents.debugger.sendCommand('Network.getResponseBody', {
requestId: params.requestId
}).then(data => {
expect(data.body).to.equal('\u0024');
done();
}).catch(result => done(result));
}
});

it('handles valid unicode characters in message', async () => {
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end('\u0024');
});
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));

server.listen(0, '127.0.0.1', () => {
w.webContents.debugger.sendCommand('Network.enable');
w.loadURL(`http://127.0.0.1:${(server.address() as AddressInfo).port}`);
});
w.loadURL(`http://127.0.0.1:${(server.address() as AddressInfo).port}`);
// If we do this synchronously, it's fast enough to attach and enable
// network capture before the load. If we do it before the loadURL, for
// some reason network capture doesn't get enabled soon enough and we get
// an error when calling `Network.getResponseBody`.
w.webContents.debugger.attach();
w.webContents.debugger.sendCommand('Network.enable');
const [,, { requestId }] = await emittedUntil(w.webContents.debugger, 'message', (_event: any, method: string, params: any) =>
method === 'Network.responseReceived' && params.response.url.startsWith('http://127.0.0.1'));
await emittedUntil(w.webContents.debugger, 'message', (_event: any, method: string, params: any) =>
method === 'Network.loadingFinished' && params.requestId === requestId);
const { body } = await w.webContents.debugger.sendCommand('Network.getResponseBody', { requestId });
expect(body).to.equal('\u0024');
});

it('does not crash for invalid unicode characters in message', (done) => {
Expand Down

0 comments on commit 2e404d6

Please sign in to comment.