Skip to content

Commit

Permalink
fix: make protocol wrapper remote-friendly again (#27044)
Browse files Browse the repository at this point in the history
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
  • Loading branch information
trop[bot] and zcbenz committed Dec 16, 2020
1 parent 8e6d332 commit 6b91371
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/browser/api/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ Object.setPrototypeOf(protocol, new Proxy({}, {

ownKeys () {
if (!app.isReady()) return [];
return Reflect.ownKeys(session.defaultSession!.protocol);
},

return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession!.protocol));
has: (target, property: string) => {
if (!app.isReady()) return false;
return Reflect.has(session.defaultSession!.protocol, property);
},

getOwnPropertyDescriptor () {
Expand Down
12 changes: 11 additions & 1 deletion spec-main/api-remote-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ipcMain, BrowserWindow } from 'electron/main';
import { emittedOnce } from './events-helpers';
import { NativeImage } from 'electron/common';
import { serialize, deserialize } from '../lib/common/type-utils';
import { nativeImage } from 'electron';
import { protocol, nativeImage } from 'electron';

const features = process._linkedBinding('electron_common_features');

Expand Down Expand Up @@ -635,6 +635,16 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'));
expect(functionWithToStringProperty.toString).to.equal('hello');
});

const protocolKeys = Object.getOwnPropertyNames(protocol);
remotely.it(protocolKeys)('remote.protocol returns all keys', (protocolKeys: [string]) => {
const protocol = require('electron').remote.protocol;
const remoteKeys = Object.getOwnPropertyNames(protocol);
expect(remoteKeys).to.deep.equal(protocolKeys);
for (const key of remoteKeys) {
expect(typeof (protocol as any)[key]).to.equal('function');
}
});
});

describe('remote object in renderer', () => {
Expand Down

0 comments on commit 6b91371

Please sign in to comment.