fix: shell.trashItem crash when called in renderer (#28748)

This commit is contained in:
Jeremy Rose 2021-04-22 13:46:41 -07:00 committed by GitHub
parent d2654c652a
commit be3c2fd0af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View file

@ -62,6 +62,8 @@ describe('shell module', () => {
});
describe('shell.trashItem()', () => {
afterEach(closeAllWindows);
it('moves an item to the trash', async () => {
const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
const filename = path.join(dir, 'temp-to-be-deleted');
@ -74,5 +76,11 @@ describe('shell module', () => {
const filename = path.join(app.getPath('temp'), 'does-not-exist');
await expect(shell.trashItem(filename)).to.eventually.be.rejected();
});
it('works in the renderer process', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank');
await expect(w.webContents.executeJavaScript('require(\'electron\').shell.trashItem(\'does-not-exist\')')).to.be.rejectedWith(/does-not-exist|Failed to move item|Failed to create FileOperation/);
});
});
});