Browse Source

fix: make protocol wrapper remote-friendly again (#27043)

Co-authored-by: Cheng Zhao <[email protected]>
trop[bot] 4 years ago
parent
commit
39f865e4e3
2 changed files with 16 additions and 2 deletions
  1. 5 1
      lib/browser/api/protocol.ts
  2. 11 1
      spec-main/api-remote-spec.ts

+ 5 - 1
lib/browser/api/protocol.ts

@@ -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 () {

+ 11 - 1
spec-main/api-remote-spec.ts

@@ -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');
 
@@ -641,6 +641,16 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
       const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, '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', () => {