electron/spec/fixtures/api/mixed-sandbox-app/main.js
trop[bot] 8eec8e150d Fix flaky sandbox tests (#14056)
Windows apparently has issues running opening two windows at once which is causing flakiness on the mixed sandbox tests.
2018-08-13 15:14:32 -07:00

77 lines
1.8 KiB
JavaScript

const {app, BrowserWindow, ipcMain} = require('electron')
const net = require('net')
const path = require('path')
process.on('uncaughtException', () => {
app.exit(1)
})
if (!process.argv.includes('--enable-mixed-sandbox')) {
app.enableMixedSandbox()
}
let currentWindowSandboxed = false
app.once('ready', () => {
function testWindow (isSandboxed, callback) {
currentWindowSandboxed = isSandboxed
let currentWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: isSandboxed
}
})
currentWindow.loadURL('about:blank')
currentWindow.webContents.once('devtools-opened', () => {
if (isSandboxed) {
argv.sandboxDevtools = true
} else {
argv.noSandboxDevtools = true
}
if (callback) {
callback()
}
finish()
})
currentWindow.webContents.openDevTools()
}
const argv = {
sandbox: null,
noSandbox: null,
sandboxDevtools: null,
noSandboxDevtools: null
}
let connected = false
testWindow(true, () => {
testWindow()
})
function finish () {
if (connected && argv.sandbox != null && argv.noSandbox != null &&
argv.noSandboxDevtools != null && argv.sandboxDevtools != null) {
client.once('end', () => {
app.exit(0)
})
client.end(JSON.stringify(argv))
}
}
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
const client = net.connect(socketPath, () => {
connected = true
finish()
})
ipcMain.on('argv', (event, value) => {
if (currentWindowSandboxed) {
argv.sandbox = value
} else {
argv.noSandbox = value
}
finish()
})
})