Update var declarations

This commit is contained in:
Kevin Sawicki 2016-02-17 09:27:25 -08:00
parent 54d7c580bd
commit 31028ab636
10 changed files with 110 additions and 181 deletions

View file

@ -66,11 +66,10 @@ describe('app module', function() {
}); });
it('emits a process exit event with the code', function(done) { it('emits a process exit event with the code', function(done) {
var appPath, electronPath, output; var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app'); var electronPath = remote.getGlobal('process').execPath;
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) {
output += data; output += data;
}); });

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

@ -37,9 +37,8 @@ describe('crash-reporter module', function() {
var called = false; var called = false;
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
var form;
server.close(); server.close();
form = new multiparty.Form(); var form = new multiparty.Form();
form.parse(req, function(error, fields) { form.parse(req, function(error, fields) {
if (called) { if (called) {
return; return;

View file

@ -20,9 +20,8 @@ describe('ipc module', function() {
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); assert.equal(dialog1, dialog2);
}); });
@ -58,9 +57,8 @@ describe('ipc module', function() {
}); });
it('can construct an object from its member', function() { it('can construct an object from its member', function() {
var call, obj; var call = remote.require(path.join(fixtures, 'module', 'call.js'));
call = remote.require(path.join(fixtures, 'module', 'call.js')); var obj = new call.constructor;
obj = new call.constructor;
assert.equal(obj.test, 'test'); assert.equal(obj.test, 'test');
}); });
}); });

View file

@ -31,15 +31,13 @@ describe('session module', function() {
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');
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;
w.loadURL(url + ":" + port); w.loadURL(url + ":" + port);
w.webContents.on('did-finish-load', function() { w.webContents.on('did-finish-load', function() {
w.webContents.session.cookies.get({ w.webContents.session.cookies.get({
@ -136,8 +134,7 @@ describe('session module', function() {
}); });
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html')); w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'));
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']

View file

@ -7,9 +7,8 @@ const session = remote.session;
describe('webRequest module', function() { describe('webRequest module', function() {
var ses = session.defaultSession; var ses = session.defaultSession;
var server = http.createServer(function(req, res) { var 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';
} }
@ -19,8 +18,7 @@ describe('webRequest module', function() {
before(function(done) { before(function(done) {
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 + "/";
done(); done();
}); });
@ -109,11 +107,10 @@ describe('webRequest module', function() {
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);
callback({ callback({
cancel: true cancel: true
@ -178,8 +175,7 @@ describe('webRequest module', function() {
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';
callback({ callback({
requestHeaders: requestHeaders requestHeaders: requestHeaders

View file

@ -128,9 +128,8 @@ describe('asar package', function() {
}); });
it('returns information of root', function() { it('returns information of root', function() {
var p, stats; var p = path.join(fixtures, 'asar', 'a.asar');
p = path.join(fixtures, 'asar', 'a.asar'); var stats = fs.lstatSync(p);
stats = fs.lstatSync(p);
assert.equal(stats.isFile(), false); assert.equal(stats.isFile(), false);
assert.equal(stats.isDirectory(), true); assert.equal(stats.isDirectory(), true);
assert.equal(stats.isSymbolicLink(), false); assert.equal(stats.isSymbolicLink(), false);
@ -607,9 +606,8 @@ describe('asar package', function() {
}); });
it('disables asar support in async API', function(done) { it('disables asar support in async API', function(done) {
var dir, file; var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
file = path.join(fixtures, 'asar', 'a.asar', 'file1'); var dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
fs.readFile(file, function(error) { fs.readFile(file, function(error) {
assert.equal(error.code, errorName); assert.equal(error.code, errorName);
fs.lstat(file, function(error) { fs.lstat(file, function(error) {
@ -737,15 +735,13 @@ describe('asar package', function() {
var originalFs = require('original-fs'); var originalFs = require('original-fs');
it('treats .asar as file', function() { it('treats .asar as file', function() {
var file, stats; var file = path.join(fixtures, 'asar', 'a.asar');
file = path.join(fixtures, 'asar', 'a.asar'); var stats = originalFs.statSync(file);
stats = originalFs.statSync(file);
assert(stats.isFile()); assert(stats.isFile());
}); });
it('is available in forked scripts', function(done) { it('is available in forked scripts', function(done) {
var child; var child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
child.on('message', function(msg) { child.on('message', function(msg) {
assert.equal(msg, 'object'); assert.equal(msg, 'object');
done(); done();

View file

@ -211,10 +211,9 @@ describe('chromium feature', function() {
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);
@ -247,28 +246,25 @@ describe('chromium feature', function() {
describe('creating a Uint8Array under browser side', function() { describe('creating a Uint8Array under browser side', function() {
it('does not crash', function() { it('does not crash', function() {
var RUint8Array; var RUint8Array = remote.getGlobal('Uint8Array');
RUint8Array = remote.getGlobal('Uint8Array');
new RUint8Array; new RUint8Array;
}); });
}); });
describe('webgl', function() { describe('webgl', function() {
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');
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();
@ -278,9 +274,8 @@ describe('chromium feature', function() {
}); });
it('SharedWorker can work', function(done) { it('SharedWorker can work', function(done) {
var message, worker; var worker = new SharedWorker('../fixtures/workers/shared_worker.js');
worker = new SharedWorker('../fixtures/workers/shared_worker.js'); var message = 'ping';
message = 'ping';
worker.port.onmessage = function(event) { worker.port.onmessage = function(event) {
assert.equal(event.data, message); assert.equal(event.data, message);
done(); done();
@ -377,8 +372,7 @@ describe('chromium feature', function() {
}) })
}); });
remote.getGlobal('setImmediate')(function() { remote.getGlobal('setImmediate')(function() {
var called; var called = false;
called = false;
Promise.resolve().then(function() { Promise.resolve().then(function() {
done(called ? void 0 : new Error('wrong sequence')); done(called ? void 0 : new Error('wrong sequence'));
}); });

View file

@ -11,8 +11,7 @@ describe('node feature', function() {
describe('child_process', function() { describe('child_process', function() {
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');
done(); done();
@ -51,9 +50,8 @@ describe('node feature', function() {
}); });
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');
done(); done();
@ -62,8 +60,7 @@ describe('node feature', function() {
}); });
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]);
done(); done();
@ -169,14 +166,12 @@ describe('node feature', function() {
} }
it('emit error when connect to a socket path without listeners', function(done) { it('emit error when connect to a socket path without listeners', function(done) {
var child, script, socketPath; var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock'); var script = path.join(fixtures, 'module', 'create_socket.js');
script = path.join(fixtures, 'module', 'create_socket.js'); var child = child_process.fork(script, [socketPath]);
child = child_process.fork(script, [socketPath]);
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);
client.on('error', function(error) { client.on('error', function(error) {
assert.equal(error.code, 'ECONNREFUSED'); assert.equal(error.code, 'ECONNREFUSED');
done(); done();
@ -187,19 +182,17 @@ describe('node feature', function() {
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(), '闲云潭影日悠悠,物换星移几度秋');
assert.equal(Buffer.byteLength(p.innerText), 45); assert.equal(Buffer.byteLength(p.innerText), 45);
}); });
it('correctly parses external one-byte UTF8 string', function() { it('correctly parses external one-byte UTF8 string', function() {
var b, p; var p = document.createElement('p');
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ñéß');
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);