process-binding-spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { expect } from 'chai';
  2. import { BrowserWindow } from 'electron/main';
  3. import { closeAllWindows } from './lib/window-helpers';
  4. describe('process._linkedBinding', () => {
  5. describe('in the main process', () => {
  6. it('can access electron_browser bindings', () => {
  7. process._linkedBinding('electron_browser_app');
  8. });
  9. it('can access electron_common bindings', () => {
  10. process._linkedBinding('electron_common_v8_util');
  11. });
  12. it('cannot access electron_renderer bindings', () => {
  13. expect(() => {
  14. process._linkedBinding('electron_renderer_ipc');
  15. }).to.throw(/No such binding was linked: electron_renderer_ipc/);
  16. });
  17. });
  18. describe('in the renderer process', () => {
  19. afterEach(closeAllWindows);
  20. it('cannot access electron_browser bindings', async () => {
  21. const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
  22. w.loadURL('about:blank');
  23. await expect(w.webContents.executeJavaScript('void process._linkedBinding(\'electron_browser_app\')'))
  24. .to.eventually.be.rejectedWith(/Script failed to execute/);
  25. });
  26. it('can access electron_common bindings', async () => {
  27. const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
  28. w.loadURL('about:blank');
  29. await w.webContents.executeJavaScript('void process._linkedBinding(\'electron_common_v8_util\')');
  30. });
  31. it('can access electron_renderer bindings', async () => {
  32. const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
  33. w.loadURL('about:blank');
  34. await w.webContents.executeJavaScript('void process._linkedBinding(\'electron_renderer_ipc\')');
  35. });
  36. });
  37. });