2016-03-25 20:03:49 +00:00
|
|
|
const assert = require('assert')
|
2018-07-10 19:43:39 +00:00
|
|
|
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')
|
2019-01-29 07:11:01 +00:00
|
|
|
const { BrowserWindow, ipcMain } = remote
|
2018-07-10 19:43:39 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
2018-07-10 19:43:39 +00:00
|
|
|
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 () {
|
2018-09-28 23:17:00 +00:00
|
|
|
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 () {
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
webFrame.setVisualZoomLevelLimits(1, 50)
|
|
|
|
webFrame.setLayoutZoomLevelLimits(0, 25)
|
|
|
|
})
|
|
|
|
})
|
2018-07-10 19:43:39 +00:00
|
|
|
|
|
|
|
it('calls a spellcheck provider', async () => {
|
2019-01-07 19:19:27 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2018-12-19 06:44:03 +00:00
|
|
|
await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html'))
|
2018-10-10 03:02:46 +00:00
|
|
|
w.focus()
|
|
|
|
await w.webContents.executeJavaScript('document.querySelector("input").focus()', true)
|
2018-07-10 19:43:39 +00:00
|
|
|
|
2018-10-18 16:11:53 +00:00
|
|
|
const spellCheckerFeedback =
|
2018-12-19 06:44:03 +00:00
|
|
|
new Promise(resolve => {
|
2018-10-18 16:11:53 +00:00
|
|
|
ipcMain.on('spec-spell-check', (e, words, callback) => {
|
|
|
|
if (words.length === 2) {
|
|
|
|
// The promise is resolved only after this event is received twice
|
|
|
|
// Array contains only 1 word first time and 2 the next time
|
|
|
|
resolve([words, callback])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const inputText = 'spleling test '
|
|
|
|
for (const keyCode of inputText) {
|
2018-09-13 16:10:51 +00:00
|
|
|
w.webContents.sendInputEvent({ type: 'char', keyCode })
|
2018-07-10 19:43:39 +00:00
|
|
|
}
|
2018-10-18 16:11:53 +00:00
|
|
|
const [words, callback] = await spellCheckerFeedback
|
|
|
|
expect(words).to.deep.equal(['spleling', 'test'])
|
|
|
|
expect(callback).to.be.true()
|
2018-07-10 19:43:39 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|