Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Mar 31, 2020
1 parent b2e3847 commit cb91e5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec-main/api-protocol-spec.ts
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import { protocol, webContents, WebContents, session, BrowserWindow, ipcMain } from 'electron';
import { promisify } from 'util';
import { AddressInfo } from 'net';
import * as ChildProcess from 'child_process';
import * as path from 'path';
import * as http from 'http';
import * as fs from 'fs';
Expand Down Expand Up @@ -637,6 +638,22 @@ describe('protocol module', () => {
});
});

describe('protocol.registerSchemeAsPrivileged', () => {
it('does not crash on exit', async () => {
const appPath = path.join(__dirname, 'fixtures', 'api', 'custom-protocol-shutdown.js');
const appProcess = ChildProcess.spawn(process.execPath, ['--enable-logging', appPath]);
let output = '';
appProcess.stdout.on('data', data => { output += data; });
appProcess.stderr.on('data', data => { output += data; });
const [code] = await emittedOnce(appProcess, 'exit');
if (code !== 0) {
console.log(code, output);
}
expect(code).to.equal(0);
expect(output).to.not.contain('VALIDATION_ERROR_DESERIALIZATION_FAILED');
});
});

describe.skip('protocol.registerSchemesAsPrivileged standard', () => {
const standardScheme = (global as any).standardScheme;
const origin = `${standardScheme}://fake-host`;
Expand Down
18 changes: 18 additions & 0 deletions spec-main/fixtures/api/custom-protocol-shutdown.js
@@ -0,0 +1,18 @@
const { app, webContents, protocol, session } = require('electron');

protocol.registerSchemesAsPrivileged([
{ scheme: 'test', privileges: { standard: true, secure: true } }
]);

app.whenReady().then(function () {
const ses = session.fromPartition('persist:test-standard-shutdown');
const web = webContents.create({ session: ses });

ses.protocol.registerStringProtocol('test', (request, callback) => {
callback('Hello World!');
});

web.webContents.loadURL('test://abc/hello.txt');

web.webContents.on('did-finish-load', () => app.quit());
});

0 comments on commit cb91e5c

Please sign in to comment.