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:
trop[bot] 2024-06-05 17:25:33 -04:00 committed by GitHub
parent ea76144fa1
commit bd17a98386
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 14 deletions

View file

@ -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();