-
Notifications
You must be signed in to change notification settings - Fork 15k
/
api-web-contents-spec.ts
71 lines (58 loc) · 2 KB
/
api-web-contents-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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import * as path from 'path'
import { BrowserWindow, ipcMain, webContents } from 'electron'
import { emittedOnce } from './events-helpers';
import { closeWindow } from './window-helpers';
const { expect } = chai
chai.use(chaiAsPromised)
const fixturesPath = path.resolve(__dirname, '../spec/fixtures')
describe('webContents module', () => {
let w: BrowserWindow = (null as unknown as BrowserWindow)
beforeEach(() => {
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
sandbox: false,
contextIsolation: false,
webviewTag: true
}
})
})
afterEach(async () => {
await closeWindow(w)
w = (null as unknown as BrowserWindow)
})
describe('getAllWebContents() API', () => {
it('returns an array of web contents', async () => {
w.loadFile(path.join(fixturesPath, 'pages', 'webview-zoom-factor.html'))
await emittedOnce(w.webContents, 'did-attach-webview')
w.webContents.openDevTools()
await emittedOnce(w.webContents, 'devtools-opened')
const all = webContents.getAllWebContents().sort((a, b) => {
return a.id - b.id
})
expect(all).to.have.length(3)
expect(all[0].getType()).to.equal('window')
expect(all[all.length - 2].getType()).to.equal('webview')
expect(all[all.length - 1].getType()).to.equal('remote')
})
})
describe('webContents.send(channel, args...)', () => {
it('does not block node async APIs when sent before document is ready', (done) => {
// Please reference https://github.com/electron/electron/issues/19368 if
// this test fails.
ipcMain.once('async-node-api-done', () => {
done()
})
w.loadFile(path.join(fixturesPath, 'pages', 'send-after-node.html'))
setTimeout(() => {
w.webContents.send("test")
}, 50)
})
})
})