Merge pull request #4523 from atom/spec-clean-up

Clean up specs post CoffeeScript conversion
This commit is contained in:
Cheng Zhao 2016-02-18 11:15:37 +08:00
commit 5f42429af1
17 changed files with 1391 additions and 1388 deletions

View file

@ -1,14 +1,10 @@
var BrowserWindow, ChildProcess, app, assert, path, ref, remote;
const assert = require('assert');
const ChildProcess = require('child_process');
const path = require('path');
const remote = require('electron').remote;
assert = require('assert');
ChildProcess = require('child_process');
path = require('path');
remote = require('electron').remote;
ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
const app = remote.require('electron').app;
const BrowserWindow = remote.require('electron').BrowserWindow;
describe('electron module', function() {
it ('can prevent exposing internal modules to require', function(done) {
@ -27,100 +23,109 @@ describe('electron module', function() {
describe('app module', function() {
describe('app.getVersion()', function() {
return it('returns the version field of package.json', function() {
return assert.equal(app.getVersion(), '0.1.0');
it('returns the version field of package.json', function() {
assert.equal(app.getVersion(), '0.1.0');
});
});
describe('app.setVersion(version)', function() {
return it('overrides the version', function() {
it('overrides the version', function() {
assert.equal(app.getVersion(), '0.1.0');
app.setVersion('test-version');
assert.equal(app.getVersion(), 'test-version');
return app.setVersion('0.1.0');
app.setVersion('0.1.0');
});
});
describe('app.getName()', function() {
return it('returns the name field of package.json', function() {
return assert.equal(app.getName(), 'Electron Test');
it('returns the name field of package.json', function() {
assert.equal(app.getName(), 'Electron Test');
});
});
describe('app.setName(name)', function() {
return it('overrides the name', function() {
it('overrides the name', function() {
assert.equal(app.getName(), 'Electron Test');
app.setName('test-name');
assert.equal(app.getName(), 'test-name');
return app.setName('Electron Test');
app.setName('Electron Test');
});
});
describe('app.getLocale()', function() {
return it('should not be empty', function() {
return assert.notEqual(app.getLocale(), '');
it('should not be empty', function() {
assert.notEqual(app.getLocale(), '');
});
});
describe('app.exit(exitCode)', function() {
var appProcess;
appProcess = null;
var appProcess = null;
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) {
var appPath, electronPath, output;
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
electronPath = remote.getGlobal('process').execPath;
it('emits a process exit event with the code', function(done) {
var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
var electronPath = remote.getGlobal('process').execPath;
var output = '';
appProcess = ChildProcess.spawn(electronPath, [appPath]);
output = '';
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') {
assert.notEqual(output.indexOf('Exit event with code: 123'), -1);
}
assert.equal(code, 123);
return done();
done();
});
});
});
return describe('BrowserWindow events', function() {
var w;
w = null;
describe('BrowserWindow events', function() {
var w = null;
afterEach(function() {
if (w != null) {
w.destroy();
}
return w = null;
w = null;
});
it('should emit browser-window-focus event when window is focused', function(done) {
app.once('browser-window-focus', function(e, window) {
assert.equal(w.id, window.id);
return done();
done();
});
w = new BrowserWindow({
show: false
});
return w.emit('focus');
w.emit('focus');
});
it('should emit browser-window-blur event when window is blured', function(done) {
app.once('browser-window-blur', function(e, window) {
assert.equal(w.id, window.id);
return done();
done();
});
w = new BrowserWindow({
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) {
return setImmediate(function() {
setImmediate(function() {
assert.equal(w.id, window.id);
return done();
done();
});
});
w = new BrowserWindow({
show: false
});
return w.emit('blur');
w.emit('blur');
});
});
});

View file

@ -42,9 +42,8 @@ describe('browser-window module', function() {
w.close();
});
w.on('closed', function() {
var content, test;
test = path.join(fixtures, 'api', 'unload');
content = fs.readFileSync(test);
var test = path.join(fixtures, 'api', 'unload');
var content = fs.readFileSync(test);
fs.unlinkSync(test);
assert.equal(String(content), 'unload');
done();
@ -66,9 +65,8 @@ describe('browser-window module', function() {
describe('window.close()', function() {
it('should emit unload handler', function(done) {
w.on('closed', function() {
var content, test;
test = path.join(fixtures, 'api', 'close');
content = fs.readFileSync(test);
var test = path.join(fixtures, 'api', 'close');
var content = fs.readFileSync(test);
fs.unlinkSync(test);
assert.equal(String(content), 'close');
done();
@ -86,8 +84,7 @@ describe('browser-window module', function() {
describe('BrowserWindow.destroy()', function() {
it('prevents users to access methods of webContents', function() {
var webContents;
webContents = w.webContents;
var webContents = w.webContents;
w.destroy();
assert.throws((function() {
webContents.getId();
@ -178,8 +175,7 @@ describe('browser-window module', function() {
it('sets the window position', function(done) {
var pos = [10, 10];
w.once('move', function() {
var newPos;
newPos = w.getPosition();
var newPos = w.getPosition();
assert.equal(newPos[0], pos[0]);
assert.equal(newPos[1], pos[1]);
done();
@ -190,16 +186,14 @@ describe('browser-window module', function() {
describe('BrowserWindow.setContentSize(width, height)', function() {
it('sets the content size', function() {
var after, size;
size = [400, 400];
var size = [400, 400];
w.setContentSize(size[0], size[1]);
after = w.getContentSize();
var after = w.getContentSize();
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
});
it('works for framless window', function() {
var after, size;
w.destroy();
w = new BrowserWindow({
show: false,
@ -207,9 +201,9 @@ describe('browser-window module', function() {
width: 400,
height: 400
});
size = [400, 400];
var size = [400, 400];
w.setContentSize(size[0], size[1]);
after = w.getContentSize();
var after = w.getContentSize();
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
});
@ -223,7 +217,6 @@ describe('browser-window module', function() {
describe('"useContentSize" option', function() {
it('make window created with content size when used', function() {
var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
@ -231,7 +224,7 @@ describe('browser-window module', function() {
height: 400,
useContentSize: true
});
contentSize = w.getContentSize();
var contentSize = w.getContentSize();
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
});
@ -243,7 +236,6 @@ describe('browser-window module', function() {
});
it('works for framless window', function() {
var contentSize, size;
w.destroy();
w = new BrowserWindow({
show: false,
@ -252,10 +244,10 @@ describe('browser-window module', function() {
height: 400,
useContentSize: true
});
contentSize = w.getContentSize();
var contentSize = w.getContentSize();
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
size = w.getSize();
var size = w.getSize();
assert.equal(size[0], 400);
assert.equal(size[1], 400);
});
@ -270,7 +262,6 @@ describe('browser-window module', function() {
}
it('creates browser window with hidden title bar', function() {
var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
@ -278,12 +269,11 @@ describe('browser-window module', function() {
height: 400,
titleBarStyle: 'hidden'
});
contentSize = w.getContentSize();
var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
});
it('creates browser window with hidden inset title bar', function() {
var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
@ -291,7 +281,7 @@ describe('browser-window module', function() {
height: 400,
titleBarStyle: 'hidden-inset'
});
contentSize = w.getContentSize();
var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
});
});
@ -312,20 +302,18 @@ describe('browser-window module', function() {
});
it('can move the window out of screen', function() {
var after;
w.setPosition(-10, -10);
after = w.getPosition();
var after = w.getPosition();
assert.equal(after[0], -10);
assert.equal(after[1], -10);
});
it('can set the window larger than screen', function() {
var after, size;
size = screen.getPrimaryDisplay().size;
var size = screen.getPrimaryDisplay().size;
size.width += 100;
size.height += 100;
w.setSize(size.width, size.height);
after = w.getSize();
var after = w.getSize();
assert.equal(after[0], size.width);
assert.equal(after[1], size.height);
});
@ -338,8 +326,7 @@ describe('browser-window module', function() {
describe('"preload" option', function() {
it('loads the script before other scripts in window', function(done) {
var preload;
preload = path.join(fixtures, 'module', 'set-global.js');
var preload = path.join(fixtures, 'module', 'set-global.js');
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'preload');
done();
@ -357,8 +344,7 @@ describe('browser-window module', function() {
describe('"node-integration" option', function() {
it('disables node integration when specified to false', function(done) {
var preload;
preload = path.join(fixtures, 'module', 'send-later.js');
var preload = path.join(fixtures, 'module', 'send-later.js');
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'undefined');
done();
@ -532,10 +518,9 @@ describe('browser-window module', function() {
describe('BrowserWindow options argument is optional', function() {
it('should create a window with default size (800x600)', function() {
var size;
w.destroy();
w = new BrowserWindow();
size = w.getSize();
var size = w.getSize();
assert.equal(size[0], 800);
assert.equal(size[1], 600);
});

View file

@ -1,55 +1,53 @@
var assert, clipboard, nativeImage, path, ref;
const assert = require('assert');
const path = require('path');
assert = require('assert');
path = require('path');
ref = require('electron'), clipboard = ref.clipboard, nativeImage = ref.nativeImage;
const clipboard = require('electron').clipboard;
const nativeImage = require('electron').nativeImage;
describe('clipboard module', function() {
var fixtures;
fixtures = path.resolve(__dirname, 'fixtures');
var fixtures = path.resolve(__dirname, 'fixtures');
describe('clipboard.readImage()', function() {
return it('returns NativeImage intance', function() {
var i, p;
p = path.join(fixtures, 'assets', 'logo.png');
i = nativeImage.createFromPath(p);
it('returns NativeImage intance', function() {
var p = path.join(fixtures, 'assets', 'logo.png');
var i = nativeImage.createFromPath(p);
clipboard.writeImage(p);
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
});
});
describe('clipboard.readText()', function() {
return it('returns unicode string correctly', function() {
var text;
text = '千江有水千江月,万里无云万里天';
it('returns unicode string correctly', function() {
var text = '千江有水千江月,万里无云万里天';
clipboard.writeText(text);
return assert.equal(clipboard.readText(), text);
assert.equal(clipboard.readText(), text);
});
});
describe('clipboard.readHtml()', function() {
return it('returns markup correctly', function() {
var markup, text;
text = '<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>';
it('returns markup correctly', function() {
var 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>';
clipboard.writeHtml(text);
return assert.equal(clipboard.readHtml(), markup);
assert.equal(clipboard.readHtml(), markup);
});
});
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}";
clipboard.writeRtf(rtf);
return assert.equal(clipboard.readRtf(), rtf);
assert.equal(clipboard.readRtf(), rtf);
});
});
return describe('clipboard.write()', function() {
return it('returns data correctly', function() {
var i, markup, p, text, rtf;
text = 'test';
rtf = '{\\rtf1\\utf8 text}';
p = path.join(fixtures, 'assets', 'logo.png');
i = nativeImage.createFromPath(p);
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>';
describe('clipboard.write()', function() {
it('returns data correctly', function() {
var text = 'test';
var rtf = '{\\rtf1\\utf8 text}';
var p = path.join(fixtures, 'assets', 'logo.png');
var 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>';
clipboard.write({
text: "test",
html: '<b>Hi</b>',
@ -59,7 +57,7 @@ describe('clipboard module', function() {
assert.equal(clipboard.readText(), text);
assert.equal(clipboard.readHtml(), markup);
assert.equal(clipboard.readRtf(), rtf);
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
});
});
});

View file

@ -1,47 +1,45 @@
var BrowserWindow, app, assert, crashReporter, http, multiparty, path, ref, remote, url;
const assert = require('assert');
const http = require('http');
const multiparty = require('multiparty');
const path = require('path');
const url = require('url');
assert = require('assert');
path = require('path');
http = require('http');
url = require('url');
multiparty = require('multiparty');
remote = require('electron').remote;
ref = remote.require('electron'), app = ref.app, crashReporter = ref.crashReporter, BrowserWindow = ref.BrowserWindow;
const remote = require('electron').remote;
const app = remote.require('electron').app;
const crashReporter = remote.require('electron').crashReporter;
const BrowserWindow = remote.require('electron').BrowserWindow;
describe('crash-reporter module', function() {
var fixtures, isCI, w;
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
beforeEach(function() {
return w = new BrowserWindow({
w = new BrowserWindow({
show: false
});
});
afterEach(function() {
return w.destroy();
w.destroy();
});
if (process.mas) {
return;
}
isCI = remote.getGlobal('isCi');
var isCI = remote.getGlobal('isCi');
if (isCI) {
return;
}
it('should send minidump when renderer crashes', function(done) {
var called, port, server;
this.timeout(120000);
called = false;
server = http.createServer(function(req, res) {
var form;
var called = false;
var server = http.createServer(function(req, res) {
server.close();
form = new multiparty.Form();
return form.parse(req, function(error, fields) {
var form = new multiparty.Form();
form.parse(req, function(error, fields) {
if (called) {
return;
}
@ -56,14 +54,14 @@ describe('crash-reporter module', function() {
assert.equal(fields['_companyName'], 'Umbrella Corporation');
assert.equal(fields['_version'], app.getVersion());
res.end('abc-123-def');
return done();
done();
});
});
port = remote.process.port;
return server.listen(port, '127.0.0.1', function() {
var port = remote.process.port;
server.listen(port, '127.0.0.1', function() {
port = server.address().port;
remote.process.port = port;
url = url.format({
const crashUrl = url.format({
protocol: 'file',
pathname: path.join(fixtures, 'api', 'crash.html'),
search: "?port=" + port
@ -74,18 +72,19 @@ describe('crash-reporter module', function() {
submitURL: "http://127.0.0.1:" + port
});
}
return w.loadURL(url);
w.loadURL(crashUrl);
});
});
return describe(".start(options)", function() {
return it('requires that the companyName and submitURL options be specified', function() {
describe(".start(options)", function() {
it('requires that the companyName and submitURL options be specified', function() {
assert.throws(function() {
return crashReporter.start({
crashReporter.start({
companyName: 'Missing submitURL'
});
});
return assert.throws(function() {
return crashReporter.start({
assert.throws(function() {
crashReporter.start({
submitURL: 'Missing companyName'
});
});

View file

@ -1,17 +1,11 @@
var assert, path, remote, BrowserWindow;
assert = require('assert');
path = require('path');
remote = require('electron').remote;
BrowserWindow = remote.BrowserWindow;
const assert = require('assert');
const path = require('path');
const BrowserWindow = require('electron').remote.BrowserWindow;
describe('debugger module', function() {
var fixtures, w;
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
beforeEach(function() {
if (w != null) {
w.destroy();
@ -22,6 +16,7 @@ describe('debugger module', function() {
height: 400
});
});
afterEach(function() {
if (w != null) {
w.destroy();

View file

@ -1,145 +1,146 @@
var BrowserWindow, assert, comparePaths, ipcMain, ipcRenderer, path, ref, ref1, remote;
const assert = require('assert');
const path = require('path');
assert = require('assert');
const ipcRenderer = require('electron').ipcRenderer;
const remote = require('electron').remote;
path = require('path');
const ipcMain = remote.require('electron').ipcMain;
const BrowserWindow = remote.require('electron').BrowserWindow;
ref = require('electron'), ipcRenderer = ref.ipcRenderer, remote = ref.remote;
ref1 = remote.require('electron'), ipcMain = ref1.ipcMain, BrowserWindow = ref1.BrowserWindow;
comparePaths = function(path1, path2) {
const comparePaths = function(path1, path2) {
if (process.platform === 'win32') {
path1 = path1.toLowerCase();
path2 = path2.toLowerCase();
}
return assert.equal(path1, path2);
assert.equal(path1, path2);
};
describe('ipc module', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
describe('remote.require', function() {
it('should returns same object for the same module', function() {
var dialog1, dialog2;
dialog1 = remote.require('electron');
dialog2 = remote.require('electron');
return assert.equal(dialog1, dialog2);
var dialog1 = remote.require('electron');
var dialog2 = remote.require('electron');
assert.equal(dialog1, dialog2);
});
it('should work when object contains id property', function() {
var a;
a = remote.require(path.join(fixtures, 'module', 'id.js'));
return assert.equal(a.id, 1127);
var a = remote.require(path.join(fixtures, 'module', 'id.js'));
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'));
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() {
return it('should be called in browser synchronously', function() {
var buf, call, result;
buf = new Buffer('test');
call = remote.require(path.join(fixtures, 'module', 'call.js'));
result = call.call(remote.createFunctionWithReturnValue(buf));
return assert.equal(result.constructor.name, 'Buffer');
it('should be called in browser synchronously', function() {
var buf = new Buffer('test');
var call = remote.require(path.join(fixtures, 'module', 'call.js'));
var result = call.call(remote.createFunctionWithReturnValue(buf));
assert.equal(result.constructor.name, 'Buffer');
});
});
describe('remote object in renderer', function() {
it('can change its properties', function() {
var property, property2;
property = remote.require(path.join(fixtures, 'module', 'property.js'));
var property = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property.property, 1127);
property.property = 1007;
assert.equal(property.property, 1007);
property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
var property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property2.property, 1007);
return property.property = 1127;
property.property = 1127;
});
return it('can construct an object from its member', function() {
var call, obj;
call = remote.require(path.join(fixtures, 'module', 'call.js'));
obj = new call.constructor;
return assert.equal(obj.test, 'test');
it('can construct an object from its member', function() {
var call = remote.require(path.join(fixtures, 'module', 'call.js'));
var obj = new call.constructor;
assert.equal(obj.test, 'test');
});
});
describe('remote value in browser', function() {
var print;
print = path.join(fixtures, 'module', 'print_name.js');
var print = path.join(fixtures, 'module', 'print_name.js');
it('keeps its constructor name for objects', function() {
var buf, print_name;
buf = new Buffer('test');
print_name = remote.require(print);
return assert.equal(print_name.print(buf), 'Buffer');
var buf = new Buffer('test');
var print_name = remote.require(print);
assert.equal(print_name.print(buf), 'Buffer');
});
return it('supports instanceof Date', function() {
var now, print_name;
now = new Date();
print_name = remote.require(print);
it('supports instanceof Date', function() {
var now = new Date();
var print_name = remote.require(print);
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() {
return it('can be used as promise in each side', function(done) {
var promise;
promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
return promise.twicePromise(Promise.resolve(1234)).then(function(value) {
it('can be used as promise in each side', function(done) {
var promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
promise.twicePromise(Promise.resolve(1234)).then(function(value) {
assert.equal(value, 2468);
return done();
done();
});
});
});
describe('ipc.sender.send', function() {
return it('should work when sending an object containing id property', function(done) {
var obj;
obj = {
it('should work when sending an object containing id property', function(done) {
var obj = {
id: 1,
name: 'ly'
};
ipcRenderer.once('message', function(event, message) {
assert.deepEqual(message, obj);
return done();
done();
});
return ipcRenderer.send('message', obj);
ipcRenderer.send('message', obj);
});
});
describe('ipc.sendSync', function() {
it('can be replied by setting event.returnValue', function() {
var msg;
msg = ipcRenderer.sendSync('echo', 'test');
return assert.equal(msg, 'test');
var msg = ipcRenderer.sendSync('echo', 'test');
assert.equal(msg, 'test');
});
return it('does not crash when reply is not sent and browser is destroyed', function(done) {
var w;
it('does not crash when reply is not sent and browser is destroyed', function(done) {
this.timeout(10000);
w = new BrowserWindow({
var w = new BrowserWindow({
show: false
});
ipcMain.once('send-sync-message', function(event) {
event.returnValue = null;
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() {
var w;
w = null;
describe('remote listeners', function() {
var w = null;
afterEach(function() {
return w.destroy();
w.destroy();
});
return it('can be added and removed correctly', function() {
var listener;
it('can be added and removed correctly', function() {
w = new BrowserWindow({
show: false
});
listener = function() {};
var listener = function() {};
w.on('test', listener);
assert.equal(w.listenerCount('test'), 1);
w.removeListener('test', listener);
return assert.equal(w.listenerCount('test'), 0);
assert.equal(w.listenerCount('test'), 0);
});
});
});

View file

@ -1,27 +1,26 @@
var Menu, MenuItem, assert, ipcRenderer, ref, ref1, remote;
const assert = require('assert');
assert = require('assert');
const remote = require('electron').remote;
const ipcRenderer = require('electron').ipcRenderer;
ref = require('electron'), remote = ref.remote, ipcRenderer = ref.ipcRenderer;
ref1 = remote.require('electron'), Menu = ref1.Menu, MenuItem = ref1.MenuItem;
const Menu = remote.require('electron').Menu;
const MenuItem = remote.require('electron').MenuItem;
describe('menu module', function() {
describe('Menu.buildFromTemplate', function() {
it('should be able to attach extra fields', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
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() {
var template;
template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
return assert.deepStrictEqual(template, [
var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
assert.deepStrictEqual(template, [
{
label: 'text',
submenu: [
@ -32,10 +31,10 @@ 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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '2',
id: '2'
@ -50,11 +49,11 @@ describe('menu module', function() {
]);
assert.equal(menu.items[0].label, '1');
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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '1',
id: '1'
@ -69,11 +68,11 @@ describe('menu module', function() {
]);
assert.equal(menu.items[0].label, '1');
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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
type: 'separator',
id: 'numbers'
@ -113,11 +112,11 @@ describe('menu module', function() {
assert.equal(menu.items[4].id, 'letters');
assert.equal(menu.items[5].label, 'a');
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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'a',
id: 'a',
@ -151,11 +150,11 @@ describe('menu module', function() {
assert.equal(menu.items[4].id, 'numbers');
assert.equal(menu.items[5].label, '1');
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() {
var menu;
menu = Menu.buildFromTemplate([
it('should continue inserting items at next index when no specifier is present', function() {
var menu = Menu.buildFromTemplate([
{
label: '4',
id: '4'
@ -178,14 +177,14 @@ describe('menu module', function() {
assert.equal(menu.items[1].label, '2');
assert.equal(menu.items[2].label, '3');
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() {
return it('should store item in @items by its index', function() {
var item, menu;
menu = Menu.buildFromTemplate([
it('should store item in @items by its index', function() {
var menu = Menu.buildFromTemplate([
{
label: '1'
}, {
@ -194,36 +193,36 @@ describe('menu module', function() {
label: '3'
}
]);
item = new MenuItem({
var item = new MenuItem({
label: 'inserted'
});
menu.insert(1, item);
assert.equal(menu.items[0].label, '1');
assert.equal(menu.items[1].label, 'inserted');
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() {
return it('should be called with the item object passed', function(done) {
var menu;
menu = Menu.buildFromTemplate([
it('should be called with the item object passed', function(done) {
var menu = Menu.buildFromTemplate([
{
label: 'text',
click: function(item) {
assert.equal(item.constructor.name, 'MenuItem');
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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
type: 'checkbox'
@ -231,11 +230,11 @@ describe('menu module', function() {
]);
assert.equal(menu.items[0].checked, false);
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() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
type: 'radio'
@ -244,8 +243,9 @@ describe('menu module', function() {
menu.delegate.executeCommand(menu.items[0].commandId);
assert.equal(menu.items[0].checked, true);
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() {
var i, j, k, menu, template;
template = [];
@ -267,10 +267,11 @@ describe('menu module', function() {
menu = Menu.buildFromTemplate(template);
menu.delegate.menuWillShow();
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() {
var groupId, i, j, k, l, m, menu, results, template;
var groupId, i, j, k, l, m, menu, template;
template = [];
for (i = j = 0; j <= 10; i = ++j) {
template.push({
@ -292,14 +293,13 @@ describe('menu module', function() {
for (i = l = 0; l <= 10; i = ++l) {
assert.equal(menu.items[i].groupId, groupId);
}
results = [];
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() {
var i, j, k, l, m, menu, n, o, p, q, results, template;
it("setting 'checked' should flip other items' 'checked' property", function() {
var i, j, k, l, m, menu, n, o, p, q, template;
template = [];
for (i = j = 0; j <= 10; i = ++j) {
template.push({
@ -339,11 +339,9 @@ describe('menu module', function() {
assert.equal(menu.items[i].checked, false);
}
assert.equal(menu.items[12].checked, true);
results = [];
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;
});
});
});

File diff suppressed because it is too large Load diff

View file

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

View file

@ -11,36 +11,36 @@ const session = remote.session;
const BrowserWindow = remote.BrowserWindow;
describe('session module', function() {
var fixtures, url, w;
this.timeout(10000);
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
url = "http://127.0.0.1";
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
var url = "http://127.0.0.1";
beforeEach(function() {
return w = new BrowserWindow({
w = new BrowserWindow({
show: false,
width: 400,
height: 400
});
});
afterEach(function() {
return w.destroy();
w.destroy();
});
describe('session.cookies', function() {
it('should get cookies', function(done) {
var server;
server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res) {
res.setHeader('Set-Cookie', ['0=0']);
res.end('finished');
return server.close();
server.close();
});
return server.listen(0, '127.0.0.1', function() {
var port;
port = server.address().port;
server.listen(0, '127.0.0.1', function() {
var port = server.address().port;
w.loadURL(url + ":" + port);
return w.webContents.on('did-finish-load', function() {
return w.webContents.session.cookies.get({
w.webContents.on('did-finish-load', function() {
w.webContents.session.cookies.get({
url: url
}, function(error, list) {
var cookie, i, len;
@ -57,13 +57,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) {
return session.defaultSession.cookies.set({
session.defaultSession.cookies.set({
url: url,
name: '1',
value: '1'
@ -71,7 +72,7 @@ describe('session module', function() {
if (error) {
return done(error);
}
return session.defaultSession.cookies.get({
session.defaultSession.cookies.get({
url: url
}, function(error, list) {
var cookie, i, len;
@ -88,12 +89,13 @@ describe('session module', function() {
}
}
}
return done('Can not find cookie');
done('Can not find cookie');
});
});
});
it('should remove cookies', function(done) {
return session.defaultSession.cookies.set({
session.defaultSession.cookies.set({
url: url,
name: '2',
value: '2'
@ -101,8 +103,8 @@ describe('session module', function() {
if (error) {
return done(error);
}
return session.defaultSession.cookies.remove(url, '2', function() {
return session.defaultSession.cookies.get({
session.defaultSession.cookies.remove(url, '2', function() {
session.defaultSession.cookies.get({
url: url
}, function(error, list) {
var cookie, i, len;
@ -115,7 +117,7 @@ describe('session module', function() {
return done('Cookie not deleted');
}
}
return done();
done();
});
});
});
@ -124,22 +126,21 @@ describe('session module', function() {
describe('session.clearStorageData(options)', function() {
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.removeAllListeners('count');
assert(!count);
return done();
done();
});
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'));
return w.webContents.on('did-finish-load', function() {
var options;
options = {
w.webContents.on('did-finish-load', function() {
var options = {
origin: "file://",
storages: ['localstorage'],
quotas: ['persistent']
};
return w.webContents.session.clearStorageData(options, function() {
return w.webContents.send('getcount');
w.webContents.session.clearStorageData(options, function() {
w.webContents.send('getcount');
});
});
});
@ -155,8 +156,9 @@ describe('session module', function() {
height: 400
});
});
afterEach(function() {
return w.destroy();
w.destroy();
});
it('can cancel default download behavior', function(done) {
@ -188,21 +190,20 @@ describe('session module', function() {
});
});
return describe('DownloadItem', function() {
var assertDownload, contentDisposition, downloadFilePath, downloadServer, mockPDF;
mockPDF = new Buffer(1024 * 1024 * 5);
contentDisposition = 'inline; filename="mock.pdf"';
downloadFilePath = path.join(fixtures, 'mock.pdf');
downloadServer = http.createServer(function(req, res) {
describe('DownloadItem', function() {
var mockPDF = new Buffer(1024 * 1024 * 5);
var contentDisposition = 'inline; filename="mock.pdf"';
var downloadFilePath = path.join(fixtures, 'mock.pdf');
var downloadServer = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Length': mockPDF.length,
'Content-Type': 'application/pdf',
'Content-Disposition': contentDisposition
});
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(filename, 'mock.pdf');
assert.equal(url, "http://127.0.0.1:" + port + "/");
@ -211,52 +212,52 @@ describe('session module', function() {
assert.equal(totalBytes, mockPDF.length);
assert.equal(disposition, contentDisposition);
assert(fs.existsSync(downloadFilePath));
return fs.unlinkSync(downloadFilePath);
fs.unlinkSync(downloadFilePath);
};
it('can download using BrowserWindow.loadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port;
port = downloadServer.address().port;
downloadServer.listen(0, '127.0.0.1', function() {
var port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', false, false);
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);
return done();
done();
});
});
});
it('can download using WebView.downloadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port, webview;
port = downloadServer.address().port;
downloadServer.listen(0, '127.0.0.1', function() {
var port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', false, false);
webview = new WebView;
var webview = new WebView;
webview.src = "file://" + fixtures + "/api/blank.html";
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) {
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port);
document.body.removeChild(webview);
return done();
done();
});
return document.body.appendChild(webview);
document.body.appendChild(webview);
});
});
it('can cancel download', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port;
port = downloadServer.address().port;
downloadServer.listen(0, '127.0.0.1', function() {
var port = downloadServer.address().port;
ipcRenderer.sendSync('set-download-option', true, false);
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(filename, 'mock.pdf');
assert.equal(mimeType, 'application/pdf');
assert.equal(receivedBytes, 0);
assert.equal(totalBytes, mockPDF.length);
assert.equal(disposition, contentDisposition);
return done();
done();
});
});
});

View file

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

View file

@ -5,78 +5,80 @@ const remote = require('electron').remote;
const session = remote.session;
describe('webRequest module', function() {
var defaultURL, server, ses;
ses = session.defaultSession;
server = http.createServer(function(req, res) {
var content;
var ses = session.defaultSession;
var server = http.createServer(function(req, res) {
res.setHeader('Custom', ['Header']);
content = req.url;
var content = req.url;
if (req.headers.accept === '*/*;test/header') {
content += 'header/received';
}
return res.end(content);
res.end(content);
});
defaultURL = null;
var defaultURL = null;
before(function(done) {
return server.listen(0, '127.0.0.1', function() {
var port;
port = server.address().port;
server.listen(0, '127.0.0.1', function() {
var port = server.address().port;
defaultURL = "http://127.0.0.1:" + port + "/";
return done();
done();
});
});
after(function() {
return server.close();
server.close();
});
describe('webRequest.onBeforeRequest', function() {
afterEach(function() {
return ses.webRequest.onBeforeRequest(null);
ses.webRequest.onBeforeRequest(null);
});
it('can cancel the request', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
return callback({
callback({
cancel: true
});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function() {
return done('unexpected success');
done('unexpected success');
},
error: function() {
return done();
done();
}
});
});
it('can filter URLs', function(done) {
var filter;
filter = {
var filter = {
urls: [defaultURL + "filter/*"]
};
ses.webRequest.onBeforeRequest(filter, function(details, callback) {
return callback({
callback({
cancel: true
});
});
return $.ajax({
$.ajax({
url: defaultURL + "nofilter/test",
success: function(data) {
assert.equal(data, '/nofilter/test');
return $.ajax({
$.ajax({
url: defaultURL + "filter/test",
success: function() {
return done('unexpected success');
done('unexpected success');
},
error: function() {
return done();
done();
}
});
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
it('receives details object', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
assert.equal(typeof details.id, 'number');
@ -85,36 +87,36 @@ describe('webRequest module', function() {
assert.equal(details.method, 'GET');
assert.equal(details.resourceType, 'xhr');
assert(!details.uploadData);
return callback({});
callback({});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
it('receives post data in details object', function(done) {
var postData = {
name: 'post test',
type: 'string'
};
ses.webRequest.onBeforeRequest(function(details, callback) {
var data;
assert.equal(details.url, defaultURL);
assert.equal(details.method, 'POST');
assert.equal(details.uploadData.length, 1);
data = qs.parse(details.uploadData[0].bytes.toString());
var data = qs.parse(details.uploadData[0].bytes.toString());
assert.deepEqual(data, postData);
return callback({
callback({
cancel: true
});
});
return $.ajax({
$.ajax({
url: defaultURL,
type: 'POST',
data: postData,
@ -125,270 +127,285 @@ 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) {
if (details.url === defaultURL) {
return callback({
callback({
redirectURL: defaultURL + "redirect"
});
} else {
return callback({});
callback({});
}
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/redirect');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onBeforeSendHeaders', function() {
afterEach(function() {
return ses.webRequest.onBeforeSendHeaders(null);
ses.webRequest.onBeforeSendHeaders(null);
});
it('receives details object', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
assert.equal(typeof details.requestHeaders, 'object');
return callback({});
callback({});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
it('can change the request headers', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
var requestHeaders;
requestHeaders = details.requestHeaders;
var requestHeaders = details.requestHeaders;
requestHeaders.Accept = '*/*;test/header';
return callback({
callback({
requestHeaders: requestHeaders
});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/header/received');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
return it('resets the whole headers', function(done) {
var requestHeaders;
requestHeaders = {
it('resets the whole headers', function(done) {
var requestHeaders = {
Test: 'header'
};
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
return callback({
callback({
requestHeaders: requestHeaders
});
});
ses.webRequest.onSendHeaders(function(details) {
assert.deepEqual(details.requestHeaders, requestHeaders);
return done();
done();
});
return $.ajax({
$.ajax({
url: defaultURL,
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onSendHeaders', 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) {
return assert.equal(typeof details.requestHeaders, 'object');
assert.equal(typeof details.requestHeaders, 'object');
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onHeadersReceived', function() {
afterEach(function() {
return ses.webRequest.onHeadersReceived(null);
ses.webRequest.onHeadersReceived(null);
});
it('receives details object', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) {
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
assert.equal(details.statusCode, 200);
assert.equal(details.responseHeaders['Custom'], 'Header');
return callback({});
callback({});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
it('can change the response header', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) {
var responseHeaders;
responseHeaders = details.responseHeaders;
var responseHeaders = details.responseHeaders;
responseHeaders['Custom'] = ['Changed'];
return callback({
callback({
responseHeaders: responseHeaders
});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Changed');
assert.equal(data, '/');
return done();
done();
},
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) {
return callback({});
callback({});
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Header');
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onResponseStarted', 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) {
assert.equal(typeof details.fromCache, 'boolean');
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
assert.equal(details.statusCode, 200);
return assert.equal(details.responseHeaders['Custom'], 'Header');
assert.equal(details.responseHeaders['Custom'], 'Header');
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data, status, xhr) {
assert.equal(xhr.getResponseHeader('Custom'), 'Header');
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onBeforeRedirect', function() {
afterEach(function() {
ses.webRequest.onBeforeRedirect(null);
return ses.webRequest.onBeforeRequest(null);
ses.webRequest.onBeforeRequest(null);
});
return it('receives details object', function(done) {
var redirectURL;
redirectURL = defaultURL + "redirect";
it('receives details object', function(done) {
var redirectURL = defaultURL + "redirect";
ses.webRequest.onBeforeRequest(function(details, callback) {
if (details.url === defaultURL) {
return callback({
callback({
redirectURL: redirectURL
});
} else {
return callback({});
callback({});
}
});
ses.webRequest.onBeforeRedirect(function(details) {
assert.equal(typeof details.fromCache, 'boolean');
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect');
assert.equal(details.statusCode, 307);
return assert.equal(details.redirectURL, redirectURL);
assert.equal(details.redirectURL, redirectURL);
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function(data) {
assert.equal(data, '/redirect');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
describe('webRequest.onCompleted', 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) {
assert.equal(typeof details.fromCache, 'boolean');
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,
success: function(data) {
assert.equal(data, '/');
return done();
done();
},
error: function(xhr, errorType) {
return done(errorType);
done(errorType);
}
});
});
});
return describe('webRequest.onErrorOccurred', function() {
describe('webRequest.onErrorOccurred', function() {
afterEach(function() {
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) {
return callback({
callback({
cancel: true
});
});
ses.webRequest.onErrorOccurred(function(details) {
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT');
return done();
done();
});
return $.ajax({
$.ajax({
url: defaultURL,
success: function() {
return done('unexpected success');
done('unexpected success');
}
});
});

File diff suppressed because it is too large Load diff

View file

@ -8,130 +8,142 @@ const BrowserWindow = remote.require('electron').BrowserWindow;
const session = remote.require('electron').session;
describe('chromium feature', function() {
var fixtures, listener;
fixtures = path.resolve(__dirname, 'fixtures');
listener = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var listener = null;
afterEach(function() {
if (listener != null) {
window.removeEventListener('message', listener);
}
return listener = null;
listener = null;
});
xdescribe('heap snapshot', function() {
return it('does not crash', function() {
return process.atomBinding('v8_util').takeHeapSnapshot();
it('does not crash', function() {
process.atomBinding('v8_util').takeHeapSnapshot();
});
});
describe('sending request of http protocol urls', function() {
return it('does not crash', function(done) {
var server;
it('does not crash', function(done) {
this.timeout(5000);
server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res) {
res.end();
server.close();
return done();
done();
});
return server.listen(0, '127.0.0.1', function() {
var port;
port = server.address().port;
return $.get("http://127.0.0.1:" + port);
server.listen(0, '127.0.0.1', function() {
var port = server.address().port;
$.get("http://127.0.0.1:" + port);
});
});
});
describe('document.hidden', function() {
var url, w;
url = "file://" + fixtures + "/pages/document-hidden.html";
w = null;
var url = "file://" + fixtures + "/pages/document-hidden.html";
var w = null;
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) {
w = new BrowserWindow({
show: false
});
w.webContents.on('ipc-message', function(event, args) {
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({
show: false
});
w.webContents.on('ipc-message', function(event, args) {
assert.deepEqual(args, ['hidden', false]);
return done();
done();
});
w.showInactive();
return w.loadURL(url);
w.loadURL(url);
});
});
xdescribe('navigator.webkitGetUserMedia', function() {
return it('calls its callbacks', function(done) {
it('calls its callbacks', function(done) {
this.timeout(5000);
return navigator.webkitGetUserMedia({
navigator.webkitGetUserMedia({
audio: true,
video: false
}, function() {
return done();
done();
}, function() {
return done();
done();
});
});
});
describe('navigator.language', function() {
return it('should not be empty', function() {
return assert.notEqual(navigator.language, '');
it('should not be empty', function() {
assert.notEqual(navigator.language, '');
});
});
describe('navigator.serviceWorker', function() {
var url, w;
url = "file://" + fixtures + "/pages/service-worker/index.html";
w = null;
var url = "file://" + fixtures + "/pages/service-worker/index.html";
var w = null;
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({
show: false
});
w.webContents.on('ipc-message', function(event, args) {
if (args[0] === 'reload') {
return w.webContents.reload();
w.webContents.reload();
} else if (args[0] === 'error') {
return done('unexpected error : ' + args[1]);
done('unexpected error : ' + args[1]);
} else if (args[0] === 'response') {
assert.equal(args[1], 'Hello from serviceWorker!');
return session.defaultSession.clearStorageData({
session.defaultSession.clearStorageData({
storages: ['serviceworkers']
}, function() {
return done();
done();
});
}
});
return w.loadURL(url);
w.loadURL(url);
});
});
describe('window.open', function() {
this.timeout(20000);
it('returns a BrowserWindowProxy object', function() {
var b;
b = window.open('about:blank', '', 'show=no');
var b = window.open('about:blank', '', 'show=no');
assert.equal(b.closed, false);
assert.equal(b.constructor.name, 'BrowserWindowProxy');
return b.close();
b.close();
});
it('accepts "node-integration" as feature', function(done) {
var b;
listener = function(event) {
assert.equal(event.data, 'undefined');
b.close();
return done();
done();
};
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) {
var b;
listener = function(event) {
@ -139,12 +151,13 @@ describe('chromium feature', function() {
ref1 = remote.getCurrentWindow().getSize(), width = ref1[0], height = ref1[1];
assert.equal(event.data, "size: " + width + " " + height);
b.close();
return done();
done();
};
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;
size = {
width: 350,
@ -153,156 +166,167 @@ describe('chromium feature', function() {
listener = function(event) {
assert.equal(event.data, "size: " + size.width + " " + size.height);
b.close();
return done();
done();
};
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() {
var url, w;
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() {
return w != null ? w.destroy() : void 0;
w != null ? w.destroy() : void 0;
});
it('is null for main window', function(done) {
w = new BrowserWindow({
show: false
});
w.webContents.on('ipc-message', function(event, args) {
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;
listener = function(event) {
assert.equal(event.data, 'object');
b.close();
return done();
done();
};
window.addEventListener('message', listener);
return b = window.open(url, '', 'show=no');
b = window.open(url, '', 'show=no');
});
});
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;
sourceId = remote.getCurrentWindow().id;
listener = function(event) {
var message;
window.removeEventListener('message', listener);
b.close();
message = JSON.parse(event.data);
var message = JSON.parse(event.data);
assert.equal(message.data, 'testing');
assert.equal(message.origin, 'file://');
assert.equal(message.sourceEqualsOpener, true);
assert.equal(message.sourceId, sourceId);
assert.equal(event.origin, 'file://');
return done();
done();
};
window.addEventListener('message', listener);
b = window.open("file://" + fixtures + "/pages/window-open-postMessage.html", '', 'show=no');
return BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
return b.postMessage('testing', '*');
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
b.postMessage('testing', '*');
});
});
});
describe('window.opener.postMessage', function() {
return it('sets source and origin correctly', function(done) {
it('sets source and origin correctly', function(done) {
var b;
listener = function(event) {
window.removeEventListener('message', listener);
b.close();
assert.equal(event.source, b);
assert.equal(event.origin, 'file://');
return done();
done();
};
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() {
return it('does not crash', function() {
var RUint8Array;
RUint8Array = remote.getGlobal('Uint8Array');
return new RUint8Array;
it('does not crash', function() {
var RUint8Array = remote.getGlobal('Uint8Array');
new RUint8Array;
});
});
describe('webgl', function() {
return it('can be get as context in canvas', function() {
var webgl;
it('can be get as context in canvas', function() {
if (process.platform === 'linux') {
return;
}
webgl = document.createElement('canvas').getContext('webgl');
return assert.notEqual(webgl, null);
var webgl = document.createElement('canvas').getContext('webgl');
assert.notEqual(webgl, null);
});
});
describe('web workers', function() {
it('Worker can work', function(done) {
var message, worker;
worker = new Worker('../fixtures/workers/worker.js');
message = 'ping';
var worker = new Worker('../fixtures/workers/worker.js');
var message = 'ping';
worker.onmessage = function(event) {
assert.equal(event.data, message);
worker.terminate();
return done();
done();
};
return worker.postMessage(message);
worker.postMessage(message);
});
return it('SharedWorker can work', function(done) {
var message, worker;
worker = new SharedWorker('../fixtures/workers/shared_worker.js');
message = 'ping';
it('SharedWorker can work', function(done) {
var worker = new SharedWorker('../fixtures/workers/shared_worker.js');
var message = 'ping';
worker.port.onmessage = function(event) {
assert.equal(event.data, message);
return done();
done();
};
return worker.port.postMessage(message);
worker.port.postMessage(message);
});
});
describe('iframe', function() {
var iframe;
iframe = null;
var iframe = null;
beforeEach(function() {
return iframe = document.createElement('iframe');
iframe = document.createElement('iframe');
});
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";
document.body.appendChild(iframe);
return iframe.onload = function() {
iframe.onload = function() {
assert.equal(iframe.contentWindow.test, 'undefined undefined undefined');
return done();
done();
};
});
});
describe('storage', function() {
return it('requesting persitent quota works', function(done) {
return navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) {
it('requesting persitent quota works', function(done) {
navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) {
assert.equal(grantedBytes, 1048576);
return done();
done();
});
});
});
describe('websockets', function() {
var WebSocketServer, server, wss;
wss = null;
server = null;
WebSocketServer = ws.Server;
var wss = null;
var server = null;
var WebSocketServer = ws.Server;
afterEach(function() {
wss.close();
return server.close();
server.close();
});
return it('has user agent', function(done) {
it('has user agent', function(done) {
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;
wss = new WebSocketServer({
server: server
@ -310,16 +334,17 @@ describe('chromium feature', function() {
wss.on('error', done);
wss.on('connection', function(ws) {
if (ws.upgradeReq.headers['user-agent']) {
return done();
done();
} else {
return done('user agent is empty');
done('user agent is empty');
}
});
new WebSocket("ws://127.0.0.1:" + port);
});
});
});
return describe('Promise', function() {
describe('Promise', function() {
it('resolves correctly in Node.js calls', function(done) {
document.registerElement('x-element', {
prototype: Object.create(HTMLElement.prototype, {
@ -328,17 +353,17 @@ describe('chromium feature', function() {
}
})
});
return setImmediate(function() {
var called;
called = false;
setImmediate(function() {
var called = false;
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');
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', {
prototype: Object.create(HTMLElement.prototype, {
createdCallback: {
@ -346,14 +371,13 @@ describe('chromium feature', function() {
}
})
});
return remote.getGlobal('setImmediate')(function() {
var called;
called = false;
remote.getGlobal('setImmediate')(function() {
var called = false;
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');
return called = true;
called = true;
});
});
});

View file

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

View file

@ -6,95 +6,96 @@ const os = require('os');
const remote = require('electron').remote;
describe('node feature', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
describe('child_process', function() {
return describe('child_process.fork', function() {
describe('child_process.fork', function() {
it('works in current process', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
var child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) {
assert.equal(msg, 'message');
return done();
done();
});
return child.send('message');
child.send('message');
});
it('preserves args', function(done) {
var args, child;
args = ['--expose_gc', '-test', '1'];
child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args);
var args = ['--expose_gc', '-test', '1'];
var child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args);
child.on('message', function(msg) {
assert.deepEqual(args, msg.slice(2));
return done();
done();
});
return child.send('message');
child.send('message');
});
it('works in forked process', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
child.on('message', function(msg) {
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) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
path: process.env['PATH']
});
child.on('message', function(msg) {
assert.equal(msg, 'message');
return done();
done();
});
return child.send('message');
child.send('message');
});
it('works in browser process', function(done) {
var child, fork;
fork = remote.require('child_process').fork;
child = fork(path.join(fixtures, 'module', 'ping.js'));
var fork = remote.require('child_process').fork;
var child = fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) {
assert.equal(msg, 'message');
return done();
done();
});
return child.send('message');
child.send('message');
});
it('has String::localeCompare working in script', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
var child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
child.on('message', function(msg) {
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) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
it('has setImmediate working in script', function(done) {
var child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
child.on('message', function(msg) {
assert.equal(msg, 'ok');
return done();
done();
});
return child.send('message');
child.send('message');
});
});
});
describe('contexts', function() {
describe('setTimeout in fs callback', function() {
if (process.env.TRAVIS === 'true') {
return;
}
return it('does not crash', function(done) {
return fs.readFile(__filename, function() {
return setTimeout(done, 0);
it('does not crash', function(done) {
fs.readFile(__filename, function() {
setTimeout(done, 0);
});
});
});
describe('throw error in node context', function() {
return it('gets caught', function(done) {
var error, lsts;
error = new Error('boo!');
lsts = process.listeners('uncaughtException');
it('gets caught', function(done) {
var error = new Error('boo!');
var lsts = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
process.on('uncaughtException', function() {
var i, len, lst;
@ -103,91 +104,97 @@ describe('node feature', function() {
lst = lsts[i];
process.on('uncaughtException', lst);
}
return done();
done();
});
return fs.readFile(__filename, function() {
fs.readFile(__filename, function() {
throw error;
});
});
});
describe('setTimeout called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) {
return remote.getGlobal('setTimeout')(done, 0);
it('can be scheduled in time', function(done) {
remote.getGlobal('setTimeout')(done, 0);
});
});
return describe('setInterval called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) {
describe('setInterval called under Chromium event loop in browser process', function() {
it('can be scheduled in time', function(done) {
var clear, interval;
clear = function() {
remote.getGlobal('clearInterval')(interval);
return done();
done();
};
return interval = remote.getGlobal('setInterval')(clear, 10);
interval = remote.getGlobal('setInterval')(clear, 10);
});
});
});
describe('message loop', function() {
describe('process.nextTick', function() {
it('emits the callback', function(done) {
return process.nextTick(done);
process.nextTick(done);
});
return it('works in nested calls', function(done) {
return process.nextTick(function() {
return process.nextTick(function() {
return process.nextTick(done);
it('works in nested calls', function(done) {
process.nextTick(function() {
process.nextTick(function() {
process.nextTick(done);
});
});
});
});
return describe('setImmediate', function() {
describe('setImmediate', function() {
it('emits the callback', function(done) {
return setImmediate(done);
setImmediate(done);
});
return it('works in nested calls', function(done) {
return setImmediate(function() {
return setImmediate(function() {
return setImmediate(done);
it('works in nested calls', function(done) {
setImmediate(function() {
setImmediate(function() {
setImmediate(done);
});
});
});
});
});
describe('net.connect', function() {
if (process.platform !== 'darwin') {
return;
}
return it('emit error when connect to a socket path without listeners', function(done) {
var child, script, socketPath;
socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
script = path.join(fixtures, 'module', 'create_socket.js');
child = child_process.fork(script, [socketPath]);
return child.on('exit', function(code) {
var client;
it('emit error when connect to a socket path without listeners', function(done) {
var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
var script = path.join(fixtures, 'module', 'create_socket.js');
var child = child_process.fork(script, [socketPath]);
child.on('exit', function(code) {
assert.equal(code, 0);
client = require('net').connect(socketPath);
return client.on('error', function(error) {
var client = require('net').connect(socketPath);
client.on('error', function(error) {
assert.equal(error.code, 'ECONNREFUSED');
return done();
done();
});
});
});
});
describe('Buffer', function() {
it('can be created from WebKit external string', function() {
var b, p;
p = document.createElement('p');
var p = document.createElement('p');
p.innerText = '闲云潭影日悠悠,物换星移几度秋';
b = new Buffer(p.innerText);
var b = new Buffer(p.innerText);
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() {
var b, p;
p = document.createElement('p');
it('correctly parses external one-byte UTF8 string', function() {
var p = document.createElement('p');
p.innerText = 'Jøhänñéß';
b = new Buffer(p.innerText);
var b = new Buffer(p.innerText);
assert.equal(b.toString(), 'Jøhänñéß');
return assert.equal(Buffer.byteLength(p.innerText), 13);
assert.equal(Buffer.byteLength(p.innerText), 13);
});
});

View file

@ -95,8 +95,7 @@ describe('<webview> tag', function() {
describe('preload attribute', function() {
it('loads the script before other scripts in window', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.message, 'function object object');
webview.removeEventListener('console-message', listener);
done();
@ -118,15 +117,14 @@ describe('<webview> tag', function() {
});
it('receives ipc message in preload script', function(done) {
var listener, listener2, message;
message = 'boom!';
listener = function(e) {
var message = 'boom!';
var listener = function(e) {
assert.equal(e.channel, 'pong');
assert.deepEqual(e.args, [message]);
webview.removeEventListener('ipc-message', listener);
done();
};
listener2 = function() {
var listener2 = function() {
webview.send('ping', message);
webview.removeEventListener('did-finish-load', listener2);
};
@ -140,9 +138,8 @@ describe('<webview> tag', function() {
describe('httpreferrer attribute', function() {
it('sets the referrer url', function(done) {
var listener, referrer;
referrer = 'http://github.com/';
listener = function(e) {
var referrer = 'http://github.com/';
var listener = function(e) {
assert.equal(e.message, referrer);
webview.removeEventListener('console-message', listener);
done();
@ -156,9 +153,8 @@ describe('<webview> tag', function() {
describe('useragent attribute', function() {
it('sets the user agent', function(done) {
var listener, referrer;
referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
listener = function(e) {
var referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
var listener = function(e) {
assert.equal(e.message, referrer);
webview.removeEventListener('console-message', listener);
done();
@ -172,10 +168,9 @@ describe('<webview> tag', function() {
describe('disablewebsecurity attribute', function() {
it('does not disable web security when not set', function(done) {
var encoded, listener, src;
src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
encoded = btoa(unescape(encodeURIComponent(src)));
listener = function(e) {
var src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
var encoded = btoa(unescape(encodeURIComponent(src)));
var listener = function(e) {
assert(/Not allowed to load local resource/.test(e.message));
webview.removeEventListener('console-message', listener);
done();
@ -186,10 +181,9 @@ describe('<webview> tag', function() {
});
it('disables web security when set', function(done) {
var encoded, listener, src;
src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
encoded = btoa(unescape(encodeURIComponent(src)));
listener = function(e) {
var src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
var encoded = btoa(unescape(encodeURIComponent(src)));
var listener = function(e) {
assert.equal(e.message, 'ok');
webview.removeEventListener('console-message', listener);
done();
@ -223,8 +217,7 @@ describe('<webview> tag', function() {
});
it('isolates storage for different id', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.message, " 0");
webview.removeEventListener('console-message', listener);
done();
@ -237,8 +230,7 @@ describe('<webview> tag', function() {
});
it('uses current session storage when no id is provided', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.message, "one 1");
webview.removeEventListener('console-message', listener);
done();
@ -252,8 +244,7 @@ describe('<webview> tag', function() {
describe('allowpopups attribute', function() {
it('can not open new window when not set', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.message, 'null');
webview.removeEventListener('console-message', listener);
done();
@ -264,8 +255,7 @@ describe('<webview> tag', function() {
});
it('can open new window when set', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.message, 'window');
webview.removeEventListener('console-message', listener);
done();
@ -327,9 +317,8 @@ describe('<webview> tag', function() {
describe('page-favicon-updated event', function() {
it('emits when favicon urls are received', function(done) {
webview.addEventListener('page-favicon-updated', function(e) {
var pageUrl;
assert.equal(e.favicons.length, 2);
pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
var pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
assert.equal(e.favicons[0], pageUrl);
done();
});
@ -350,10 +339,9 @@ describe('<webview> tag', function() {
});
describe('did-navigate event', function() {
var p, pageUrl;
p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
var p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
p = p.replace(/\\/g, '/');
pageUrl = url.format({
var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
@ -370,10 +358,9 @@ describe('<webview> tag', function() {
});
describe('did-navigate-in-page event', function() {
it('emits when an anchor link is clicked', function(done) {
var p, pageUrl;
p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html');
var p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html');
p = p.replace(/\\/g, '/');
pageUrl = url.format({
var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
@ -396,10 +383,9 @@ describe('<webview> tag', function() {
});
it('emits when window.location.hash is changed', function(done) {
var p, pageUrl;
p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
var p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
p = p.replace(/\\/g, '/');
pageUrl = url.format({
var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
@ -425,8 +411,7 @@ describe('<webview> tag', function() {
describe('devtools-opened event', function() {
it('should fire when webview.openDevTools() is called', function(done) {
var listener;
listener = function() {
var listener = function() {
webview.removeEventListener('devtools-opened', listener);
webview.closeDevTools();
done();
@ -442,12 +427,11 @@ describe('<webview> tag', function() {
describe('devtools-closed event', function() {
it('should fire when webview.closeDevTools() is called', function(done) {
var listener, listener2;
listener2 = function() {
var listener2 = function() {
webview.removeEventListener('devtools-closed', listener2);
done();
};
listener = function() {
var listener = function() {
webview.removeEventListener('devtools-opened', listener);
webview.closeDevTools();
};
@ -463,8 +447,7 @@ describe('<webview> tag', function() {
describe('devtools-focused event', function() {
it('should fire when webview.openDevTools() is called', function(done) {
var listener;
listener = function() {
var listener = function() {
webview.removeEventListener('devtools-focused', listener);
webview.closeDevTools();
done();
@ -480,13 +463,12 @@ describe('<webview> tag', function() {
describe('<webview>.reload()', function() {
it('should emit beforeunload handler', function(done) {
var listener, listener2;
listener = function(e) {
var listener = function(e) {
assert.equal(e.channel, 'onbeforeunload');
webview.removeEventListener('ipc-message', listener);
done();
};
listener2 = function() {
var listener2 = function() {
webview.reload();
webview.removeEventListener('did-finish-load', listener2);
};
@ -500,8 +482,7 @@ describe('<webview> tag', function() {
describe('<webview>.clearHistory()', function() {
it('should clear the navigation history', function(done) {
var listener;
listener = function(e) {
var listener = function(e) {
assert.equal(e.channel, 'history');
assert.equal(e.args[0], 2);
assert(webview.canGoBack());
@ -518,14 +499,12 @@ describe('<webview> tag', function() {
});
describe('basic auth', function() {
var auth;
auth = require('basic-auth');
var auth = require('basic-auth');
it('should authenticate with correct credentials', function(done) {
var message, server;
message = 'Authenticated';
server = http.createServer(function(req, res) {
var credentials;
credentials = auth(req);
var message = 'Authenticated';
var server = http.createServer(function(req, res) {
var credentials = auth(req);
if (credentials.name === 'test' && credentials.pass === 'test') {
res.end(message);
} else {
@ -534,8 +513,7 @@ describe('<webview> tag', function() {
server.close();
});
server.listen(0, '127.0.0.1', function() {
var port;
port = server.address().port;
var port = server.address().port;
webview.addEventListener('ipc-message', function(e) {
assert.equal(e.channel, message);
done();
@ -549,11 +527,9 @@ describe('<webview> tag', function() {
describe('dom-ready event', function() {
it('emits when document is loaded', function(done) {
var server;
server = http.createServer(function() {});
var server = http.createServer(function() {});
server.listen(0, '127.0.0.1', function() {
var port;
port = server.address().port;
var port = server.address().port;
webview.addEventListener('dom-ready', function() {
done();
});
@ -575,14 +551,12 @@ describe('<webview> tag', function() {
}
it('should support user gesture', function(done) {
var listener, listener2;
listener = function() {
var listener = function() {
webview.removeEventListener('enter-html-full-screen', listener);
done();
};
listener2 = function() {
var jsScript;
jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
var listener2 = function() {
var jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
webview.executeJavaScript(jsScript, true);
webview.removeEventListener('did-finish-load', listener2);
};
@ -634,8 +608,7 @@ describe('<webview> tag', function() {
describe('media-started-playing media-paused events', function() {
it('emits when audio starts and stops playing', function(done) {
var audioPlayed;
audioPlayed = false;
var audioPlayed = false;
webview.addEventListener('media-started-playing', function() {
audioPlayed = true;
});
@ -650,9 +623,8 @@ describe('<webview> tag', function() {
describe('found-in-page event', function() {
it('emits when a request is made', function(done) {
var listener, listener2, requestId;
requestId = null;
listener = function(e) {
var requestId = null;
var listener = function(e) {
assert.equal(e.result.requestId, requestId);
if (e.result.finalUpdate) {
assert.equal(e.result.matches, 3);
@ -660,7 +632,7 @@ describe('<webview> tag', function() {
done();
}
};
listener2 = function() {
var listener2 = function() {
requestId = webview.findInPage("virtual");
};
webview.addEventListener('found-in-page', listener);