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'); const app = remote.require('electron').app;
const BrowserWindow = remote.require('electron').BrowserWindow;
ChildProcess = require('child_process');
path = require('path');
remote = require('electron').remote;
ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
describe('electron module', function() { describe('electron module', function() {
it ('can prevent exposing internal modules to require', function(done) { it ('can prevent exposing internal modules to require', function(done) {
@ -27,100 +23,109 @@ 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(), '');
}); });
}); });
describe('app.exit(exitCode)', function() { describe('app.exit(exitCode)', function() {
var appProcess; var appProcess = null;
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) {
var appPath, electronPath, output; it('emits a process exit event with the code', function(done) {
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app'); var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
electronPath = remote.getGlobal('process').execPath; var electronPath = remote.getGlobal('process').execPath;
var output = '';
appProcess = ChildProcess.spawn(electronPath, [appPath]); appProcess = ChildProcess.spawn(electronPath, [appPath]);
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() {
var w; describe('BrowserWindow events', function() {
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

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

@ -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'); const remote = require('electron').remote;
const app = remote.require('electron').app;
path = require('path'); const crashReporter = remote.require('electron').crashReporter;
const BrowserWindow = remote.require('electron').BrowserWindow;
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;
describe('crash-reporter module', function() { describe('crash-reporter module', function() {
var fixtures, isCI, w; var fixtures = path.resolve(__dirname, 'fixtures');
fixtures = path.resolve(__dirname, 'fixtures'); var w = null;
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) {
return; return;
} }
isCI = remote.getGlobal('isCi');
var isCI = remote.getGlobal('isCi');
if (isCI) { if (isCI) {
return; return;
} }
it('should send minidump when renderer crashes', function(done) { it('should send minidump when renderer crashes', function(done) {
var called, port, server;
this.timeout(120000); this.timeout(120000);
called = false;
server = http.createServer(function(req, res) { var called = false;
var form; var server = http.createServer(function(req, res) {
server.close(); server.close();
form = new multiparty.Form(); var form = new multiparty.Form();
return form.parse(req, function(error, fields) { form.parse(req, function(error, fields) {
if (called) { if (called) {
return; return;
} }
@ -56,14 +54,14 @@ 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();
}); });
}); });
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;
url = url.format({ const crashUrl = url.format({
protocol: 'file', protocol: 'file',
pathname: path.join(fixtures, 'api', 'crash.html'), pathname: path.join(fixtures, 'api', 'crash.html'),
search: "?port=" + port search: "?port=" + port
@ -74,18 +72,19 @@ describe('crash-reporter module', function() {
submitURL: "http://127.0.0.1:" + port 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() { 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

@ -1,17 +1,11 @@
var assert, path, remote, BrowserWindow; const assert = require('assert');
const path = require('path');
assert = require('assert'); const BrowserWindow = require('electron').remote.BrowserWindow;
path = require('path');
remote = require('electron').remote;
BrowserWindow = remote.BrowserWindow;
describe('debugger module', function() { describe('debugger module', function() {
var fixtures, w; var fixtures = path.resolve(__dirname, 'fixtures');
fixtures = path.resolve(__dirname, 'fixtures'); var w = null;
w = null;
beforeEach(function() { beforeEach(function() {
if (w != null) { if (w != null) {
w.destroy(); w.destroy();
@ -22,6 +16,7 @@ describe('debugger module', function() {
height: 400 height: 400
}); });
}); });
afterEach(function() { afterEach(function() {
if (w != null) { if (w != null) {
w.destroy(); 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; const comparePaths = function(path1, path2) {
ref1 = remote.require('electron'), ipcMain = ref1.ipcMain, BrowserWindow = ref1.BrowserWindow;
comparePaths = function(path1, path2) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
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() {
var fixtures; var fixtures = path.join(__dirname, 'fixtures');
fixtures = path.join(__dirname, 'fixtures');
describe('remote.require', function() { describe('remote.require', function() {
it('should returns same object for the same module', function() { it('should returns same object for the same module', function() {
var dialog1, dialog2; var dialog1 = remote.require('electron');
dialog1 = remote.require('electron'); var dialog2 = remote.require('electron');
dialog2 = remote.require('electron'); assert.equal(dialog1, dialog2);
return 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, call, result; var buf = new Buffer('test');
buf = new Buffer('test'); var call = remote.require(path.join(fixtures, 'module', 'call.js'));
call = remote.require(path.join(fixtures, 'module', 'call.js')); var result = call.call(remote.createFunctionWithReturnValue(buf));
result = call.call(remote.createFunctionWithReturnValue(buf)); assert.equal(result.constructor.name, 'Buffer');
return assert.equal(result.constructor.name, 'Buffer');
}); });
}); });
describe('remote object in renderer', function() { describe('remote object in renderer', function() {
it('can change its properties', function() { it('can change its properties', function() {
var property, property2; var property = remote.require(path.join(fixtures, 'module', 'property.js'));
property = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property.property, 1127); assert.equal(property.property, 1127);
property.property = 1007; property.property = 1007;
assert.equal(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); 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; it('can construct an object from its member', function() {
call = remote.require(path.join(fixtures, 'module', 'call.js')); var call = remote.require(path.join(fixtures, 'module', 'call.js'));
obj = new call.constructor; var obj = new call.constructor;
return assert.equal(obj.test, 'test'); assert.equal(obj.test, 'test');
}); });
}); });
describe('remote value in browser', function() { describe('remote value in browser', function() {
var print; var print = path.join(fixtures, 'module', 'print_name.js');
print = path.join(fixtures, 'module', 'print_name.js');
it('keeps its constructor name for objects', function() { it('keeps its constructor name for objects', function() {
var buf, print_name; var buf = new Buffer('test');
buf = new Buffer('test'); var print_name = remote.require(print);
print_name = remote.require(print); assert.equal(print_name.print(buf), 'Buffer');
return assert.equal(print_name.print(buf), 'Buffer');
}); });
return it('supports instanceof Date', function() {
var now, print_name; it('supports instanceof Date', function() {
now = new Date(); var now = new Date();
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; var promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
promise = remote.require(path.join(fixtures, 'module', 'promise.js')); promise.twicePromise(Promise.resolve(1234)).then(function(value) {
return 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 = {
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; var msg = ipcRenderer.sendSync('echo', 'test');
msg = ipcRenderer.sendSync('echo', 'test'); assert.equal(msg, 'test');
return 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); this.timeout(10000);
w = new BrowserWindow({
var w = new BrowserWindow({
show: false show: false
}); });
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() {
var w; describe('remote listeners', function() {
w = null; var w = null;
afterEach(function() { 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({ w = new BrowserWindow({
show: false show: false
}); });
listener = function() {}; var listener = 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

@ -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; const Menu = remote.require('electron').Menu;
const MenuItem = remote.require('electron').MenuItem;
ref1 = remote.require('electron'), Menu = ref1.Menu, MenuItem = ref1.MenuItem;
describe('menu module', function() { describe('menu module', function() {
describe('Menu.buildFromTemplate', function() { describe('Menu.buildFromTemplate', function() {
it('should be able to attach extra fields', function() { it('should be able to attach extra fields', function() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: 'text', label: 'text',
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; var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;"); assert.deepStrictEqual(template, [
return assert.deepStrictEqual(template, [
{ {
label: 'text', label: 'text',
submenu: [ 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() { it('should position before existing item', function() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: '2', label: '2',
id: '2' id: '2'
@ -50,11 +49,11 @@ 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() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: '1', label: '1',
id: '1' id: '1'
@ -69,11 +68,11 @@ 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() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
type: 'separator', type: 'separator',
id: 'numbers' id: 'numbers'
@ -113,11 +112,11 @@ 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() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: 'a', label: 'a',
id: 'a', id: 'a',
@ -151,11 +150,11 @@ 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() {
var menu; it('should continue inserting items at next index when no specifier is present', function() {
menu = Menu.buildFromTemplate([ var menu = Menu.buildFromTemplate([
{ {
label: '4', label: '4',
id: '4' id: '4'
@ -178,14 +177,14 @@ 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 item, menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: '1' label: '1'
}, { }, {
@ -194,36 +193,36 @@ describe('menu module', function() {
label: '3' label: '3'
} }
]); ]);
item = new MenuItem({ var item = new MenuItem({
label: 'inserted' label: 'inserted'
}); });
menu.insert(1, item); menu.insert(1, item);
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; var menu = Menu.buildFromTemplate([
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; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: 'text', label: 'text',
type: 'checkbox' type: 'checkbox'
@ -231,11 +230,11 @@ 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() {
var menu; var menu = Menu.buildFromTemplate([
menu = Menu.buildFromTemplate([
{ {
label: 'text', label: 'text',
type: 'radio' type: 'radio'
@ -244,8 +243,9 @@ 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() {
var i, j, k, menu, template; var i, j, k, menu, template;
template = []; template = [];
@ -267,10 +267,11 @@ 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() {
var groupId, i, j, k, l, m, menu, results, template; var groupId, i, j, k, l, m, menu, template;
template = []; template = [];
for (i = j = 0; j <= 10; i = ++j) { for (i = j = 0; j <= 10; i = ++j) {
template.push({ template.push({
@ -292,14 +293,13 @@ 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() {
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 = []; template = [];
for (i = j = 0; j <= 10; i = ++j) { for (i = j = 0; j <= 10; i = ++j) {
template.push({ template.push({
@ -339,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;
}); });
}); });
}); });

File diff suppressed because it is too large Load diff

View file

@ -1,25 +1,21 @@
var assert, screen; const assert = require('assert');
const screen = require('electron').screen;
assert = require('assert');
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; var point = screen.getCursorScreenPoint();
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() {
return it('returns a display object', function() { describe('screen.getPrimaryDisplay()', function() {
var display; it('returns a display object', function() {
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

@ -11,36 +11,36 @@ const session = remote.session;
const BrowserWindow = remote.BrowserWindow; const BrowserWindow = remote.BrowserWindow;
describe('session module', function() { describe('session module', function() {
var fixtures, url, w;
this.timeout(10000); this.timeout(10000);
fixtures = path.resolve(__dirname, 'fixtures');
w = null; var fixtures = path.resolve(__dirname, 'fixtures');
url = "http://127.0.0.1"; var w = null;
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
}); });
}); });
afterEach(function() { afterEach(function() {
return w.destroy(); w.destroy();
}); });
describe('session.cookies', function() { describe('session.cookies', function() {
it('should get cookies', function(done) { it('should get cookies', function(done) {
var server; var 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 = 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;
@ -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) { 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'
@ -71,7 +72,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;
@ -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) { 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'
@ -101,8 +103,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;
@ -115,7 +117,7 @@ describe('session module', function() {
return done('Cookie not deleted'); return done('Cookie not deleted');
} }
} }
return done(); done();
}); });
}); });
}); });
@ -124,22 +126,21 @@ 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 = {
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');
}); });
}); });
}); });
@ -155,8 +156,9 @@ describe('session module', function() {
height: 400 height: 400
}); });
}); });
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) {
@ -188,21 +190,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 + "/");
@ -211,52 +212,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

@ -1,24 +1,18 @@
var assert, path, webFrame; const assert = require('assert');
const path = require('path');
assert = require('assert'); const webFrame = require('electron').webFrame;
path = require('path');
webFrame = require('electron').webFrame;
describe('webFrame module', function() { describe('webFrame module', function() {
var fixtures; var fixtures = path.resolve(__dirname, 'fixtures');
fixtures = path.resolve(__dirname, 'fixtures'); describe('webFrame.registerURLSchemeAsPrivileged', function() {
return describe('webFrame.registerURLSchemeAsPrivileged', function() { it('supports fetch api', function(done) {
return it('supports fetch api', function(done) {
var url;
webFrame.registerURLSchemeAsPrivileged('file'); webFrame.registerURLSchemeAsPrivileged('file');
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

@ -5,78 +5,80 @@ const remote = require('electron').remote;
const session = remote.session; const session = remote.session;
describe('webRequest module', function() { describe('webRequest module', function() {
var defaultURL, server, ses; var ses = session.defaultSession;
ses = session.defaultSession; var server = http.createServer(function(req, res) {
server = http.createServer(function(req, res) {
var content;
res.setHeader('Custom', ['Header']); res.setHeader('Custom', ['Header']);
content = req.url; var content = req.url;
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);
}); });
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 = 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();
} }
}); });
}); });
it('can filter URLs', function(done) { it('can filter URLs', function(done) {
var filter; var filter = {
filter = {
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);
} }
}); });
}); });
it('receives details object', function(done) { it('receives details object', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
assert.equal(typeof details.id, 'number'); assert.equal(typeof details.id, 'number');
@ -85,36 +87,36 @@ 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);
} }
}); });
}); });
it('receives post data in details object', function(done) { it('receives post data in details object', function(done) {
var postData = { var postData = {
name: 'post test', name: 'post test',
type: 'string' type: 'string'
}; };
ses.webRequest.onBeforeRequest(function(details, callback) { ses.webRequest.onBeforeRequest(function(details, callback) {
var data;
assert.equal(details.url, defaultURL); assert.equal(details.url, defaultURL);
assert.equal(details.method, 'POST'); assert.equal(details.method, 'POST');
assert.equal(details.uploadData.length, 1); 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); 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,
@ -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) { 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);
} }
}); });
}); });
}); });
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);
} }
}); });
}); });
it('can change the request headers', function(done) { it('can change the request headers', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) { ses.webRequest.onBeforeSendHeaders(function(details, callback) {
var requestHeaders; var 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) {
var requestHeaders; it('resets the whole headers', function(done) {
requestHeaders = { var 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);
} }
}); });
}); });
}); });
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);
} }
}); });
}); });
}); });
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) {
ses.webRequest.onHeadersReceived(function(details, callback) { ses.webRequest.onHeadersReceived(function(details, callback) {
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);
} }
}); });
}); });
}); });
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);
} }
}); });
}); });
}); });
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) {
var redirectURL; it('receives details object', function(done) {
redirectURL = defaultURL + "redirect"; var 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);
} }
}); });
}); });
}); });
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');
} }
}); });
}); });

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; const session = remote.require('electron').session;
describe('chromium feature', function() { describe('chromium feature', function() {
var fixtures, listener; var fixtures = path.resolve(__dirname, 'fixtures');
fixtures = path.resolve(__dirname, 'fixtures'); var listener = null;
listener = null;
afterEach(function() { afterEach(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);
}); });
}); });
}); });
describe('document.hidden', function() { describe('document.hidden', function() {
var url, w; var url = "file://" + fixtures + "/pages/document-hidden.html";
url = "file://" + fixtures + "/pages/document-hidden.html"; var w = null;
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) {
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', 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, '');
}); });
}); });
describe('navigator.serviceWorker', function() { describe('navigator.serviceWorker', function() {
var url, w; var url = "file://" + fixtures + "/pages/service-worker/index.html";
url = "file://" + fixtures + "/pages/service-worker/index.html"; var w = null;
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); w.loadURL(url);
}); });
}); });
describe('window.open', function() { describe('window.open', 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) {
var b; var b;
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) {
var b; var b;
listener = function(event) { listener = function(event) {
@ -139,12 +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,
@ -153,156 +166,167 @@ 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) {
var message;
window.removeEventListener('message', listener); window.removeEventListener('message', listener);
b.close(); b.close();
message = JSON.parse(event.data); var message = JSON.parse(event.data);
assert.equal(message.data, 'testing'); assert.equal(message.data, 'testing');
assert.equal(message.origin, 'file://'); assert.equal(message.origin, 'file://');
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 = remote.getGlobal('Uint8Array');
RUint8Array = remote.getGlobal('Uint8Array'); new RUint8Array;
return 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;
if (process.platform === 'linux') { if (process.platform === 'linux') {
return; return;
} }
webgl = document.createElement('canvas').getContext('webgl'); var webgl = document.createElement('canvas').getContext('webgl');
return assert.notEqual(webgl, null); assert.notEqual(webgl, null);
}); });
}); });
describe('web workers', function() { describe('web workers', function() {
it('Worker can work', function(done) { it('Worker can work', function(done) {
var message, worker; var worker = new Worker('../fixtures/workers/worker.js');
worker = new Worker('../fixtures/workers/worker.js'); var message = 'ping';
message = 'ping';
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) {
var message, worker; it('SharedWorker can work', function(done) {
worker = new SharedWorker('../fixtures/workers/shared_worker.js'); var worker = new SharedWorker('../fixtures/workers/shared_worker.js');
message = 'ping'; var 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);
}); });
}); });
describe('iframe', function() { describe('iframe', function() {
var iframe; var iframe = null;
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();
}); });
}); });
}); });
describe('websockets', function() { describe('websockets', function() {
var WebSocketServer, server, wss; var wss = null;
wss = null; var server = null;
server = null; var WebSocketServer = ws.Server;
WebSocketServer = ws.Server;
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
@ -310,16 +334,17 @@ 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);
}); });
}); });
}); });
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, {
@ -328,17 +353,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: {
@ -346,14 +371,13 @@ describe('chromium feature', function() {
} }
}) })
}); });
return remote.getGlobal('setImmediate')(function() { remote.getGlobal('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('y-element'); document.createElement('y-element');
return called = true; called = true;
}); });
}); });
}); });

