forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-web-utils-spec.ts
53 lines (50 loc) · 1.89 KB
/
api-web-utils-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { expect } from 'chai';
import * as path from 'node:path';
import { BrowserWindow } from 'electron/main';
import { defer } from './lib/spec-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(() => w.close());
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(() => w.close());
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();
}
});
});
});