2020-03-20 20:28:31 +00:00
|
|
|
import { expect } from 'chai';
|
2023-02-08 01:22:18 +00:00
|
|
|
import { BrowserWindow } from 'electron/main';
|
|
|
|
import { closeAllWindows } from './lib/window-helpers';
|
2018-11-06 23:52:06 +00:00
|
|
|
|
|
|
|
describe('feature-string parsing', () => {
|
|
|
|
it('is indifferent to whitespace around keys and values', () => {
|
2021-11-10 16:54:51 +00:00
|
|
|
const { parseCommaSeparatedKeyValue } = require('../lib/browser/parse-features-string');
|
2019-08-28 20:54:42 +00:00
|
|
|
const checkParse = (string: string, parsed: Record<string, string | boolean>) => {
|
2021-04-19 22:46:54 +00:00
|
|
|
const features = parseCommaSeparatedKeyValue(string);
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(features).to.deep.equal(parsed);
|
|
|
|
};
|
|
|
|
checkParse('a=yes,c=d', { a: true, c: 'd' });
|
|
|
|
checkParse('a=yes ,c=d', { a: true, c: 'd' });
|
|
|
|
checkParse('a=yes, c=d', { a: true, c: 'd' });
|
|
|
|
checkParse('a=yes , c=d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a=yes , c=d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a= yes , c=d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a = yes , c=d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a = yes , c =d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a = yes , c = d', { a: true, c: 'd' });
|
|
|
|
checkParse(' a = yes , c = d ', { a: true, c: 'd' });
|
|
|
|
});
|
|
|
|
});
|
2023-02-08 01:22:18 +00:00
|
|
|
|
|
|
|
describe('process._linkedBinding', () => {
|
|
|
|
describe('in the main process', () => {
|
|
|
|
it('can access electron_browser bindings', () => {
|
|
|
|
process._linkedBinding('electron_browser_app');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can access electron_common bindings', () => {
|
|
|
|
process._linkedBinding('electron_common_v8_util');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('cannot access electron_renderer bindings', () => {
|
|
|
|
expect(() => {
|
|
|
|
process._linkedBinding('electron_renderer_ipc');
|
|
|
|
}).to.throw(/No such binding was linked: electron_renderer_ipc/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('in the renderer process', () => {
|
|
|
|
afterEach(closeAllWindows);
|
|
|
|
|
|
|
|
it('cannot access electron_browser bindings', async () => {
|
|
|
|
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
|
|
|
w.loadURL('about:blank');
|
|
|
|
await expect(w.webContents.executeJavaScript('void process._linkedBinding(\'electron_browser_app\')'))
|
|
|
|
.to.eventually.be.rejectedWith(/Script failed to execute/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can access electron_common bindings', async () => {
|
|
|
|
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
|
|
|
w.loadURL('about:blank');
|
|
|
|
await w.webContents.executeJavaScript('void process._linkedBinding(\'electron_common_v8_util\')');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can access electron_renderer bindings', async () => {
|
|
|
|
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
|
|
|
w.loadURL('about:blank');
|
|
|
|
await w.webContents.executeJavaScript('void process._linkedBinding(\'electron_renderer_ipc\')');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|