From: Cheng Zhao Date: Wed, 18 May 2016 13:14:51 +0000 (+0900) Subject: spec: ipcRenderer.sendTo sends message to WebContents X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a58b84bbd76a931c43dfe1c5b9e9908a5f108518;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git spec: ipcRenderer.sendTo sends message to WebContents --- diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 102b23e..46aa847 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -3,11 +3,8 @@ const assert = require('assert') const path = require('path') -const ipcRenderer = require('electron').ipcRenderer -const remote = require('electron').remote - -const ipcMain = remote.require('electron').ipcMain -const BrowserWindow = remote.require('electron').BrowserWindow +const {ipcRenderer, remote} = require('electron') +const {ipcMain, webContents, BrowserWindow} = remote const comparePaths = function (path1, path2) { 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 () { var w = null diff --git a/spec/fixtures/pages/ping-pong.html b/spec/fixtures/pages/ping-pong.html new file mode 100644 index 0000000..d10e789 --- /dev/null +++ b/spec/fixtures/pages/ping-pong.html @@ -0,0 +1,11 @@ + + + + + +