diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 6cb668206d47..1c42a96da453 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -14,13 +14,14 @@ const {app, ipcMain, BrowserWindow, protocol, webContents} = remote const isCI = remote.getGlobal('isCi') const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled') -describe('BrowserWindow module', function () { - var fixtures = path.resolve(__dirname, 'fixtures') - var w = null - var ws = null - var server, postData +describe('BrowserWindow module', () => { + const fixtures = path.resolve(__dirname, 'fixtures') + let w = null + let ws = null + let server + let postData - before(function (done) { + before((done) => { const filePath = path.join(fixtures, 'pages', 'a.html') const fileStats = fs.statSync(filePath) postData = [ @@ -36,14 +37,12 @@ describe('BrowserWindow module', function () { modificationTime: fileStats.mtime.getTime() / 1000 } ] - server = http.createServer(function (req, res) { + server = http.createServer((req, res) => { function respond () { if (req.method === 'POST') { let body = '' req.on('data', (data) => { - if (data) { - body += data - } + if (data) body += data }) req.on('end', () => { let parsedData = qs.parse(body) @@ -61,18 +60,18 @@ describe('BrowserWindow module', function () { } setTimeout(respond, req.url.includes('slow') ? 200 : 0) }) - server.listen(0, '127.0.0.1', function () { - server.url = 'http://127.0.0.1:' + server.address().port + server.listen(0, '127.0.0.1', () => { + server.url = `http://127.0.0.1:${server.address().port}` done() }) }) - after(function () { + after(() => { server.close() server = null }) - beforeEach(function () { + beforeEach(() => { w = new BrowserWindow({ show: false, width: 400, @@ -83,14 +82,14 @@ describe('BrowserWindow module', function () { }) }) - afterEach(function () { - return closeWindow(w).then(function () { w = null }) + afterEach(() => { + return closeWindow(w).then(() => { w = null }) }) - describe('BrowserWindow.close()', function () { + describe('BrowserWindow.close()', () => { let server - before(function (done) { + before((done) => { server = http.createServer((request, response) => { switch (request.url) { case '/404': @@ -119,36 +118,28 @@ describe('BrowserWindow module', function () { }) }) - after(function () { + after(() => { server.close() server = null }) - it('should emit unload handler', function (done) { - w.webContents.on('did-finish-load', function () { - w.close() - }) - w.once('closed', function () { - var test = path.join(fixtures, 'api', 'unload') - var content = fs.readFileSync(test) + it('should emit unload handler', (done) => { + w.webContents.on('did-finish-load', () => { w.close() }) + w.once('closed', () => { + const test = path.join(fixtures, 'api', 'unload') + const content = fs.readFileSync(test) fs.unlinkSync(test) assert.equal(String(content), 'unload') done() }) w.loadURL('file://' + path.join(fixtures, 'api', 'unload.html')) }) - - it('should emit beforeunload handler', function (done) { - w.once('onbeforeunload', function () { - done() - }) - w.webContents.on('did-finish-load', function () { - w.close() - }) - w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false.html')) + it('should emit beforeunload handler', (done) => { + w.once('onbeforeunload', () => { done() }) + w.webContents.on('did-finish-load', () => { w.close() }) + w.loadURL(`file://${path.join(fixtures, 'api', 'beforeunload-false.html')}`) }) - - it('should not crash when invoked synchronously inside navigation observer', function (done) { + it('should not crash when invoked synchronously inside navigation observer', (done) => { const events = [ { name: 'did-start-loading', url: `${server.url}/200` }, { name: 'did-get-redirect-request', url: `${server.url}/301` }, @@ -174,69 +165,60 @@ describe('BrowserWindow module', function () { } let gen = genNavigationEvent() - ipcRenderer.on(responseEvent, function () { + ipcRenderer.on(responseEvent, () => { if (!gen.next().value) done() }) gen.next() }) }) - describe('window.close()', function () { - it('should emit unload handler', function (done) { - w.once('closed', function () { - var test = path.join(fixtures, 'api', 'close') - var content = fs.readFileSync(test) + describe('window.close()', () => { + it('should emit unload handler', (done) => { + w.once('closed', () => { + const test = path.join(fixtures, 'api', 'close') + const content = fs.readFileSync(test) fs.unlinkSync(test) assert.equal(String(content), 'close') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'close.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'close.html')}`) }) - - it('should emit beforeunload handler', function (done) { - w.once('onbeforeunload', function () { - done() - }) - w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')) + it('should emit beforeunload handler', (done) => { + w.once('onbeforeunload', () => { done() }) + w.loadURL(`file://${path.join(fixtures, 'api', 'close-beforeunload-false.html')}`) }) }) - describe('BrowserWindow.destroy()', function () { - it('prevents users to access methods of webContents', function () { + describe('BrowserWindow.destroy()', () => { + it('prevents users to access methods of webContents', () => { const contents = w.webContents w.destroy() - assert.throws(function () { + assert.throws(() => { contents.getId() }, /Object has been destroyed/) }) }) - describe('BrowserWindow.loadURL(url)', function () { - it('should emit did-start-loading event', function (done) { - w.webContents.on('did-start-loading', function () { - done() - }) + describe('BrowserWindow.loadURL(url)', () => { + it('should emit did-start-loading event', (done) => { + w.webContents.on('did-start-loading', () => { done() }) w.loadURL('about:blank') }) - - it('should emit ready-to-show event', function (done) { - w.on('ready-to-show', function () { - done() - }) + it('should emit ready-to-show event', (done) => { + w.on('ready-to-show', () => { done() }) w.loadURL('about:blank') }) - - it('should emit did-get-response-details event', function (done) { + it('should emit did-get-response-details event', (done) => { // expected {fileName: resourceType} pairs - var expectedResources = { + const expectedResources = { 'did-get-response-details.html': 'mainFrame', 'logo.png': 'image' } - var responses = 0 - w.webContents.on('did-get-response-details', function (event, status, newUrl, oldUrl, responseCode, method, referrer, headers, resourceType) { - responses++ - var fileName = newUrl.slice(newUrl.lastIndexOf('/') + 1) - var expectedType = expectedResources[fileName] + let responses = 0 + w.webContents.on('did-get-response-details', (event, status, newUrl, oldUrl, responseCode, method, referrer, headers, resourceType) => { + responses += 1 + const fileName = newUrl.slice(newUrl.lastIndexOf('/') + 1) + const expectedType = expectedResources[fileName] assert(!!expectedType, `Unexpected response details for ${newUrl}`) assert(typeof status === 'boolean', 'status should be boolean') assert.equal(responseCode, 200) @@ -245,15 +227,12 @@ describe('BrowserWindow module', function () { assert(!!headers, 'headers should be present') assert(typeof headers === 'object', 'headers should be object') assert.equal(resourceType, expectedType, 'Incorrect resourceType') - if (responses === Object.keys(expectedResources).length) { - done() - } + if (responses === Object.keys(expectedResources).length) done() }) - w.loadURL('file://' + path.join(fixtures, 'pages', 'did-get-response-details.html')) + w.loadURL(`file://${path.join(fixtures, 'pages', 'did-get-response-details.html')}`) }) - - it('should emit did-fail-load event for files that do not exist', function (done) { - w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) { + it('should emit did-fail-load event for files that do not exist', (done) => { + w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => { assert.equal(code, -6) assert.equal(desc, 'ERR_FILE_NOT_FOUND') assert.equal(isMainFrame, true) @@ -261,9 +240,8 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://a.txt') }) - - it('should emit did-fail-load event for invalid URL', function (done) { - w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) { + it('should emit did-fail-load event for invalid URL', (done) => { + w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => { assert.equal(desc, 'ERR_INVALID_URL') assert.equal(code, -300) assert.equal(isMainFrame, true) @@ -271,25 +249,22 @@ describe('BrowserWindow module', function () { }) w.loadURL('http://example:port') }) - - it('should set `mainFrame = false` on did-fail-load events in iframes', function (done) { - w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) { + it('should set `mainFrame = false` on did-fail-load events in iframes', (done) => { + w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => { assert.equal(isMainFrame, false) done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'did-fail-load-iframe.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'did-fail-load-iframe.html')}`) }) - - it('does not crash in did-fail-provisional-load handler', function (done) { - w.webContents.once('did-fail-provisional-load', function () { + it('does not crash in did-fail-provisional-load handler', (done) => { + w.webContents.once('did-fail-provisional-load', () => { w.loadURL('http://127.0.0.1:11111') done() }) w.loadURL('http://127.0.0.1:11111') }) - - it('should emit did-fail-load event for URL exceeding character limit', function (done) { - w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) { + it('should emit did-fail-load event for URL exceeding character limit', (done) => { + w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => { assert.equal(desc, 'ERR_INVALID_URL') assert.equal(code, -300) assert.equal(isMainFrame, true) @@ -299,17 +274,14 @@ describe('BrowserWindow module', function () { w.loadURL(`data:image/png;base64,${data}`) }) - describe('POST navigations', function () { - afterEach(() => { - w.webContents.session.webRequest.onBeforeSendHeaders(null) - }) + describe('POST navigations', () => { + afterEach(() => { w.webContents.session.webRequest.onBeforeSendHeaders(null) }) - it('supports specifying POST data', function (done) { + it('supports specifying POST data', (done) => { w.webContents.on('did-finish-load', () => done()) w.loadURL(server.url, {postData: postData}) }) - - it('sets the content type header on URL encoded forms', function (done) { + it('sets the content type header on URL encoded forms', (done) => { w.webContents.on('did-finish-load', () => { w.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { assert.equal(details.requestHeaders['content-type'], 'application/x-www-form-urlencoded') @@ -325,8 +297,7 @@ describe('BrowserWindow module', function () { }) w.loadURL(server.url) }) - - it('sets the content type header on multi part forms', function (done) { + it('sets the content type header on multi part forms', (done) => { w.webContents.on('did-finish-load', () => { w.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { assert(details.requestHeaders['content-type'].startsWith('multipart/form-data; boundary=----WebKitFormBoundary')) @@ -350,7 +321,7 @@ describe('BrowserWindow module', function () { }) it('should support support base url for data urls', (done) => { - ipcMain.once('answer', function (event, test) { + ipcMain.once('answer', (event, test) => { assert.equal(test, 'test') done() }) @@ -358,33 +329,27 @@ describe('BrowserWindow module', function () { }) }) - describe('will-navigate event', function () { + describe('will-navigate event', () => { it('allows the window to be closed from the event listener', (done) => { ipcRenderer.send('close-on-will-navigate', w.id) - ipcRenderer.once('closed-on-will-navigate', () => { - done() - }) - w.loadURL('file://' + fixtures + '/pages/will-navigate.html') + ipcRenderer.once('closed-on-will-navigate', () => { done() }) + w.loadURL(`file://${fixtures}/pages/will-navigate.html`) }) }) - describe('BrowserWindow.show()', function () { - if (isCI) { - return - } + describe('BrowserWindow.show()', () => { + if (isCI) return - it('should focus on window', function () { + it('should focus on window', () => { w.show() assert(w.isFocused()) }) - - it('should make the window visible', function () { + it('should make the window visible', () => { w.show() assert(w.isVisible()) }) - - it('emits when window is shown', function (done) { - w.once('show', function () { + it('emits when window is shown', (done) => { + w.once('show', () => { assert.equal(w.isVisible(), true) done() }) @@ -392,25 +357,21 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.hide()', function () { - if (isCI) { - return - } + describe('BrowserWindow.hide()', () => { + if (isCI) return - it('should defocus on window', function () { + it('should defocus on window', () => { w.hide() assert(!w.isFocused()) }) - - it('should make the window not visible', function () { + it('should make the window not visible', () => { w.show() w.hide() assert(!w.isVisible()) }) - - it('emits when window is hidden', function (done) { + it('emits when window is hidden', (done) => { w.show() - w.once('hide', function () { + w.once('hide', () => { assert.equal(w.isVisible(), false) done() }) @@ -418,46 +379,46 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.showInactive()', function () { - it('should not focus on window', function () { + describe('BrowserWindow.showInactive()', () => { + it('should not focus on window', () => { w.showInactive() assert(!w.isFocused()) }) }) - describe('BrowserWindow.focus()', function () { - it('does not make the window become visible', function () { + describe('BrowserWindow.focus()', () => { + it('does not make the window become visible', () => { assert.equal(w.isVisible(), false) w.focus() assert.equal(w.isVisible(), false) }) }) - describe('BrowserWindow.blur()', function () { - it('removes focus from window', function () { + describe('BrowserWindow.blur()', () => { + it('removes focus from window', () => { w.blur() assert(!w.isFocused()) }) }) - describe('BrowserWindow.capturePage(rect, callback)', function () { - it('calls the callback with a Buffer', function (done) { + describe('BrowserWindow.capturePage(rect, callback)', () => { + it('calls the callback with a Buffer', (done) => { w.capturePage({ x: 0, y: 0, width: 100, height: 100 - }, function (image) { + }, (image) => { assert.equal(image.isEmpty(), true) done() }) }) }) - describe('BrowserWindow.setSize(width, height)', function () { - it('sets the window size', function (done) { - var size = [300, 400] - w.once('resize', function () { + describe('BrowserWindow.setSize(width, height)', () => { + it('sets the window size', (done) => { + const size = [300, 400] + w.once('resize', () => { assertBoundsEqual(w.getSize(), size) done() }) @@ -465,8 +426,8 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setMinimum/MaximumSize(width, height)', function () { - it('sets the maximum and minimum size of the window', function () { + describe('BrowserWindow.setMinimum/MaximumSize(width, height)', () => { + it('sets the maximum and minimum size of the window', () => { assert.deepEqual(w.getMinimumSize(), [0, 0]) assert.deepEqual(w.getMaximumSize(), [0, 0]) @@ -480,12 +441,12 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setAspectRatio(ratio)', function () { - it('resets the behaviour when passing in 0', function (done) { - var size = [300, 400] + describe('BrowserWindow.setAspectRatio(ratio)', () => { + it('resets the behaviour when passing in 0', (done) => { + const size = [300, 400] w.setAspectRatio(1 / 2) w.setAspectRatio(0) - w.once('resize', function () { + w.once('resize', () => { assertBoundsEqual(w.getSize(), size) done() }) @@ -493,11 +454,11 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setPosition(x, y)', function () { - it('sets the window position', function (done) { - var pos = [10, 10] - w.once('move', function () { - var newPos = w.getPosition() + describe('BrowserWindow.setPosition(x, y)', () => { + it('sets the window position', (done) => { + const pos = [10, 10] + w.once('move', () => { + const newPos = w.getPosition() assert.equal(newPos[0], pos[0]) assert.equal(newPos[1], pos[1]) done() @@ -506,16 +467,15 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setContentSize(width, height)', function () { - it('sets the content size', function () { - var size = [400, 400] + describe('BrowserWindow.setContentSize(width, height)', () => { + it('sets the content size', () => { + const size = [400, 400] w.setContentSize(size[0], size[1]) var after = w.getContentSize() assert.equal(after[0], size[0]) assert.equal(after[1], size[1]) }) - - it('works for a frameless window', function () { + it('works for a frameless window', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -523,25 +483,24 @@ describe('BrowserWindow module', function () { width: 400, height: 400 }) - var size = [400, 400] + const size = [400, 400] w.setContentSize(size[0], size[1]) - var after = w.getContentSize() + const after = w.getContentSize() assert.equal(after[0], size[0]) assert.equal(after[1], size[1]) }) }) - describe('BrowserWindow.setContentBounds(bounds)', function () { - it('sets the content size and position', function (done) { - var bounds = {x: 10, y: 10, width: 250, height: 250} - w.once('resize', function () { + describe('BrowserWindow.setContentBounds(bounds)', () => { + it('sets the content size and position', (done) => { + const bounds = {x: 10, y: 10, width: 250, height: 250} + w.once('resize', () => { assertBoundsEqual(w.getContentBounds(), bounds) done() }) w.setContentBounds(bounds) }) - - it('works for a frameless window', function (done) { + it('works for a frameless window', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -549,8 +508,8 @@ describe('BrowserWindow module', function () { width: 300, height: 300 }) - var bounds = {x: 10, y: 10, width: 250, height: 250} - w.once('resize', function () { + const bounds = {x: 10, y: 10, width: 250, height: 250} + w.once('resize', () => { assert.deepEqual(w.getContentBounds(), bounds) done() }) @@ -558,9 +517,9 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setProgressBar(progress)', function () { - it('sets the progress', function () { - assert.doesNotThrow(function () { + describe('BrowserWindow.setProgressBar(progress)', () => { + it('sets the progress', () => { + assert.doesNotThrow(() => { if (process.platform === 'darwin') { app.dock.setIcon(path.join(fixtures, 'assets', 'logo.png')) } @@ -572,28 +531,25 @@ describe('BrowserWindow module', function () { w.setProgressBar(-1) }) }) - - it('sets the progress using "paused" mode', function () { - assert.doesNotThrow(function () { + it('sets the progress using "paused" mode', () => { + assert.doesNotThrow(() => { w.setProgressBar(0.5, {mode: 'paused'}) }) }) - - it('sets the progress using "error" mode', function () { - assert.doesNotThrow(function () { + it('sets the progress using "error" mode', () => { + assert.doesNotThrow(() => { w.setProgressBar(0.5, {mode: 'error'}) }) }) - - it('sets the progress using "normal" mode', function () { - assert.doesNotThrow(function () { + it('sets the progress using "normal" mode', () => { + assert.doesNotThrow(() => { w.setProgressBar(0.5, {mode: 'normal'}) }) }) }) - describe('BrowserWindow.setAlwaysOnTop(flag, level)', function () { - it('sets the window as always on top', function () { + describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => { + it('sets the window as always on top', () => { assert.equal(w.isAlwaysOnTop(), false) w.setAlwaysOnTop(true, 'screen-saver') assert.equal(w.isAlwaysOnTop(), true) @@ -602,26 +558,23 @@ describe('BrowserWindow module', function () { w.setAlwaysOnTop(true) assert.equal(w.isAlwaysOnTop(), true) }) - - it('raises an error when relativeLevel is out of bounds', function () { + it('raises an error when relativeLevel is out of bounds', () => { if (process.platform !== 'darwin') return - assert.throws(function () { + assert.throws(() => { w.setAlwaysOnTop(true, '', -2147483644) }) - assert.throws(function () { + assert.throws(() => { w.setAlwaysOnTop(true, '', 2147483632) }) }) }) - describe('BrowserWindow.alwaysOnTop() resets level on minimize', function () { - if (process.platform !== 'darwin') { - return - } + describe('BrowserWindow.alwaysOnTop() resets level on minimize', () => { + if (process.platform !== 'darwin') return - it('resets the windows level on minimize', function () { + it('resets the windows level on minimize', () => { assert.equal(w.isAlwaysOnTop(), false) w.setAlwaysOnTop(true, 'screen-saver') assert.equal(w.isAlwaysOnTop(), true) @@ -637,10 +590,8 @@ describe('BrowserWindow module', function () { it('is not available on non-macOS platforms', () => { assert.ok(!w.setAutoHideCursor) }) - return } - it('allows changing cursor auto-hiding', () => { assert.doesNotThrow(() => { w.setAutoHideCursor(false) @@ -651,9 +602,7 @@ describe('BrowserWindow module', function () { describe('BrowserWindow.selectPreviousTab()', () => { it('does not throw', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return assert.doesNotThrow(() => { w.selectPreviousTab() @@ -663,9 +612,7 @@ describe('BrowserWindow module', function () { describe('BrowserWindow.selectNextTab()', () => { it('does not throw', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return assert.doesNotThrow(() => { w.selectNextTab() @@ -675,9 +622,7 @@ describe('BrowserWindow module', function () { describe('BrowserWindow.mergeAllWindows()', () => { it('does not throw', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return assert.doesNotThrow(() => { w.mergeAllWindows() @@ -687,9 +632,7 @@ describe('BrowserWindow module', function () { describe('BrowserWindow.moveTabToNewWindow()', () => { it('does not throw', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return assert.doesNotThrow(() => { w.moveTabToNewWindow() @@ -699,9 +642,7 @@ describe('BrowserWindow module', function () { describe('BrowserWindow.toggleTabBar()', () => { it('does not throw', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return assert.doesNotThrow(() => { w.toggleTabBar() @@ -709,11 +650,10 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.addTabbedWindow()', function (done) { - it('does not throw', function () { - if (process.platform !== 'darwin') { - return - } + describe('BrowserWindow.addTabbedWindow()', (done) => { + it('does not throw', () => { + if (process.platform !== 'darwin') return + const tabbedWindow = new BrowserWindow({}) assert.doesNotThrow(() => { w.addTabbedWindow(tabbedWindow) @@ -722,9 +662,9 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setVibrancy(type)', function () { - it('allows setting, changing, and removing the vibrancy', function () { - assert.doesNotThrow(function () { + describe('BrowserWindow.setVibrancy(type)', () => { + it('allows setting, changing, and removing the vibrancy', () => { + assert.doesNotThrow(() => { w.setVibrancy('light') w.setVibrancy('dark') w.setVibrancy(null) @@ -734,13 +674,13 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setAppDetails(options)', function () { - it('supports setting the app details', function () { + describe('BrowserWindow.setAppDetails(options)', () => { + it('supports setting the app details', () => { if (process.platform !== 'win32') return const iconPath = path.join(fixtures, 'assets', 'icon.ico') - assert.doesNotThrow(function () { + assert.doesNotThrow(() => { w.setAppDetails({appId: 'my.app.id'}) w.setAppDetails({appIconPath: iconPath, appIconIndex: 0}) w.setAppDetails({appIconPath: iconPath}) @@ -757,47 +697,39 @@ describe('BrowserWindow module', function () { w.setAppDetails({}) }) - assert.throws(function () { + assert.throws(() => { w.setAppDetails() }, /Insufficient number of arguments\./) }) }) - describe('BrowserWindow.fromId(id)', function () { - it('returns the window with id', function () { + describe('BrowserWindow.fromId(id)', () => { + it('returns the window with id', () => { assert.equal(w.id, BrowserWindow.fromId(w.id).id) }) }) - describe('BrowserWindow.fromWebContents(webContents)', function () { + describe('BrowserWindow.fromWebContents(webContents)', () => { let contents = null - beforeEach(function () { - contents = webContents.create({}) - }) + beforeEach(() => { contents = webContents.create({}) }) - afterEach(function () { - contents.destroy() - }) + afterEach(() => { contents.destroy() }) - it('returns the window with the webContents', function () { + it('returns the window with the webContents', () => { assert.equal(BrowserWindow.fromWebContents(w.webContents).id, w.id) assert.equal(BrowserWindow.fromWebContents(contents), undefined) }) }) - describe('BrowserWindow.fromDevToolsWebContents(webContents)', function () { + describe('BrowserWindow.fromDevToolsWebContents(webContents)', () => { let contents = null - beforeEach(function () { - contents = webContents.create({}) - }) + beforeEach(() => { contents = webContents.create({}) }) - afterEach(function () { - contents.destroy() - }) + afterEach(() => { contents.destroy() }) - it('returns the window with the webContents', function (done) { + it('returns the window with the webContents', (done) => { w.webContents.once('devtools-opened', () => { assert.equal(BrowserWindow.fromDevToolsWebContents(w.devToolsWebContents).id, w.id) assert.equal(BrowserWindow.fromDevToolsWebContents(w.webContents), undefined) @@ -808,8 +740,8 @@ describe('BrowserWindow module', function () { }) }) - describe('BrowserWindow.setOpacity(opacity)', function () { - it('make window with initial opacity', function () { + describe('BrowserWindow.setOpacity(opacity)', () => { + it('make window with initial opacity', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -819,9 +751,8 @@ describe('BrowserWindow module', function () { }) assert.equal(w.getOpacity(), 0.5) }) - - it('allows setting the opacity', function () { - assert.doesNotThrow(function () { + it('allows setting the opacity', () => { + assert.doesNotThrow(() => { w.setOpacity(0.0) assert.equal(w.getOpacity(), 0.0) w.setOpacity(0.5) @@ -832,8 +763,8 @@ describe('BrowserWindow module', function () { }) }) - describe('"useContentSize" option', function () { - it('make window created with content size when used', function () { + describe('"useContentSize" option', () => { + it('make window created with content size when used', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -841,18 +772,16 @@ describe('BrowserWindow module', function () { height: 400, useContentSize: true }) - var contentSize = w.getContentSize() + const contentSize = w.getContentSize() assert.equal(contentSize[0], 400) assert.equal(contentSize[1], 400) }) - - it('make window created with window size when not used', function () { - var size = w.getSize() + it('make window created with window size when not used', () => { + const size = w.getSize() assert.equal(size[0], 400) assert.equal(size[1], 400) }) - - it('works for a frameless window', function () { + it('works for a frameless window', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -861,24 +790,20 @@ describe('BrowserWindow module', function () { height: 400, useContentSize: true }) - var contentSize = w.getContentSize() + const contentSize = w.getContentSize() assert.equal(contentSize[0], 400) assert.equal(contentSize[1], 400) - var size = w.getSize() + const size = w.getSize() assert.equal(size[0], 400) assert.equal(size[1], 400) }) }) - describe('"titleBarStyle" option', function () { - if (process.platform !== 'darwin') { - return - } - if (parseInt(os.release().split('.')[0]) < 14) { - return - } + describe('"titleBarStyle" option', () => { + if (process.platform !== 'darwin') return + if (parseInt(os.release().split('.')[0]) < 14) return - it('creates browser window with hidden title bar', function () { + it('creates browser window with hidden title bar', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -886,11 +811,10 @@ describe('BrowserWindow module', function () { height: 400, titleBarStyle: 'hidden' }) - var contentSize = w.getContentSize() + const contentSize = w.getContentSize() assert.equal(contentSize[1], 400) }) - - it('creates browser window with hidden inset title bar', function () { + it('creates browser window with hidden inset title bar', () => { w.destroy() w = new BrowserWindow({ show: false, @@ -898,17 +822,15 @@ describe('BrowserWindow module', function () { height: 400, titleBarStyle: 'hidden-inset' }) - var contentSize = w.getContentSize() + const contentSize = w.getContentSize() assert.equal(contentSize[1], 400) }) }) - describe('enableLargerThanScreen" option', function () { - if (process.platform === 'linux') { - return - } + describe('enableLargerThanScreen" option', () => { + if (process.platform === 'linux') return - beforeEach(function () { + beforeEach(() => { w.destroy() w = new BrowserWindow({ show: true, @@ -918,15 +840,14 @@ describe('BrowserWindow module', function () { }) }) - it('can move the window out of screen', function () { + it('can move the window out of screen', () => { w.setPosition(-10, -10) - var after = w.getPosition() + const after = w.getPosition() assert.equal(after[0], -10) assert.equal(after[1], -10) }) - - it('can set the window larger than screen', function () { - var size = screen.getPrimaryDisplay().size + it('can set the window larger than screen', () => { + const size = screen.getPrimaryDisplay().size size.width += 100 size.height += 100 w.setSize(size.width, size.height) @@ -934,8 +855,8 @@ describe('BrowserWindow module', function () { }) }) - describe('"zoomToPageWidth" option', function () { - it('sets the window width to the page width when used', function () { + describe('"zoomToPageWidth" option', () => { + it('sets the window width to the page width when used', () => { if (process.platform !== 'darwin') return w.destroy() @@ -950,8 +871,8 @@ describe('BrowserWindow module', function () { }) }) - describe('"tabbingIdentifier" option', function () { - it('can be set on a window', function () { + describe('"tabbingIdentifier" option', () => { + it('can be set on a window', () => { w.destroy() w = new BrowserWindow({ tabbingIdentifier: 'group1' @@ -964,15 +885,13 @@ describe('BrowserWindow module', function () { }) }) - describe('"webPreferences" option', function () { - afterEach(function () { - ipcMain.removeAllListeners('answer') - }) + describe('"webPreferences" option', () => { + afterEach(() => { ipcMain.removeAllListeners('answer') }) - describe('"preload" option', function () { - it('loads the script before other scripts in window', function (done) { - var preload = path.join(fixtures, 'module', 'set-global.js') - ipcMain.once('answer', function (event, test) { + describe('"preload" option', () => { + it('loads the script before other scripts in window', (done) => { + const preload = path.join(fixtures, 'module', 'set-global.js') + ipcMain.once('answer', (event, test) => { assert.equal(test, 'preload') done() }) @@ -983,12 +902,11 @@ describe('BrowserWindow module', function () { preload: preload } }) - w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'preload.html')}`) }) - - it('can successfully delete the Buffer global', function (done) { - var preload = path.join(fixtures, 'module', 'delete-buffer.js') - ipcMain.once('answer', function (event, test) { + it('can successfully delete the Buffer global', (done) => { + const preload = path.join(fixtures, 'module', 'delete-buffer.js') + ipcMain.once('answer', (event, test) => { assert.equal(test.toString(), 'buffer') done() }) @@ -999,14 +917,14 @@ describe('BrowserWindow module', function () { preload: preload } }) - w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'preload.html')}`) }) }) - describe('"node-integration" option', function () { - it('disables node integration when specified to false', function (done) { - var preload = path.join(fixtures, 'module', 'send-later.js') - ipcMain.once('answer', function (event, typeofProcess, typeofBuffer) { + describe('"node-integration" option', () => { + it('disables node integration when specified to false', (done) => { + const preload = path.join(fixtures, 'module', 'send-later.js') + ipcMain.once('answer', (event, typeofProcess, typeofBuffer) => { assert.equal(typeofProcess, 'undefined') assert.equal(typeofBuffer, 'undefined') done() @@ -1019,11 +937,11 @@ describe('BrowserWindow module', function () { nodeIntegration: false } }) - w.loadURL('file://' + path.join(fixtures, 'api', 'blank.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'blank.html')}`) }) }) - describe('"sandbox" option', function () { + describe('"sandbox" option', () => { function waitForEvents (emitter, events, callback) { let count = events.length for (let event of events) { @@ -1044,19 +962,19 @@ describe('BrowserWindow module', function () { }) } - before(function (done) { - protocol.interceptStringProtocol('http', crossDomainHandler, function () { + before((done) => { + protocol.interceptStringProtocol('http', crossDomainHandler, () => { done() }) }) - after(function (done) { - protocol.uninterceptProtocol('http', function () { + after((done) => { + protocol.uninterceptProtocol('http', () => { done() }) }) - it('exposes ipcRenderer to preload script', function (done) { + it('exposes ipcRenderer to preload script', (done) => { ipcMain.once('answer', function (event, test) { assert.equal(test, 'preload') done() @@ -1072,7 +990,7 @@ describe('BrowserWindow module', function () { w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html')) }) - it('exposes "exit" event to preload script', function (done) { + it('exposes "exit" event to preload script', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1094,7 +1012,7 @@ describe('BrowserWindow module', function () { }) }) - it('should open windows in same domain with cross-scripting enabled', function (done) { + it('should open windows in same domain with cross-scripting enabled', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1123,7 +1041,7 @@ describe('BrowserWindow module', function () { }) }) - it('should open windows in another domain with cross-scripting disabled', function (done) { + it('should open windows in another domain with cross-scripting disabled', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1162,7 +1080,7 @@ describe('BrowserWindow module', function () { }) }) - it('should inherit the sandbox setting in opened windows', function (done) { + it('should inherit the sandbox setting in opened windows', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1180,7 +1098,7 @@ describe('BrowserWindow module', function () { w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`) }) - it('should open windows with the options configured via new-window event listeners', function (done) { + it('should open windows with the options configured via new-window event listeners', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1199,7 +1117,7 @@ describe('BrowserWindow module', function () { w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`) }) - it('should set ipc event sender correctly', function (done) { + it('should set ipc event sender correctly', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1230,15 +1148,15 @@ describe('BrowserWindow module', function () { }) }) - describe('event handling', function () { - it('works for window events', function (done) { + describe('event handling', () => { + it('works for window events', (done) => { waitForEvents(w, [ 'page-title-updated' ], done) w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?window-events')) }) - it('works for stop events', function (done) { + it('works for stop events', (done) => { waitForEvents(w.webContents, [ 'did-navigate', 'did-fail-load', @@ -1247,7 +1165,7 @@ describe('BrowserWindow module', function () { w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?webcontents-stop')) }) - it('works for web contents events', function (done) { + it('works for web contents events', (done) => { waitForEvents(w.webContents, [ 'did-finish-load', 'did-frame-finish-load', @@ -1262,7 +1180,7 @@ describe('BrowserWindow module', function () { }) }) - it('can get printer list', function (done) { + it('can get printer list', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1272,14 +1190,14 @@ describe('BrowserWindow module', function () { } }) w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E') - w.webContents.once('did-finish-load', function () { + w.webContents.once('did-finish-load', () => { const printers = w.webContents.getPrinters() assert.equal(Array.isArray(printers), true) done() }) }) - it('can print to PDF', function (done) { + it('can print to PDF', (done) => { w.destroy() w = new BrowserWindow({ show: false, @@ -1289,7 +1207,7 @@ describe('BrowserWindow module', function () { } }) w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E') - w.webContents.once('did-finish-load', function () { + w.webContents.once('did-finish-load', () => { w.webContents.printToPDF({}, function (error, data) { assert.equal(error, null) assert.equal(data instanceof Buffer, true) @@ -1426,33 +1344,29 @@ describe('BrowserWindow module', function () { assert.equal(content, 'Hello') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-blank.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}`) }) - it('opens window of same domain with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-file.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'native-window-open-file.html')}`) }) - it('blocks accessing cross-origin frames', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'Blocked a frame with origin "file://" from accessing a cross-origin frame.') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-cross-origin.html')) + w.loadURL(`file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}`) }) - it('opens window from