From 67642312f427ce0b87f12a84557b34b08946d2b6 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Fri, 11 Oct 2019 10:20:08 -0700 Subject: [PATCH] test: remove remote usage from webFrame test (#20512) --- spec-main/api-web-frame-spec.ts | 40 +++++++++++++++++++++++++++++ spec/api-web-frame-spec.js | 45 +-------------------------------- spec/webview-spec.js | 1 - 3 files changed, 41 insertions(+), 45 deletions(-) create mode 100644 spec-main/api-web-frame-spec.ts diff --git a/spec-main/api-web-frame-spec.ts b/spec-main/api-web-frame-spec.ts new file mode 100644 index 000000000000..a64492894268 --- /dev/null +++ b/spec-main/api-web-frame-spec.ts @@ -0,0 +1,40 @@ +import { expect } from 'chai' +import * as path from 'path' +import { BrowserWindow, ipcMain } from 'electron' +import { closeAllWindows } from './window-helpers' + +describe('webFrame module', () => { + const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures') + + afterEach(closeAllWindows) + + it('calls a spellcheck provider', async () => { + const 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<[string[], boolean]>(resolve => { + ipcMain.on('spec-spell-check', (e, words, callbackDefined) => { + 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, callbackDefined]) + } + }) + }) + const inputText = `spleling test you're ` + for (const keyCode of inputText) { + w.webContents.sendInputEvent({ type: 'char', keyCode }) + } + const [words, callbackDefined] = await spellCheckerFeedback + expect(words.sort()).to.deep.equal(['spleling', 'test', `you're`, 'you', 're'].sort()) + expect(callbackDefined).to.be.true() + }) +}) \ No newline at end of file diff --git a/spec/api-web-frame-spec.js b/spec/api-web-frame-spec.js index e0a6772b0ead..25f318707374 100644 --- a/spec/api-web-frame-spec.js +++ b/spec/api-web-frame-spec.js @@ -1,24 +1,11 @@ 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 { webFrame } = require('electron') 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) @@ -26,36 +13,6 @@ describe('webFrame module', function () { }).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) }) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 3f497f6f1d17..57969fd82136 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -4,7 +4,6 @@ const path = require('path') const http = require('http') const url = require('url') const { ipcRenderer } = require('electron') -const { closeWindow } = require('./window-helpers') const { emittedOnce, waitForEvent } = require('./events-helpers') const { expect } = chai