Remove unneeded returns

This commit is contained in:
Kevin Sawicki 2016-02-16 17:39:11 -08:00
parent e63c3c727a
commit 12adaa0570
14 changed files with 773 additions and 826 deletions

View file

@ -23,38 +23,38 @@ describe('electron module', function() {
describe('app module', function() { describe('app module', function() {
describe('app.getVersion()', function() { describe('app.getVersion()', function() {
return it('returns the version field of package.json', function() { it('returns the version field of package.json', function() {
return assert.equal(app.getVersion(), '0.1.0'); assert.equal(app.getVersion(), '0.1.0');
}); });
}); });
describe('app.setVersion(version)', function() { describe('app.setVersion(version)', function() {
return it('overrides the version', function() { it('overrides the version', function() {
assert.equal(app.getVersion(), '0.1.0'); assert.equal(app.getVersion(), '0.1.0');
app.setVersion('test-version'); app.setVersion('test-version');
assert.equal(app.getVersion(), 'test-version'); assert.equal(app.getVersion(), 'test-version');
return app.setVersion('0.1.0'); app.setVersion('0.1.0');
}); });
}); });
describe('app.getName()', function() { describe('app.getName()', function() {
return it('returns the name field of package.json', function() { it('returns the name field of package.json', function() {
return assert.equal(app.getName(), 'Electron Test'); assert.equal(app.getName(), 'Electron Test');
}); });
}); });
describe('app.setName(name)', function() { describe('app.setName(name)', function() {
return it('overrides the name', function() { it('overrides the name', function() {
assert.equal(app.getName(), 'Electron Test'); assert.equal(app.getName(), 'Electron Test');
app.setName('test-name'); app.setName('test-name');
assert.equal(app.getName(), 'test-name'); assert.equal(app.getName(), 'test-name');
return app.setName('Electron Test'); app.setName('Electron Test');
}); });
}); });
describe('app.getLocale()', function() { describe('app.getLocale()', function() {
return it('should not be empty', function() { it('should not be empty', function() {
return assert.notEqual(app.getLocale(), ''); assert.notEqual(app.getLocale(), '');
}); });
}); });
@ -62,71 +62,71 @@ describe('app module', function() {
var appProcess = null; var appProcess = null;
afterEach(function() { afterEach(function() {
return appProcess != null ? appProcess.kill() : void 0; appProcess != null ? appProcess.kill() : void 0;
}); });
return it('emits a process exit event with the code', function(done) { it('emits a process exit event with the code', function(done) {
var appPath, electronPath, output; var appPath, electronPath, output;
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app'); appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
electronPath = remote.getGlobal('process').execPath; electronPath = remote.getGlobal('process').execPath;
appProcess = ChildProcess.spawn(electronPath, [appPath]); appProcess = ChildProcess.spawn(electronPath, [appPath]);
output = ''; output = '';
appProcess.stdout.on('data', function(data) { appProcess.stdout.on('data', function(data) {
return output += data; output += data;
}); });
return appProcess.on('close', function(code) { appProcess.on('close', function(code) {
if (process.platform !== 'win32') { if (process.platform !== 'win32') {
assert.notEqual(output.indexOf('Exit event with code: 123'), -1); assert.notEqual(output.indexOf('Exit event with code: 123'), -1);
} }
assert.equal(code, 123); assert.equal(code, 123);
return done(); done();
}); });
}); });
}); });
return describe('BrowserWindow events', function() { describe('BrowserWindow events', function() {
var w = null; var w = null;
afterEach(function() { afterEach(function() {
if (w != null) { if (w != null) {
w.destroy(); w.destroy();
} }
return w = null; w = null;
}); });
it('should emit browser-window-focus event when window is focused', function(done) { it('should emit browser-window-focus event when window is focused', function(done) {
app.once('browser-window-focus', function(e, window) { app.once('browser-window-focus', function(e, window) {
assert.equal(w.id, window.id); assert.equal(w.id, window.id);
return done(); done();
}); });
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
return w.emit('focus'); w.emit('focus');
}); });
it('should emit browser-window-blur event when window is blured', function(done) { it('should emit browser-window-blur event when window is blured', function(done) {
app.once('browser-window-blur', function(e, window) { app.once('browser-window-blur', function(e, window) {
assert.equal(w.id, window.id); assert.equal(w.id, window.id);
return done(); done();
}); });
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
return w.emit('blur'); w.emit('blur');
}); });
return it('should emit browser-window-created event when window is created', function(done) { it('should emit browser-window-created event when window is created', function(done) {
app.once('browser-window-created', function(e, window) { app.once('browser-window-created', function(e, window) {
return setImmediate(function() { setImmediate(function() {
assert.equal(w.id, window.id); assert.equal(w.id, window.id);
return done(); done();
}); });
}); });
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
return w.emit('blur'); w.emit('blur');
}); });
}); });
}); });

View file

