From fc468cce3bdaa1ca3db2cd189dd9b06e12784cc7 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 13 May 2020 20:05:44 +0200 Subject: [PATCH] test: skip remote module related tests when enable_remote_module = false (#23557) --- spec-main/api-browser-window-spec.ts | 6 +++--- spec-main/api-web-contents-spec.ts | 18 ++++++++++-------- spec-main/fixtures/module/delete-buffer.js | 4 +++- spec-main/webview-spec.ts | 5 ++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 784297000539..8342c337ee20 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1936,7 +1936,7 @@ describe('BrowserWindow module', () => { }); }); - describe('"enableRemoteModule" option', () => { + ifdescribe(features.isRemoteModuleEnabled())('"enableRemoteModule" option', () => { const generateSpecs = (description: string, sandbox: boolean) => { describe(description, () => { const preload = path.join(__dirname, 'fixtures', 'module', 'preload-remote.js'); @@ -2294,7 +2294,7 @@ describe('BrowserWindow module', () => { }); // see #9387 - it('properly manages remote object references after page reload', (done) => { + ifit(features.isRemoteModuleEnabled())('properly manages remote object references after page reload', (done) => { const w = new BrowserWindow({ show: false, webPreferences: { @@ -2327,7 +2327,7 @@ describe('BrowserWindow module', () => { }); }); - it('properly manages remote object references after page reload in child window', (done) => { + ifit(features.isRemoteModuleEnabled())('properly manages remote object references after page reload in child window', (done) => { const w = new BrowserWindow({ show: false, webPreferences: { diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index 2e98bb442df2..3f5964e46ed3 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -831,11 +831,10 @@ describe('webContents module', () => { const protocol = session.defaultSession.protocol; protocol.registerStringProtocol(scheme, (request, callback) => { const response = ``; callback({ data: response, mimeType: 'text/html' }); @@ -921,14 +920,15 @@ describe('webContents module', () => { }); it('can persist zoom level across navigation', (done) => { - const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } }); + const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); let finalNavigation = false; ipcMain.on('set-zoom', (e, host) => { const zoomLevel = hostZoomMap[host]; if (!finalNavigation) w.webContents.zoomLevel = zoomLevel; e.sender.send(`${host}-zoom-set`); }); - ipcMain.on('host1-zoom-level', (e, zoomLevel) => { + ipcMain.on('host1-zoom-level', (e) => { + const zoomLevel = e.sender.getZoomLevel(); const expectedZoomLevel = hostZoomMap.host1; expect(zoomLevel).to.equal(expectedZoomLevel); if (finalNavigation) { @@ -937,7 +937,8 @@ describe('webContents module', () => { w.loadURL(`${scheme}://host2`); } }); - ipcMain.once('host2-zoom-level', (e, zoomLevel) => { + ipcMain.once('host2-zoom-level', (e) => { + const zoomLevel = e.sender.getZoomLevel(); const expectedZoomLevel = hostZoomMap.host2; expect(zoomLevel).to.equal(expectedZoomLevel); finalNavigation = true; @@ -947,7 +948,7 @@ describe('webContents module', () => { }); it('can propagate zoom level across same session', (done) => { - const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, enableRemoteModule: true } }); + const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); const w2 = new BrowserWindow({ show: false }); w2.webContents.on('did-finish-load', () => { const zoomLevel1 = w.webContents.zoomLevel; @@ -1047,7 +1048,8 @@ describe('webContents module', () => { w2.close(); done(); }); - ipcMain.once('temporary-zoom-set', (e, zoomLevel) => { + ipcMain.once('temporary-zoom-set', (e) => { + const zoomLevel = e.sender.getZoomLevel(); w2.loadFile(path.join(fixturesPath, 'pages', 'c.html')); finalZoomLevel = zoomLevel; }); diff --git a/spec-main/fixtures/module/delete-buffer.js b/spec-main/fixtures/module/delete-buffer.js index abbacb741497..8888e2b255b6 100644 --- a/spec-main/fixtures/module/delete-buffer.js +++ b/spec-main/fixtures/module/delete-buffer.js @@ -6,6 +6,8 @@ delete window.Buffer; delete global.Buffer; // Test that remote.js doesn't use Buffer global -remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar')); +if (remote) { + remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar')); +} window.test = Buffer.from('buffer'); diff --git a/spec-main/webview-spec.ts b/spec-main/webview-spec.ts index 44c7ed6a43c2..66a4cd6eae27 100644 --- a/spec-main/webview-spec.ts +++ b/spec-main/webview-spec.ts @@ -2,8 +2,11 @@ import * as path from 'path'; import { BrowserWindow, session, ipcMain, app, WebContents } from 'electron/main'; import { closeAllWindows } from './window-helpers'; import { emittedOnce } from './events-helpers'; +import { ifdescribe } from './spec-helpers'; import { expect } from 'chai'; +const features = process.electronBinding('features'); + async function loadWebView (w: WebContents, attributes: Record, openDevTools: boolean = false): Promise { await w.executeJavaScript(` new Promise((resolve, reject) => { @@ -570,7 +573,7 @@ describe(' tag', function () { }); }); - describe('enableremotemodule attribute', () => { + ifdescribe(features.isRemoteModuleEnabled())('enableremotemodule attribute', () => { let w: BrowserWindow; beforeEach(async () => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } });