diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 18e34da61e37..b4921d147ed3 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1913,8 +1913,8 @@ describe('BrowserWindow module', () => { const [, test] = await emittedOnce(ipcMain, 'answer'); expect(test).to.eql('preload'); }); - it('can successfully delete the Buffer global', async () => { - const preload = path.join(__dirname, 'fixtures', 'module', 'delete-buffer.js'); + ifit(features.isRemoteModuleEnabled())('can successfully delete the Buffer global', async () => { + const preload = path.join(__dirname, 'fixtures', 'remote', 'delete-buffer.js'); const w = new BrowserWindow({ show: false, webPreferences: { @@ -2039,7 +2039,7 @@ describe('BrowserWindow module', () => { ifdescribe(features.isRemoteModuleEnabled())('"enableRemoteModule" option', () => { const generateSpecs = (description: string, sandbox: boolean) => { describe(description, () => { - const preload = path.join(__dirname, 'fixtures', 'module', 'preload-remote.js'); + const preload = path.join(__dirname, 'fixtures', 'remote', 'preload-remote.js'); it('disables the remote module by default', async () => { const w = new BrowserWindow({ diff --git a/spec-main/api-remote-spec.ts b/spec-main/api-remote-spec.ts index 9ae21d6c8a34..ec444fa0d023 100644 --- a/spec-main/api-remote-spec.ts +++ b/spec-main/api-remote-spec.ts @@ -216,7 +216,7 @@ describe('typeUtils serialization/deserialization', () => { }); ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { - const fixtures = path.join(__dirname, 'fixtures'); + const fixtures = path.join(__dirname, 'fixtures', 'remote'); describe('', () => { const w = makeWindow(); @@ -318,7 +318,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { w().webContents.once('did-finish-load', () => { w().webContents.loadURL('about:blank'); }); - w().loadFile(path.join(fixtures, 'api', 'send-on-exit.html')); + w().loadFile(path.join(fixtures, 'send-on-exit.html')); await emittedOnce(ipcMain, 'SENT_ON_EXIT'); }); }); @@ -330,7 +330,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { afterEach(closeAllWindows); it('works when created in preload script', async () => { - const preload = path.join(fixtures, 'module', 'preload-remote-function.js'); + const preload = path.join(fixtures, 'preload-remote-function.js'); const w = new BrowserWindow({ show: false, webPreferences: { @@ -354,7 +354,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { }); const message = emittedOnce(ipcMain, 'error-message'); - w.loadFile(path.join(fixtures, 'api', 'render-view-deleted.html')); + w.loadFile(path.join(fixtures, 'render-view-deleted.html')); const [, msg] = await message; expect(msg).to.match(/^Cannot call method 'getURL' on missing remote object/); }); @@ -439,7 +439,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { enableRemoteModule: true } }); - await w.loadFile(path.join(fixtures, 'api', 'remote-event-handler.html')); + await w.loadFile(path.join(fixtures, 'remote-event-handler.html')); w.webContents.reload(); await emittedOnce(w.webContents, 'did-finish-load'); @@ -482,12 +482,12 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { expect(a).to.equal(b); }); - remotely.it(path.join(fixtures, 'module', 'id.js'))('should work when object contains id property', (module: string) => { + remotely.it(path.join(fixtures, 'id.js'))('should work when object contains id property', (module: string) => { const { id } = require('electron').remote.require(module); expect(id).to.equal(1127); }); - remotely.it(path.join(fixtures, 'module', 'no-prototype.js'))('should work when object has no prototype', (module: string) => { + remotely.it(path.join(fixtures, 'no-prototype.js'))('should work when object has no prototype', (module: string) => { const a = require('electron').remote.require(module); expect(a.foo.bar).to.equal('baz'); expect(a.foo.baz).to.equal(false); @@ -517,13 +517,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const path = require('path'); { - const a = require('electron').remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js')); + const a = require('electron').remote.require(path.join(fixtures, 'export-function-with-properties.js')); expect(typeof a).to.equal('function'); expect(a.bar).to.equal('baz'); } { - const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-properties.js')); + const a = require('electron').remote.require(path.join(fixtures, 'function-with-properties.js')); expect(typeof a).to.equal('object'); expect(a.foo()).to.equal('hello'); expect(a.foo.bar).to.equal('baz'); @@ -533,7 +533,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { } { - const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-missing-properties.js')).setup(); + const a = require('electron').remote.require(path.join(fixtures, 'function-with-missing-properties.js')).setup(); expect(a.bar()).to.equal(true); expect(a.bar.baz).to.be.undefined(); } @@ -541,7 +541,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { remotely.it(fixtures)('should work with static class members', (fixtures: string) => { const path = require('path'); - const a = require('electron').remote.require(path.join(fixtures, 'module', 'remote-static.js')); + const a = require('electron').remote.require(path.join(fixtures, 'remote-static.js')); expect(typeof a.Foo).to.equal('function'); expect(a.Foo.foo()).to.equal(3); expect(a.Foo.bar).to.equal('baz'); @@ -550,7 +550,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { remotely.it(fixtures)('includes the length of functions specified as arguments', (fixtures: string) => { const path = require('path'); - const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-args.js')); + const a = require('electron').remote.require(path.join(fixtures, 'function-with-args.js')); /* eslint-disable @typescript-eslint/no-unused-vars */ expect(a((a: any, b: any, c: any) => {})).to.equal(3); expect(a((a: any) => {})).to.equal(1); @@ -560,7 +560,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { remotely.it(fixtures)('handles circular references in arrays and objects', (fixtures: string) => { const path = require('path'); - const a = require('electron').remote.require(path.join(fixtures, 'module', 'circular.js')); + const a = require('electron').remote.require(path.join(fixtures, 'circular.js')); let arrayA: any[] = ['foo']; const arrayB = [arrayA, 'bar']; @@ -619,7 +619,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const { remote } = require('electron'); const path = require('path'); const buf = Buffer.from('test'); - const call = remote.require(path.join(fixtures, 'module', 'call.js')); + const call = remote.require(path.join(fixtures, 'call.js')); const result = call.call((remote as any).createFunctionWithReturnValue(buf)); expect(result).to.be.an.instanceOf(Uint8Array); }); @@ -640,7 +640,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const { readText } = require('electron').remote.clipboard; expect(readText.toString().startsWith('function')).to.be.true(); - const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'module', 'to-string-non-function.js')); + const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'to-string-non-function.js')); expect(functionWithToStringProperty.toString).to.equal('hello'); }); }); @@ -650,7 +650,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const remotely = makeRemotely(win); remotely.it(fixtures)('can change its properties', (fixtures: string) => { - const module = require('path').join(fixtures, 'module', 'property.js'); + const module = require('path').join(fixtures, 'property.js'); const property = require('electron').remote.require(module); expect(property.property).to.equal(1127); property.property = null; @@ -672,7 +672,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { }); remotely.it(fixtures)('rethrows errors getting/setting properties', (fixtures: string) => { - const foo = require('electron').remote.require(require('path').join(fixtures, 'module', 'error-properties.js')); + const foo = require('electron').remote.require(require('path').join(fixtures, 'error-properties.js')); expect(() => { // eslint-disable-next-line @@ -686,18 +686,18 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { remotely.it(fixtures)('can set a remote property with a remote object', (fixtures: string) => { const { remote } = require('electron'); - const foo = remote.require(require('path').join(fixtures, 'module', 'remote-object-set.js')); + const foo = remote.require(require('path').join(fixtures, 'remote-object-set.js')); foo.bar = remote.getCurrentWindow(); }); remotely.it(fixtures)('can construct an object from its member', (fixtures: string) => { - const call = require('electron').remote.require(require('path').join(fixtures, 'module', 'call.js')); + const call = require('electron').remote.require(require('path').join(fixtures, 'call.js')); const obj = new call.constructor(); expect(obj.test).to.equal('test'); }); remotely.it(fixtures)('can reassign and delete its member functions', (fixtures: string) => { - const remoteFunctions = require('electron').remote.require(require('path').join(fixtures, 'module', 'function.js')); + const remoteFunctions = require('electron').remote.require(require('path').join(fixtures, 'function.js')); expect(remoteFunctions.aFunction()).to.equal(1127); remoteFunctions.aFunction = () => { return 1234; }; @@ -724,7 +724,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { describe('remote value in browser', () => { const remotely = makeRemotely(makeWindow()); - const print = path.join(fixtures, 'module', 'print_name.js'); + const print = path.join(fixtures, 'print_name.js'); remotely.it(print)('preserves NaN', (print: string) => { const printName = require('electron').remote.require(print); @@ -836,13 +836,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const remotely = makeRemotely(makeWindow()); remotely.it(fixtures)('can be used as promise in each side', async (fixtures: string) => { - const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'promise.js')); + const promise = require('electron').remote.require(require('path').join(fixtures, 'promise.js')); const value = await promise.twicePromise(Promise.resolve(1234)); expect(value).to.equal(2468); }); remotely.it(fixtures)('handles rejections via catch(onRejected)', async (fixtures: string) => { - const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'rejected-promise.js')); + const promise = require('electron').remote.require(require('path').join(fixtures, 'rejected-promise.js')); const error = await new Promise(resolve => { promise.reject(Promise.resolve(1234)).catch(resolve); }); @@ -850,7 +850,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { }); remotely.it(fixtures)('handles rejections via then(onFulfilled, onRejected)', async (fixtures: string) => { - const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'rejected-promise.js')); + const promise = require('electron').remote.require(require('path').join(fixtures, 'rejected-promise.js')); const error = await new Promise(resolve => { promise.reject(Promise.resolve(1234)).then(() => {}, resolve); }); @@ -864,7 +864,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { process.once('unhandledRejection', onUnhandledRejection); remotely(async (fixtures: string) => { - const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'unhandled-rejection.js')); + const promise = require('electron').remote.require(require('path').join(fixtures, 'unhandled-rejection.js')); return new Promise((resolve, reject) => { promise.reject().then(() => { reject(new Error('Promise was not rejected')); @@ -897,7 +897,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { promise.reject().then(() => { reject(new Error('Promise was not rejected')); }); - }), path.join(fixtures, 'module', 'unhandled-rejection.js')).then( + }), path.join(fixtures, 'unhandled-rejection.js')).then( (message) => { try { expect(message).to.equal('rejected'); @@ -947,17 +947,17 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const remotely = makeRemotely(makeWindow()); remotely.it(fixtures)('can get methods', (fixtures: string) => { - const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); expect(base.method()).to.equal('method'); }); remotely.it(fixtures)('can get properties', (fixtures: string) => { - const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); expect(base.readonly).to.equal('readonly'); }); remotely.it(fixtures)('can change properties', (fixtures: string) => { - const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); expect(base.value).to.equal('old'); base.value = 'new'; expect(base.value).to.equal('new'); @@ -965,13 +965,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { }); remotely.it(fixtures)('has unenumerable methods', (fixtures: string) => { - const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); expect(base).to.not.have.ownProperty('method'); expect(Object.getPrototypeOf(base)).to.have.ownProperty('method'); }); remotely.it(fixtures)('keeps prototype chain in derived class', (fixtures: string) => { - const { derived } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + const { derived } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); expect(derived.method()).to.equal('method'); expect(derived.readonly).to.equal('readonly'); expect(derived).to.not.have.ownProperty('method'); @@ -981,7 +981,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { }); remotely.it(fixtures)('is referenced by methods in prototype chain', (fixtures: string) => { - let { derived } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js')); + let { derived } = require('electron').remote.require(require('path').join(fixtures, 'class.js')); const method = derived.method; derived = null; global.gc(); @@ -993,14 +993,14 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => { const remotely = makeRemotely(makeWindow()); remotely.it(fixtures)('throws errors from the main process', (fixtures: string) => { - const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'module', 'exception.js')); + const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'exception.js')); expect(() => { throwFunction(); }).to.throw(/undefined/); }); remotely.it(fixtures)('tracks error cause', (fixtures: string) => { - const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'module', 'exception.js')); + const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'exception.js')); try { throwFunction(new Error('error from main')); expect.fail(); diff --git a/spec-main/fixtures/module/call.js b/spec-main/fixtures/remote/call.js similarity index 100% rename from spec-main/fixtures/module/call.js rename to spec-main/fixtures/remote/call.js diff --git a/spec-main/fixtures/module/circular.js b/spec-main/fixtures/remote/circular.js similarity index 100% rename from spec-main/fixtures/module/circular.js rename to spec-main/fixtures/remote/circular.js diff --git a/spec-main/fixtures/module/class.js b/spec-main/fixtures/remote/class.js similarity index 100% rename from spec-main/fixtures/module/class.js rename to spec-main/fixtures/remote/class.js diff --git a/spec-main/fixtures/module/delete-buffer.js b/spec-main/fixtures/remote/delete-buffer.js similarity index 70% rename from spec-main/fixtures/module/delete-buffer.js rename to spec-main/fixtures/remote/delete-buffer.js index 8888e2b255b6..abbacb741497 100644 --- a/spec-main/fixtures/module/delete-buffer.js +++ b/spec-main/fixtures/remote/delete-buffer.js @@ -6,8 +6,6 @@ delete window.Buffer; delete global.Buffer; // Test that remote.js doesn't use Buffer global -if (remote) { - remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar')); -} +remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar')); window.test = Buffer.from('buffer'); diff --git a/spec-main/fixtures/module/error-properties.js b/spec-main/fixtures/remote/error-properties.js similarity index 100% rename from spec-main/fixtures/module/error-properties.js rename to spec-main/fixtures/remote/error-properties.js diff --git a/spec-main/fixtures/module/exception.js b/spec-main/fixtures/remote/exception.js similarity index 100% rename from spec-main/fixtures/module/exception.js rename to spec-main/fixtures/remote/exception.js diff --git a/spec-main/fixtures/module/export-function-with-properties.js b/spec-main/fixtures/remote/export-function-with-properties.js similarity index 100% rename from spec-main/fixtures/module/export-function-with-properties.js rename to spec-main/fixtures/remote/export-function-with-properties.js diff --git a/spec-main/fixtures/module/function-with-args.js b/spec-main/fixtures/remote/function-with-args.js similarity index 100% rename from spec-main/fixtures/module/function-with-args.js rename to spec-main/fixtures/remote/function-with-args.js diff --git a/spec-main/fixtures/module/function-with-missing-properties.js b/spec-main/fixtures/remote/function-with-missing-properties.js similarity index 100% rename from spec-main/fixtures/module/function-with-missing-properties.js rename to spec-main/fixtures/remote/function-with-missing-properties.js diff --git a/spec-main/fixtures/module/function-with-properties.js b/spec-main/fixtures/remote/function-with-properties.js similarity index 100% rename from spec-main/fixtures/module/function-with-properties.js rename to spec-main/fixtures/remote/function-with-properties.js diff --git a/spec-main/fixtures/module/function.js b/spec-main/fixtures/remote/function.js similarity index 100% rename from spec-main/fixtures/module/function.js rename to spec-main/fixtures/remote/function.js diff --git a/spec-main/fixtures/module/id.js b/spec-main/fixtures/remote/id.js similarity index 100% rename from spec-main/fixtures/module/id.js rename to spec-main/fixtures/remote/id.js diff --git a/spec-main/fixtures/module/no-prototype.js b/spec-main/fixtures/remote/no-prototype.js similarity index 100% rename from spec-main/fixtures/module/no-prototype.js rename to spec-main/fixtures/remote/no-prototype.js diff --git a/spec-main/fixtures/module/preload-remote-function.js b/spec-main/fixtures/remote/preload-remote-function.js similarity index 100% rename from spec-main/fixtures/module/preload-remote-function.js rename to spec-main/fixtures/remote/preload-remote-function.js diff --git a/spec-main/fixtures/module/preload-remote.js b/spec-main/fixtures/remote/preload-remote.js similarity index 100% rename from spec-main/fixtures/module/preload-remote.js rename to spec-main/fixtures/remote/preload-remote.js diff --git a/spec-main/fixtures/module/print_name.js b/spec-main/fixtures/remote/print_name.js similarity index 100% rename from spec-main/fixtures/module/print_name.js rename to spec-main/fixtures/remote/print_name.js diff --git a/spec-main/fixtures/module/promise.js b/spec-main/fixtures/remote/promise.js similarity index 100% rename from spec-main/fixtures/module/promise.js rename to spec-main/fixtures/remote/promise.js diff --git a/spec-main/fixtures/module/property.js b/spec-main/fixtures/remote/property.js similarity index 100% rename from spec-main/fixtures/module/property.js rename to spec-main/fixtures/remote/property.js diff --git a/spec-main/fixtures/module/rejected-promise.js b/spec-main/fixtures/remote/rejected-promise.js similarity index 100% rename from spec-main/fixtures/module/rejected-promise.js rename to spec-main/fixtures/remote/rejected-promise.js diff --git a/spec-main/fixtures/api/remote-event-handler.html b/spec-main/fixtures/remote/remote-event-handler.html similarity index 100% rename from spec-main/fixtures/api/remote-event-handler.html rename to spec-main/fixtures/remote/remote-event-handler.html diff --git a/spec-main/fixtures/module/remote-object-set.js b/spec-main/fixtures/remote/remote-object-set.js similarity index 100% rename from spec-main/fixtures/module/remote-object-set.js rename to spec-main/fixtures/remote/remote-object-set.js diff --git a/spec-main/fixtures/module/remote-static.js b/spec-main/fixtures/remote/remote-static.js similarity index 100% rename from spec-main/fixtures/module/remote-static.js rename to spec-main/fixtures/remote/remote-static.js diff --git a/spec-main/fixtures/api/render-view-deleted.html b/spec-main/fixtures/remote/render-view-deleted.html similarity index 100% rename from spec-main/fixtures/api/render-view-deleted.html rename to spec-main/fixtures/remote/render-view-deleted.html diff --git a/spec-main/fixtures/api/send-on-exit.html b/spec-main/fixtures/remote/send-on-exit.html similarity index 100% rename from spec-main/fixtures/api/send-on-exit.html rename to spec-main/fixtures/remote/send-on-exit.html diff --git a/spec-main/fixtures/module/to-string-non-function.js b/spec-main/fixtures/remote/to-string-non-function.js similarity index 100% rename from spec-main/fixtures/module/to-string-non-function.js rename to spec-main/fixtures/remote/to-string-non-function.js diff --git a/spec-main/fixtures/module/unhandled-rejection.js b/spec-main/fixtures/remote/unhandled-rejection.js similarity index 100% rename from spec-main/fixtures/module/unhandled-rejection.js rename to spec-main/fixtures/remote/unhandled-rejection.js