|
@@ -615,6 +615,22 @@ describe('BrowserWindow module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ describe('BrowserWindow.alwaysOnTop() resets level on minimize', function () {
|
|
|
+ if (process.platform !== 'darwin') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ it('resets the windows level on minimize', function () {
|
|
|
+ assert.equal(w.isAlwaysOnTop(), false)
|
|
|
+ w.setAlwaysOnTop(true, 'screen-saver')
|
|
|
+ assert.equal(w.isAlwaysOnTop(), true)
|
|
|
+ w.minimize()
|
|
|
+ assert.equal(w.isAlwaysOnTop(), false)
|
|
|
+ w.restore()
|
|
|
+ assert.equal(w.isAlwaysOnTop(), true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
describe('BrowserWindow.setAutoHideCursor(autoHide)', () => {
|
|
|
if (process.platform !== 'darwin') {
|
|
|
it('is not available on non-macOS platforms', () => {
|
|
@@ -989,6 +1005,7 @@ describe('BrowserWindow module', function () {
|
|
|
preload: preload
|
|
|
}
|
|
|
})
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preload)
|
|
|
let htmlPath = path.join(fixtures, 'api', 'sandbox.html?window-open')
|
|
|
const pageUrl = 'file://' + htmlPath
|
|
|
w.loadURL(pageUrl)
|
|
@@ -1019,6 +1036,7 @@ describe('BrowserWindow module', function () {
|
|
|
preload: preload
|
|
|
}
|
|
|
})
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preload)
|
|
|
let htmlPath = path.join(fixtures, 'api', 'sandbox.html?window-open-external')
|
|
|
const pageUrl = 'file://' + htmlPath
|
|
|
let popupWindow
|
|
@@ -1050,6 +1068,43 @@ describe('BrowserWindow module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ it('should inherit the sandbox setting in opened windows', function (done) {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false,
|
|
|
+ webPreferences: {
|
|
|
+ sandbox: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
|
|
|
+ ipcMain.once('answer', (event, args) => {
|
|
|
+ assert.equal(args.includes('--enable-sandbox'), true)
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ 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) {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false,
|
|
|
+ webPreferences: {
|
|
|
+ sandbox: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'foo', 'bar')
|
|
|
+ ipcMain.once('answer', (event, args, webPreferences) => {
|
|
|
+ assert.equal(webPreferences.foo, 'bar')
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)
|
|
|
+ })
|
|
|
+
|
|
|
it('should set ipc event sender correctly', function (done) {
|
|
|
w.destroy()
|
|
|
w = new BrowserWindow({
|
|
@@ -1310,6 +1365,68 @@ describe('BrowserWindow module', function () {
|
|
|
})
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-native-addon.html'))
|
|
|
})
|
|
|
+
|
|
|
+ it('should inherit the nativeWindowOpen setting in opened windows', function (done) {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false,
|
|
|
+ webPreferences: {
|
|
|
+ nativeWindowOpen: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
|
|
|
+ ipcMain.once('answer', (event, args) => {
|
|
|
+ assert.equal(args.includes('--native-window-open'), true)
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ 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) {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false,
|
|
|
+ webPreferences: {
|
|
|
+ nativeWindowOpen: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js')
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath)
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'foo', 'bar')
|
|
|
+ ipcMain.once('answer', (event, args, webPreferences) => {
|
|
|
+ assert.equal(webPreferences.foo, 'bar')
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('retains the original web preferences when window.location is changed to a new origin', async function () {
|
|
|
+ await serveFileFromProtocol('foo', path.join(fixtures, 'api', 'window-open-location-change.html'))
|
|
|
+ await serveFileFromProtocol('bar', path.join(fixtures, 'api', 'window-open-location-final.html'))
|
|
|
+
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: true,
|
|
|
+ webPreferences: {
|
|
|
+ nodeIntegration: false,
|
|
|
+ nativeWindowOpen: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', path.join(fixtures, 'api', 'window-open-preload.js'))
|
|
|
+ ipcMain.once('answer', (event, args, typeofProcess) => {
|
|
|
+ assert.equal(args.includes('--node-integration=false'), true)
|
|
|
+ assert.equal(args.includes('--native-window-open'), true)
|
|
|
+ assert.equal(typeofProcess, 'undefined')
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ w.loadURL(`file://${path.join(fixtures, 'api', 'window-open-location-open.html')}`)
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -2690,3 +2807,20 @@ const isScaleFactorRounding = () => {
|
|
|
// Return true if scale factor is odd number above 2
|
|
|
return scaleFactor > 2 && scaleFactor % 2 === 1
|
|
|
}
|
|
|
+
|
|
|
+function serveFileFromProtocol (protocolName, filePath) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ protocol.registerBufferProtocol(protocolName, (request, callback) => {
|
|
|
+ callback({
|
|
|
+ mimeType: 'text/html',
|
|
|
+ data: fs.readFileSync(filePath)
|
|
|
+ })
|
|
|
+ }, (error) => {
|
|
|
+ if (error != null) {
|
|
|
+ reject(error)
|
|
|
+ } else {
|
|
|
+ resolve()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|