mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
- api-subframe: 'should not crash when changing subframe src' never closed w - api-view: 'can be added as a child of another View' declared a local const w shadowing the describe-level one the afterEach closes - api-web-frame / api-web-utils: defer(() => w.close()) and afterAll win.close() don't await 'closed', so windows were still in getAllWindows() when the global leak check fired; use closeWindow() which awaits
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { BrowserWindow } from 'electron/main';
|
|
|
|
import { expect } from 'chai';
|
|
import { describe, it } from 'vitest';
|
|
|
|
import * as path from 'node:path';
|
|
|
|
import { defer } from './lib/spec-helpers';
|
|
import { closeWindow } from './lib/window-helpers';
|
|
|
|
// import { once } from 'node:events';
|
|
|
|
describe('webUtils module', () => {
|
|
const fixtures = path.resolve(__dirname, 'fixtures');
|
|
|
|
describe('getPathForFile', () => {
|
|
it('returns nothing for a Blob', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
contextIsolation: false,
|
|
nodeIntegration: true,
|
|
sandbox: false
|
|
}
|
|
});
|
|
defer(() => closeWindow(w));
|
|
await w.loadFile(path.resolve(fixtures, 'pages', 'file-input.html'));
|
|
const pathFromWebUtils = await w.webContents.executeJavaScript(
|
|
'require("electron").webUtils.getPathForFile(new Blob([1, 2, 3]))'
|
|
);
|
|
expect(pathFromWebUtils).to.equal('');
|
|
});
|
|
|
|
it('reports the correct path for a File object', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
contextIsolation: false,
|
|
nodeIntegration: true,
|
|
sandbox: false
|
|
}
|
|
});
|
|
defer(() => closeWindow(w));
|
|
await w.loadFile(path.resolve(fixtures, 'pages', 'file-input.html'));
|
|
const { debugger: debug } = w.webContents;
|
|
debug.attach();
|
|
try {
|
|
const {
|
|
root: { nodeId }
|
|
} = await debug.sendCommand('DOM.getDocument');
|
|
const { nodeId: inputNodeId } = await debug.sendCommand('DOM.querySelector', { nodeId, selector: 'input' });
|
|
await debug.sendCommand('DOM.setFileInputFiles', {
|
|
files: [__filename],
|
|
nodeId: inputNodeId
|
|
});
|
|
const pathFromWebUtils = await w.webContents.executeJavaScript(
|
|
'require("electron").webUtils.getPathForFile(document.querySelector("input").files[0])'
|
|
);
|
|
expect(pathFromWebUtils).to.equal(__filename);
|
|
} finally {
|
|
debug.detach();
|
|
}
|
|
});
|
|
});
|
|
});
|