@ -8,50 +8,46 @@ describe('clipboard module', function() {
var fixtures = path.resolve(__dirname, 'fixtures'); var fixtures = path.resolve(__dirname, 'fixtures');
describe('clipboard.readImage()', function() { describe('clipboard.readImage()', function() {
return it('returns NativeImage intance', function() { it('returns NativeImage intance', function() {
var i, p; var p = path.join(fixtures, 'assets', 'logo.png');
p = path.join(fixtures, 'assets', 'logo.png'); var i = nativeImage.createFromPath(p);
i = nativeImage.createFromPath(p);
clipboard.writeImage(p); clipboard.writeImage(p);
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()); assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
}); });
}); });
describe('clipboard.readText()', function() { describe('clipboard.readText()', function() {
return it('returns unicode string correctly', function() { it('returns unicode string correctly', function() {
var text; var text = '千江有水千江月,万里无云万里天';
text = '千江有水千江月,万里无云万里天';
clipboard.writeText(text); clipboard.writeText(text);
return assert.equal(clipboard.readText(), text); assert.equal(clipboard.readText(), text);
}); });
}); });
describe('clipboard.readHtml()', function() { describe('clipboard.readHtml()', function() {
return it('returns markup correctly', function() { it('returns markup correctly', function() {
var markup, text; var text = '<string>Hi</string>';
text = '<string>Hi</string>'; var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><string>Hi</string>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><string>Hi</string>' : '<string>Hi</string>';
markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><string>Hi</string>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><string>Hi</string>' : '<string>Hi</string>';
clipboard.writeHtml(text); clipboard.writeHtml(text);
return assert.equal(clipboard.readHtml(), markup); assert.equal(clipboard.readHtml(), markup);
}); });
}); });
describe('clipboard.readRtf', function() { describe('clipboard.readRtf', function() {
return it('returns rtf text correctly', function() { it('returns rtf text correctly', function() {
var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}"; var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}";
clipboard.writeRtf(rtf); clipboard.writeRtf(rtf);
return assert.equal(clipboard.readRtf(), rtf); assert.equal(clipboard.readRtf(), rtf);
}); });
}); });
return describe('clipboard.write()', function() { describe('clipboard.write()', function() {
return it('returns data correctly', function() { it('returns data correctly', function() {
var i, markup, p, text, rtf; var text = 'test';
text = 'test'; var rtf = '{\\rtf1\\utf8 text}';
rtf = '{\\rtf1\\utf8 text}'; var p = path.join(fixtures, 'assets', 'logo.png');
p = path.join(fixtures, 'assets', 'logo.png'); var i = nativeImage.createFromPath(p);
i = nativeImage.createFromPath(p); var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>';
markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>';
clipboard.write({ clipboard.write({
text: "test", text: "test",
html: '<b>Hi</b>', html: '<b>Hi</b>',
@ -61,7 +57,7 @@ describe('clipboard module', function() {
assert.equal(clipboard.readText(), text); assert.equal(clipboard.readText(), text);
assert.equal(clipboard.readHtml(), markup); assert.equal(clipboard.readHtml(), markup);
assert.equal(clipboard.readRtf(), rtf); assert.equal(clipboard.readRtf(), rtf);
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()); assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
}); });
}); });
}); });

View file

@ -14,13 +14,13 @@ describe('crash-reporter module', function() {
var w = null; var w = null;
beforeEach(function() { beforeEach(function() {
return w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
}); });
afterEach(function() { afterEach(function() {
return w.destroy(); w.destroy();
}); });
if (process.mas) { if (process.mas) {
@ -40,7 +40,7 @@ describe('crash-reporter module', function() {
var form; var form;
server.close(); server.close();
form = new multiparty.Form(); form = new multiparty.Form();
return form.parse(req, function(error, fields) { form.parse(req, function(error, fields) {
if (called) { if (called) {
return; return;
} }
@ -55,11 +55,11 @@ describe('crash-reporter module', function() {
assert.equal(fields['_companyName'], 'Umbrella Corporation'); assert.equal(fields['_companyName'], 'Umbrella Corporation');
assert.equal(fields['_version'], app.getVersion()); assert.equal(fields['_version'], app.getVersion());
res.end('abc-123-def'); res.end('abc-123-def');
return done(); done();
}); });
}); });
var port = remote.process.port; var port = remote.process.port;
return server.listen(port, '127.0.0.1', function() { server.listen(port, '127.0.0.1', function() {
port = server.address().port; port = server.address().port;
remote.process.port = port; remote.process.port = port;
const crashUrl = url.format({ const crashUrl = url.format({
@ -73,19 +73,19 @@ describe('crash-reporter module', function() {
submitURL: "http://127.0.0.1:" + port submitURL: "http://127.0.0.1:" + port
}); });
} }
return w.loadURL(crashUrl); w.loadURL(crashUrl);
}); });
}); });
return describe(".start(options)", function() { describe(".start(options)", function() {
return it('requires that the companyName and submitURL options be specified', function() { it('requires that the companyName and submitURL options be specified', function() {
assert.throws(function() { assert.throws(function() {
return crashReporter.start({ crashReporter.start({
companyName: 'Missing submitURL' companyName: 'Missing submitURL'
}); });
}); });
return assert.throws(function() { assert.throws(function() {
return crashReporter.start({ crashReporter.start({
submitURL: 'Missing companyName' submitURL: 'Missing companyName'
}); });
}); });

View file

@ -12,7 +12,7 @@ const comparePaths = function(path1, path2) {
path1 = path1.toLowerCase(); path1 = path1.toLowerCase();
path2 = path2.toLowerCase(); path2 = path2.toLowerCase();
} }
return assert.equal(path1, path2); assert.equal(path1, path2);
}; };
describe('ipc module', function() { describe('ipc module', function() {
@ -23,27 +23,26 @@ describe('ipc module', function() {
var dialog1, dialog2; var dialog1, dialog2;
dialog1 = remote.require('electron'); dialog1 = remote.require('electron');
dialog2 = remote.require('electron'); dialog2 = remote.require('electron');
return assert.equal(dialog1, dialog2); assert.equal(dialog1, dialog2);
}); });
it('should work when object contains id property', function() { it('should work when object contains id property', function() {
var a; var a = remote.require(path.join(fixtures, 'module', 'id.js'));
a = remote.require(path.join(fixtures, 'module', 'id.js')); assert.equal(a.id, 1127);
return assert.equal(a.id, 1127);
}); });
return it('should search module from the user app', function() { it('should search module from the user app', function() {
comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js')); comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'));
return comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules')); comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'));
}); });
}); });
describe('remote.createFunctionWithReturnValue', function() { describe('remote.createFunctionWithReturnValue', function() {
return it('should be called in browser synchronously', function() { it('should be called in browser synchronously', function() {
var buf = new Buffer('test'); var buf = new Buffer('test');
var call = remote.require(path.join(fixtures, 'module', 'call.js')); var call = remote.require(path.join(fixtures, 'module', 'call.js'));
var result = call.call(remote.createFunctionWithReturnValue(buf)); var result = call.call(remote.createFunctionWithReturnValue(buf));
return assert.equal(result.constructor.name, 'Buffer'); assert.equal(result.constructor.name, 'Buffer');
}); });
}); });
@ -55,14 +54,14 @@ describe('ipc module', function() {
assert.equal(property.property, 1007); assert.equal(property.property, 1007);
var property2 = remote.require(path.join(fixtures, 'module', 'property.js')); var property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property2.property, 1007); assert.equal(property2.property, 1007);
return property.property = 1127; property.property = 1127;
}); });
return it('can construct an object from its member', function() { it('can construct an object from its member', function() {
var call, obj; var call, obj;
call = remote.require(path.join(fixtures, 'module', 'call.js')); call = remote.require(path.join(fixtures, 'module', 'call.js'));
obj = new call.constructor; obj = new call.constructor;
return assert.equal(obj.test, 'test'); assert.equal(obj.test, 'test');
}); });
}); });
@ -72,48 +71,48 @@ describe('ipc module', function() {
it('keeps its constructor name for objects', function() { it('keeps its constructor name for objects', function() {
var buf = new Buffer('test'); var buf = new Buffer('test');
var print_name = remote.require(print); var print_name = remote.require(print);
return assert.equal(print_name.print(buf), 'Buffer'); assert.equal(print_name.print(buf), 'Buffer');
}); });
return it('supports instanceof Date', function() { it('supports instanceof Date', function() {
var now = new Date(); var now = new Date();
var print_name = remote.require(print); var print_name = remote.require(print);
assert.equal(print_name.print(now), 'Date'); assert.equal(print_name.print(now), 'Date');
return assert.deepEqual(print_name.echo(now), now); assert.deepEqual(print_name.echo(now), now);
}); });
}); });
describe('remote promise', function() { describe('remote promise', function() {
return it('can be used as promise in each side', function(done) { it('can be used as promise in each side', function(done) {
var promise = remote.require(path.join(fixtures, 'module', 'promise.js')); var promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
return promise.twicePromise(Promise.resolve(1234)).then(function(value) { promise.twicePromise(Promise.resolve(1234)).then(function(value) {
assert.equal(value, 2468); assert.equal(value, 2468);
return done(); done();
}); });
}); });
}); });
describe('ipc.sender.send', function() { describe('ipc.sender.send', function() {
return it('should work when sending an object containing id property', function(done) { it('should work when sending an object containing id property', function(done) {
var obj = { var obj = {
id: 1, id: 1,
name: 'ly' name: 'ly'
}; };
ipcRenderer.once('message', function(event, message) { ipcRenderer.once('message', function(event, message) {
assert.deepEqual(message, obj); assert.deepEqual(message, obj);
return done(); done();
}); });
return ipcRenderer.send('message', obj); ipcRenderer.send('message', obj);
}); });
}); });
describe('ipc.sendSync', function() { describe('ipc.sendSync', function() {
it('can be replied by setting event.returnValue', function() { it('can be replied by setting event.returnValue', function() {
var msg = ipcRenderer.sendSync('echo', 'test'); var msg = ipcRenderer.sendSync('echo', 'test');
return assert.equal(msg, 'test'); assert.equal(msg, 'test');
}); });
return it('does not crash when reply is not sent and browser is destroyed', function(done) { it('does not crash when reply is not sent and browser is destroyed', function(done) {
this.timeout(10000); this.timeout(10000);
var w = new BrowserWindow({ var w = new BrowserWindow({
@ -122,20 +121,20 @@ describe('ipc module', function() {
ipcMain.once('send-sync-message', function(event) { ipcMain.once('send-sync-message', function(event) {
event.returnValue = null; event.returnValue = null;
w.destroy(); w.destroy();
return done(); done();
}); });
return w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html')); w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'));
}); });
}); });
return describe('remote listeners', function() { describe('remote listeners', function() {
var w = null; var w = null;
afterEach(function() { afterEach(function() {
return w.destroy(); w.destroy();
}); });
return it('can be added and removed correctly', function() { it('can be added and removed correctly', function() {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
@ -143,7 +142,7 @@ describe('ipc module', function() {
w.on('test', listener); w.on('test', listener);
assert.equal(w.listenerCount('test'), 1); assert.equal(w.listenerCount('test'), 1);
w.removeListener('test', listener); w.removeListener('test', listener);
return assert.equal(w.listenerCount('test'), 0); assert.equal(w.listenerCount('test'), 0);
}); });
}); });
}); });

View file

@ -15,12 +15,12 @@ describe('menu module', function() {
extra: 'field' extra: 'field'
} }
]); ]);
return assert.equal(menu.items[0].extra, 'field'); assert.equal(menu.items[0].extra, 'field');
}); });
it('does not modify the specified template', function() { it('does not modify the specified template', function() {
var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;"); var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
return assert.deepStrictEqual(template, [ assert.deepStrictEqual(template, [
{ {
label: 'text', label: 'text',
submenu: [ submenu: [
@ -32,7 +32,7 @@ describe('menu module', function() {
]); ]);
}); });
return describe('Menu.buildFromTemplate should reorder based on item position specifiers', function() { describe('Menu.buildFromTemplate should reorder based on item position specifiers', function() {
it('should position before existing item', function() { it('should position before existing item', function() {
var menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
@ -49,7 +49,7 @@ describe('menu module', function() {
]); ]);
assert.equal(menu.items[0].label, '1'); assert.equal(menu.items[0].label, '1');
assert.equal(menu.items[1].label, '2'); assert.equal(menu.items[1].label, '2');
return assert.equal(menu.items[2].label, '3'); assert.equal(menu.items[2].label, '3');
}); });
it('should position after existing item', function() { it('should position after existing item', function() {
@ -68,7 +68,7 @@ describe('menu module', function() {
]); ]);
assert.equal(menu.items[0].label, '1'); assert.equal(menu.items[0].label, '1');
assert.equal(menu.items[1].label, '2'); assert.equal(menu.items[1].label, '2');
return assert.equal(menu.items[2].label, '3'); assert.equal(menu.items[2].label, '3');
}); });
it('should position at endof existing separator groups', function() { it('should position at endof existing separator groups', function() {
@ -112,7 +112,7 @@ describe('menu module', function() {
assert.equal(menu.items[4].id, 'letters'); assert.equal(menu.items[4].id, 'letters');
assert.equal(menu.items[5].label, 'a'); assert.equal(menu.items[5].label, 'a');
assert.equal(menu.items[6].label, 'b'); assert.equal(menu.items[6].label, 'b');
return assert.equal(menu.items[7].label, 'c'); assert.equal(menu.items[7].label, 'c');
}); });
it('should create separator group if endof does not reference existing separator group', function() { it('should create separator group if endof does not reference existing separator group', function() {
@ -150,10 +150,10 @@ describe('menu module', function() {
assert.equal(menu.items[4].id, 'numbers'); assert.equal(menu.items[4].id, 'numbers');
assert.equal(menu.items[5].label, '1'); assert.equal(menu.items[5].label, '1');
assert.equal(menu.items[6].label, '2'); assert.equal(menu.items[6].label, '2');
return assert.equal(menu.items[7].label, '3'); assert.equal(menu.items[7].label, '3');
}); });
return it('should continue inserting items at next index when no specifier is present', function() { it('should continue inserting items at next index when no specifier is present', function() {
var menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
label: '4', label: '4',
@ -177,13 +177,13 @@ describe('menu module', function() {
assert.equal(menu.items[1].label, '2'); assert.equal(menu.items[1].label, '2');
assert.equal(menu.items[2].label, '3'); assert.equal(menu.items[2].label, '3');
assert.equal(menu.items[3].label, '4'); assert.equal(menu.items[3].label, '4');
return assert.equal(menu.items[4].label, '5'); assert.equal(menu.items[4].label, '5');
}); });
}); });
}); });
describe('Menu.insert', function() { describe('Menu.insert', function() {
return it('should store item in @items by its index', function() { it('should store item in @items by its index', function() {
var menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
label: '1' label: '1'
@ -200,27 +200,27 @@ describe('menu module', function() {
assert.equal(menu.items[0].label, '1'); assert.equal(menu.items[0].label, '1');
assert.equal(menu.items[1].label, 'inserted'); assert.equal(menu.items[1].label, 'inserted');
assert.equal(menu.items[2].label, '2'); assert.equal(menu.items[2].label, '2');
return assert.equal(menu.items[3].label, '3'); assert.equal(menu.items[3].label, '3');
}); });
}); });
describe('MenuItem.click', function() { describe('MenuItem.click', function() {
return it('should be called with the item object passed', function(done) { it('should be called with the item object passed', function(done) {
var menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
label: 'text', label: 'text',
click: function(item) { click: function(item) {
assert.equal(item.constructor.name, 'MenuItem'); assert.equal(item.constructor.name, 'MenuItem');
assert.equal(item.label, 'text'); assert.equal(item.label, 'text');
return done(); done();
} }
} }
]); ]);
return menu.delegate.executeCommand(menu.items[0].commandId); menu.delegate.executeCommand(menu.items[0].commandId);
}); });
}); });
return describe('MenuItem with checked property', function() { describe('MenuItem with checked property', function() {
it('clicking an checkbox item should flip the checked property', function() { it('clicking an checkbox item should flip the checked property', function() {
var menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
@ -230,7 +230,7 @@ describe('menu module', function() {
]); ]);
assert.equal(menu.items[0].checked, false); assert.equal(menu.items[0].checked, false);
menu.delegate.executeCommand(menu.items[0].commandId); menu.delegate.executeCommand(menu.items[0].commandId);
return assert.equal(menu.items[0].checked, true); assert.equal(menu.items[0].checked, true);
}); });
it('clicking an radio item should always make checked property true', function() { it('clicking an radio item should always make checked property true', function() {
@ -243,7 +243,7 @@ describe('menu module', function() {
menu.delegate.executeCommand(menu.items[0].commandId); menu.delegate.executeCommand(menu.items[0].commandId);
assert.equal(menu.items[0].checked, true); assert.equal(menu.items[0].checked, true);
menu.delegate.executeCommand(menu.items[0].commandId); menu.delegate.executeCommand(menu.items[0].commandId);
return assert.equal(menu.items[0].checked, true); assert.equal(menu.items[0].checked, true);
}); });
it('at least have one item checked in each group', function() { it('at least have one item checked in each group', function() {
@ -267,7 +267,7 @@ describe('menu module', function() {
menu = Menu.buildFromTemplate(template); menu = Menu.buildFromTemplate(template);
menu.delegate.menuWillShow(); menu.delegate.menuWillShow();
assert.equal(menu.items[0].checked, true); assert.equal(menu.items[0].checked, true);
return assert.equal(menu.items[12].checked, true); assert.equal(menu.items[12].checked, true);
}); });
it('should assign groupId automatically', function() { it('should assign groupId automatically', function() {
@ -293,14 +293,12 @@ describe('menu module', function() {
for (i = l = 0; l <= 10; i = ++l) { for (i = l = 0; l <= 10; i = ++l) {
assert.equal(menu.items[i].groupId, groupId); assert.equal(menu.items[i].groupId, groupId);
} }
results = [];
for (i = m = 12; m <= 20; i = ++m) { for (i = m = 12; m <= 20; i = ++m) {
results.push(assert.equal(menu.items[i].groupId, groupId + 1)); assert.equal(menu.items[i].groupId, groupId + 1);
} }
return results;
}); });
return it("setting 'checked' should flip other items' 'checked' property", function() { it("setting 'checked' should flip other items' 'checked' property", function() {
var i, j, k, l, m, menu, n, o, p, q, results, template; var i, j, k, l, m, menu, n, o, p, q, results, template;
template = []; template = [];
for (i = j = 0; j <= 10; i = ++j) { for (i = j = 0; j <= 10; i = ++j) {
@ -341,11 +339,9 @@ describe('menu module', function() {
assert.equal(menu.items[i].checked, false); assert.equal(menu.items[i].checked, false);
} }
assert.equal(menu.items[12].checked, true); assert.equal(menu.items[12].checked, true);
results = [];
for (i = q = 13; q <= 20; i = ++q) { for (i = q = 13; q <= 20; i = ++q) {
results.push(assert.equal(menu.items[i].checked, false)); assert.equal(menu.items[i].checked, false);
} }
return results;
}); });
}); });
}); });

View file

@ -14,24 +14,24 @@ describe('protocol module', function() {
}; };
afterEach(function(done) { afterEach(function(done) {
return protocol.unregisterProtocol(protocolName, function() { protocol.unregisterProtocol(protocolName, function() {
return protocol.uninterceptProtocol('http', function() { protocol.uninterceptProtocol('http', function() {
return done(); done();
}); });
}); });
}); });
describe('protocol.register(Any)Protocol', function() { describe('protocol.register(Any)Protocol', function() {
var emptyHandler = function(request, callback) { var emptyHandler = function(request, callback) {
return callback(); callback();
}; };
it('throws error when scheme is already registered', function(done) { it('throws error when scheme is already registered', function(done) {
return protocol.registerStringProtocol(protocolName, emptyHandler, function(error) { protocol.registerStringProtocol(protocolName, emptyHandler, function(error) {
assert.equal(error, null); assert.equal(error, null);
return protocol.registerBufferProtocol(protocolName, emptyHandler, function(error) { protocol.registerBufferProtocol(protocolName, emptyHandler, function(error) {
assert.notEqual(error, null); assert.notEqual(error, null);
return done(); done();
}); });
}); });
}); });
@ -40,34 +40,34 @@ describe('protocol module', function() {
var doubleHandler = function(request, callback) { var doubleHandler = function(request, callback) {
try { try {
callback(text); callback(text);
return callback(); callback();
} catch (error) { } catch (error) {
// Ignore error // Ignore error
} }
}; };
return protocol.registerStringProtocol(protocolName, doubleHandler, function(error) { protocol.registerStringProtocol(protocolName, doubleHandler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
it('sends error when callback is called with nothing', function(done) { it('sends error when callback is called with nothing', function(done) {
return protocol.registerBufferProtocol(protocolName, emptyHandler, function(error) { protocol.registerBufferProtocol(protocolName, emptyHandler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); return done('request succeeded but it should not');
@ -80,24 +80,24 @@ describe('protocol module', function() {
}); });
}); });
return it('does not crash when callback is called in next tick', function(done) { it('does not crash when callback is called in next tick', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return setImmediate(function() { setImmediate(function() {
return callback(text); callback(text);
}); });
}; };
return protocol.registerStringProtocol(protocolName, handler, function(error) { protocol.registerStringProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -105,10 +105,10 @@ describe('protocol module', function() {
}); });
describe('protocol.unregisterProtocol', function() { describe('protocol.unregisterProtocol', function() {
return it('returns error when scheme does not exist', function(done) { it('returns error when scheme does not exist', function(done) {
return protocol.unregisterProtocol('not-exist', function(error) { protocol.unregisterProtocol('not-exist', function(error) {
assert.notEqual(error, null); assert.notEqual(error, null);
return done(); done();
}); });
}); });
}); });
@ -116,9 +116,9 @@ describe('protocol module', function() {
describe('protocol.registerStringProtocol', function() { describe('protocol.registerStringProtocol', function() {
it('sends string as response', function(done) { it('sends string as response', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(text); callback(text);
}; };
return protocol.registerStringProtocol(protocolName, handler, function(error) { protocol.registerStringProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
@ -126,10 +126,10 @@ describe('protocol module', function() {
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -137,21 +137,21 @@ describe('protocol module', function() {
it('sets Access-Control-Allow-Origin', function(done) { it('sets Access-Control-Allow-Origin', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(text); callback(text);
}; };
return protocol.registerStringProtocol(protocolName, handler, function(error) { protocol.registerStringProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data, status, request) { success: function(data, status, request) {
assert.equal(data, text); assert.equal(data, text);
assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*'); assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*');
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -159,44 +159,44 @@ describe('protocol module', function() {
it('sends object as response', function(done) { it('sends object as response', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback({ callback({
data: text, data: text,
mimeType: 'text/html' mimeType: 'text/html'
}); });
}; };
return protocol.registerStringProtocol(protocolName, handler, function(error) { protocol.registerStringProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
return it('fails when sending object other than string', function(done) { it('fails when sending object other than string', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(new Date); callback(new Date);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
@ -208,20 +208,20 @@ describe('protocol module', function() {
it('sends Buffer as response', function(done) { it('sends Buffer as response', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(buffer); callback(buffer);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -229,22 +229,22 @@ describe('protocol module', function() {
it('sets Access-Control-Allow-Origin', function(done) { it('sets Access-Control-Allow-Origin', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(buffer); callback(buffer);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data, status, request) { success: function(data, status, request) {
assert.equal(data, text); assert.equal(data, text);
assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*'); assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*');
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -252,44 +252,44 @@ describe('protocol module', function() {
it('sends object as response', function(done) { it('sends object as response', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback({ callback({
data: buffer, data: buffer,
mimeType: 'text/html' mimeType: 'text/html'
}); });
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
return it('fails when sending string', function(done) { it('fails when sending string', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(text); callback(text);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
@ -304,9 +304,9 @@ describe('protocol module', function() {
it('sends file path as response', function(done) { it('sends file path as response', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(filePath); callback(filePath);
}; };
return protocol.registerFileProtocol(protocolName, handler, function(error) { protocol.registerFileProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
@ -327,42 +327,41 @@ describe('protocol module', function() {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(filePath); return callback(filePath);
}; };
return protocol.registerFileProtocol(protocolName, handler, function(error) { protocol.registerFileProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data, status, request) { success: function(data, status, request) {
assert.equal(data, String(fileContent)); assert.equal(data, String(fileContent));
assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*'); assert.equal(request.getResponseHeader('Access-Control-Allow-Origin'), '*');
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
it('sends object as response', function(done) { it('sends object as response', function(done) {
var handler; var handler = function(request, callback) {
handler = function(request, callback) {
return callback({ return callback({
path: filePath path: filePath
}); });
}; };
return protocol.registerFileProtocol(protocolName, handler, function(error) { protocol.registerFileProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, String(fileContent)); assert.equal(data, String(fileContent));
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -370,21 +369,21 @@ describe('protocol module', function() {
it('can send normal file', function(done) { it('can send normal file', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(normalPath); callback(normalPath);
}; };
return protocol.registerFileProtocol(protocolName, handler, function(error) { protocol.registerFileProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, String(normalContent)); assert.equal(data, String(normalContent));
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -393,41 +392,41 @@ describe('protocol module', function() {
it('fails when sending unexist-file', function(done) { it('fails when sending unexist-file', function(done) {
var fakeFilePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'not-exist'); var fakeFilePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'not-exist');
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(fakeFilePath); callback(fakeFilePath);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
}); });
return it('fails when sending unsupported content', function(done) { it('fails when sending unsupported content', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(new Date); callback(new Date);
}; };
return protocol.registerBufferProtocol(protocolName, handler, function(error) { protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
@ -439,29 +438,28 @@ describe('protocol module', function() {
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
assert.notEqual(req.headers.accept, ''); assert.notEqual(req.headers.accept, '');
res.end(text); res.end(text);
return server.close(); server.close();
}); });
return server.listen(0, '127.0.0.1', function() { return server.listen(0, '127.0.0.1', function() {
var handler, port, url; var port = server.address().port;
port = server.address().port; var url = "http://127.0.0.1:" + port;
url = "http://127.0.0.1:" + port; var handler = function(request, callback) {
handler = function(request, callback) { callback({
return callback({
url: url url: url
}); });
}; };
return protocol.registerHttpProtocol(protocolName, handler, function(error) { protocol.registerHttpProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -470,43 +468,43 @@ describe('protocol module', function() {
it('fails when sending invalid url', function(done) { it('fails when sending invalid url', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback({ callback({
url: 'url' url: 'url'
}); });
}; };
return protocol.registerHttpProtocol(protocolName, handler, function(error) { protocol.registerHttpProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
}); });
return it('fails when sending unsupported content', function(done) { it('fails when sending unsupported content', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(new Date); callback(new Date);
}; };
return protocol.registerHttpProtocol(protocolName, handler, function(error) { protocol.registerHttpProtocol(protocolName, handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: protocolName + "://fake-host", url: protocolName + "://fake-host",
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
@ -515,55 +513,55 @@ describe('protocol module', function() {
describe('protocol.isProtocolHandled', function() { describe('protocol.isProtocolHandled', function() {
it('returns true for file:', function(done) { it('returns true for file:', function(done) {
return protocol.isProtocolHandled('file', function(result) { protocol.isProtocolHandled('file', function(result) {
assert.equal(result, true); assert.equal(result, true);
return done(); done();
}); });
}); });
it('returns true for http:', function(done) { it('returns true for http:', function(done) {
return protocol.isProtocolHandled('http', function(result) { protocol.isProtocolHandled('http', function(result) {
assert.equal(result, true); assert.equal(result, true);
return done(); done();
}); });
}); });
it('returns true for https:', function(done) { it('returns true for https:', function(done) {
return protocol.isProtocolHandled('https', function(result) { protocol.isProtocolHandled('https', function(result) {
assert.equal(result, true); assert.equal(result, true);
return done(); done();
}); });
}); });
it('returns false when scheme is not registred', function(done) { it('returns false when scheme is not registred', function(done) {
return protocol.isProtocolHandled('no-exist', function(result) { protocol.isProtocolHandled('no-exist', function(result) {
assert.equal(result, false); assert.equal(result, false);
return done(); done();
}); });
}); });
it('returns true for custom protocol', function(done) { it('returns true for custom protocol', function(done) {
var emptyHandler = function(request, callback) { var emptyHandler = function(request, callback) {
return callback(); callback();
}; };
return protocol.registerStringProtocol(protocolName, emptyHandler, function(error) { protocol.registerStringProtocol(protocolName, emptyHandler, function(error) {
assert.equal(error, null); assert.equal(error, null);
return protocol.isProtocolHandled(protocolName, function(result) { protocol.isProtocolHandled(protocolName, function(result) {
assert.equal(result, true); assert.equal(result, true);
return done(); done();
}); });
}); });
}); });
return it('returns true for intercepted protocol', function(done) { it('returns true for intercepted protocol', function(done) {
var emptyHandler = function(request, callback) { var emptyHandler = function(request, callback) {
return callback(); callback();
}; };
return protocol.interceptStringProtocol('http', emptyHandler, function(error) { protocol.interceptStringProtocol('http', emptyHandler, function(error) {
assert.equal(error, null); assert.equal(error, null);
return protocol.isProtocolHandled('http', function(result) { protocol.isProtocolHandled('http', function(result) {
assert.equal(result, true); assert.equal(result, true);
return done(); done();
}); });
}); });
}); });
@ -571,15 +569,15 @@ describe('protocol module', function() {
describe('protocol.intercept(Any)Protocol', function() { describe('protocol.intercept(Any)Protocol', function() {
var emptyHandler = function(request, callback) { var emptyHandler = function(request, callback) {
return callback(); callback();
}; };
it('throws error when scheme is already intercepted', function(done) { it('throws error when scheme is already intercepted', function(done) {
return protocol.interceptStringProtocol('http', emptyHandler, function(error) { protocol.interceptStringProtocol('http', emptyHandler, function(error) {
assert.equal(error, null); assert.equal(error, null);
return protocol.interceptBufferProtocol('http', emptyHandler, function(error) { protocol.interceptBufferProtocol('http', emptyHandler, function(error) {
assert.notEqual(error, null); assert.notEqual(error, null);
return done(); done();
}); });
}); });
}); });
@ -593,39 +591,39 @@ describe('protocol module', function() {
// Ignore error // Ignore error
} }
}; };
return protocol.interceptStringProtocol('http', doubleHandler, function(error) { protocol.interceptStringProtocol('http', doubleHandler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: 'http://fake-host', url: 'http://fake-host',
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
return it('sends error when callback is called with nothing', function(done) { it('sends error when callback is called with nothing', function(done) {
if (process.env.TRAVIS === 'true') { if (process.env.TRAVIS === 'true') {
return done(); return done();
} }
return protocol.interceptBufferProtocol('http', emptyHandler, function(error) { protocol.interceptBufferProtocol('http', emptyHandler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: 'http://fake-host', url: 'http://fake-host',
success: function() { success: function() {
return done('request succeeded but it should not'); done('request succeeded but it should not');
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
assert.equal(errorType, 'error'); assert.equal(errorType, 'error');
return done(); done();
} }
}); });
}); });
@ -635,20 +633,20 @@ describe('protocol module', function() {
describe('protocol.interceptStringProtocol', function() { describe('protocol.interceptStringProtocol', function() {
it('can intercept http protocol', function(done) { it('can intercept http protocol', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(text); callback(text);
}; };
return protocol.interceptStringProtocol('http', handler, function(error) { protocol.interceptStringProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: 'http://fake-host', url: 'http://fake-host',
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -656,51 +654,50 @@ describe('protocol module', function() {
it('can set content-type', function(done) { it('can set content-type', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback({ callback({
mimeType: 'application/json', mimeType: 'application/json',
data: '{"value": 1}' data: '{"value": 1}'
}); });
}; };
return protocol.interceptStringProtocol('http', handler, function(error) { protocol.interceptStringProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: 'http://fake-host', url: 'http://fake-host',
success: function(data) { success: function(data) {
assert.equal(typeof data, 'object'); assert.equal(typeof data, 'object');
assert.equal(data.value, 1); assert.equal(data.value, 1);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
return it('can receive post data', function(done) { it('can receive post data', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
var uploadData; var uploadData = request.uploadData[0].bytes.toString();
uploadData = request.uploadData[0].bytes.toString(); callback({
return callback({
data: uploadData data: uploadData
}); });
}; };
return protocol.interceptStringProtocol('http', handler, function(error) { protocol.interceptStringProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: "http://fake-host", url: "http://fake-host",
type: "POST", type: "POST",
data: postData, data: postData,
success: function(data) { success: function(data) {
assert.deepEqual(qs.parse(data), postData); assert.deepEqual(qs.parse(data), postData);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -710,45 +707,44 @@ describe('protocol module', function() {
describe('protocol.interceptBufferProtocol', function() { describe('protocol.interceptBufferProtocol', function() {
it('can intercept http protocol', function(done) { it('can intercept http protocol', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
return callback(new Buffer(text)); callback(new Buffer(text));
}; };
return protocol.interceptBufferProtocol('http', handler, function(error) { protocol.interceptBufferProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: 'http://fake-host', url: 'http://fake-host',
success: function(data) { success: function(data) {
assert.equal(data, text); assert.equal(data, text);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
}); });
return it('can receive post data', function(done) { it('can receive post data', function(done) {
var handler = function(request, callback) { var handler = function(request, callback) {
var uploadData; var uploadData = request.uploadData[0].bytes;
uploadData = request.uploadData[0].bytes; callback(uploadData);
return callback(uploadData);
}; };
return protocol.interceptBufferProtocol('http', handler, function(error) { protocol.interceptBufferProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: "http://fake-host", url: "http://fake-host",
type: "POST", type: "POST",
data: postData, data: postData,
success: function(data) { success: function(data) {
assert.equal(data, $.param(postData)); assert.equal(data, $.param(postData));
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -756,24 +752,22 @@ describe('protocol module', function() {
}); });
describe('protocol.interceptHttpProtocol', function() { describe('protocol.interceptHttpProtocol', function() {
return it('can send POST request', function(done) { it('can send POST request', function(done) {
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
var body; var body = '';
body = '';
req.on('data', function(chunk) { req.on('data', function(chunk) {
return body += chunk; body += chunk;
}); });
req.on('end', function() { req.on('end', function() {
return res.end(body); res.end(body);
}); });
return server.close(); server.close();
}); });
return server.listen(0, '127.0.0.1', function() { server.listen(0, '127.0.0.1', function() {
var port = server.address().port; var port = server.address().port;
var url = "http://127.0.0.1:" + port; var url = "http://127.0.0.1:" + port;
var handler = function(request, callback) { var handler = function(request, callback) {
var data; var data = {
data = {
url: url, url: url,
method: 'POST', method: 'POST',
uploadData: { uploadData: {
@ -782,22 +776,22 @@ describe('protocol module', function() {
}, },
session: null session: null
}; };
return callback(data); callback(data);
}; };
return protocol.interceptHttpProtocol('http', handler, function(error) { protocol.interceptHttpProtocol('http', handler, function(error) {
if (error) { if (error) {
return done(error); return done(error);
} }
return $.ajax({ $.ajax({
url: "http://fake-host", url: "http://fake-host",
type: "POST", type: "POST",
data: postData, data: postData,
success: function(data) { success: function(data) {
assert.deepEqual(qs.parse(data), postData); assert.deepEqual(qs.parse(data), postData);
return done(); done();
}, },
error: function(xhr, errorType, error) { error: function(xhr, errorType, error) {
return done(error); done(error);
} }
}); });
}); });
@ -805,18 +799,18 @@ describe('protocol module', function() {
}); });
}); });
return describe('protocol.uninterceptProtocol', function() { describe('protocol.uninterceptProtocol', function() {
it('returns error when scheme does not exist', function(done) { it('returns error when scheme does not exist', function(done) {
return protocol.uninterceptProtocol('not-exist', function(error) { protocol.uninterceptProtocol('not-exist', function(error) {
assert.notEqual(error, null); assert.notEqual(error, null);
return done(); done();
}); });
}); });
return it('returns error when scheme is not intercepted', function(done) { it('returns error when scheme is not intercepted', function(done) {
return protocol.uninterceptProtocol('http', function(error) { protocol.uninterceptProtocol('http', function(error) {
assert.notEqual(error, null); assert.notEqual(error, null);
return done(); done();
}); });
}); });
}); });

View file

@ -3,19 +3,19 @@ const screen = require('electron').screen;
describe('screen module', function() { describe('screen module', function() {
describe('screen.getCursorScreenPoint()', function() { describe('screen.getCursorScreenPoint()', function() {
return it('returns a point object', function() { it('returns a point object', function() {
var point = screen.getCursorScreenPoint(); var point = screen.getCursorScreenPoint();
assert.equal(typeof point.x, 'number'); assert.equal(typeof point.x, 'number');
return assert.equal(typeof point.y, 'number'); assert.equal(typeof point.y, 'number');
}); });
}); });
return describe('screen.getPrimaryDisplay()', function() { describe('screen.getPrimaryDisplay()', function() {
return it('returns a display object', function() { it('returns a display object', function() {
var display = screen.getPrimaryDisplay(); var display = screen.getPrimaryDisplay();
assert.equal(typeof display.scaleFactor, 'number'); assert.equal(typeof display.scaleFactor, 'number');
assert(display.size.width > 0); assert(display.size.width > 0);
return assert(display.size.height > 0); assert(display.size.height > 0);
}); });
}); });
}); });

View file

@ -18,7 +18,7 @@ describe('session module', function() {
var url = "http://127.0.0.1"; var url = "http://127.0.0.1";
beforeEach(function() { beforeEach(function() {
return w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
width: 400, width: 400,
height: 400 height: 400
@ -26,7 +26,7 @@ describe('session module', function() {
}); });
afterEach(function() { afterEach(function() {
return w.destroy(); w.destroy();
}); });
describe('session.cookies', function() { describe('session.cookies', function() {
@ -35,14 +35,14 @@ describe('session module', function() {
server = http.createServer(function(req, res) { server = http.createServer(function(req, res) {
res.setHeader('Set-Cookie', ['0=0']); res.setHeader('Set-Cookie', ['0=0']);
res.end('finished'); res.end('finished');
return server.close(); server.close();
}); });
return server.listen(0, '127.0.0.1', function() { server.listen(0, '127.0.0.1', function() {
var port; var port;
port = server.address().port; port = server.address().port;
w.loadURL(url + ":" + port); w.loadURL(url + ":" + port);
return w.webContents.on('did-finish-load', function() { w.webContents.on('did-finish-load', function() {
return w.webContents.session.cookies.get({ w.webContents.session.cookies.get({
url: url url: url
}, function(error, list) { }, function(error, list) {
var cookie, i, len; var cookie, i, len;
@ -59,14 +59,14 @@ describe('session module', function() {
} }
} }
} }
return done('Can not find cookie'); done('Can not find cookie');
}); });
}); });
}); });
}); });
it('should over-write the existent cookie', function(done) { it('should over-write the existent cookie', function(done) {
return session.defaultSession.cookies.set({ session.defaultSession.cookies.set({
url: url, url: url,
name: '1', name: '1',
value: '1' value: '1'
@ -74,7 +74,7 @@ describe('session module', function() {
if (error) { if (error) {
return done(error); return done(error);
} }
return session.defaultSession.cookies.get({ session.defaultSession.cookies.get({
url: url url: url
}, function(error, list) { }, function(error, list) {
var cookie, i, len; var cookie, i, len;
@ -91,13 +91,13 @@ describe('session module', function() {
} }
} }
} }
return done('Can not find cookie'); done('Can not find cookie');
}); });
}); });
}); });
it('should remove cookies', function(done) { it('should remove cookies', function(done) {
return session.defaultSession.cookies.set({ session.defaultSession.cookies.set({
url: url, url: url,
name: '2', name: '2',
value: '2' value: '2'
@ -105,8 +105,8 @@ describe('session module', function() {
if (error) { if (error) {
return done(error); return done(error);
} }
return session.defaultSession.cookies.remove(url, '2', function() { session.defaultSession.cookies.remove(url, '2', function() {
return session.defaultSession.cookies.get({ session.defaultSession.cookies.get({
url: url url: url
}, function(error, list) { }, function(error, list) {
var cookie, i, len; var cookie, i, len;
@ -119,7 +119,7 @@ describe('session module', function() {
return done('Cookie not deleted'); return done('Cookie not deleted');
} }
} }
return done(); done();
}); });
}); });
}); });
@ -128,22 +128,22 @@ describe('session module', function() {
describe('session.clearStorageData(options)', function() { describe('session.clearStorageData(options)', function() {
fixtures = path.resolve(__dirname, 'fixtures'); fixtures = path.resolve(__dirname, 'fixtures');
return it('clears localstorage data', function(done) { it('clears localstorage data', function(done) {
ipcMain.on('count', function(event, count) { ipcMain.on('count', function(event, count) {
ipcMain.removeAllListeners('count'); ipcMain.removeAllListeners('count');
assert(!count); assert(!count);
return done(); done();
}); });
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html')); w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'));
return w.webContents.on('did-finish-load', function() { w.webContents.on('did-finish-load', function() {
var options; var options;
options = { options = {
origin: "file://", origin: "file://",
storages: ['localstorage'], storages: ['localstorage'],
quotas: ['persistent'] quotas: ['persistent']
}; };
return w.webContents.session.clearStorageData(options, function() { w.webContents.session.clearStorageData(options, function() {
return w.webContents.send('getcount'); w.webContents.send('getcount');
}); });
}); });
}); });
@ -161,7 +161,7 @@ describe('session module', function() {
}); });
afterEach(function() { afterEach(function() {
return w.destroy(); w.destroy();
}); });
it('can cancel default download behavior', function(done) { it('can cancel default download behavior', function(done) {
@ -193,21 +193,20 @@ describe('session module', function() {
}); });
}); });
return describe('DownloadItem', function() { describe('DownloadItem', function() {
var assertDownload, contentDisposition, downloadFilePath, downloadServer, mockPDF; var mockPDF = new Buffer(1024 * 1024 * 5);
mockPDF = new Buffer(1024 * 1024 * 5); var contentDisposition = 'inline; filename="mock.pdf"';
contentDisposition = 'inline; filename="mock.pdf"'; var downloadFilePath = path.join(fixtures, 'mock.pdf');
downloadFilePath = path.join(fixtures, 'mock.pdf'); var downloadServer = http.createServer(function(req, res) {
downloadServer = http.createServer(function(req, res) {
res.writeHead(200, { res.writeHead(200, {
'Content-Length': mockPDF.length, 'Content-Length': mockPDF.length,
'Content-Type': 'application/pdf', 'Content-Type': 'application/pdf',
'Content-Disposition': contentDisposition 'Content-Disposition': contentDisposition
}); });
res.end(mockPDF); res.end(mockPDF);
return downloadServer.close(); downloadServer.close();
}); });
assertDownload = function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) { var assertDownload = function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) {
assert.equal(state, 'completed'); assert.equal(state, 'completed');
assert.equal(filename, 'mock.pdf'); assert.equal(filename, 'mock.pdf');
assert.equal(url, "http://127.0.0.1:" + port + "/"); assert.equal(url, "http://127.0.0.1:" + port + "/");
@ -216,55 +215,52 @@ describe('session module', function() {
assert.equal(totalBytes, mockPDF.length); assert.equal(totalBytes, mockPDF.length);
assert.equal(disposition, contentDisposition); assert.equal(disposition, contentDisposition);
assert(fs.existsSync(downloadFilePath)); assert(fs.existsSync(downloadFilePath));
return fs.unlinkSync(downloadFilePath); fs.unlinkSync(downloadFilePath);
}; };
it('can download using BrowserWindow.loadURL', function(done) { it('can download using BrowserWindow.loadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() { downloadServer.listen(0, '127.0.0.1', function() {
var port; var port = downloadServer.address().port;
port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', false, false); ipcRenderer.sendSync('set-download-option', false, false);
w.loadURL(url + ":" + port); w.loadURL(url + ":" + port);
return ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port); assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port);
return done(); done();
}); });
}); });
}); });
it('can download using WebView.downloadURL', function(done) { it('can download using WebView.downloadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() { downloadServer.listen(0, '127.0.0.1', function() {
var port, webview; var port = downloadServer.address().port;
port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', false, false); ipcRenderer.sendSync('set-download-option', false, false);
webview = new WebView; var webview = new WebView;
webview.src = "file://" + fixtures + "/api/blank.html"; webview.src = "file://" + fixtures + "/api/blank.html";
webview.addEventListener('did-finish-load', function() { webview.addEventListener('did-finish-load', function() {
return webview.downloadURL(url + ":" + port + "/"); webview.downloadURL(url + ":" + port + "/");
}); });
ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port); assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port);
document.body.removeChild(webview); document.body.removeChild(webview);
return done(); done();
}); });
return document.body.appendChild(webview); document.body.appendChild(webview);
}); });
}); });
it('can cancel download', function(done) { it('can cancel download', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() { downloadServer.listen(0, '127.0.0.1', function() {
var port; var port = downloadServer.address().port;
port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', true, false); ipcRenderer.sendSync('set-download-option', true, false);
w.loadURL(url + ":" + port + "/"); w.loadURL(url + ":" + port + "/");
return ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
assert.equal(state, 'cancelled'); assert.equal(state, 'cancelled');
assert.equal(filename, 'mock.pdf'); assert.equal(filename, 'mock.pdf');
assert.equal(mimeType, 'application/pdf'); assert.equal(mimeType, 'application/pdf');
assert.equal(receivedBytes, 0); assert.equal(receivedBytes, 0);
assert.equal(totalBytes, mockPDF.length); assert.equal(totalBytes, mockPDF.length);
assert.equal(disposition, contentDisposition); assert.equal(disposition, contentDisposition);
return done(); done();
}); });
}); });
}); });

View file

@ -4,15 +4,15 @@ const webFrame = require('electron').webFrame;
describe('webFrame module', function() { describe('webFrame module', function() {
var fixtures = path.resolve(__dirname, 'fixtures'); var fixtures = path.resolve(__dirname, 'fixtures');
return describe('webFrame.registerURLSchemeAsPrivileged', function() { describe('webFrame.registerURLSchemeAsPrivileged', function() {
return it('supports fetch api', function(done) { it('supports fetch api', function(done) {
webFrame.registerURLSchemeAsPrivileged('file'); webFrame.registerURLSchemeAsPrivileged('file');
var url = "file://" + fixtures + "/assets/logo.png"; var url = "file://" + fixtures + "/assets/logo.png";
return fetch(url).then(function(response) { fetch(url).then(function(response) {
assert(response.ok); assert(response.ok);
return done(); done();
})["catch"](function(err) { }).catch(function(err) {
return done('unexpected error : ' + err); done('unexpected error : ' + err);
}); });
}); });
}); });

View file

@ -13,41 +13,41 @@ describe('webRequest module', function() {
if (req.headers.accept === '*/*;test/header') { if (req.headers.accept === '*/*;test/header') {
content += 'header/received'; content += 'header/received';
} }
return res.end(content); res.end(content);
}); });
var defaultURL = null; var defaultURL = null;
before(function(done) { before(function(done) {
return server.listen(0, '127.0.0.1', function() { server.listen(0, '127.0.0.1', function() {
var port; var port;
port = server.address().port; port = server.address().port;
defaultURL = "http://127.0.0.1:" + port + "/"; defaultURL = "http://127.0.0.1:" + port + "/";
return done(); done();
}); });
}); });
after(function() { after(function() {
return server.close(); server.close();
}); });
describe('webRequest.onBeforeRequest', function() { describe('webRequest.onBeforeRequest', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onBeforeRequest(null); ses.webRequest.onBeforeRequest(null);
}); });
it('can cancel the request', function(done) { it('can cancel the request', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
return callback({ callback({
cancel: true cancel: true
}); });
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function() { success: function() {
return done('unexpected success'); done('unexpected success');
}, },
error: function() { error: function() {
return done(); done();
} }
}); });
}); });
@ -57,26 +57,26 @@ describe('webRequest module', function() {
urls: [defaultURL + "filter/*"] urls: [defaultURL + "filter/*"]
}; };
ses.webRequest.onBeforeRequest(filter, function(details, callback) { ses.webRequest.onBeforeRequest(filter, function(details, callback) {
return callback({ callback({
cancel: true cancel: true
}); });
}); });
return $.ajax({ $.ajax({
url: defaultURL + "nofilter/test", url: defaultURL + "nofilter/test",
success: function(data) { success: function(data) {
assert.equal(data, '/nofilter/test'); assert.equal(data, '/nofilter/test');
return $.ajax({ $.ajax({
url: defaultURL + "filter/test", url: defaultURL + "filter/test",
success: function() { success: function() {
return done('unexpected success'); done('unexpected success');
}, },
error: function() { error: function() {
return done(); done();
} }
}); });
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -89,16 +89,16 @@ describe('webRequest module', function() {
assert.equal(details.method, 'GET'); assert.equal(details.method, 'GET');
assert.equal(details.resourceType, 'xhr'); assert.equal(details.resourceType, 'xhr');
assert(!details.uploadData); assert(!details.uploadData);
return callback({}); callback({});
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -115,11 +115,11 @@ describe('webRequest module', function() {
assert.equal(details.uploadData.length, 1); assert.equal(details.uploadData.length, 1);
data = qs.parse(details.uploadData[0].bytes.toString()); data = qs.parse(details.uploadData[0].bytes.toString());
assert.deepEqual(data, postData); assert.deepEqual(data, postData);
return callback({ callback({
cancel: true cancel: true
}); });
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
type: 'POST', type: 'POST',
data: postData, data: postData,
@ -131,24 +131,24 @@ describe('webRequest module', function() {
}); });
}); });
return it('can redirect the request', function(done) { it('can redirect the request', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
if (details.url === defaultURL) { if (details.url === defaultURL) {
return callback({ callback({
redirectURL: defaultURL + "redirect" redirectURL: defaultURL + "redirect"
}); });
} else { } else {
return callback({}); callback({});
} }
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/redirect'); assert.equal(data, '/redirect');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -156,22 +156,22 @@ describe('webRequest module', function() {
describe('webRequest.onBeforeSendHeaders', function() { describe('webRequest.onBeforeSendHeaders', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onBeforeSendHeaders(null); ses.webRequest.onBeforeSendHeaders(null);
}); });
it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) { ses.webRequest.onBeforeSendHeaders(function(details, callback) {
assert.equal(typeof details.requestHeaders, 'object'); assert.equal(typeof details.requestHeaders, 'object');
return callback({}); callback({});
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -181,40 +181,39 @@ describe('webRequest module', function() {
var requestHeaders; var requestHeaders;
requestHeaders = details.requestHeaders; requestHeaders = details.requestHeaders;
requestHeaders.Accept = '*/*;test/header'; requestHeaders.Accept = '*/*;test/header';
return callback({ callback({
requestHeaders: requestHeaders requestHeaders: requestHeaders
}); });
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/header/received'); assert.equal(data, '/header/received');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
return it('resets the whole headers', function(done) { it('resets the whole headers', function(done) {
var requestHeaders; var requestHeaders = {
requestHeaders = {
Test: 'header' Test: 'header'
}; };
ses.webRequest.onBeforeSendHeaders(function(details, callback) { ses.webRequest.onBeforeSendHeaders(function(details, callback) {
return callback({ callback({
requestHeaders: requestHeaders requestHeaders: requestHeaders
}); });
}); });
ses.webRequest.onSendHeaders(function(details) { ses.webRequest.onSendHeaders(function(details) {
assert.deepEqual(details.requestHeaders, requestHeaders); assert.deepEqual(details.requestHeaders, requestHeaders);
return done(); done();
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -222,21 +221,21 @@ describe('webRequest module', function() {
describe('webRequest.onSendHeaders', function() { describe('webRequest.onSendHeaders', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onSendHeaders(null); ses.webRequest.onSendHeaders(null);
}); });
return it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onSendHeaders(function(details) { ses.webRequest.onSendHeaders(function(details) {
return assert.equal(typeof details.requestHeaders, 'object'); assert.equal(typeof details.requestHeaders, 'object');
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -244,7 +243,7 @@ describe('webRequest module', function() {
describe('webRequest.onHeadersReceived', function() { describe('webRequest.onHeadersReceived', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onHeadersReceived(null); ses.webRequest.onHeadersReceived(null);
}); });
it('receives details object', function(done) { it('receives details object', function(done) {
@ -252,55 +251,54 @@ describe('webRequest module', function() {
assert.equal(details.statusLine, 'HTTP/1.1 200 OK'); assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
assert.equal(details.statusCode, 200); assert.equal(details.statusCode, 200);
assert.equal(details.responseHeaders['Custom'], 'Header'); assert.equal(details.responseHeaders['Custom'], 'Header');
return callback({}); callback({});
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
it('can change the response header', function(done) { it('can change the response header', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) { ses.webRequest.onHeadersReceived(function(details, callback) {
var responseHeaders; var responseHeaders = details.responseHeaders;
responseHeaders = details.responseHeaders;
responseHeaders['Custom'] = ['Changed']; responseHeaders['Custom'] = ['Changed'];
return callback({ callback({
responseHeaders: responseHeaders responseHeaders: responseHeaders
}); });
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data, status, xhr) { success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Changed'); assert.equal(xhr.getResponseHeader('Custom'), 'Changed');
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
return it('does not change header by default', function(done) { it('does not change header by default', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) { ses.webRequest.onHeadersReceived(function(details, callback) {
return callback({}); callback({});
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data, status, xhr) { success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Header'); assert.equal(xhr.getResponseHeader('Custom'), 'Header');
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -308,25 +306,25 @@ describe('webRequest module', function() {
describe('webRequest.onResponseStarted', function() { describe('webRequest.onResponseStarted', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onResponseStarted(null); ses.webRequest.onResponseStarted(null);
}); });
return it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onResponseStarted(function(details) { ses.webRequest.onResponseStarted(function(details) {
assert.equal(typeof details.fromCache, 'boolean'); assert.equal(typeof details.fromCache, 'boolean');
assert.equal(details.statusLine, 'HTTP/1.1 200 OK'); assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
assert.equal(details.statusCode, 200); assert.equal(details.statusCode, 200);
return assert.equal(details.responseHeaders['Custom'], 'Header'); assert.equal(details.responseHeaders['Custom'], 'Header');
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data, status, xhr) { success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Header'); assert.equal(xhr.getResponseHeader('Custom'), 'Header');
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -335,35 +333,34 @@ describe('webRequest module', function() {
describe('webRequest.onBeforeRedirect', function() { describe('webRequest.onBeforeRedirect', function() {
afterEach(function() { afterEach(function() {
ses.webRequest.onBeforeRedirect(null); ses.webRequest.onBeforeRedirect(null);
return ses.webRequest.onBeforeRequest(null); ses.webRequest.onBeforeRequest(null);
}); });
return it('receives details object', function(done) { it('receives details object', function(done) {
var redirectURL; var redirectURL = defaultURL + "redirect";
redirectURL = defaultURL + "redirect";
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
if (details.url === defaultURL) { if (details.url === defaultURL) {
return callback({ callback({
redirectURL: redirectURL redirectURL: redirectURL
}); });
} else { } else {
return callback({}); callback({});
} }
}); });
ses.webRequest.onBeforeRedirect(function(details) { ses.webRequest.onBeforeRedirect(function(details) {
assert.equal(typeof details.fromCache, 'boolean'); assert.equal(typeof details.fromCache, 'boolean');
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect'); assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect');
assert.equal(details.statusCode, 307); assert.equal(details.statusCode, 307);
return assert.equal(details.redirectURL, redirectURL); assert.equal(details.redirectURL, redirectURL);
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/redirect'); assert.equal(data, '/redirect');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
@ -371,48 +368,48 @@ describe('webRequest module', function() {
describe('webRequest.onCompleted', function() { describe('webRequest.onCompleted', function() {
afterEach(function() { afterEach(function() {
return ses.webRequest.onCompleted(null); ses.webRequest.onCompleted(null);
}); });
return it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onCompleted(function(details) { ses.webRequest.onCompleted(function(details) {
assert.equal(typeof details.fromCache, 'boolean'); assert.equal(typeof details.fromCache, 'boolean');
assert.equal(details.statusLine, 'HTTP/1.1 200 OK'); assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
return assert.equal(details.statusCode, 200); assert.equal(details.statusCode, 200);
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function(data) { success: function(data) {
assert.equal(data, '/'); assert.equal(data, '/');
return done(); done();
}, },
error: function(xhr, errorType) { error: function(xhr, errorType) {
return done(errorType); done(errorType);
} }
}); });
}); });
}); });
return describe('webRequest.onErrorOccurred', function() { describe('webRequest.onErrorOccurred', function() {
afterEach(function() { afterEach(function() {
ses.webRequest.onErrorOccurred(null); ses.webRequest.onErrorOccurred(null);
return ses.webRequest.onBeforeRequest(null); ses.webRequest.onBeforeRequest(null);
}); });
return it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
return callback({ callback({
cancel: true cancel: true
}); });
}); });
ses.webRequest.onErrorOccurred(function(details) { ses.webRequest.onErrorOccurred(function(details) {
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT'); assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT');
return done(); done();
}); });
return $.ajax({ $.ajax({
url: defaultURL, url: defaultURL,
success: function() { success: function() {
return done('unexpected success'); done('unexpected success');
} }
}); });
}); });

View file

@ -23,121 +23,108 @@ describe('asar package', function() {
}); });
it('reads a normal file', function() { it('reads a normal file', function() {
var file1, file2, file3; var file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
assert.equal(fs.readFileSync(file1).toString().trim(), 'file1'); assert.equal(fs.readFileSync(file1).toString().trim(), 'file1');
file2 = path.join(fixtures, 'asar', 'a.asar', 'file2'); var file2 = path.join(fixtures, 'asar', 'a.asar', 'file2');
assert.equal(fs.readFileSync(file2).toString().trim(), 'file2'); assert.equal(fs.readFileSync(file2).toString().trim(), 'file2');
file3 = path.join(fixtures, 'asar', 'a.asar', 'file3'); var file3 = path.join(fixtures, 'asar', 'a.asar', 'file3');
return assert.equal(fs.readFileSync(file3).toString().trim(), 'file3'); assert.equal(fs.readFileSync(file3).toString().trim(), 'file3');
}); });
it('reads from a empty file', function() { it('reads from a empty file', function() {
var buffer, file; var file = path.join(fixtures, 'asar', 'empty.asar', 'file1');
file = path.join(fixtures, 'asar', 'empty.asar', 'file1'); var buffer = fs.readFileSync(file);
buffer = fs.readFileSync(file);
assert.equal(buffer.length, 0); assert.equal(buffer.length, 0);
return assert.equal(buffer.toString(), ''); assert.equal(buffer.toString(), '');
}); });
it('reads a linked file', function() { it('reads a linked file', function() {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link1');
p = path.join(fixtures, 'asar', 'a.asar', 'link1'); assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
return assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
}); });
it('reads a file from linked directory', function() { it('reads a file from linked directory', function() {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1');
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1');
assert.equal(fs.readFileSync(p).toString().trim(), 'file1'); assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1'); p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
return assert.equal(fs.readFileSync(p).toString().trim(), 'file1'); assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
}); });
it('throws ENOENT error when can not find file', function() { it('throws ENOENT error when can not find file', function() {
var p, throws; var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var throws = function() {
throws = function() { fs.readFileSync(p);
return fs.readFileSync(p);
}; };
return assert.throws(throws, /ENOENT/); assert.throws(throws, /ENOENT/);
}); });
it('passes ENOENT error to callback when can not find file', function() { it('passes ENOENT error to callback when can not find file', function() {
var async, p; var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var async = false;
async = false;
fs.readFile(p, function(e) { fs.readFile(p, function(e) {
assert(async); assert(async);
return assert(/ENOENT/.test(e)); assert(/ENOENT/.test(e));
}); });
return async = true; async = true;
}); });
return it('reads a normal file with unpacked files', function() { it('reads a normal file with unpacked files', function() {
var p; var p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt');
p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt'); assert.equal(fs.readFileSync(p).toString().trim(), 'a');
return assert.equal(fs.readFileSync(p).toString().trim(), 'a');
}); });
}); });
describe('fs.readFile', function() { describe('fs.readFile', function() {
it('reads a normal file', function(done) { it('reads a normal file', function(done) {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'file1');
p = path.join(fixtures, 'asar', 'a.asar', 'file1'); fs.readFile(p, function(err, content) {
return fs.readFile(p, function(err, content) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(String(content).trim(), 'file1'); assert.equal(String(content).trim(), 'file1');
return done(); done();
}); });
}); });
it('reads from a empty file', function(done) { it('reads from a empty file', function(done) {
var p; var p = path.join(fixtures, 'asar', 'empty.asar', 'file1');
p = path.join(fixtures, 'asar', 'empty.asar', 'file1'); fs.readFile(p, function(err, content) {
return fs.readFile(p, function(err, content) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(String(content), ''); assert.equal(String(content), '');
return done(); done();
}); });
}); });
it('reads a linked file', function(done) { it('reads a linked file', function(done) {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link1');
p = path.join(fixtures, 'asar', 'a.asar', 'link1'); fs.readFile(p, function(err, content) {
return fs.readFile(p, function(err, content) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(String(content).trim(), 'file1'); assert.equal(String(content).trim(), 'file1');
return done(); done();
}); });
}); });
it('reads a file from linked directory', function(done) { it('reads a file from linked directory', function(done) {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1'); fs.readFile(p, function(err, content) {
return fs.readFile(p, function(err, content) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(String(content).trim(), 'file1'); assert.equal(String(content).trim(), 'file1');
return done(); done();
}); });
}); });
return it('throws ENOENT error when can not find file', function(done) { it('throws ENOENT error when can not find file', function(done) {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); fs.readFile(p, function(err) {
return fs.readFile(p, function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
return done(); done();
}); });
}); });
}); });
describe('fs.lstatSync', function() { describe('fs.lstatSync', function() {
it('handles path with trailing slash correctly', function() { it('handles path with trailing slash correctly', function() {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
fs.lstatSync(p); fs.lstatSync(p);
return fs.lstatSync(p + '/'); fs.lstatSync(p + '/');
}); });
it('returns information of root', function() { it('returns information of root', function() {
@ -147,7 +134,7 @@ describe('asar package', function() {
assert.equal(stats.isFile(), false); assert.equal(stats.isFile(), false);
assert.equal(stats.isDirectory(), true); assert.equal(stats.isDirectory(), true);
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
return assert.equal(stats.size, 0); assert.equal(stats.size, 0);
}); });
it('returns information of a normal file', function() { it('returns information of a normal file', function() {
@ -163,7 +150,7 @@ describe('asar package', function() {
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
results.push(assert.equal(stats.size, 6)); results.push(assert.equal(stats.size, 6));
} }
return results; results;
}); });
it('returns information of a normal directory', function() { it('returns information of a normal directory', function() {
@ -179,7 +166,7 @@ describe('asar package', function() {
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
results.push(assert.equal(stats.size, 0)); results.push(assert.equal(stats.size, 0));
} }
return results; results;
}); });
it('returns information of a linked file', function() { it('returns information of a linked file', function() {
@ -195,7 +182,7 @@ describe('asar package', function() {
assert.equal(stats.isSymbolicLink(), true); assert.equal(stats.isSymbolicLink(), true);
results.push(assert.equal(stats.size, 0)); results.push(assert.equal(stats.size, 0));
} }
return results; results;
}); });
it('returns information of a linked directory', function() { it('returns information of a linked directory', function() {
@ -211,29 +198,27 @@ describe('asar package', function() {
assert.equal(stats.isSymbolicLink(), true); assert.equal(stats.isSymbolicLink(), true);
results.push(assert.equal(stats.size, 0)); results.push(assert.equal(stats.size, 0));
} }
return results; results;
}); });
return it('throws ENOENT error when can not find file', function() { it('throws ENOENT error when can not find file', function() {
var file, j, len, p, ref2, results, throws; var file, j, len, p, ref2, throws;
ref2 = ['file4', 'file5', path.join('dir1', 'file4')]; ref2 = ['file4', 'file5', path.join('dir1', 'file4')];
results = [];
for (j = 0, len = ref2.length; j < len; j++) { for (j = 0, len = ref2.length; j < len; j++) {
file = ref2[j]; file = ref2[j];
p = path.join(fixtures, 'asar', 'a.asar', file); p = path.join(fixtures, 'asar', 'a.asar', file);
throws = function() { throws = function() {
return fs.lstatSync(p); fs.lstatSync(p);
}; };
results.push(assert.throws(throws, /ENOENT/)); assert.throws(throws, /ENOENT/);
} }
return results;
}); });
}); });
describe('fs.lstat', function() { describe('fs.lstat', function() {
it('handles path with trailing slash correctly', function(done) { it('handles path with trailing slash correctly', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1'); var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
return fs.lstat(p + '/', done); fs.lstat(p + '/', done);
}); });
it('returns information of root', function(done) { it('returns information of root', function(done) {
@ -244,7 +229,7 @@ describe('asar package', function() {
assert.equal(stats.isDirectory(), true); assert.equal(stats.isDirectory(), true);
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
assert.equal(stats.size, 0); assert.equal(stats.size, 0);
return done(); done();
}); });
}); });
@ -256,7 +241,7 @@ describe('asar package', function() {
assert.equal(stats.isDirectory(), false); assert.equal(stats.isDirectory(), false);
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
assert.equal(stats.size, 6); assert.equal(stats.size, 6);
return done(); done();
}); });
}); });
@ -268,7 +253,7 @@ describe('asar package', function() {
assert.equal(stats.isDirectory(), true); assert.equal(stats.isDirectory(), true);
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
assert.equal(stats.size, 0); assert.equal(stats.size, 0);
return done(); done();
}); });
}); });
@ -280,7 +265,7 @@ describe('asar package', function() {
assert.equal(stats.isDirectory(), false); assert.equal(stats.isDirectory(), false);
assert.equal(stats.isSymbolicLink(), true); assert.equal(stats.isSymbolicLink(), true);
assert.equal(stats.size, 0); assert.equal(stats.size, 0);
return done(); done();
}); });
}); });
@ -292,15 +277,15 @@ describe('asar package', function() {
assert.equal(stats.isDirectory(), false); assert.equal(stats.isDirectory(), false);
assert.equal(stats.isSymbolicLink(), true); assert.equal(stats.isSymbolicLink(), true);
assert.equal(stats.size, 0); assert.equal(stats.size, 0);
return done(); done();
}); });
}); });
return it('throws ENOENT error when can not find file', function(done) { it('throws ENOENT error when can not find file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'file4'); var p = path.join(fixtures, 'asar', 'a.asar', 'file4');
fs.lstat(p, function(err) { fs.lstat(p, function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
return done(); done();
}); });
}); });
}); });
@ -310,44 +295,44 @@ describe('asar package', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = 'a.asar'; var p = 'a.asar';
var r = fs.realpathSync(path.join(parent, p)); var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
}); });
it('returns real path of a normal file', function() { it('returns real path of a normal file', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'file1'); var p = path.join('a.asar', 'file1');
var r = fs.realpathSync(path.join(parent, p)); var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
}); });
it('returns real path of a normal directory', function() { it('returns real path of a normal directory', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'dir1'); var p = path.join('a.asar', 'dir1');
var r = fs.realpathSync(path.join(parent, p)); var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
}); });
it('returns real path of a linked file', function() { it('returns real path of a linked file', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link1'); var p = path.join('a.asar', 'link2', 'link1');
var r = fs.realpathSync(path.join(parent, p)); var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, 'a.asar', 'file1')); assert.equal(r, path.join(parent, 'a.asar', 'file1'));
}); });
it('returns real path of a linked directory', function() { it('returns real path of a linked directory', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link2'); var p = path.join('a.asar', 'link2', 'link2');
var r = fs.realpathSync(path.join(parent, p)); var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, 'a.asar', 'dir1')); assert.equal(r, path.join(parent, 'a.asar', 'dir1'));
}); });
return it('throws ENOENT error when can not find file', function() { it('throws ENOENT error when can not find file', function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'not-exist'); var p = path.join('a.asar', 'not-exist');
var throws = function() { var throws = function() {
return fs.realpathSync(path.join(parent, p)); fs.realpathSync(path.join(parent, p));
}; };
return assert.throws(throws, /ENOENT/); assert.throws(throws, /ENOENT/);
}); });
}); });
@ -355,58 +340,58 @@ describe('asar package', function() {
it('returns real path root', function(done) { it('returns real path root', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = 'a.asar'; var p = 'a.asar';
return fs.realpath(path.join(parent, p), function(err, r) { fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
return done(); done();
}); });
}); });
it('returns real path of a normal file', function(done) { it('returns real path of a normal file', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'file1'); var p = path.join('a.asar', 'file1');
return fs.realpath(path.join(parent, p), function(err, r) { fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
return done(); done();
}); });
}); });
it('returns real path of a normal directory', function(done) { it('returns real path of a normal directory', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'dir1'); var p = path.join('a.asar', 'dir1');
return fs.realpath(path.join(parent, p), function(err, r) { fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(r, path.join(parent, p)); assert.equal(r, path.join(parent, p));
return done(); done();
}); });
}); });
it('returns real path of a linked file', function(done) { it('returns real path of a linked file', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link1'); var p = path.join('a.asar', 'link2', 'link1');
return fs.realpath(path.join(parent, p), function(err, r) { fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(r, path.join(parent, 'a.asar', 'file1')); assert.equal(r, path.join(parent, 'a.asar', 'file1'));
return done(); done();
}); });
}); });
it('returns real path of a linked directory', function(done) { it('returns real path of a linked directory', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link2'); var p = path.join('a.asar', 'link2', 'link2');
return fs.realpath(path.join(parent, p), function(err, r) { fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(r, path.join(parent, 'a.asar', 'dir1')); assert.equal(r, path.join(parent, 'a.asar', 'dir1'));
return done(); done();
}); });
}); });
return it('throws ENOENT error when can not find file', function(done) { it('throws ENOENT error when can not find file', function(done) {
var parent = fs.realpathSync(path.join(fixtures, 'asar')); var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'not-exist'); var p = path.join('a.asar', 'not-exist');
return fs.realpath(path.join(parent, p), function(err) { fs.realpath(path.join(parent, p), function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
return done(); done();
}); });
}); });
}); });
@ -414,27 +399,27 @@ describe('asar package', function() {
it('reads dirs from root', function() { it('reads dirs from root', function() {
var p = path.join(fixtures, 'asar', 'a.asar'); var p = path.join(fixtures, 'asar', 'a.asar');
var dirs = fs.readdirSync(p); var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']); assert.deepEqual(dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']);
}); });
it('reads dirs from a normal dir', function() { it('reads dirs from a normal dir', function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'dir1'); var p = path.join(fixtures, 'asar', 'a.asar', 'dir1');
var dirs = fs.readdirSync(p); var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']); assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
}); });
it('reads dirs from a linked dir', function() { it('reads dirs from a linked dir', function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2'); var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2');
var dirs = fs.readdirSync(p); var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']); assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
}); });
return it('throws ENOENT error when can not find file', function() { it('throws ENOENT error when can not find file', function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var throws = function() { var throws = function() {
return fs.readdirSync(p); fs.readdirSync(p);
}; };
return assert.throws(throws, /ENOENT/); assert.throws(throws, /ENOENT/);
}); });
}); });
@ -444,7 +429,7 @@ describe('asar package', function() {
fs.readdir(p, function(err, dirs) { fs.readdir(p, function(err, dirs) {
assert.equal(err, null); assert.equal(err, null);
assert.deepEqual(dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']); assert.deepEqual(dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']);
return done(); done();
}); });
}); });
@ -453,7 +438,7 @@ describe('asar package', function() {
fs.readdir(p, function(err, dirs) { fs.readdir(p, function(err, dirs) {
assert.equal(err, null); assert.equal(err, null);
assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']); assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
return done(); done();
}); });
}); });
it('reads dirs from a linked dir', function(done) { it('reads dirs from a linked dir', function(done) {
@ -461,15 +446,15 @@ describe('asar package', function() {
fs.readdir(p, function(err, dirs) { fs.readdir(p, function(err, dirs) {
assert.equal(err, null); assert.equal(err, null);
assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']); assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
return done(); done();
}); });
}); });
return it('throws ENOENT error when can not find file', function(done) { it('throws ENOENT error when can not find file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.readdir(p, function(err) { fs.readdir(p, function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
return done(); done();
}); });
}); });
}); });
@ -478,7 +463,6 @@ describe('asar package', function() {
it('opens a normal/linked/under-linked-directory file', function() { it('opens a normal/linked/under-linked-directory file', function() {
var buffer, fd, file, j, len, p, ref2, results; var buffer, fd, file, j, len, p, ref2, results;
ref2 = ['file1', 'link1', path.join('link2', 'file1')]; ref2 = ['file1', 'link1', path.join('link2', 'file1')];
results = [];
for (j = 0, len = ref2.length; j < len; j++) { for (j = 0, len = ref2.length; j < len; j++) {
file = ref2[j]; file = ref2[j];
p = path.join(fixtures, 'asar', 'a.asar', file); p = path.join(fixtures, 'asar', 'a.asar', file);
@ -486,59 +470,57 @@ describe('asar package', function() {
buffer = new Buffer(6); buffer = new Buffer(6);
fs.readSync(fd, buffer, 0, 6, 0); fs.readSync(fd, buffer, 0, 6, 0);
assert.equal(String(buffer).trim(), 'file1'); assert.equal(String(buffer).trim(), 'file1');
results.push(fs.closeSync(fd)); fs.closeSync(fd);
} }
return results;
}); });
return it('throws ENOENT error when can not find file', function() { it('throws ENOENT error when can not find file', function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var throws = function() { var throws = function() {
return fs.openSync(p); fs.openSync(p);
}; };
return assert.throws(throws, /ENOENT/); assert.throws(throws, /ENOENT/);
}); });
}); });
describe('fs.open', function() { describe('fs.open', function() {
it('opens a normal file', function(done) { it('opens a normal file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'file1'); var p = path.join(fixtures, 'asar', 'a.asar', 'file1');
return fs.open(p, 'r', function(err, fd) { fs.open(p, 'r', function(err, fd) {
var buffer;
assert.equal(err, null); assert.equal(err, null);
buffer = new Buffer(6); var buffer = new Buffer(6);
return fs.read(fd, buffer, 0, 6, 0, function(err) { fs.read(fd, buffer, 0, 6, 0, function(err) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(String(buffer).trim(), 'file1'); assert.equal(String(buffer).trim(), 'file1');
return fs.close(fd, done); fs.close(fd, done);
}); });
}); });
}); });
return it('throws ENOENT error when can not find file', function(done) { it('throws ENOENT error when can not find file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.open(p, 'r', function(err) { fs.open(p, 'r', function(err) {
assert.equal(err.code, 'ENOENT'); assert.equal(err.code, 'ENOENT');
return done(); done();
}); });
}); });
}); });
describe('fs.mkdir', function() { describe('fs.mkdir', function() {
return it('throws error when calling inside asar archive', function(done) { it('throws error when calling inside asar archive', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.mkdir(p, function(err) { fs.mkdir(p, function(err) {
assert.equal(err.code, 'ENOTDIR'); assert.equal(err.code, 'ENOTDIR');
return done(); done();
}); });
}); });
}); });
describe('fs.mkdirSync', function() { describe('fs.mkdirSync', function() {
return it('throws error when calling inside asar archive', function() { it('throws error when calling inside asar archive', function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return assert.throws((function() { assert.throws((function() {
return fs.mkdirSync(p); fs.mkdirSync(p);
}), new RegExp('ENOTDIR')); }), new RegExp('ENOTDIR'));
}); });
}); });
@ -548,19 +530,19 @@ describe('asar package', function() {
var child = child_process.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js')); var child = child_process.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'message'); assert.equal(msg, 'message');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
return it('supports asar in the forked js', function(done) { it('supports asar in the forked js', function(done) {
var file = path.join(fixtures, 'asar', 'a.asar', 'file1'); var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
var child = child_process.fork(path.join(fixtures, 'module', 'asar.js')); var child = child_process.fork(path.join(fixtures, 'module', 'asar.js'));
child.on('message', function(content) { child.on('message', function(content) {
assert.equal(content, fs.readFileSync(file).toString()); assert.equal(content, fs.readFileSync(file).toString());
return done(); done();
}); });
return child.send(file); child.send(file);
}); });
}); });
@ -576,14 +558,13 @@ describe('asar package', function() {
execFile(echo, ['test'], function(error, stdout) { execFile(echo, ['test'], function(error, stdout) {
assert.equal(error, null); assert.equal(error, null);
assert.equal(stdout, 'test\n'); assert.equal(stdout, 'test\n');
return done(); done();
}); });
}); });
return xit('execFileSync executes binaries', function() { xit('execFileSync executes binaries', function() {
var output; var output = execFileSync(echo, ['test']);
output = execFileSync(echo, ['test']); assert.equal(String(output), 'test\n');
return assert.equal(String(output), 'test\n');
}); });
}); });
@ -591,47 +572,45 @@ describe('asar package', function() {
var internalModuleReadFile = process.binding('fs').internalModuleReadFile; var internalModuleReadFile = process.binding('fs').internalModuleReadFile;
it('read a normal file', function() { it('read a normal file', function() {
var file1, file2, file3; var file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
assert.equal(internalModuleReadFile(file1).toString().trim(), 'file1'); assert.equal(internalModuleReadFile(file1).toString().trim(), 'file1');
file2 = path.join(fixtures, 'asar', 'a.asar', 'file2'); var file2 = path.join(fixtures, 'asar', 'a.asar', 'file2');
assert.equal(internalModuleReadFile(file2).toString().trim(), 'file2'); assert.equal(internalModuleReadFile(file2).toString().trim(), 'file2');
file3 = path.join(fixtures, 'asar', 'a.asar', 'file3'); var file3 = path.join(fixtures, 'asar', 'a.asar', 'file3');
return assert.equal(internalModuleReadFile(file3).toString().trim(), 'file3'); assert.equal(internalModuleReadFile(file3).toString().trim(), 'file3');
}); });
return it('reads a normal file with unpacked files', function() { it('reads a normal file with unpacked files', function() {
var p; var p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt');
p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt'); assert.equal(internalModuleReadFile(p).toString().trim(), 'a');
return assert.equal(internalModuleReadFile(p).toString().trim(), 'a');
}); });
}); });
return describe('process.noAsar', function() { describe('process.noAsar', function() {
var errorName = process.platform === 'win32' ? 'ENOENT' : 'ENOTDIR'; var errorName = process.platform === 'win32' ? 'ENOENT' : 'ENOTDIR';
beforeEach(function() { beforeEach(function() {
return process.noAsar = true; process.noAsar = true;
}); });
afterEach(function() { afterEach(function() {
return process.noAsar = false; process.noAsar = false;
}); });
it('disables asar support in sync API', function() { it('disables asar support in sync API', function() {
var file = path.join(fixtures, 'asar', 'a.asar', 'file1'); var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
var dir = path.join(fixtures, 'asar', 'a.asar', 'dir1'); var dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
assert.throws((function() { assert.throws((function() {
return fs.readFileSync(file); fs.readFileSync(file);
}), new RegExp(errorName)); }), new RegExp(errorName));
assert.throws((function() { assert.throws((function() {
return fs.lstatSync(file); fs.lstatSync(file);
}), new RegExp(errorName)); }), new RegExp(errorName));
assert.throws((function() { assert.throws((function() {
return fs.realpathSync(file); fs.realpathSync(file);
}), new RegExp(errorName)); }), new RegExp(errorName));
return assert.throws((function() { assert.throws((function() {
return fs.readdirSync(dir); fs.readdirSync(dir);
}), new RegExp(errorName)); }), new RegExp(errorName));
}); });
@ -639,30 +618,29 @@ describe('asar package', function() {
var dir, file; var dir, file;
file = path.join(fixtures, 'asar', 'a.asar', 'file1'); file = path.join(fixtures, 'asar', 'a.asar', 'file1');
dir = path.join(fixtures, 'asar', 'a.asar', 'dir1'); dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
return fs.readFile(file, function(error) { fs.readFile(file, function(error) {
assert.equal(error.code, errorName); assert.equal(error.code, errorName);
return fs.lstat(file, function(error) { fs.lstat(file, function(error) {
assert.equal(error.code, errorName); assert.equal(error.code, errorName);
return fs.realpath(file, function(error) { fs.realpath(file, function(error) {
assert.equal(error.code, errorName); assert.equal(error.code, errorName);
return fs.readdir(dir, function(error) { fs.readdir(dir, function(error) {
assert.equal(error.code, errorName); assert.equal(error.code, errorName);
return done(); done();
}); });
}); });
}); });
}); });
}); });
return it('treats *.asar as normal file', function() { it('treats *.asar as normal file', function() {
var asar, content1, content2, originalFs; var originalFs = require('original-fs');
originalFs = require('original-fs'); var asar = path.join(fixtures, 'asar', 'a.asar');
asar = path.join(fixtures, 'asar', 'a.asar'); var content1 = fs.readFileSync(asar);
content1 = fs.readFileSync(asar); var content2 = originalFs.readFileSync(asar);
content2 = originalFs.readFileSync(asar);
assert.equal(content1.compare(content2), 0); assert.equal(content1.compare(content2), 0);
return assert.throws((function() { assert.throws((function() {
return fs.readdirSync(asar); fs.readdirSync(asar);
}), /ENOTDIR/); }), /ENOTDIR/);
}); });
}); });
@ -673,43 +651,43 @@ describe('asar package', function() {
it('can request a file in package', function(done) { it('can request a file in package', function(done) {
var p = path.resolve(fixtures, 'asar', 'a.asar', 'file1'); var p = path.resolve(fixtures, 'asar', 'a.asar', 'file1');
return $.get("file://" + p, function(data) { $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file1'); assert.equal(data.trim(), 'file1');
return done(); done();
}); });
}); });
it('can request a file in package with unpacked files', function(done) { it('can request a file in package with unpacked files', function(done) {
var p = path.resolve(fixtures, 'asar', 'unpack.asar', 'a.txt'); var p = path.resolve(fixtures, 'asar', 'unpack.asar', 'a.txt');
return $.get("file://" + p, function(data) { $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'a'); assert.equal(data.trim(), 'a');
return done(); done();
}); });
}); });
it('can request a linked file in package', function(done) { it('can request a linked file in package', function(done) {
var p = path.resolve(fixtures, 'asar', 'a.asar', 'link2', 'link1'); var p = path.resolve(fixtures, 'asar', 'a.asar', 'link2', 'link1');
return $.get("file://" + p, function(data) { $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file1'); assert.equal(data.trim(), 'file1');
return done(); done();
}); });
}); });
it('can request a file in filesystem', function(done) { it('can request a file in filesystem', function(done) {
var p = path.resolve(fixtures, 'asar', 'file'); var p = path.resolve(fixtures, 'asar', 'file');
return $.get("file://" + p, function(data) { $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file'); assert.equal(data.trim(), 'file');
return done(); done();
}); });
}); });
it('gets 404 when file is not found', function(done) { it('gets 404 when file is not found', function(done) {
var p = path.resolve(fixtures, 'asar', 'a.asar', 'no-exist'); var p = path.resolve(fixtures, 'asar', 'a.asar', 'no-exist');
return $.ajax({ $.ajax({
url: "file://" + p, url: "file://" + p,
error: function(err) { error: function(err) {
assert.equal(err.status, 404); assert.equal(err.status, 404);
return done(); done();
} }
}); });
}); });
@ -717,7 +695,7 @@ describe('asar package', function() {
it('sets __dirname correctly', function(done) { it('sets __dirname correctly', function(done) {
after(function() { after(function() {
w.destroy(); w.destroy();
return ipcMain.removeAllListeners('dirname'); ipcMain.removeAllListeners('dirname');
}); });
var w = new BrowserWindow({ var w = new BrowserWindow({
@ -733,15 +711,15 @@ describe('asar package', function() {
}); });
ipcMain.once('dirname', function(event, dirname) { ipcMain.once('dirname', function(event, dirname) {
assert.equal(dirname, path.dirname(p)); assert.equal(dirname, path.dirname(p));
return done(); done();
}); });
return w.loadURL(u); w.loadURL(u);
}); });
return it('loads script tag in html', function(done) { it('loads script tag in html', function(done) {
after(function() { after(function() {
w.destroy(); w.destroy();
return ipcMain.removeAllListeners('ping'); ipcMain.removeAllListeners('ping');
}); });
var w = new BrowserWindow({ var w = new BrowserWindow({
@ -756,9 +734,9 @@ describe('asar package', function() {
pathname: p pathname: p
}); });
w.loadURL(u); w.loadURL(u);
return ipcMain.once('ping', function(event, message) { ipcMain.once('ping', function(event, message) {
assert.equal(message, 'pong'); assert.equal(message, 'pong');
return done(); done();
}); });
}); });
}); });
@ -770,17 +748,17 @@ describe('asar package', function() {
var file, stats; var file, stats;
file = path.join(fixtures, 'asar', 'a.asar'); file = path.join(fixtures, 'asar', 'a.asar');
stats = originalFs.statSync(file); stats = originalFs.statSync(file);
return assert(stats.isFile()); assert(stats.isFile());
}); });
return it('is available in forked scripts', function(done) { it('is available in forked scripts', function(done) {
var child; var child;
child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js')); child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'object'); assert.equal(msg, 'object');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
}); });
@ -788,41 +766,39 @@ describe('asar package', function() {
var gfs = require('graceful-fs'); var gfs = require('graceful-fs');
it('recognize asar archvies', function() { it('recognize asar archvies', function() {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'link1');
p = path.join(fixtures, 'asar', 'a.asar', 'link1'); assert.equal(gfs.readFileSync(p).toString().trim(), 'file1');
return assert.equal(gfs.readFileSync(p).toString().trim(), 'file1');
}); });
return it('does not touch global fs object', function() { it('does not touch global fs object', function() {
return assert.notEqual(fs.readdir, gfs.readdir); assert.notEqual(fs.readdir, gfs.readdir);
}); });
}); });
describe('mkdirp module', function() { describe('mkdirp module', function() {
var mkdirp = require('mkdirp'); var mkdirp = require('mkdirp');
return it('throws error when calling inside asar archive', function() { it('throws error when calling inside asar archive', function() {
var p; var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist'); assert.throws((function() {
return assert.throws((function() { mkdirp.sync(p);
return mkdirp.sync(p);
}), new RegExp('ENOTDIR')); }), new RegExp('ENOTDIR'));
}); });
}); });
return describe('native-image', function() { describe('native-image', function() {
it('reads image from asar archive', function() { it('reads image from asar archive', function() {
var p = path.join(fixtures, 'asar', 'logo.asar', 'logo.png'); var p = path.join(fixtures, 'asar', 'logo.asar', 'logo.png');
var logo = nativeImage.createFromPath(p); var logo = nativeImage.createFromPath(p);
return assert.deepEqual(logo.getSize(), { assert.deepEqual(logo.getSize(), {
width: 55, width: 55,
height: 55 height: 55
}); });
}); });
return it('reads image from asar archive with unpacked files', function() { it('reads image from asar archive with unpacked files', function() {
var p = path.join(fixtures, 'asar', 'unpack.asar', 'atom.png'); var p = path.join(fixtures, 'asar', 'unpack.asar', 'atom.png');
var logo = nativeImage.createFromPath(p); var logo = nativeImage.createFromPath(p);
return assert.deepEqual(logo.getSize(), { assert.deepEqual(logo.getSize(), {
width: 1024, width: 1024,
height: 1024 height: 1024
}); });

View file

@ -15,28 +15,27 @@ describe('chromium feature', function() {
if (listener != null) { if (listener != null) {
window.removeEventListener('message', listener); window.removeEventListener('message', listener);
} }
return listener = null; listener = null;
}); });
xdescribe('heap snapshot', function() { xdescribe('heap snapshot', function() {
return it('does not crash', function() { it('does not crash', function() {
return process.atomBinding('v8_util').takeHeapSnapshot(); process.atomBinding('v8_util').takeHeapSnapshot();
}); });
}); });
describe('sending request of http protocol urls', function() { describe('sending request of http protocol urls', function() {
return it('does not crash', function(done) { it('does not crash', function(done) {
var server;
this.timeout(5000); this.timeout(5000);
server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res) {
res.end(); res.end();
server.close(); server.close();
return done(); done();
}); });
return server.listen(0, '127.0.0.1', function() { server.listen(0, '127.0.0.1', function() {
var port; var port = server.address().port;
port = server.address().port; $.get("http://127.0.0.1:" + port);
return $.get("http://127.0.0.1:" + port);
}); });
}); });
}); });
@ -46,7 +45,7 @@ describe('chromium feature', function() {
var w = null; var w = null;
afterEach(function() { afterEach(function() {
return w != null ? w.destroy() : void 0; w != null ? w.destroy() : void 0;
}); });
it('is set correctly when window is not shown', function(done) { it('is set correctly when window is not shown', function(done) {
@ -55,41 +54,42 @@ describe('chromium feature', function() {
}); });
w.webContents.on('ipc-message', function(event, args) { w.webContents.on('ipc-message', function(event, args) {
assert.deepEqual(args, ['hidden', true]); assert.deepEqual(args, ['hidden', true]);
return done(); done();
}); });
return w.loadURL(url); w.loadURL(url);
}); });
return it('is set correctly when window is inactive', function(done) { it('is set correctly when window is inactive', function(done) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
w.webContents.on('ipc-message', function(event, args) { w.webContents.on('ipc-message', function(event, args) {
assert.deepEqual(args, ['hidden', false]); assert.deepEqual(args, ['hidden', false]);
return done(); done();
}); });
w.showInactive(); w.showInactive();
return w.loadURL(url); w.loadURL(url);
}); });
}); });
xdescribe('navigator.webkitGetUserMedia', function() { xdescribe('navigator.webkitGetUserMedia', function() {
return it('calls its callbacks', function(done) { it('calls its callbacks', function(done) {
this.timeout(5000); this.timeout(5000);
return navigator.webkitGetUserMedia({
navigator.webkitGetUserMedia({
audio: true, audio: true,
video: false video: false
}, function() { }, function() {
return done(); done();
}, function() { }, function() {
return done(); done();
}); });
}); });
}); });
describe('navigator.language', function() { describe('navigator.language', function() {
return it('should not be empty', function() { it('should not be empty', function() {
return assert.notEqual(navigator.language, ''); assert.notEqual(navigator.language, '');
}); });
}); });
@ -98,28 +98,28 @@ describe('chromium feature', function() {
var w = null; var w = null;
afterEach(function() { afterEach(function() {
return w != null ? w.destroy() : void 0; w != null ? w.destroy() : void 0;
}); });
return it('should register for file scheme', function(done) { it('should register for file scheme', function(done) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
w.webContents.on('ipc-message', function(event, args) { w.webContents.on('ipc-message', function(event, args) {
if (args[0] === 'reload') { if (args[0] === 'reload') {
return w.webContents.reload(); w.webContents.reload();
} else if (args[0] === 'error') { } else if (args[0] === 'error') {
return done('unexpected error : ' + args[1]); done('unexpected error : ' + args[1]);
} else if (args[0] === 'response') { } else if (args[0] === 'response') {
assert.equal(args[1], 'Hello from serviceWorker!'); assert.equal(args[1], 'Hello from serviceWorker!');
return session.defaultSession.clearStorageData({ session.defaultSession.clearStorageData({
storages: ['serviceworkers'] storages: ['serviceworkers']
}, function() { }, function() {
return done(); done();
}); });
} }
}); });
return w.loadURL(url); sw.loadURL(url);
}); });
}); });
@ -127,11 +127,10 @@ describe('chromium feature', function() {
this.timeout(20000); this.timeout(20000);
it('returns a BrowserWindowProxy object', function() { it('returns a BrowserWindowProxy object', function() {
var b; var b = window.open('about:blank', '', 'show=no');
b = window.open('about:blank', '', 'show=no');
assert.equal(b.closed, false); assert.equal(b.closed, false);
assert.equal(b.constructor.name, 'BrowserWindowProxy'); assert.equal(b.constructor.name, 'BrowserWindowProxy');
return b.close(); b.close();
}); });
it('accepts "node-integration" as feature', function(done) { it('accepts "node-integration" as feature', function(done) {
@ -139,10 +138,10 @@ describe('chromium feature', function() {
listener = function(event) { listener = function(event) {
assert.equal(event.data, 'undefined'); assert.equal(event.data, 'undefined');
b.close(); b.close();
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-opener-node.html", '', 'nodeIntegration=no,show=no'); b = window.open("file://" + fixtures + "/pages/window-opener-node.html", '', 'nodeIntegration=no,show=no');
}); });
it('inherit options of parent window', function(done) { it('inherit options of parent window', function(done) {
@ -152,13 +151,13 @@ describe('chromium feature', function() {
ref1 = remote.getCurrentWindow().getSize(), width = ref1[0], height = ref1[1]; ref1 = remote.getCurrentWindow().getSize(), width = ref1[0], height = ref1[1];
assert.equal(event.data, "size: " + width + " " + height); assert.equal(event.data, "size: " + width + " " + height);
b.close(); b.close();
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', 'show=no'); b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', 'show=no');
}); });
return it('does not override child options', function(done) { it('does not override child options', function(done) {
var b, size; var b, size;
size = { size = {
width: 350, width: 350,
@ -167,45 +166,48 @@ describe('chromium feature', function() {
listener = function(event) { listener = function(event) {
assert.equal(event.data, "size: " + size.width + " " + size.height); assert.equal(event.data, "size: " + size.width + " " + size.height);
b.close(); b.close();
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', "show=no,width=" + size.width + ",height=" + size.height); b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', "show=no,width=" + size.width + ",height=" + size.height);
}); });
}); });
describe('window.opener', function() { describe('window.opener', function() {
var url, w;
this.timeout(10000); this.timeout(10000);
url = "file://" + fixtures + "/pages/window-opener.html";
w = null; var url = "file://" + fixtures + "/pages/window-opener.html";
var w = null;
afterEach(function() { afterEach(function() {
return w != null ? w.destroy() : void 0; w != null ? w.destroy() : void 0;
}); });
it('is null for main window', function(done) { it('is null for main window', function(done) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}); });
w.webContents.on('ipc-message', function(event, args) { w.webContents.on('ipc-message', function(event, args) {
assert.deepEqual(args, ['opener', null]); assert.deepEqual(args, ['opener', null]);
return done(); done();
}); });
return w.loadURL(url); w.loadURL(url);
}); });
return it('is not null for window opened by window.open', function(done) {
it('is not null for window opened by window.open', function(done) {
var b; var b;
listener = function(event) { listener = function(event) {
assert.equal(event.data, 'object'); assert.equal(event.data, 'object');
b.close(); b.close();
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
return b = window.open(url, '', 'show=no'); b = window.open(url, '', 'show=no');
}); });
}); });
describe('window.postMessage', function() { describe('window.postMessage', function() {
return it('sets the source and origin correctly', function(done) { it('sets the source and origin correctly', function(done) {
var b, sourceId; var b, sourceId;
sourceId = remote.getCurrentWindow().id; sourceId = remote.getCurrentWindow().id;
listener = function(event) { listener = function(event) {
@ -218,47 +220,47 @@ describe('chromium feature', function() {
assert.equal(message.sourceEqualsOpener, true); assert.equal(message.sourceEqualsOpener, true);
assert.equal(message.sourceId, sourceId); assert.equal(message.sourceId, sourceId);
assert.equal(event.origin, 'file://'); assert.equal(event.origin, 'file://');
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
b = window.open("file://" + fixtures + "/pages/window-open-postMessage.html", '', 'show=no'); b = window.open("file://" + fixtures + "/pages/window-open-postMessage.html", '', 'show=no');
return BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() { BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
return b.postMessage('testing', '*'); b.postMessage('testing', '*');
}); });
}); });
}); });
describe('window.opener.postMessage', function() { describe('window.opener.postMessage', function() {
return it('sets source and origin correctly', function(done) { it('sets source and origin correctly', function(done) {
var b; var b;
listener = function(event) { listener = function(event) {
window.removeEventListener('message', listener); window.removeEventListener('message', listener);
b.close(); b.close();
assert.equal(event.source, b); assert.equal(event.source, b);
assert.equal(event.origin, 'file://'); assert.equal(event.origin, 'file://');
return done(); done();
}; };
window.addEventListener('message', listener); window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-opener-postMessage.html", '', 'show=no'); b = window.open("file://" + fixtures + "/pages/window-opener-postMessage.html", '', 'show=no');
}); });
}); });
describe('creating a Uint8Array under browser side', function() { describe('creating a Uint8Array under browser side', function() {
return it('does not crash', function() { it('does not crash', function() {
var RUint8Array; var RUint8Array;
RUint8Array = remote.getGlobal('Uint8Array'); RUint8Array = remote.getGlobal('Uint8Array');
return new RUint8Array; new RUint8Array;
}); });
}); });
describe('webgl', function() { describe('webgl', function() {
return it('can be get as context in canvas', function() { it('can be get as context in canvas', function() {
var webgl; var webgl;
if (process.platform === 'linux') { if (process.platform === 'linux') {
return; return;
} }
webgl = document.createElement('canvas').getContext('webgl'); webgl = document.createElement('canvas').getContext('webgl');
return assert.notEqual(webgl, null); assert.notEqual(webgl, null);
}); });
}); });
@ -270,20 +272,20 @@ describe('chromium feature', function() {
worker.onmessage = function(event) { worker.onmessage = function(event) {
assert.equal(event.data, message); assert.equal(event.data, message);
worker.terminate(); worker.terminate();
return done(); done();
}; };
return worker.postMessage(message); worker.postMessage(message);
}); });
return it('SharedWorker can work', function(done) { it('SharedWorker can work', function(done) {
var message, worker; var message, worker;
worker = new SharedWorker('../fixtures/workers/shared_worker.js'); worker = new SharedWorker('../fixtures/workers/shared_worker.js');
message = 'ping'; message = 'ping';
worker.port.onmessage = function(event) { worker.port.onmessage = function(event) {
assert.equal(event.data, message); assert.equal(event.data, message);
return done(); done();
}; };
return worker.port.postMessage(message); worker.port.postMessage(message);
}); });
}); });
@ -291,28 +293,28 @@ describe('chromium feature', function() {
var iframe = null; var iframe = null;
beforeEach(function() { beforeEach(function() {
return iframe = document.createElement('iframe'); iframe = document.createElement('iframe');
}); });
afterEach(function() { afterEach(function() {
return document.body.removeChild(iframe); document.body.removeChild(iframe);
}); });
return it('does not have node integration', function(done) { it('does not have node integration', function(done) {
iframe.src = "file://" + fixtures + "/pages/set-global.html"; iframe.src = "file://" + fixtures + "/pages/set-global.html";
document.body.appendChild(iframe); document.body.appendChild(iframe);
return iframe.onload = function() { iframe.onload = function() {
assert.equal(iframe.contentWindow.test, 'undefined undefined undefined'); assert.equal(iframe.contentWindow.test, 'undefined undefined undefined');
return done(); done();
}; };
}); });
}); });
describe('storage', function() { describe('storage', function() {
return it('requesting persitent quota works', function(done) { it('requesting persitent quota works', function(done) {
return navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) { navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) {
assert.equal(grantedBytes, 1048576); assert.equal(grantedBytes, 1048576);
return done(); done();
}); });
}); });
}); });
@ -324,12 +326,12 @@ describe('chromium feature', function() {
afterEach(function() { afterEach(function() {
wss.close(); wss.close();
return server.close(); server.close();
}); });
return it('has user agent', function(done) { it('has user agent', function(done) {
server = http.createServer(); server = http.createServer();
return server.listen(0, '127.0.0.1', function() { server.listen(0, '127.0.0.1', function() {
var port = server.address().port; var port = server.address().port;
wss = new WebSocketServer({ wss = new WebSocketServer({
server: server server: server
@ -337,9 +339,9 @@ describe('chromium feature', function() {
wss.on('error', done); wss.on('error', done);
wss.on('connection', function(ws) { wss.on('connection', function(ws) {
if (ws.upgradeReq.headers['user-agent']) { if (ws.upgradeReq.headers['user-agent']) {
return done(); done();
} else { } else {
return done('user agent is empty'); done('user agent is empty');
} }
}); });
new WebSocket("ws://127.0.0.1:" + port); new WebSocket("ws://127.0.0.1:" + port);
@ -347,7 +349,7 @@ describe('chromium feature', function() {
}); });
}); });
return describe('Promise', function() { describe('Promise', function() {
it('resolves correctly in Node.js calls', function(done) { it('resolves correctly in Node.js calls', function(done) {
document.registerElement('x-element', { document.registerElement('x-element', {
prototype: Object.create(HTMLElement.prototype, { prototype: Object.create(HTMLElement.prototype, {
@ -356,18 +358,17 @@ describe('chromium feature', function() {
} }
}) })
}); });
return setImmediate(function() { setImmediate(function() {
var called; var called = false;
called = false;
Promise.resolve().then(function() { Promise.resolve().then(function() {
return done(called ? void 0 : new Error('wrong sequence')); done(called ? void 0 : new Error('wrong sequence'));
}); });
document.createElement('x-element'); document.createElement('x-element');
return called = true; called = true;
}); });
}); });
return it('resolves correctly in Electron calls', function(done) { it('resolves correctly in Electron calls', function(done) {
document.registerElement('y-element', { document.registerElement('y-element', {
prototype: Object.create(HTMLElement.prototype, { prototype: Object.create(HTMLElement.prototype, {
createdCallback: { createdCallback: {
@ -375,14 +376,14 @@ describe('chromium feature', function() {
} }
}) })
}); });
return remote.getGlobal('setImmediate')(function() { remote.getGlobal('setImmediate')(function() {
var called; var called;
called = false; called = false;
Promise.resolve().then(function() { Promise.resolve().then(function() {
return done(called ? void 0 : new Error('wrong sequence')); done(called ? void 0 : new Error('wrong sequence'));
}); });
document.createElement('y-element'); document.createElement('y-element');
return called = true; called = true;
}); });
}); });
}); });

View file

@ -9,40 +9,37 @@ describe('third-party module', function() {
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) { if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
describe('runas', function() { describe('runas', function() {
it('can be required in renderer', function() { it('can be required in renderer', function() {
return require('runas'); require('runas');
}); });
return it('can be required in node binary', function(done) { it('can be required in node binary', function(done) {
var child, runas; var runas = path.join(fixtures, 'module', 'runas.js');
runas = path.join(fixtures, 'module', 'runas.js'); var child = require('child_process').fork(runas);
child = require('child_process').fork(runas); child.on('message', function(msg) {
return child.on('message', function(msg) {
assert.equal(msg, 'ok'); assert.equal(msg, 'ok');
return done(); done();
}); });
}); });
}); });
describe('ffi', function() { describe('ffi', function() {
return it('does not crash', function() { it('does not crash', function() {
var ffi, libm; var ffi = require('ffi');
ffi = require('ffi'); var libm = ffi.Library('libm', {
libm = ffi.Library('libm', {
ceil: ['double', ['double']] ceil: ['double', ['double']]
}); });
return assert.equal(libm.ceil(1.5), 2); assert.equal(libm.ceil(1.5), 2);
}); });
}); });
} }
return describe('q', function() { describe('q', function() {
var Q; var Q = require('q');
Q = require('q'); describe('Q.when', function() {
return describe('Q.when', function() { it('emits the fullfil callback', function(done) {
return it('emits the fullfil callback', function(done) { Q(true).then(function(val) {
return Q(true).then(function(val) {
assert.equal(val, true); assert.equal(val, true);
return done(); done();
}); });
}); });
}); });

View file

@ -9,48 +9,45 @@ describe('node feature', function() {
var fixtures = path.join(__dirname, 'fixtures'); var fixtures = path.join(__dirname, 'fixtures');
describe('child_process', function() { describe('child_process', function() {
return describe('child_process.fork', function() { describe('child_process.fork', function() {
it('works in current process', function(done) { it('works in current process', function(done) {
var child; var child;
child = child_process.fork(path.join(fixtures, 'module', 'ping.js')); child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'message'); assert.equal(msg, 'message');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
it('preserves args', function(done) { it('preserves args', function(done) {
var args, child; var args = ['--expose_gc', '-test', '1'];
args = ['--expose_gc', '-test', '1']; var child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args);
child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args);
child.on('message', function(msg) { child.on('message', function(msg) {
assert.deepEqual(args, msg.slice(2)); assert.deepEqual(args, msg.slice(2));
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
it('works in forked process', function(done) { it('works in forked process', function(done) {
var child; var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'message'); assert.equal(msg, 'message');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
it('works in forked process when options.env is specifed', function(done) { it('works in forked process when options.env is specifed', function(done) {
var child; var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
path: process.env['PATH'] path: process.env['PATH']
}); });
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'message'); assert.equal(msg, 'message');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
it('works in browser process', function(done) { it('works in browser process', function(done) {
@ -59,9 +56,9 @@ describe('node feature', function() {
child = fork(path.join(fixtures, 'module', 'ping.js')); child = fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'message'); assert.equal(msg, 'message');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
it('has String::localeCompare working in script', function(done) { it('has String::localeCompare working in script', function(done) {
@ -69,19 +66,18 @@ describe('node feature', function() {
child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js')); child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.deepEqual(msg, [0, -1, 1]); assert.deepEqual(msg, [0, -1, 1]);
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
return it('has setImmediate working in script', function(done) { it('has setImmediate working in script', function(done) {
var child; var child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'ok'); assert.equal(msg, 'ok');
return done(); done();
}); });
return child.send('message'); child.send('message');
}); });
}); });
}); });
@ -92,18 +88,17 @@ describe('node feature', function() {
return; return;
} }
return it('does not crash', function(done) { it('does not crash', function(done) {
return fs.readFile(__filename, function() { fs.readFile(__filename, function() {
return setTimeout(done, 0); setTimeout(done, 0);
}); });
}); });
}); });
describe('throw error in node context', function() { describe('throw error in node context', function() {
return it('gets caught', function(done) { it('gets caught', function(done) {
var error, lsts; var error = new Error('boo!');
error = new Error('boo!'); var lsts = process.listeners('uncaughtException');
lsts = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException'); process.removeAllListeners('uncaughtException');
process.on('uncaughtException', function() { process.on('uncaughtException', function() {
var i, len, lst; var i, len, lst;
@ -112,28 +107,28 @@ describe('node feature', function() {
lst = lsts[i]; lst = lsts[i];
process.on('uncaughtException', lst); process.on('uncaughtException', lst);
} }
return done(); done();
}); });
return fs.readFile(__filename, function() { fs.readFile(__filename, function() {
throw error; throw error;
}); });
}); });
}); });
describe('setTimeout called under Chromium event loop in browser process', function() { describe('setTimeout called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) { it('can be scheduled in time', function(done) {
return remote.getGlobal('setTimeout')(done, 0); remote.getGlobal('setTimeout')(done, 0);
}); });
}); });
return describe('setInterval called under Chromium event loop in browser process', function() { describe('setInterval called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) { it('can be scheduled in time', function(done) {
var clear, interval; var clear, interval;
clear = function() { clear = function() {
remote.getGlobal('clearInterval')(interval); remote.getGlobal('clearInterval')(interval);
return done(); done();
}; };
return interval = remote.getGlobal('setInterval')(clear, 10); interval = remote.getGlobal('setInterval')(clear, 10);
}); });
}); });
}); });
@ -141,27 +136,27 @@ describe('node feature', function() {
describe('message loop', function() { describe('message loop', function() {
describe('process.nextTick', function() { describe('process.nextTick', function() {
it('emits the callback', function(done) { it('emits the callback', function(done) {
return process.nextTick(done); process.nextTick(done);
}); });
return it('works in nested calls', function(done) { it('works in nested calls', function(done) {
return process.nextTick(function() { process.nextTick(function() {
return process.nextTick(function() { process.nextTick(function() {
return process.nextTick(done); process.nextTick(done);
}); });
}); });
}); });
}); });
return describe('setImmediate', function() { describe('setImmediate', function() {
it('emits the callback', function(done) { it('emits the callback', function(done) {
return setImmediate(done); setImmediate(done);
}); });
return it('works in nested calls', function(done) { it('works in nested calls', function(done) {
return setImmediate(function() { setImmediate(function() {
return setImmediate(function() { setImmediate(function() {
return setImmediate(done); setImmediate(done);
}); });
}); });
}); });
@ -173,18 +168,18 @@ describe('node feature', function() {
return; return;
} }
return it('emit error when connect to a socket path without listeners', function(done) { it('emit error when connect to a socket path without listeners', function(done) {
var child, script, socketPath; var child, script, socketPath;
socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock'); socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
script = path.join(fixtures, 'module', 'create_socket.js'); script = path.join(fixtures, 'module', 'create_socket.js');
child = child_process.fork(script, [socketPath]); child = child_process.fork(script, [socketPath]);
return child.on('exit', function(code) { child.on('exit', function(code) {
var client; var client;
assert.equal(code, 0); assert.equal(code, 0);
client = require('net').connect(socketPath); client = require('net').connect(socketPath);
return client.on('error', function(error) { client.on('error', function(error) {
assert.equal(error.code, 'ECONNREFUSED'); assert.equal(error.code, 'ECONNREFUSED');
return done(); done();
}); });
}); });
}); });
@ -197,16 +192,16 @@ describe('node feature', function() {
p.innerText = '闲云潭影日悠悠,物换星移几度秋'; p.innerText = '闲云潭影日悠悠,物换星移几度秋';
b = new Buffer(p.innerText); b = new Buffer(p.innerText);
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋'); assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋');
return assert.equal(Buffer.byteLength(p.innerText), 45); assert.equal(Buffer.byteLength(p.innerText), 45);
}); });
return it('correctly parses external one-byte UTF8 string', function() { it('correctly parses external one-byte UTF8 string', function() {
var b, p; var b, p;
p = document.createElement('p'); p = document.createElement('p');
p.innerText = 'Jøhänñéß'; p.innerText = 'Jøhänñéß';
b = new Buffer(p.innerText); b = new Buffer(p.innerText);
assert.equal(b.toString(), 'Jøhänñéß'); assert.equal(b.toString(), 'Jøhänñéß');
return assert.equal(Buffer.byteLength(p.innerText), 13); assert.equal(Buffer.byteLength(p.innerText), 13);
}); });
}); });