-
Notifications
You must be signed in to change notification settings - Fork 15k
/
api-web-frame-spec.js
82 lines (69 loc) · 2.56 KB
/
api-web-frame-spec.js
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
72
73
74
75
76
77
78
79
80
81
82
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const path = require('path')
const { closeWindow } = require('./window-helpers')
const { remote, webFrame } = require('electron')
const { BrowserWindow, ipcMain } = remote
const { expect } = chai
chai.use(dirtyChai)
/* Most of the APIs here don't use standard callbacks */
/* eslint-disable standard/no-callback-literal */
describe('webFrame module', function () {
const fixtures = path.resolve(__dirname, 'fixtures')
let w = null
afterEach(function () {
return closeWindow(w).then(function () { w = null })
})
it('supports setting the visual and layout zoom level limits', function () {
expect(() => {
webFrame.setVisualZoomLevelLimits(1, 50)
webFrame.setLayoutZoomLevelLimits(0, 25)
}).to.not.throw()
})
it('calls a spellcheck provider', async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html'))
w.focus()
await w.webContents.executeJavaScript('document.querySelector("input").focus()', true)
const spellCheckerFeedback =
new Promise(resolve => {
ipcMain.on('spec-spell-check', (e, words, callback) => {
if (words.length === 5) {
// The API calls the provider after every completed word.
// The promise is resolved only after this event is received with all words.
resolve([words, callback])
}
})
})
const inputText = `spleling test you're `
for (const keyCode of inputText) {
w.webContents.sendInputEvent({ type: 'char', keyCode })
}
const [words, callback] = await spellCheckerFeedback
expect(words.sort()).to.deep.equal(['spleling', 'test', `you're`, 'you', 're'].sort())
expect(callback).to.be.true()
})
it('top is self for top frame', () => {
expect(webFrame.top.context).to.equal(webFrame.context)
})
it('opener is null for top frame', () => {
expect(webFrame.opener).to.be.null()
})
it('firstChild is null for top frame', () => {
expect(webFrame.firstChild).to.be.null()
})
it('getFrameForSelector() does not crash when not found', () => {
expect(webFrame.getFrameForSelector('unexist-selector')).to.be.null()
})
it('findFrameByName() does not crash when not found', () => {
expect(webFrame.findFrameByName('unexist-name')).to.be.null()
})
it('findFrameByRoutingId() does not crash when not found', () => {
expect(webFrame.findFrameByRoutingId(-1)).to.be.null()
})
})