Merge pull request #14049 from electron/fix-flaky-sandbox-tests
fix: Fix flaky sandbox tests
This commit is contained in:
commit
cb4b3e7be0
1 changed files with 30 additions and 33 deletions
63
spec/fixtures/api/mixed-sandbox-app/main.js
vendored
63
spec/fixtures/api/mixed-sandbox-app/main.js
vendored
|
@ -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({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
sandboxWindow.loadURL('about:blank')
|
||||
|
||||
noSandboxWindow = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
noSandboxWindow.loadURL('about:blank')
|
||||
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,
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue