electron/spec/api-web-frame-spec.js

83 lines
2.6 KiB
JavaScript
Raw Normal View History

const chai = require('chai')
const dirtyChai = require('dirty-chai')
2016-03-25 20:03:49 +00:00
const path = require('path')
2018-09-13 16:10:51 +00:00
const { closeWindow } = require('./window-helpers')
const { remote, webFrame } = require('electron')
const { BrowserWindow, ipcMain } = remote
2018-09-13 16:10:51 +00:00
const { expect } = chai
chai.use(dirtyChai)
2016-01-12 02:40:23 +00:00
2017-11-23 22:22:43 +00:00
/* Most of the APIs here don't use standard callbacks */
/* eslint-disable standard/no-callback-literal */
2016-03-25 20:03:49 +00:00
describe('webFrame module', function () {
const fixtures = path.resolve(__dirname, 'fixtures')
let w = null
2016-11-29 20:30:40 +00:00
afterEach(function () {
return closeWindow(w).then(function () { w = null })
})
2016-11-22 16:43:14 +00:00
it('supports setting the visual and layout zoom level limits', function () {
expect(() => {
2016-11-22 16:43:14 +00:00
webFrame.setVisualZoomLevelLimits(1, 50)
webFrame.setLayoutZoomLevelLimits(0, 25)
}).to.not.throw()
2016-11-22 16:43:14 +00:00
})
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) {
2018-09-13 16:10:51 +00:00
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()
})
2016-03-25 20:03:49 +00:00
})