spec: ipcRenderer.sendTo sends message to WebContents
This commit is contained in:
parent
ae1f442b02
commit
a58b84bbd7
2 changed files with 37 additions and 5 deletions
|
@ -3,11 +3,8 @@
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer
|
const {ipcRenderer, remote} = require('electron')
|
||||||
const remote = require('electron').remote
|
const {ipcMain, webContents, BrowserWindow} = remote
|
||||||
|
|
||||||
const ipcMain = remote.require('electron').ipcMain
|
|
||||||
const BrowserWindow = remote.require('electron').BrowserWindow
|
|
||||||
|
|
||||||
const comparePaths = function (path1, path2) {
|
const comparePaths = function (path1, path2) {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
|
@ -237,6 +234,30 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('ipcRenderer.sendTo', function () {
|
||||||
|
let contents = null
|
||||||
|
beforeEach(function () {
|
||||||
|
contents = webContents.create({})
|
||||||
|
})
|
||||||
|
afterEach(function () {
|
||||||
|
ipcRenderer.removeAllListeners('pong')
|
||||||
|
contents.destroy()
|
||||||
|
contents = null
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sends message to WebContents', function (done) {
|
||||||
|
const webContentsId = remote.getCurrentWebContents().id
|
||||||
|
ipcRenderer.once('pong', function (event, id) {
|
||||||
|
assert.equal(webContentsId, id)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
contents.once('did-finish-load', function () {
|
||||||
|
ipcRenderer.sendTo(contents.id, 'ping', webContentsId)
|
||||||
|
})
|
||||||
|
contents.loadURL('file://' + path.join(fixtures, 'pages', 'ping-pong.html'))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('remote listeners', function () {
|
describe('remote listeners', function () {
|
||||||
var w = null
|
var w = null
|
||||||
|
|
||||||
|
|
11
spec/fixtures/pages/ping-pong.html
vendored
Normal file
11
spec/fixtures/pages/ping-pong.html
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
ipcRenderer.on('ping', function (event, id) {
|
||||||
|
ipcRenderer.sendTo(id, 'pong', id)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue