fix: WebUSB should not crash when using in-memory partitions (#42365)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
ea76144fa1
commit
bd17a98386
3 changed files with 68 additions and 14 deletions
|
@ -3505,18 +3505,44 @@ describe('navigator.usb', () => {
|
|||
`, true);
|
||||
};
|
||||
|
||||
const getDevices: any = () => {
|
||||
return w.webContents.executeJavaScript(`
|
||||
navigator.usb.getDevices().then(devices => devices.map(device => device.toString())).catch(err => err.toString());
|
||||
`, true);
|
||||
};
|
||||
|
||||
const notFoundError = 'NotFoundError: Failed to execute \'requestDevice\' on \'USB\': No device selected.';
|
||||
|
||||
after(() => {
|
||||
server.close();
|
||||
closeAllWindows();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
session.defaultSession.setPermissionCheckHandler(null);
|
||||
session.defaultSession.setDevicePermissionHandler(null);
|
||||
session.defaultSession.removeAllListeners('select-usb-device');
|
||||
});
|
||||
|
||||
it('does not crash when using in-memory partitions', async () => {
|
||||
const sesWin = new BrowserWindow({
|
||||
webPreferences: {
|
||||
partition: 'test-partition'
|
||||
}
|
||||
});
|
||||
|
||||
await sesWin.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||
server = http.createServer((req, res) => {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.end('<body>');
|
||||
});
|
||||
|
||||
serverUrl = (await listen(server)).url;
|
||||
|
||||
const devices = await getDevices();
|
||||
expect(devices).to.be.an('array').that.is.empty();
|
||||
});
|
||||
|
||||
it('does not return a device if select-usb-device event is not defined', async () => {
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||
const device = await requestDevices();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue