fix: re-entrancy issues in webContents.loadURL()
(#48043)
This commit is contained in:
parent
cea5034019
commit
a130d4ebfe
3 changed files with 53 additions and 2 deletions
|
@ -484,7 +484,7 @@ describe('webContents module', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('fails if loadURL is called inside a non-reentrant critical section', (done) => {
|
||||
it('fails if loadURL is called inside did-start-loading', (done) => {
|
||||
w.webContents.once('did-fail-load', (_event, _errorCode, _errorDescription, validatedURL) => {
|
||||
expect(validatedURL).to.contain('blank.html');
|
||||
done();
|
||||
|
@ -497,6 +497,49 @@ describe('webContents module', () => {
|
|||
w.loadURL('data:text/html,<h1>HELLO</h1>');
|
||||
});
|
||||
|
||||
it('fails if loadurl is called after the navigation is ready to commit', () => {
|
||||
w.webContents.once('did-fail-load', (_event, _errorCode, _errorDescription, validatedURL) => {
|
||||
expect(validatedURL).to.contain('blank.html');
|
||||
});
|
||||
|
||||
// @ts-expect-error internal-only event.
|
||||
w.webContents.once('-ready-to-commit-navigation', () => {
|
||||
w.loadURL(`file://${fixturesPath}/pages/blank.html`);
|
||||
});
|
||||
|
||||
w.loadURL('data:text/html,<h1>HELLO</h1>');
|
||||
});
|
||||
|
||||
it('fails if loadURL is called inside did-redirect-navigation', (done) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.url === '/302') {
|
||||
res.statusCode = 302;
|
||||
res.setHeader('Location', '/200');
|
||||
res.end();
|
||||
} else if (req.url === '/200') {
|
||||
res.end('ok');
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
|
||||
w.webContents.once('did-fail-load', (_event, _errorCode, _errorDescription, validatedURL) => {
|
||||
expect(validatedURL).to.contain('blank.html');
|
||||
server.close();
|
||||
done();
|
||||
});
|
||||
|
||||
listen(server).then(({ url }) => {
|
||||
w.webContents.once('did-redirect-navigation', () => {
|
||||
w.loadURL(`file://${fixturesPath}/pages/blank.html`);
|
||||
});
|
||||
w.loadURL(`${url}/302`);
|
||||
}).catch(e => {
|
||||
server.close();
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('sets appropriate error information on rejection', async () => {
|
||||
let err: any;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue