Merge pull request #14049 from electron/fix-flaky-sandbox-tests

fix: Fix flaky sandbox tests
This commit is contained in:
John Kleinschmidt 2018-08-13 13:26:52 -07:00 committed by GitHub
commit cb4b3e7be0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,27 +10,32 @@ if (!process.argv.includes('--enable-mixed-sandbox')) {
app.enableMixedSandbox()
}
let sandboxWindow
let noSandboxWindow
let currentWindowSandboxed = false
app.once('ready', () => {
sandboxWindow = new BrowserWindow({
function testWindow (isSandboxed, callback) {
currentWindowSandboxed = isSandboxed
let currentWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: true
sandbox: isSandboxed
}
})
sandboxWindow.loadURL('about:blank')
noSandboxWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: false
currentWindow.loadURL('about:blank')
currentWindow.webContents.once('devtools-opened', () => {
if (isSandboxed) {
argv.sandboxDevtools = true
} else {
argv.noSandboxDevtools = true
}
if (callback) {
callback()
}
finish()
})
noSandboxWindow.loadURL('about:blank')
currentWindow.webContents.openDevTools()
}
const argv = {
sandbox: null,
@ -41,6 +46,10 @@ app.once('ready', () => {
let connected = false
testWindow(true, () => {
testWindow()
})
function finish () {
if (connected && argv.sandbox != null && argv.noSandbox != null &&
argv.noSandboxDevtools != null && argv.sandboxDevtools != null) {
@ -57,22 +66,10 @@ app.once('ready', () => {
finish()
})
noSandboxWindow.webContents.once('devtools-opened', () => {
argv.noSandboxDevtools = true
finish()
})
noSandboxWindow.webContents.openDevTools()
sandboxWindow.webContents.once('devtools-opened', () => {
argv.sandboxDevtools = true
finish()
})
sandboxWindow.webContents.openDevTools()
ipcMain.on('argv', (event, value) => {
if (event.sender === sandboxWindow.webContents) {
if (currentWindowSandboxed) {
argv.sandbox = value
} else if (event.sender === noSandboxWindow.webContents) {
} else {
argv.noSandbox = value
}
finish()