Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: move window.open postMessage test to main runner to fix flake #18735

Merged
merged 1 commit into from Jun 11, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,7 +1,8 @@
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { BrowserWindow, session } from 'electron'
import { BrowserWindow, session, ipcMain } from 'electron'
import { emittedOnce } from './events-helpers';
import { closeAllWindows } from './window-helpers';
import * as https from 'https';
import * as path from 'path';
import * as fs from 'fs';
@@ -70,3 +71,19 @@ describe('reporting api', () => {
}
})
})

describe('window.postMessage', () => {
afterEach(async () => {
await closeAllWindows()
})

it('sets the source and origin correctly', async () => {
const w = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true}})
w.loadURL(`file://${fixturesPath}/pages/window-open-postMessage-driver.html`)
const [, message] = await emittedOnce(ipcMain, 'complete')
expect(message.data).to.equal('testing')
expect(message.origin).to.equal('file://')
expect(message.sourceEqualsOpener).to.equal(true)
expect(message.eventOrigin).to.equal('file://')
})
})
@@ -39,3 +39,9 @@ export const closeWindow = async (
}
}
}

export async function closeAllWindows() {
for (const w of BrowserWindow.getAllWindows()) {
await closeWindow(w, {assertNotWindows: false})
}
}
@@ -721,27 +721,6 @@ describe('chromium feature', () => {
})

describe('window.postMessage', () => {
it('sets the source and origin correctly', (done) => {
let b = null
listener = (event) => {
window.removeEventListener('message', listener)
b.close()
const message = JSON.parse(event.data)
expect(message.data).to.equal('testing')
expect(message.origin).to.equal('file://')
expect(message.sourceEqualsOpener).to.be.true()
expect(event.origin).to.equal('file://')
done()
}
window.addEventListener('message', listener)
app.once('browser-window-created', (event, { webContents }) => {
webContents.once('did-finish-load', () => {
b.postMessage('testing', '*')
})
})
b = window.open(`file://${fixtures}/pages/window-open-postMessage.html`, '', 'show=no')
})

it('throws an exception when the targetOrigin cannot be converted to a string', () => {
const b = window.open('')
expect(() => {
@@ -0,0 +1,10 @@
<script>
const child = window.open(`./window-open-postMessage.html`, '', 'show=no')
window.onmessage = (e) => {
if (e.data === 'ready') {
child.postMessage('testing', '*')
} else {
require('electron').ipcRenderer.send('complete', {eventOrigin: e.origin, ...JSON.parse(e.data)})
}
}
</script>
@@ -8,6 +8,7 @@
sourceEqualsOpener: e.source === window.opener
}), '*');
});
window.opener.postMessage("ready", "*")
</script>
</body>
</html>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.