|
@@ -10,6 +10,7 @@ const qs = require('querystring')
|
|
|
const http = require('http')
|
|
|
const { closeWindow } = require('./window-helpers')
|
|
|
const { emittedOnce } = require('./events-helpers')
|
|
|
+const { createNetworkSandbox } = require('./network-helper')
|
|
|
const { ipcRenderer, remote } = require('electron')
|
|
|
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
|
|
|
|
|
@@ -305,7 +306,6 @@ describe('BrowserWindow module', () => {
|
|
|
})
|
|
|
|
|
|
it('should return a promise that resolves even if pushState occurs during navigation', async () => {
|
|
|
- const data = Buffer.alloc(2 * 1024 * 1024).toString('base64')
|
|
|
const p = w.loadURL('data:text/html,<script>window.history.pushState({}, "/foo")</script>')
|
|
|
await expect(p).to.eventually.be.fulfilled()
|
|
|
})
|
|
@@ -2033,17 +2033,29 @@ describe('BrowserWindow module', () => {
|
|
|
})
|
|
|
|
|
|
describe('nativeWindowOpen option', () => {
|
|
|
- beforeEach(() => {
|
|
|
+ const networkSandbox = createNetworkSandbox(protocol)
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ // used to create cross-origin navigation situations
|
|
|
+ await networkSandbox.serveFileFromProtocol('foo', path.join(fixtures, 'api', 'window-open-location-change.html'))
|
|
|
+ await networkSandbox.serveFileFromProtocol('bar', path.join(fixtures, 'api', 'window-open-location-final.html'))
|
|
|
+
|
|
|
w.destroy()
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
|
webPreferences: {
|
|
|
nodeIntegration: true,
|
|
|
- nativeWindowOpen: true
|
|
|
+ nativeWindowOpen: true,
|
|
|
+ // tests relies on preloads in opened windows
|
|
|
+ nodeIntegrationInSubFrames: true
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ afterEach(async () => {
|
|
|
+ await networkSandbox.reset()
|
|
|
+ })
|
|
|
+
|
|
|
it('opens window of about:blank with cross-scripting enabled', (done) => {
|
|
|
ipcMain.once('answer', (event, content) => {
|
|
|
assert.strictEqual(content, 'Hello')
|
|
@@ -2088,7 +2100,9 @@ describe('BrowserWindow module', () => {
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
|
webPreferences: {
|
|
|
- nativeWindowOpen: true
|
|
|
+ nativeWindowOpen: true,
|
|
|
+ // test relies on preloads in opened window
|
|
|
+ nodeIntegrationInSubFrames: true
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -2105,7 +2119,9 @@ describe('BrowserWindow module', () => {
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
|
webPreferences: {
|
|
|
- nativeWindowOpen: true
|
|
|
+ nativeWindowOpen: true,
|
|
|
+ // test relies on preloads in opened window
|
|
|
+ nodeIntegrationInSubFrames: true
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -2119,14 +2135,13 @@ describe('BrowserWindow module', () => {
|
|
|
w.loadFile(path.join(fixtures, 'api', 'new-window.html'))
|
|
|
})
|
|
|
it('retains the original web preferences when window.location is changed to a new origin', async () => {
|
|
|
- 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: {
|
|
|
- nativeWindowOpen: true
|
|
|
+ nativeWindowOpen: true,
|
|
|
+ // test relies on preloads in opened window
|
|
|
+ nodeIntegrationInSubFrames: true
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -2139,7 +2154,33 @@ describe('BrowserWindow module', () => {
|
|
|
expect(typeofProcess).to.eql('undefined')
|
|
|
})
|
|
|
|
|
|
+ it('window.opener is not null when window.location is changed to a new origin', async () => {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: true,
|
|
|
+ webPreferences: {
|
|
|
+ nativeWindowOpen: true,
|
|
|
+ // test relies on preloads in opened window
|
|
|
+ nodeIntegrationInSubFrames: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', path.join(fixtures, 'api', 'window-open-preload.js'))
|
|
|
+ const p = emittedOnce(ipcMain, 'answer')
|
|
|
+ w.loadFile(path.join(fixtures, 'api', 'window-open-location-open.html'))
|
|
|
+ const [, , , windowOpenerIsNull] = await p
|
|
|
+ expect(windowOpenerIsNull).to.be.false('window.opener is null')
|
|
|
+ })
|
|
|
+
|
|
|
it('should have nodeIntegration disabled in child windows', async () => {
|
|
|
+ w.destroy()
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false,
|
|
|
+ webPreferences: {
|
|
|
+ nodeIntegration: true,
|
|
|
+ nativeWindowOpen: true
|
|
|
+ }
|
|
|
+ })
|
|
|
const p = emittedOnce(ipcMain, 'answer')
|
|
|
w.loadFile(path.join(fixtures, 'api', 'native-window-open-argv.html'))
|
|
|
const [, typeofProcess] = await p
|
|
@@ -3836,22 +3877,3 @@ 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) => {
|
|
|
- // Disabled due to false positive in StandardJS
|
|
|
- // eslint-disable-next-line standard/no-callback-literal
|
|
|
- callback({
|
|
|
- mimeType: 'text/html',
|
|
|
- data: fs.readFileSync(filePath)
|
|
|
- })
|
|
|
- }, (error) => {
|
|
|
- if (error != null) {
|
|
|
- reject(error)
|
|
|
- } else {
|
|
|
- resolve()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
-}
|