const fs = require('fs')
const path = require('path')
const {remote} = require('electron')
+const {closeWindow} = require('./window-helpers')
const {app, BrowserWindow, ipcMain} = remote
let window = null
beforeEach(function () {
- if (window != null) {
- window.destroy()
- }
window = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- if (window != null) {
- window.destroy()
- }
- window = null
+ return closeWindow(window).then(function () { window = null })
})
it('always returns the internal electron module', function (done) {
})
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
it('can import certificate into platform cert store', function (done) {
var w = null
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
it('should emit browser-window-focus event when window is focused', function (done) {
const path = require('path')
const os = require('os')
const http = require('http')
+const {closeWindow} = require('./window-helpers')
const remote = require('electron').remote
const screen = require('electron').screen
})
beforeEach(function () {
- if (w != null) {
- w.destroy()
- }
w = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
describe('BrowserWindow.close()', function () {
const multiparty = require('multiparty')
const path = require('path')
const url = require('url')
+const {closeWindow} = require('./window-helpers')
const remote = require('electron').remote
const app = remote.require('electron').app
})
afterEach(function () {
- w.destroy()
+ return closeWindow(w).then(function () { w = null })
})
if (process.mas) {
const assert = require('assert')
const path = require('path')
+const {closeWindow} = require('./window-helpers')
const BrowserWindow = require('electron').remote.BrowserWindow
describe('debugger module', function () {
var w = null
beforeEach(function () {
- if (w != null) {
- w.destroy()
- }
w = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
describe('debugger.attach', function () {
const assert = require('assert')
const path = require('path')
+const {closeWindow} = require('./window-helpers')
const {ipcRenderer, remote} = require('electron')
const {ipcMain, webContents, BrowserWindow} = remote
describe('ipc module', function () {
var fixtures = path.join(__dirname, 'fixtures')
+ var w = null
+
+ afterEach(function () {
+ return closeWindow(w).then(function () { w = null })
+ })
+
describe('remote.require', function () {
it('should returns same object for the same module', function () {
var dialog1 = remote.require('electron')
it('does not crash when reply is not sent and browser is destroyed', function (done) {
this.timeout(10000)
- var w = new BrowserWindow({
+ w = new BrowserWindow({
show: false
})
ipcMain.once('send-sync-message', function (event) {
event.returnValue = null
- w.destroy()
done()
})
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
})
it('does not crash when reply is sent by multiple listeners', function (done) {
- var w = new BrowserWindow({
+ w = new BrowserWindow({
show: false
})
ipcMain.on('send-sync-message', function (event) {
})
ipcMain.on('send-sync-message', function (event) {
event.returnValue = null
- w.destroy()
done()
})
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
})
describe('remote listeners', function () {
- var w = null
-
- afterEach(function () {
- w.destroy()
- })
-
it('can be added and removed correctly', function () {
w = new BrowserWindow({
show: false
const http = require('http')
const path = require('path')
const qs = require('querystring')
+const {closeWindow} = require('./window-helpers')
const remote = require('electron').remote
const {BrowserWindow, protocol, webContents} = remote
afterEach(function (done) {
protocol.unregisterProtocol(standardScheme, function () {
- if (w != null) {
- w.destroy()
- }
- w = null
- done()
+ closeWindow(w).then(function () {
+ w = null
+ done()
+ })
})
})
const http = require('http')
const path = require('path')
const fs = require('fs')
+const {closeWindow} = require('./window-helpers')
const {ipcRenderer, remote} = require('electron')
const {ipcMain, session, BrowserWindow} = remote
var url = 'http://127.0.0.1'
beforeEach(function () {
- if (w != null) {
- w.destroy()
- }
w = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
describe('session.defaultSession', function () {
})
afterEach(function () {
- w.destroy()
+ return closeWindow(w).then(function () { w = null })
})
it('can cancel default download behavior', function (done) {
const assert = require('assert')
const path = require('path')
+const {closeWindow} = require('./window-helpers')
const {remote} = require('electron')
const {BrowserWindow, webContents} = remote
let w
beforeEach(function () {
- if (w != null) {
- w.destroy()
- }
w = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- if (w != null) {
- w.destroy()
- }
- w = null
+ return closeWindow(w).then(function () { w = null })
})
describe('getAllWebContents() API', function () {
const ChildProcess = require('child_process')
const fs = require('fs')
const path = require('path')
+const {closeWindow} = require('./window-helpers')
const nativeImage = require('electron').nativeImage
const remote = require('electron').remote
it('sets __dirname correctly', function (done) {
after(function () {
- w.destroy()
ipcMain.removeAllListeners('dirname')
+ return closeWindow(w).then(function () { w = null })
})
var w = new BrowserWindow({
it('loads script tag in html', function (done) {
after(function () {
- w.destroy()
ipcMain.removeAllListeners('ping')
+ return closeWindow(w).then(function () { w = null })
})
var w = new BrowserWindow({
--- /dev/null
+exports.closeWindow = (window) => {
+ if (window == null || window.isDestroyed()) {
+ return Promise.resolve()
+ } else {
+ return new Promise((resolve, reject) => {
+ window.once('closed', () => {
+ resolve()
+ })
+ window.setClosable(true)
+ window.close()
+ })
+ }
+}