feat: add senderIsMainFrame
to messages sent via ipcRenderer.sendTo()
(#38868)
* feat: add isMainFrame to events emitted via ipcRenderer.sendTo() * chore: rename isMainFrame to senderIsMainFrame
This commit is contained in:
parent
09e6e4b9a7
commit
3df6d337f3
11 changed files with 71 additions and 21 deletions
|
@ -9,7 +9,14 @@ describe('ipcRenderer module', () => {
|
|||
|
||||
let w: BrowserWindow;
|
||||
before(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
nodeIntegrationInSubFrames: true,
|
||||
contextIsolation: false
|
||||
}
|
||||
});
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
after(async () => {
|
||||
|
@ -154,7 +161,36 @@ describe('ipcRenderer module', () => {
|
|||
ipcRenderer.sendTo(${contents.id}, 'ping', ${JSON.stringify(payload)})
|
||||
ipcRenderer.once('pong', (event, data) => resolve(data))
|
||||
})`);
|
||||
expect(data).to.equal(payload);
|
||||
expect(data.payload).to.equal(payload);
|
||||
expect(data.senderIsMainFrame).to.be.true();
|
||||
});
|
||||
|
||||
it('sends message to WebContents from a child frame', async () => {
|
||||
const frameCreated = once(w.webContents, 'frame-created') as Promise<[any, Electron.FrameCreatedDetails]>;
|
||||
|
||||
const promise = w.webContents.executeJavaScript(`new Promise(resolve => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = 'data:text/html,';
|
||||
iframe.name = 'iframe';
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
ipcRenderer.once('pong', (event, data) => resolve(data));
|
||||
})`);
|
||||
|
||||
const [, details] = await frameCreated;
|
||||
expect(details.frame.name).to.equal('iframe');
|
||||
|
||||
await once(details.frame, 'dom-ready');
|
||||
|
||||
details.frame.executeJavaScript(`new Promise(resolve => {
|
||||
const { ipcRenderer } = require('electron');
|
||||
ipcRenderer.sendTo(${contents.id}, 'ping', ${JSON.stringify(payload)});
|
||||
})`);
|
||||
|
||||
const data = await promise;
|
||||
expect(data.payload).to.equal(payload);
|
||||
expect(data.senderIsMainFrame).to.be.false();
|
||||
});
|
||||
|
||||
it('sends message on channel with non-ASCII characters to WebContents', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue