|
@@ -4,7 +4,10 @@ const dirtyChai = require('dirty-chai')
|
|
|
const fs = require('fs')
|
|
|
const path = require('path')
|
|
|
const os = require('os')
|
|
|
-const { shell } = require('electron')
|
|
|
+const { shell, remote } = require('electron')
|
|
|
+const { BrowserWindow } = remote
|
|
|
+
|
|
|
+const { closeWindow } = require('./window-helpers')
|
|
|
|
|
|
const { expect } = chai
|
|
|
chai.use(dirtyChai)
|
|
@@ -23,6 +26,7 @@ describe('shell module', () => {
|
|
|
|
|
|
describe('shell.openExternal()', () => {
|
|
|
let envVars = {}
|
|
|
+ let w
|
|
|
|
|
|
beforeEach(function () {
|
|
|
envVars = {
|
|
@@ -32,7 +36,9 @@ describe('shell module', () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- afterEach(() => {
|
|
|
+ afterEach(async () => {
|
|
|
+ await closeWindow(w)
|
|
|
+ w = null
|
|
|
// reset env vars to prevent side effects
|
|
|
if (process.platform === 'linux') {
|
|
|
process.env.DE = envVars.de
|
|
@@ -49,7 +55,24 @@ describe('shell module', () => {
|
|
|
process.env.DISPLAY = ''
|
|
|
}
|
|
|
|
|
|
- shell.openExternal(url).then(() => done())
|
|
|
+ // Ensure an external window is activated via a new window's blur event
|
|
|
+ w = new BrowserWindow()
|
|
|
+ let promiseResolved = false
|
|
|
+ let blurEventEmitted = false
|
|
|
+
|
|
|
+ w.on('blur', () => {
|
|
|
+ blurEventEmitted = true
|
|
|
+ if (promiseResolved) {
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ shell.openExternal(url).then(() => {
|
|
|
+ promiseResolved = true
|
|
|
+ if (blurEventEmitted || process.platform === 'linux') {
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|