View file

@ -3,43 +3,43 @@ const path = require('path');
const temp = require('temp'); const temp = require('temp');
describe('third-party module', function() { describe('third-party module', function() {
var fixtures; var fixtures = path.join(__dirname, 'fixtures');
fixtures = path.join(__dirname, 'fixtures');
temp.track(); temp.track();
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) {
var child, runas; it('can be required in node binary', function(done) {
runas = path.join(fixtures, 'module', 'runas.js'); var runas = path.join(fixtures, 'module', 'runas.js');
child = require('child_process').fork(runas); var child = require('child_process').fork(runas);
return child.on('message', function(msg) { 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() {
var Q; describe('q', function() {
Q = require('q'); var Q = require('q');
return describe('Q.when', function() { describe('Q.when', function() {
return it('emits the fullfil callback', function(done) { it('emits the fullfil callback', function(done) {
return Q(true).then(function(val) { Q(true).then(function(val) {
assert.equal(val, true); assert.equal(val, true);
return done(); done();
}); });
}); });
}); });

View file

@ -6,95 +6,96 @@ const os = require('os');
const remote = require('electron').remote; const remote = require('electron').remote;
describe('node feature', function() { describe('node feature', function() {
var fixtures; var fixtures = path.join(__dirname, 'fixtures');
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_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) {
var child, fork; var fork = remote.require('child_process').fork;
fork = remote.require('child_process').fork; var 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) {
var child; var 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) {
var child; it('has setImmediate working in script', function(done) {
child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js')); var 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');
}); });
}); });
}); });
describe('contexts', function() { describe('contexts', function() {
describe('setTimeout in fs callback', function() { describe('setTimeout in fs callback', function() {
if (process.env.TRAVIS === 'true') { if (process.env.TRAVIS === 'true') {
return; return;
} }
return it('does not crash', function(done) {
return fs.readFile(__filename, function() { it('does not crash', function(done) {
return setTimeout(done, 0); fs.readFile(__filename, function() {
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;
@ -103,91 +104,97 @@ 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() {
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; 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);
}); });
}); });
}); });
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) {
return process.nextTick(function() { it('works in nested calls', function(done) {
return process.nextTick(function() { process.nextTick(function() {
return process.nextTick(done); process.nextTick(function() {
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) {
return setImmediate(function() { it('works in nested calls', function(done) {
return setImmediate(function() { setImmediate(function() {
return setImmediate(done); setImmediate(function() {
setImmediate(done);
}); });
}); });
}); });
}); });
}); });
describe('net.connect', function() { describe('net.connect', function() {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
return; return;
} }
return it('emit error when connect to a socket path without listeners', function(done) {
var child, script, socketPath; it('emit error when connect to a socket path without listeners', function(done) {
socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock'); var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
script = path.join(fixtures, 'module', 'create_socket.js'); var script = path.join(fixtures, 'module', 'create_socket.js');
child = child_process.fork(script, [socketPath]); var child = child_process.fork(script, [socketPath]);
return child.on('exit', function(code) { child.on('exit', function(code) {
var client;
assert.equal(code, 0); assert.equal(code, 0);
client = require('net').connect(socketPath); var 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();
}); });
}); });
}); });
}); });
describe('Buffer', function() { describe('Buffer', function() {
it('can be created from WebKit external string', function() { it('can be created from WebKit external string', function() {
var b, p; var p = document.createElement('p');
p = document.createElement('p');
p.innerText = '闲云潭影日悠悠,物换星移几度秋'; p.innerText = '闲云潭影日悠悠,物换星移几度秋';
b = new Buffer(p.innerText); var 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() {
var b, p; it('correctly parses external one-byte UTF8 string', function() {
p = document.createElement('p'); var p = document.createElement('p');
p.innerText = 'Jøhänñéß'; p.innerText = 'Jøhänñéß';
b = new Buffer(p.innerText); var 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);
}); });
}); });

View file

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