});
it('emits a process exit event with the code', function(done) {
- var appPath, electronPath, output;
- appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
- electronPath = remote.getGlobal('process').execPath;
+ var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
+ var electronPath = remote.getGlobal('process').execPath;
+ var output = '';
appProcess = ChildProcess.spawn(electronPath, [appPath]);
- output = '';
appProcess.stdout.on('data', function(data) {
output += data;
});
w.close();
});
w.on('closed', function() {
- var content, test;
- test = path.join(fixtures, 'api', 'unload');
- content = fs.readFileSync(test);
+ var test = path.join(fixtures, 'api', 'unload');
+ var content = fs.readFileSync(test);
fs.unlinkSync(test);
assert.equal(String(content), 'unload');
done();
describe('window.close()', function() {
it('should emit unload handler', function(done) {
w.on('closed', function() {
- var content, test;
- test = path.join(fixtures, 'api', 'close');
- content = fs.readFileSync(test);
+ var test = path.join(fixtures, 'api', 'close');
+ var content = fs.readFileSync(test);
fs.unlinkSync(test);
assert.equal(String(content), 'close');
done();
describe('BrowserWindow.destroy()', function() {
it('prevents users to access methods of webContents', function() {
- var webContents;
- webContents = w.webContents;
+ var webContents = w.webContents;
w.destroy();
assert.throws((function() {
webContents.getId();
it('sets the window position', function(done) {
var pos = [10, 10];
w.once('move', function() {
- var newPos;
- newPos = w.getPosition();
+ var newPos = w.getPosition();
assert.equal(newPos[0], pos[0]);
assert.equal(newPos[1], pos[1]);
done();
describe('BrowserWindow.setContentSize(width, height)', function() {
it('sets the content size', function() {
- var after, size;
- size = [400, 400];
+ var size = [400, 400];
w.setContentSize(size[0], size[1]);
- after = w.getContentSize();
+ var after = w.getContentSize();
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
});
it('works for framless window', function() {
- var after, size;
w.destroy();
w = new BrowserWindow({
show: false,
width: 400,
height: 400
});
- size = [400, 400];
+ var size = [400, 400];
w.setContentSize(size[0], size[1]);
- after = w.getContentSize();
+ var after = w.getContentSize();
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
});
describe('"useContentSize" option', function() {
it('make window created with content size when used', function() {
- var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
height: 400,
useContentSize: true
});
- contentSize = w.getContentSize();
+ var contentSize = w.getContentSize();
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
});
});
it('works for framless window', function() {
- var contentSize, size;
w.destroy();
w = new BrowserWindow({
show: false,
height: 400,
useContentSize: true
});
- contentSize = w.getContentSize();
+ var contentSize = w.getContentSize();
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
- size = w.getSize();
+ var size = w.getSize();
assert.equal(size[0], 400);
assert.equal(size[1], 400);
});
}
it('creates browser window with hidden title bar', function() {
- var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
height: 400,
titleBarStyle: 'hidden'
});
- contentSize = w.getContentSize();
+ var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
});
it('creates browser window with hidden inset title bar', function() {
- var contentSize;
w.destroy();
w = new BrowserWindow({
show: false,
height: 400,
titleBarStyle: 'hidden-inset'
});
- contentSize = w.getContentSize();
+ var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
});
});
});
it('can move the window out of screen', function() {
- var after;
w.setPosition(-10, -10);
- after = w.getPosition();
+ var after = w.getPosition();
assert.equal(after[0], -10);
assert.equal(after[1], -10);
});
it('can set the window larger than screen', function() {
- var after, size;
- size = screen.getPrimaryDisplay().size;
+ var size = screen.getPrimaryDisplay().size;
size.width += 100;
size.height += 100;
w.setSize(size.width, size.height);
- after = w.getSize();
+ var after = w.getSize();
assert.equal(after[0], size.width);
assert.equal(after[1], size.height);
});
describe('"preload" option', function() {
it('loads the script before other scripts in window', function(done) {
- var preload;
- preload = path.join(fixtures, 'module', 'set-global.js');
+ var preload = path.join(fixtures, 'module', 'set-global.js');
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'preload');
done();
describe('"node-integration" option', function() {
it('disables node integration when specified to false', function(done) {
- var preload;
- preload = path.join(fixtures, 'module', 'send-later.js');
+ var preload = path.join(fixtures, 'module', 'send-later.js');
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'undefined');
done();
describe('BrowserWindow options argument is optional', function() {
it('should create a window with default size (800x600)', function() {
- var size;
w.destroy();
w = new BrowserWindow();
- size = w.getSize();
+ var size = w.getSize();
assert.equal(size[0], 800);
assert.equal(size[1], 600);
});
var called = false;
var server = http.createServer(function(req, res) {
- var form;
server.close();
- form = new multiparty.Form();
+ var form = new multiparty.Form();
form.parse(req, function(error, fields) {
if (called) {
return;
describe('remote.require', function() {
it('should returns same object for the same module', function() {
- var dialog1, dialog2;
- dialog1 = remote.require('electron');
- dialog2 = remote.require('electron');
+ var dialog1 = remote.require('electron');
+ var dialog2 = remote.require('electron');
assert.equal(dialog1, dialog2);
});
});
it('can construct an object from its member', function() {
- var call, obj;
- call = remote.require(path.join(fixtures, 'module', 'call.js'));
- obj = new call.constructor;
+ var call = remote.require(path.join(fixtures, 'module', 'call.js'));
+ var obj = new call.constructor;
assert.equal(obj.test, 'test');
});
});
describe('session.cookies', function() {
it('should get cookies', function(done) {
- var server;
- server = http.createServer(function(req, res) {
+ var server = http.createServer(function(req, res) {
res.setHeader('Set-Cookie', ['0=0']);
res.end('finished');
server.close();
});
server.listen(0, '127.0.0.1', function() {
- var port;
- port = server.address().port;
+ var port = server.address().port;
w.loadURL(url + ":" + port);
w.webContents.on('did-finish-load', function() {
w.webContents.session.cookies.get({
});
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'));
w.webContents.on('did-finish-load', function() {
- var options;
- options = {
+ var options = {
origin: "file://",
storages: ['localstorage'],
quotas: ['persistent']
describe('webRequest module', function() {
var ses = session.defaultSession;
var server = http.createServer(function(req, res) {
- var content;
res.setHeader('Custom', ['Header']);
- content = req.url;
+ var content = req.url;
if (req.headers.accept === '*/*;test/header') {
content += 'header/received';
}
before(function(done) {
server.listen(0, '127.0.0.1', function() {
- var port;
- port = server.address().port;
+ var port = server.address().port;
defaultURL = "http://127.0.0.1:" + port + "/";
done();
});
type: 'string'
};
ses.webRequest.onBeforeRequest(function(details, callback) {
- var data;
assert.equal(details.url, defaultURL);
assert.equal(details.method, 'POST');
assert.equal(details.uploadData.length, 1);
- data = qs.parse(details.uploadData[0].bytes.toString());
+ var data = qs.parse(details.uploadData[0].bytes.toString());
assert.deepEqual(data, postData);
callback({
cancel: true
it('can change the request headers', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
- var requestHeaders;
- requestHeaders = details.requestHeaders;
+ var requestHeaders = details.requestHeaders;
requestHeaders.Accept = '*/*;test/header';
callback({
requestHeaders: requestHeaders
});
it('returns information of root', function() {
- var p, stats;
- p = path.join(fixtures, 'asar', 'a.asar');
- stats = fs.lstatSync(p);
+ var p = path.join(fixtures, 'asar', 'a.asar');
+ var stats = fs.lstatSync(p);
assert.equal(stats.isFile(), false);
assert.equal(stats.isDirectory(), true);
assert.equal(stats.isSymbolicLink(), false);
});
it('disables asar support in async API', function(done) {
- var dir, file;
- file = path.join(fixtures, 'asar', 'a.asar', 'file1');
- dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
+ var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
+ var dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
fs.readFile(file, function(error) {
assert.equal(error.code, errorName);
fs.lstat(file, function(error) {
var originalFs = require('original-fs');
it('treats .asar as file', function() {
- var file, stats;
- file = path.join(fixtures, 'asar', 'a.asar');
- stats = originalFs.statSync(file);
+ var file = path.join(fixtures, 'asar', 'a.asar');
+ var stats = originalFs.statSync(file);
assert(stats.isFile());
});
it('is available in forked scripts', function(done) {
- var child;
- child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
+ var child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
child.on('message', function(msg) {
assert.equal(msg, 'object');
done();
var b, sourceId;
sourceId = remote.getCurrentWindow().id;
listener = function(event) {
- var message;
window.removeEventListener('message', listener);
b.close();
- message = JSON.parse(event.data);
+ var message = JSON.parse(event.data);
assert.equal(message.data, 'testing');
assert.equal(message.origin, 'file://');
assert.equal(message.sourceEqualsOpener, true);
describe('creating a Uint8Array under browser side', function() {
it('does not crash', function() {
- var RUint8Array;
- RUint8Array = remote.getGlobal('Uint8Array');
+ var RUint8Array = remote.getGlobal('Uint8Array');
new RUint8Array;
});
});
describe('webgl', function() {
it('can be get as context in canvas', function() {
- var webgl;
if (process.platform === 'linux') {
return;
}
- webgl = document.createElement('canvas').getContext('webgl');
+ var webgl = document.createElement('canvas').getContext('webgl');
assert.notEqual(webgl, null);
});
});
describe('web workers', function() {
it('Worker can work', function(done) {
- var message, worker;
- worker = new Worker('../fixtures/workers/worker.js');
- message = 'ping';
+ var worker = new Worker('../fixtures/workers/worker.js');
+ var message = 'ping';
worker.onmessage = function(event) {
assert.equal(event.data, message);
worker.terminate();
});
it('SharedWorker can work', function(done) {
- var message, worker;
- worker = new SharedWorker('../fixtures/workers/shared_worker.js');
- message = 'ping';
+ var worker = new SharedWorker('../fixtures/workers/shared_worker.js');
+ var message = 'ping';
worker.port.onmessage = function(event) {
assert.equal(event.data, message);
done();
})
});
remote.getGlobal('setImmediate')(function() {
- var called;
- called = false;
+ var called = false;
Promise.resolve().then(function() {
done(called ? void 0 : new Error('wrong sequence'));
});
describe('child_process', function() {
describe('child_process.fork', function() {
it('works in current process', function(done) {
- var child;
- child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
+ var child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) {
assert.equal(msg, 'message');
done();
});
it('works in browser process', function(done) {
- var child, fork;
- fork = remote.require('child_process').fork;
- child = fork(path.join(fixtures, 'module', 'ping.js'));
+ var fork = remote.require('child_process').fork;
+ var child = fork(path.join(fixtures, 'module', 'ping.js'));
child.on('message', function(msg) {
assert.equal(msg, 'message');
done();
});
it('has String::localeCompare working in script', function(done) {
- var child;
- child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
+ var child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
child.on('message', function(msg) {
assert.deepEqual(msg, [0, -1, 1]);
done();
}
it('emit error when connect to a socket path without listeners', function(done) {
- var child, script, socketPath;
- socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
- script = path.join(fixtures, 'module', 'create_socket.js');
- child = child_process.fork(script, [socketPath]);
+ var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
+ var script = path.join(fixtures, 'module', 'create_socket.js');
+ var child = child_process.fork(script, [socketPath]);
child.on('exit', function(code) {
- var client;
assert.equal(code, 0);
- client = require('net').connect(socketPath);
+ var client = require('net').connect(socketPath);
client.on('error', function(error) {
assert.equal(error.code, 'ECONNREFUSED');
done();
describe('Buffer', function() {
it('can be created from WebKit external string', function() {
- var b, p;
- p = document.createElement('p');
+ var p = document.createElement('p');
p.innerText = '闲云潭影日悠悠,物换星移几度秋';
- b = new Buffer(p.innerText);
+ var b = new Buffer(p.innerText);
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋');
assert.equal(Buffer.byteLength(p.innerText), 45);
});
it('correctly parses external one-byte UTF8 string', function() {
- var b, p;
- p = document.createElement('p');
+ var p = document.createElement('p');
p.innerText = 'Jøhänñéß';
- b = new Buffer(p.innerText);
+ var b = new Buffer(p.innerText);
assert.equal(b.toString(), 'Jøhänñéß');
assert.equal(Buffer.byteLength(p.innerText), 13);
});
describe('preload attribute', function() {
it('loads the script before other scripts in window', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.message, 'function object object');
webview.removeEventListener('console-message', listener);
done();
});
it('receives ipc message in preload script', function(done) {
- var listener, listener2, message;
- message = 'boom!';
- listener = function(e) {
+ var message = 'boom!';
+ var listener = function(e) {
assert.equal(e.channel, 'pong');
assert.deepEqual(e.args, [message]);
webview.removeEventListener('ipc-message', listener);
done();
};
- listener2 = function() {
+ var listener2 = function() {
webview.send('ping', message);
webview.removeEventListener('did-finish-load', listener2);
};
describe('httpreferrer attribute', function() {
it('sets the referrer url', function(done) {
- var listener, referrer;
- referrer = 'http://github.com/';
- listener = function(e) {
+ var referrer = 'http://github.com/';
+ var listener = function(e) {
assert.equal(e.message, referrer);
webview.removeEventListener('console-message', listener);
done();
describe('useragent attribute', function() {
it('sets the user agent', function(done) {
- var listener, referrer;
- referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
- listener = function(e) {
+ var referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
+ var listener = function(e) {
assert.equal(e.message, referrer);
webview.removeEventListener('console-message', listener);
done();
describe('disablewebsecurity attribute', function() {
it('does not disable web security when not set', function(done) {
- var encoded, listener, src;
- src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
- encoded = btoa(unescape(encodeURIComponent(src)));
- listener = function(e) {
+ var src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
+ var encoded = btoa(unescape(encodeURIComponent(src)));
+ var listener = function(e) {
assert(/Not allowed to load local resource/.test(e.message));
webview.removeEventListener('console-message', listener);
done();
});
it('disables web security when set', function(done) {
- var encoded, listener, src;
- src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
- encoded = btoa(unescape(encodeURIComponent(src)));
- listener = function(e) {
+ var src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
+ var encoded = btoa(unescape(encodeURIComponent(src)));
+ var listener = function(e) {
assert.equal(e.message, 'ok');
webview.removeEventListener('console-message', listener);
done();
});
it('isolates storage for different id', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.message, " 0");
webview.removeEventListener('console-message', listener);
done();
});
it('uses current session storage when no id is provided', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.message, "one 1");
webview.removeEventListener('console-message', listener);
done();
describe('allowpopups attribute', function() {
it('can not open new window when not set', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.message, 'null');
webview.removeEventListener('console-message', listener);
done();
});
it('can open new window when set', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.message, 'window');
webview.removeEventListener('console-message', listener);
done();
describe('page-favicon-updated event', function() {
it('emits when favicon urls are received', function(done) {
webview.addEventListener('page-favicon-updated', function(e) {
- var pageUrl;
assert.equal(e.favicons.length, 2);
- pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
+ var pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
assert.equal(e.favicons[0], pageUrl);
done();
});
});
describe('did-navigate event', function() {
- var p, pageUrl;
- p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
+ var p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
p = p.replace(/\\/g, '/');
- pageUrl = url.format({
+ var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
});
describe('did-navigate-in-page event', function() {
it('emits when an anchor link is clicked', function(done) {
- var p, pageUrl;
- p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html');
+ var p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html');
p = p.replace(/\\/g, '/');
- pageUrl = url.format({
+ var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
});
it('emits when window.location.hash is changed', function(done) {
- var p, pageUrl;
- p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
+ var p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
p = p.replace(/\\/g, '/');
- pageUrl = url.format({
+ var pageUrl = url.format({
protocol: 'file',
slashes: true,
pathname: p
describe('devtools-opened event', function() {
it('should fire when webview.openDevTools() is called', function(done) {
- var listener;
- listener = function() {
+ var listener = function() {
webview.removeEventListener('devtools-opened', listener);
webview.closeDevTools();
done();
describe('devtools-closed event', function() {
it('should fire when webview.closeDevTools() is called', function(done) {
- var listener, listener2;
- listener2 = function() {
+ var listener2 = function() {
webview.removeEventListener('devtools-closed', listener2);
done();
};
- listener = function() {
+ var listener = function() {
webview.removeEventListener('devtools-opened', listener);
webview.closeDevTools();
};
describe('devtools-focused event', function() {
it('should fire when webview.openDevTools() is called', function(done) {
- var listener;
- listener = function() {
+ var listener = function() {
webview.removeEventListener('devtools-focused', listener);
webview.closeDevTools();
done();
describe('<webview>.reload()', function() {
it('should emit beforeunload handler', function(done) {
- var listener, listener2;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.channel, 'onbeforeunload');
webview.removeEventListener('ipc-message', listener);
done();
};
- listener2 = function() {
+ var listener2 = function() {
webview.reload();
webview.removeEventListener('did-finish-load', listener2);
};
describe('<webview>.clearHistory()', function() {
it('should clear the navigation history', function(done) {
- var listener;
- listener = function(e) {
+ var listener = function(e) {
assert.equal(e.channel, 'history');
assert.equal(e.args[0], 2);
assert(webview.canGoBack());
});
describe('basic auth', function() {
- var auth;
- auth = require('basic-auth');
+ var auth = require('basic-auth');
+
it('should authenticate with correct credentials', function(done) {
- var message, server;
- message = 'Authenticated';
- server = http.createServer(function(req, res) {
- var credentials;
- credentials = auth(req);
+ var message = 'Authenticated';
+ var server = http.createServer(function(req, res) {
+ var credentials = auth(req);
if (credentials.name === 'test' && credentials.pass === 'test') {
res.end(message);
} else {
server.close();
});
server.listen(0, '127.0.0.1', function() {
- var port;
- port = server.address().port;
+ var port = server.address().port;
webview.addEventListener('ipc-message', function(e) {
assert.equal(e.channel, message);
done();
describe('dom-ready event', function() {
it('emits when document is loaded', function(done) {
- var server;
- server = http.createServer(function() {});
+ var server = http.createServer(function() {});
server.listen(0, '127.0.0.1', function() {
- var port;
- port = server.address().port;
+ var port = server.address().port;
webview.addEventListener('dom-ready', function() {
done();
});
}
it('should support user gesture', function(done) {
- var listener, listener2;
- listener = function() {
+ var listener = function() {
webview.removeEventListener('enter-html-full-screen', listener);
done();
};
- listener2 = function() {
- var jsScript;
- jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
+ var listener2 = function() {
+ var jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
webview.executeJavaScript(jsScript, true);
webview.removeEventListener('did-finish-load', listener2);
};
describe('media-started-playing media-paused events', function() {
it('emits when audio starts and stops playing', function(done) {
- var audioPlayed;
- audioPlayed = false;
+ var audioPlayed = false;
webview.addEventListener('media-started-playing', function() {
audioPlayed = true;
});
describe('found-in-page event', function() {
it('emits when a request is made', function(done) {
- var listener, listener2, requestId;
- requestId = null;
- listener = function(e) {
+ var requestId = null;
+ var listener = function(e) {
assert.equal(e.result.requestId, requestId);
if (e.result.finalUpdate) {
assert.equal(e.result.matches, 3);
done();
}
};
- listener2 = function() {
+ var listener2 = function() {
requestId = webview.findInPage("virtual");
};
webview.addEventListener('found-in-page', listener);