autoformat more files
This commit is contained in:
parent
06b556c34c
commit
f35f362272
47 changed files with 4458 additions and 4459 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,63 +1,63 @@
|
|||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
|
||||
const clipboard = require('electron').clipboard;
|
||||
const nativeImage = require('electron').nativeImage;
|
||||
const clipboard = require('electron').clipboard
|
||||
const nativeImage = require('electron').nativeImage
|
||||
|
||||
describe('clipboard module', function() {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
describe('clipboard module', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
|
||||
describe('clipboard.readImage()', function() {
|
||||
it('returns NativeImage intance', function() {
|
||||
var p = path.join(fixtures, 'assets', 'logo.png');
|
||||
var i = nativeImage.createFromPath(p);
|
||||
clipboard.writeImage(p);
|
||||
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
|
||||
});
|
||||
});
|
||||
describe('clipboard.readImage()', function () {
|
||||
it('returns NativeImage intance', function () {
|
||||
var p = path.join(fixtures, 'assets', 'logo.png')
|
||||
var i = nativeImage.createFromPath(p)
|
||||
clipboard.writeImage(p)
|
||||
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
|
||||
})
|
||||
})
|
||||
|
||||
describe('clipboard.readText()', function() {
|
||||
it('returns unicode string correctly', function() {
|
||||
var text = '千江有水千江月,万里无云万里天';
|
||||
clipboard.writeText(text);
|
||||
assert.equal(clipboard.readText(), text);
|
||||
});
|
||||
});
|
||||
describe('clipboard.readText()', function () {
|
||||
it('returns unicode string correctly', function () {
|
||||
var text = '千江有水千江月,万里无云万里天'
|
||||
clipboard.writeText(text)
|
||||
assert.equal(clipboard.readText(), text)
|
||||
})
|
||||
})
|
||||
|
||||
describe('clipboard.readHtml()', function() {
|
||||
it('returns markup correctly', function() {
|
||||
var text = '<string>Hi</string>';
|
||||
var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><string>Hi</string>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><string>Hi</string>' : '<string>Hi</string>';
|
||||
clipboard.writeHtml(text);
|
||||
assert.equal(clipboard.readHtml(), markup);
|
||||
});
|
||||
});
|
||||
describe('clipboard.readHtml()', function () {
|
||||
it('returns markup correctly', function () {
|
||||
var text = '<string>Hi</string>'
|
||||
var markup = process.platform === 'darwin' ? "<meta charset='utf-8'><string>Hi</string>" : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><string>Hi</string>' : '<string>Hi</string>'
|
||||
clipboard.writeHtml(text)
|
||||
assert.equal(clipboard.readHtml(), markup)
|
||||
})
|
||||
})
|
||||
|
||||
describe('clipboard.readRtf', function() {
|
||||
it('returns rtf text correctly', function() {
|
||||
var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}";
|
||||
clipboard.writeRtf(rtf);
|
||||
assert.equal(clipboard.readRtf(), rtf);
|
||||
});
|
||||
});
|
||||
describe('clipboard.readRtf', function () {
|
||||
it('returns rtf text correctly', function () {
|
||||
var rtf = '{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}'
|
||||
clipboard.writeRtf(rtf)
|
||||
assert.equal(clipboard.readRtf(), rtf)
|
||||
})
|
||||
})
|
||||
|
||||
describe('clipboard.write()', function() {
|
||||
it('returns data correctly', function() {
|
||||
var text = 'test';
|
||||
var rtf = '{\\rtf1\\utf8 text}';
|
||||
var p = path.join(fixtures, 'assets', 'logo.png');
|
||||
var i = nativeImage.createFromPath(p);
|
||||
var markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>';
|
||||
describe('clipboard.write()', function () {
|
||||
it('returns data correctly', function () {
|
||||
var text = 'test'
|
||||
var rtf = '{\\rtf1\\utf8 text}'
|
||||
var p = path.join(fixtures, 'assets', 'logo.png')
|
||||
var i = nativeImage.createFromPath(p)
|
||||
var markup = process.platform === 'darwin' ? "<meta charset='utf-8'><b>Hi</b>" : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>'
|
||||
clipboard.write({
|
||||
text: "test",
|
||||
text: 'test',
|
||||
html: '<b>Hi</b>',
|
||||
rtf: '{\\rtf1\\utf8 text}',
|
||||
image: p
|
||||
});
|
||||
assert.equal(clipboard.readText(), text);
|
||||
assert.equal(clipboard.readHtml(), markup);
|
||||
assert.equal(clipboard.readRtf(), rtf);
|
||||
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
assert.equal(clipboard.readText(), text)
|
||||
assert.equal(clipboard.readHtml(), markup)
|
||||
assert.equal(clipboard.readRtf(), rtf)
|
||||
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const multiparty = require('multiparty');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const multiparty = require('multiparty')
|
||||
const path = require('path')
|
||||
const url = require('url')
|
||||
|
||||
const remote = require('electron').remote;
|
||||
const app = remote.require('electron').app;
|
||||
const crashReporter = remote.require('electron').crashReporter;
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow;
|
||||
const remote = require('electron').remote
|
||||
const app = remote.require('electron').app
|
||||
const crashReporter = remote.require('electron').crashReporter
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||
|
||||
describe('crash-reporter module', function() {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
var w = null;
|
||||
describe('crash-reporter module', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
var w = null
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
w.destroy();
|
||||
});
|
||||
afterEach(function () {
|
||||
w.destroy()
|
||||
})
|
||||
|
||||
if (process.mas) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
var isCI = remote.getGlobal('isCi');
|
||||
var isCI = remote.getGlobal('isCi')
|
||||
if (isCI) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
it('should send minidump when renderer crashes', function(done) {
|
||||
this.timeout(120000);
|
||||
it('should send minidump when renderer crashes', function (done) {
|
||||
this.timeout(120000)
|
||||
|
||||
var called = false;
|
||||
var server = http.createServer(function(req, res) {
|
||||
server.close();
|
||||
var form = new multiparty.Form();
|
||||
form.parse(req, function(error, fields) {
|
||||
var called = false
|
||||
var server = http.createServer(function (req, res) {
|
||||
server.close()
|
||||
var form = new multiparty.Form()
|
||||
form.parse(req, function (error, fields) {
|
||||
if (called) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
called = true;
|
||||
assert.equal(fields['prod'], 'Electron');
|
||||
assert.equal(fields['ver'], process.versions['electron']);
|
||||
assert.equal(fields['process_type'], 'renderer');
|
||||
assert.equal(fields['platform'], process.platform);
|
||||
assert.equal(fields['extra1'], 'extra1');
|
||||
assert.equal(fields['extra2'], 'extra2');
|
||||
assert.equal(fields['_productName'], 'Zombies');
|
||||
assert.equal(fields['_companyName'], 'Umbrella Corporation');
|
||||
assert.equal(fields['_version'], app.getVersion());
|
||||
res.end('abc-123-def');
|
||||
done();
|
||||
});
|
||||
});
|
||||
var port = remote.process.port;
|
||||
server.listen(port, '127.0.0.1', function() {
|
||||
port = server.address().port;
|
||||
remote.process.port = port;
|
||||
called = true
|
||||
assert.equal(fields['prod'], 'Electron')
|
||||
assert.equal(fields['ver'], process.versions['electron'])
|
||||
assert.equal(fields['process_type'], 'renderer')
|
||||
assert.equal(fields['platform'], process.platform)
|
||||
assert.equal(fields['extra1'], 'extra1')
|
||||
assert.equal(fields['extra2'], 'extra2')
|
||||
assert.equal(fields['_productName'], 'Zombies')
|
||||
assert.equal(fields['_companyName'], 'Umbrella Corporation')
|
||||
assert.equal(fields['_version'], app.getVersion())
|
||||
res.end('abc-123-def')
|
||||
done()
|
||||
})
|
||||
})
|
||||
var port = remote.process.port
|
||||
server.listen(port, '127.0.0.1', function () {
|
||||
port = server.address().port
|
||||
remote.process.port = port
|
||||
const crashUrl = url.format({
|
||||
protocol: 'file',
|
||||
pathname: path.join(fixtures, 'api', 'crash.html'),
|
||||
search: "?port=" + port
|
||||
});
|
||||
search: '?port=' + port
|
||||
})
|
||||
if (process.platform === 'darwin') {
|
||||
crashReporter.start({
|
||||
companyName: 'Umbrella Corporation',
|
||||
submitURL: "http://127.0.0.1:" + port
|
||||
});
|
||||
submitURL: 'http://127.0.0.1:' + port
|
||||
})
|
||||
}
|
||||
w.loadURL(crashUrl);
|
||||
});
|
||||
});
|
||||
w.loadURL(crashUrl)
|
||||
})
|
||||
})
|
||||
|
||||
describe(".start(options)", function() {
|
||||
it('requires that the companyName and submitURL options be specified', function() {
|
||||
assert.throws(function() {
|
||||
describe('.start(options)', function () {
|
||||
it('requires that the companyName and submitURL options be specified', function () {
|
||||
assert.throws(function () {
|
||||
crashReporter.start({
|
||||
companyName: 'Missing submitURL'
|
||||
});
|
||||
});
|
||||
assert.throws(function() {
|
||||
})
|
||||
})
|
||||
assert.throws(function () {
|
||||
crashReporter.start({
|
||||
submitURL: 'Missing companyName'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,133 +1,133 @@
|
|||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const BrowserWindow = require('electron').remote.BrowserWindow;
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const BrowserWindow = require('electron').remote.BrowserWindow
|
||||
|
||||
describe('debugger module', function() {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
var w = null;
|
||||
describe('debugger module', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
var w = null
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
if (w != null) {
|
||||
w.destroy();
|
||||
w.destroy()
|
||||
}
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
width: 400,
|
||||
height: 400
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
if (w != null) {
|
||||
w.destroy();
|
||||
w.destroy()
|
||||
}
|
||||
w = null;
|
||||
});
|
||||
w = null
|
||||
})
|
||||
|
||||
describe('debugger.attach', function() {
|
||||
it('fails when devtools is already open', function(done) {
|
||||
w.webContents.on('did-finish-load', function() {
|
||||
w.webContents.openDevTools();
|
||||
describe('debugger.attach', function () {
|
||||
it('fails when devtools is already open', function (done) {
|
||||
w.webContents.on('did-finish-load', function () {
|
||||
w.webContents.openDevTools()
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
assert(w.webContents.debugger.isAttached());
|
||||
done();
|
||||
assert(w.webContents.debugger.isAttached())
|
||||
done()
|
||||
}
|
||||
});
|
||||
w.webContents.loadURL('file://' + path.join(fixtures, 'pages', 'a.html'));
|
||||
});
|
||||
})
|
||||
w.webContents.loadURL('file://' + path.join(fixtures, 'pages', 'a.html'))
|
||||
})
|
||||
|
||||
it('fails when protocol version is not supported', function(done) {
|
||||
it('fails when protocol version is not supported', function (done) {
|
||||
try {
|
||||
w.webContents.debugger.attach("2.0");
|
||||
w.webContents.debugger.attach('2.0')
|
||||
} catch(err) {
|
||||
assert(!w.webContents.debugger.isAttached());
|
||||
done();
|
||||
assert(!w.webContents.debugger.isAttached())
|
||||
done()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
it('attaches when no protocol version is specified', function(done) {
|
||||
it('attaches when no protocol version is specified', function (done) {
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
done('unexpected error : ' + err);
|
||||
done('unexpected error : ' + err)
|
||||
}
|
||||
assert(w.webContents.debugger.isAttached());
|
||||
done();
|
||||
});
|
||||
});
|
||||
assert(w.webContents.debugger.isAttached())
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('debugger.detach', function() {
|
||||
it('fires detach event', function(done) {
|
||||
w.webContents.debugger.on('detach', function(e, reason) {
|
||||
assert.equal(reason, 'target closed');
|
||||
assert(!w.webContents.debugger.isAttached());
|
||||
done();
|
||||
});
|
||||
describe('debugger.detach', function () {
|
||||
it('fires detach event', function (done) {
|
||||
w.webContents.debugger.on('detach', function (e, reason) {
|
||||
assert.equal(reason, 'target closed')
|
||||
assert(!w.webContents.debugger.isAttached())
|
||||
done()
|
||||
})
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
done('unexpected error : ' + err);
|
||||
done('unexpected error : ' + err)
|
||||
}
|
||||
w.webContents.debugger.detach();
|
||||
});
|
||||
});
|
||||
w.webContents.debugger.detach()
|
||||
})
|
||||
})
|
||||
|
||||
describe('debugger.sendCommand', function() {
|
||||
it('retuns response', function(done) {
|
||||
w.webContents.loadURL('about:blank');
|
||||
describe('debugger.sendCommand', function () {
|
||||
it('retuns response', function (done) {
|
||||
w.webContents.loadURL('about:blank')
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
done('unexpected error : ' + err);
|
||||
done('unexpected error : ' + err)
|
||||
}
|
||||
var callback = function (err, res) {
|
||||
assert(!res.wasThrown)
|
||||
assert.equal(res.result.value, 6)
|
||||
w.webContents.debugger.detach()
|
||||
done()
|
||||
}
|
||||
var callback = function(err, res) {
|
||||
assert(!res.wasThrown);
|
||||
assert.equal(res.result.value, 6);
|
||||
w.webContents.debugger.detach();
|
||||
done();
|
||||
};
|
||||
const params = {
|
||||
"expression": "4+2",
|
||||
};
|
||||
w.webContents.debugger.sendCommand("Runtime.evaluate", params, callback);
|
||||
});
|
||||
'expression': '4+2',
|
||||
}
|
||||
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
|
||||
})
|
||||
|
||||
it('fires message event', function(done) {
|
||||
it('fires message event', function (done) {
|
||||
var url = process.platform != 'win32' ?
|
||||
'file://' + path.join(fixtures, 'pages', 'a.html') :
|
||||
'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/');
|
||||
w.webContents.loadURL(url);
|
||||
'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')
|
||||
w.webContents.loadURL(url)
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
done('unexpected error : ' + err);
|
||||
done('unexpected error : ' + err)
|
||||
}
|
||||
w.webContents.debugger.on('message', function(e, method, params) {
|
||||
if(method == "Console.messageAdded") {
|
||||
assert.equal(params.message.type, 'log');
|
||||
assert.equal(params.message.url, url);
|
||||
assert.equal(params.message.text, 'a');
|
||||
w.webContents.debugger.detach();
|
||||
done();
|
||||
w.webContents.debugger.on('message', function (e, method, params) {
|
||||
if (method == 'Console.messageAdded') {
|
||||
assert.equal(params.message.type, 'log')
|
||||
assert.equal(params.message.url, url)
|
||||
assert.equal(params.message.text, 'a')
|
||||
w.webContents.debugger.detach()
|
||||
done()
|
||||
}
|
||||
});
|
||||
w.webContents.debugger.sendCommand("Console.enable");
|
||||
});
|
||||
})
|
||||
w.webContents.debugger.sendCommand('Console.enable')
|
||||
})
|
||||
|
||||
it('returns error message when command fails', function(done) {
|
||||
w.webContents.loadURL('about:blank');
|
||||
it('returns error message when command fails', function (done) {
|
||||
w.webContents.loadURL('about:blank')
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
w.webContents.debugger.attach()
|
||||
} catch(err) {
|
||||
done('unexpected error : ' + err);
|
||||
done('unexpected error : ' + err)
|
||||
}
|
||||
w.webContents.debugger.sendCommand("Test", function(err) {
|
||||
assert.equal(err.message, '\'Test\' wasn\'t found');
|
||||
w.webContents.debugger.detach();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
w.webContents.debugger.sendCommand('Test', function (err) {
|
||||
assert.equal(err.message, "'Test' wasn't found")
|
||||
w.webContents.debugger.detach()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
const assert = require('assert');
|
||||
const deprecations = require('electron').deprecations;
|
||||
const assert = require('assert')
|
||||
const deprecations = require('electron').deprecations
|
||||
|
||||
describe('deprecations', function() {
|
||||
beforeEach(function() {
|
||||
deprecations.setHandler(null);
|
||||
process.throwDeprecation = true;
|
||||
});
|
||||
describe('deprecations', function () {
|
||||
beforeEach(function () {
|
||||
deprecations.setHandler(null)
|
||||
process.throwDeprecation = true
|
||||
})
|
||||
|
||||
it('allows a deprecation handler function to be specified', function() {
|
||||
var messages = [];
|
||||
it('allows a deprecation handler function to be specified', function () {
|
||||
var messages = []
|
||||
|
||||
deprecations.setHandler(function (message) {
|
||||
messages.push(message);
|
||||
});
|
||||
messages.push(message)
|
||||
})
|
||||
|
||||
require('electron').webFrame.registerUrlSchemeAsSecure('some-scheme');
|
||||
require('electron').webFrame.registerUrlSchemeAsSecure('some-scheme')
|
||||
|
||||
assert.deepEqual(messages, ['registerUrlSchemeAsSecure is deprecated. Use registerURLSchemeAsSecure instead.']);
|
||||
});
|
||||
assert.deepEqual(messages, ['registerUrlSchemeAsSecure is deprecated. Use registerURLSchemeAsSecure instead.'])
|
||||
})
|
||||
|
||||
it('throws an exception if no deprecation handler is specified', function() {
|
||||
assert.throws(function() {
|
||||
require('electron').webFrame.registerUrlSchemeAsPrivileged('some-scheme');
|
||||
}, "registerUrlSchemeAsPrivileged is deprecated. Use registerURLSchemeAsPrivileged instead.");
|
||||
});
|
||||
});
|
||||
it('throws an exception if no deprecation handler is specified', function () {
|
||||
assert.throws(function () {
|
||||
require('electron').webFrame.registerUrlSchemeAsPrivileged('some-scheme')
|
||||
}, 'registerUrlSchemeAsPrivileged is deprecated. Use registerURLSchemeAsPrivileged instead.')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
const assert = require('assert');
|
||||
const desktopCapturer = require('electron').desktopCapturer;
|
||||
const assert = require('assert')
|
||||
const desktopCapturer = require('electron').desktopCapturer
|
||||
|
||||
describe('desktopCapturer', function() {
|
||||
it('should return a non-empty array of sources', function(done) {
|
||||
describe('desktopCapturer', function () {
|
||||
it('should return a non-empty array of sources', function (done) {
|
||||
desktopCapturer.getSources({
|
||||
types: ['window', 'screen']
|
||||
}, function(error, sources) {
|
||||
assert.equal(error, null);
|
||||
assert.notEqual(sources.length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, function (error, sources) {
|
||||
assert.equal(error, null)
|
||||
assert.notEqual(sources.length, 0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('does not throw an error when called more than once (regression)', function(done) {
|
||||
var callCount = 0;
|
||||
it('does not throw an error when called more than once (regression)', function (done) {
|
||||
var callCount = 0
|
||||
var callback = function (error, sources) {
|
||||
callCount++;
|
||||
assert.equal(error, null);
|
||||
assert.notEqual(sources.length, 0);
|
||||
if (callCount === 2) done();
|
||||
};
|
||||
callCount++
|
||||
assert.equal(error, null)
|
||||
assert.notEqual(sources.length, 0)
|
||||
if (callCount === 2) done()
|
||||
}
|
||||
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, callback);
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, callback);
|
||||
});
|
||||
});
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,210 +1,210 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const remote = require('electron').remote;
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
const remote = require('electron').remote
|
||||
|
||||
const ipcMain = remote.require('electron').ipcMain;
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow;
|
||||
const ipcMain = remote.require('electron').ipcMain
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||
|
||||
const comparePaths = function(path1, path2) {
|
||||
const comparePaths = function (path1, path2) {
|
||||
if (process.platform === 'win32') {
|
||||
path1 = path1.toLowerCase();
|
||||
path2 = path2.toLowerCase();
|
||||
path1 = path1.toLowerCase()
|
||||
path2 = path2.toLowerCase()
|
||||
}
|
||||
assert.equal(path1, path2);
|
||||
};
|
||||
assert.equal(path1, path2)
|
||||
}
|
||||
|
||||
describe('ipc module', function() {
|
||||
var fixtures = path.join(__dirname, 'fixtures');
|
||||
describe('ipc module', function () {
|
||||
var fixtures = path.join(__dirname, 'fixtures')
|
||||
|
||||
describe('remote.require', function() {
|
||||
it('should returns same object for the same module', function() {
|
||||
var dialog1 = remote.require('electron');
|
||||
var dialog2 = remote.require('electron');
|
||||
assert.equal(dialog1, dialog2);
|
||||
});
|
||||
describe('remote.require', function () {
|
||||
it('should returns same object for the same module', function () {
|
||||
var dialog1 = remote.require('electron')
|
||||
var dialog2 = remote.require('electron')
|
||||
assert.equal(dialog1, dialog2)
|
||||
})
|
||||
|
||||
it('should work when object contains id property', function() {
|
||||
var a = remote.require(path.join(fixtures, 'module', 'id.js'));
|
||||
assert.equal(a.id, 1127);
|
||||
});
|
||||
it('should work when object contains id property', function () {
|
||||
var a = remote.require(path.join(fixtures, 'module', 'id.js'))
|
||||
assert.equal(a.id, 1127)
|
||||
})
|
||||
|
||||
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.paths[0]), path.resolve(__dirname, 'static', 'node_modules'));
|
||||
});
|
||||
});
|
||||
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.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote.createFunctionWithReturnValue', function() {
|
||||
it('should be called in browser synchronously', function() {
|
||||
var buf = new Buffer('test');
|
||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'));
|
||||
var result = call.call(remote.createFunctionWithReturnValue(buf));
|
||||
assert.equal(result.constructor.name, 'Buffer');
|
||||
});
|
||||
});
|
||||
describe('remote.createFunctionWithReturnValue', function () {
|
||||
it('should be called in browser synchronously', function () {
|
||||
var buf = new Buffer('test')
|
||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||
var result = call.call(remote.createFunctionWithReturnValue(buf))
|
||||
assert.equal(result.constructor.name, 'Buffer')
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote object in renderer', function() {
|
||||
it('can change its properties', function() {
|
||||
var property = remote.require(path.join(fixtures, 'module', 'property.js'));
|
||||
assert.equal(property.property, 1127);
|
||||
property.property = 1007;
|
||||
assert.equal(property.property, 1007);
|
||||
var property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
|
||||
assert.equal(property2.property, 1007);
|
||||
property.property = 1127;
|
||||
});
|
||||
describe('remote object in renderer', function () {
|
||||
it('can change its properties', function () {
|
||||
var property = remote.require(path.join(fixtures, 'module', 'property.js'))
|
||||
assert.equal(property.property, 1127)
|
||||
property.property = 1007
|
||||
assert.equal(property.property, 1007)
|
||||
var property2 = remote.require(path.join(fixtures, 'module', 'property.js'))
|
||||
assert.equal(property2.property, 1007)
|
||||
property.property = 1127
|
||||
})
|
||||
|
||||
it('can construct an object from its member', function() {
|
||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'));
|
||||
var obj = new call.constructor;
|
||||
assert.equal(obj.test, 'test');
|
||||
});
|
||||
it('can construct an object from its member', function () {
|
||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||
var obj = new call.constructor
|
||||
assert.equal(obj.test, 'test')
|
||||
})
|
||||
|
||||
it('can reassign and delete its member functions', function() {
|
||||
var remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'));
|
||||
assert.equal(remoteFunctions.aFunction(), 1127);
|
||||
it('can reassign and delete its member functions', function () {
|
||||
var remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'))
|
||||
assert.equal(remoteFunctions.aFunction(), 1127)
|
||||
|
||||
remoteFunctions.aFunction = function () { return 1234; };
|
||||
assert.equal(remoteFunctions.aFunction(), 1234);
|
||||
remoteFunctions.aFunction = function () { return 1234; }
|
||||
assert.equal(remoteFunctions.aFunction(), 1234)
|
||||
|
||||
assert.equal(delete remoteFunctions.aFunction, true);
|
||||
});
|
||||
});
|
||||
assert.equal(delete remoteFunctions.aFunction, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote value in browser', function() {
|
||||
var print = path.join(fixtures, 'module', 'print_name.js');
|
||||
describe('remote value in browser', function () {
|
||||
var print = path.join(fixtures, 'module', 'print_name.js')
|
||||
|
||||
it('keeps its constructor name for objects', function() {
|
||||
var buf = new Buffer('test');
|
||||
var print_name = remote.require(print);
|
||||
assert.equal(print_name.print(buf), 'Buffer');
|
||||
});
|
||||
it('keeps its constructor name for objects', function () {
|
||||
var buf = new Buffer('test')
|
||||
var print_name = remote.require(print)
|
||||
assert.equal(print_name.print(buf), 'Buffer')
|
||||
})
|
||||
|
||||
it('supports instanceof Date', function() {
|
||||
var now = new Date();
|
||||
var print_name = remote.require(print);
|
||||
assert.equal(print_name.print(now), 'Date');
|
||||
assert.deepEqual(print_name.echo(now), now);
|
||||
});
|
||||
});
|
||||
it('supports instanceof Date', function () {
|
||||
var now = new Date()
|
||||
var print_name = remote.require(print)
|
||||
assert.equal(print_name.print(now), 'Date')
|
||||
assert.deepEqual(print_name.echo(now), now)
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote promise', function() {
|
||||
it('can be used as promise in each side', function(done) {
|
||||
var promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
|
||||
promise.twicePromise(Promise.resolve(1234)).then(function(value) {
|
||||
assert.equal(value, 2468);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('remote promise', function () {
|
||||
it('can be used as promise in each side', function (done) {
|
||||
var promise = remote.require(path.join(fixtures, 'module', 'promise.js'))
|
||||
promise.twicePromise(Promise.resolve(1234)).then(function (value) {
|
||||
assert.equal(value, 2468)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote webContents', function() {
|
||||
it('can return same object with different getters', function() {
|
||||
var contents1 = remote.getCurrentWindow().webContents;
|
||||
var contents2 = remote.getCurrentWebContents();
|
||||
assert(contents1 == contents2);
|
||||
});
|
||||
});
|
||||
describe('remote webContents', function () {
|
||||
it('can return same object with different getters', function () {
|
||||
var contents1 = remote.getCurrentWindow().webContents
|
||||
var contents2 = remote.getCurrentWebContents()
|
||||
assert(contents1 == contents2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote class', function() {
|
||||
let cl = remote.require(path.join(fixtures, 'module', 'class.js'));
|
||||
let base = cl.base;
|
||||
let derived = cl.derived;
|
||||
describe('remote class', function () {
|
||||
let cl = remote.require(path.join(fixtures, 'module', 'class.js'))
|
||||
let base = cl.base
|
||||
let derived = cl.derived
|
||||
|
||||
it('can get methods', function() {
|
||||
assert.equal(base.method(), 'method');
|
||||
});
|
||||
it('can get methods', function () {
|
||||
assert.equal(base.method(), 'method')
|
||||
})
|
||||
|
||||
it('can get properties', function() {
|
||||
assert.equal(base.readonly, 'readonly');
|
||||
});
|
||||
it('can get properties', function () {
|
||||
assert.equal(base.readonly, 'readonly')
|
||||
})
|
||||
|
||||
it('can change properties', function() {
|
||||
assert.equal(base.value, 'old');
|
||||
base.value = 'new';
|
||||
assert.equal(base.value, 'new');
|
||||
base.value = 'old';
|
||||
});
|
||||
it('can change properties', function () {
|
||||
assert.equal(base.value, 'old')
|
||||
base.value = 'new'
|
||||
assert.equal(base.value, 'new')
|
||||
base.value = 'old'
|
||||
})
|
||||
|
||||
it('has unenumerable methods', function() {
|
||||
assert(!base.hasOwnProperty('method'));
|
||||
assert(Object.getPrototypeOf(base).hasOwnProperty('method'));
|
||||
});
|
||||
it('has unenumerable methods', function () {
|
||||
assert(!base.hasOwnProperty('method'))
|
||||
assert(Object.getPrototypeOf(base).hasOwnProperty('method'))
|
||||
})
|
||||
|
||||
it('keeps prototype chain in derived class', function() {
|
||||
assert.equal(derived.method(), 'method');
|
||||
assert.equal(derived.readonly, 'readonly');
|
||||
assert(!derived.hasOwnProperty('method'));
|
||||
let proto = Object.getPrototypeOf(derived);
|
||||
assert(!proto.hasOwnProperty('method'));
|
||||
assert(Object.getPrototypeOf(proto).hasOwnProperty('method'));
|
||||
});
|
||||
});
|
||||
it('keeps prototype chain in derived class', function () {
|
||||
assert.equal(derived.method(), 'method')
|
||||
assert.equal(derived.readonly, 'readonly')
|
||||
assert(!derived.hasOwnProperty('method'))
|
||||
let proto = Object.getPrototypeOf(derived)
|
||||
assert(!proto.hasOwnProperty('method'))
|
||||
assert(Object.getPrototypeOf(proto).hasOwnProperty('method'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipc.sender.send', function() {
|
||||
it('should work when sending an object containing id property', function(done) {
|
||||
describe('ipc.sender.send', function () {
|
||||
it('should work when sending an object containing id property', function (done) {
|
||||
var obj = {
|
||||
id: 1,
|
||||
name: 'ly'
|
||||
};
|
||||
ipcRenderer.once('message', function(event, message) {
|
||||
assert.deepEqual(message, obj);
|
||||
done();
|
||||
});
|
||||
ipcRenderer.send('message', obj);
|
||||
});
|
||||
}
|
||||
ipcRenderer.once('message', function (event, message) {
|
||||
assert.deepEqual(message, obj)
|
||||
done()
|
||||
})
|
||||
ipcRenderer.send('message', obj)
|
||||
})
|
||||
|
||||
it('can send instance of Date', function(done) {
|
||||
const currentDate = new Date();
|
||||
ipcRenderer.once('message', function(event, value) {
|
||||
assert.equal(value, currentDate.toISOString());
|
||||
done();
|
||||
});
|
||||
ipcRenderer.send('message', currentDate);
|
||||
});
|
||||
});
|
||||
it('can send instance of Date', function (done) {
|
||||
const currentDate = new Date()
|
||||
ipcRenderer.once('message', function (event, value) {
|
||||
assert.equal(value, currentDate.toISOString())
|
||||
done()
|
||||
})
|
||||
ipcRenderer.send('message', currentDate)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipc.sendSync', function() {
|
||||
it('can be replied by setting event.returnValue', function() {
|
||||
var msg = ipcRenderer.sendSync('echo', 'test');
|
||||
assert.equal(msg, 'test');
|
||||
});
|
||||
describe('ipc.sendSync', function () {
|
||||
it('can be replied by setting event.returnValue', function () {
|
||||
var msg = ipcRenderer.sendSync('echo', 'test')
|
||||
assert.equal(msg, 'test')
|
||||
})
|
||||
|
||||
it('does not crash when reply is not sent and browser is destroyed', function(done) {
|
||||
this.timeout(10000);
|
||||
it('does not crash when reply is not sent and browser is destroyed', function (done) {
|
||||
this.timeout(10000)
|
||||
|
||||
var w = new BrowserWindow({
|
||||
show: false
|
||||
});
|
||||
ipcMain.once('send-sync-message', function(event) {
|
||||
event.returnValue = null;
|
||||
w.destroy();
|
||||
done();
|
||||
});
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'));
|
||||
});
|
||||
});
|
||||
})
|
||||
ipcMain.once('send-sync-message', function (event) {
|
||||
event.returnValue = null
|
||||
w.destroy()
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote listeners', function() {
|
||||
var w = null;
|
||||
describe('remote listeners', function () {
|
||||
var w = null
|
||||
|
||||
afterEach(function() {
|
||||
w.destroy();
|
||||
});
|
||||
afterEach(function () {
|
||||
w.destroy()
|
||||
})
|
||||
|
||||
it('can be added and removed correctly', function() {
|
||||
it('can be added and removed correctly', function () {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
});
|
||||
var listener = function() {};
|
||||
w.on('test', listener);
|
||||
assert.equal(w.listenerCount('test'), 1);
|
||||
w.removeListener('test', listener);
|
||||
assert.equal(w.listenerCount('test'), 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
var listener = function () {}
|
||||
w.on('test', listener)
|
||||
assert.equal(w.listenerCount('test'), 1)
|
||||
w.removeListener('test', listener)
|
||||
assert.equal(w.listenerCount('test'), 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
const assert = require('assert');
|
||||
const assert = require('assert')
|
||||
|
||||
const remote = require('electron').remote;
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const remote = require('electron').remote
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
|
||||
const Menu = remote.require('electron').Menu;
|
||||
const MenuItem = remote.require('electron').MenuItem;
|
||||
const Menu = remote.require('electron').Menu
|
||||
const MenuItem = remote.require('electron').MenuItem
|
||||
|
||||
describe('menu module', function() {
|
||||
describe('Menu.buildFromTemplate', function() {
|
||||
it('should be able to attach extra fields', function() {
|
||||
describe('menu module', function () {
|
||||
describe('Menu.buildFromTemplate', function () {
|
||||
it('should be able to attach extra fields', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'text',
|
||||
extra: 'field'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].extra, 'field');
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].extra, 'field')
|
||||
})
|
||||
|
||||
it('does not modify the specified template', function() {
|
||||
var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
|
||||
it('does not modify the specified template', function () {
|
||||
var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;")
|
||||
assert.deepStrictEqual(template, [
|
||||
{
|
||||
label: 'text',
|
||||
|
@ -29,11 +29,11 @@ describe('menu module', function() {
|
|||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
});
|
||||
])
|
||||
})
|
||||
|
||||
it('does not throw exceptions for undefined/null values', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
it('does not throw exceptions for undefined/null values', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'text',
|
||||
|
@ -43,12 +43,12 @@ describe('menu module', function() {
|
|||
label: 'text again',
|
||||
accelerator: null
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Menu.buildFromTemplate should reorder based on item position specifiers', function() {
|
||||
it('should position before existing item', function() {
|
||||
describe('Menu.buildFromTemplate should reorder based on item position specifiers', function () {
|
||||
it('should position before existing item', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '2',
|
||||
|
@ -61,13 +61,13 @@ describe('menu module', function() {
|
|||
id: '1',
|
||||
position: 'before=2'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].label, '1');
|
||||
assert.equal(menu.items[1].label, '2');
|
||||
assert.equal(menu.items[2].label, '3');
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].label, '1')
|
||||
assert.equal(menu.items[1].label, '2')
|
||||
assert.equal(menu.items[2].label, '3')
|
||||
})
|
||||
|
||||
it('should position after existing item', function() {
|
||||
it('should position after existing item', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '1',
|
||||
|
@ -80,13 +80,13 @@ describe('menu module', function() {
|
|||
id: '2',
|
||||
position: 'after=1'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].label, '1');
|
||||
assert.equal(menu.items[1].label, '2');
|
||||
assert.equal(menu.items[2].label, '3');
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].label, '1')
|
||||
assert.equal(menu.items[1].label, '2')
|
||||
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 = Menu.buildFromTemplate([
|
||||
{
|
||||
type: 'separator',
|
||||
|
@ -119,18 +119,18 @@ describe('menu module', function() {
|
|||
id: '3',
|
||||
position: 'endof=numbers'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].id, 'numbers');
|
||||
assert.equal(menu.items[1].label, '1');
|
||||
assert.equal(menu.items[2].label, '2');
|
||||
assert.equal(menu.items[3].label, '3');
|
||||
assert.equal(menu.items[4].id, 'letters');
|
||||
assert.equal(menu.items[5].label, 'a');
|
||||
assert.equal(menu.items[6].label, 'b');
|
||||
assert.equal(menu.items[7].label, 'c');
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].id, 'numbers')
|
||||
assert.equal(menu.items[1].label, '1')
|
||||
assert.equal(menu.items[2].label, '2')
|
||||
assert.equal(menu.items[3].label, '3')
|
||||
assert.equal(menu.items[4].id, 'letters')
|
||||
assert.equal(menu.items[5].label, 'a')
|
||||
assert.equal(menu.items[6].label, 'b')
|
||||
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 = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'a',
|
||||
|
@ -157,18 +157,18 @@ describe('menu module', function() {
|
|||
id: '3',
|
||||
position: 'endof=numbers'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].id, 'letters');
|
||||
assert.equal(menu.items[1].label, 'a');
|
||||
assert.equal(menu.items[2].label, 'b');
|
||||
assert.equal(menu.items[3].label, 'c');
|
||||
assert.equal(menu.items[4].id, 'numbers');
|
||||
assert.equal(menu.items[5].label, '1');
|
||||
assert.equal(menu.items[6].label, '2');
|
||||
assert.equal(menu.items[7].label, '3');
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].id, 'letters')
|
||||
assert.equal(menu.items[1].label, 'a')
|
||||
assert.equal(menu.items[2].label, 'b')
|
||||
assert.equal(menu.items[3].label, 'c')
|
||||
assert.equal(menu.items[4].id, 'numbers')
|
||||
assert.equal(menu.items[5].label, '1')
|
||||
assert.equal(menu.items[6].label, '2')
|
||||
assert.equal(menu.items[7].label, '3')
|
||||
})
|
||||
|
||||
it('should continue inserting items at next index when no specifier is present', function() {
|
||||
it('should continue inserting items at next index when no specifier is present', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '4',
|
||||
|
@ -187,18 +187,18 @@ describe('menu module', function() {
|
|||
label: '3',
|
||||
id: '3'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].label, '1');
|
||||
assert.equal(menu.items[1].label, '2');
|
||||
assert.equal(menu.items[2].label, '3');
|
||||
assert.equal(menu.items[3].label, '4');
|
||||
assert.equal(menu.items[4].label, '5');
|
||||
});
|
||||
});
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].label, '1')
|
||||
assert.equal(menu.items[1].label, '2')
|
||||
assert.equal(menu.items[2].label, '3')
|
||||
assert.equal(menu.items[3].label, '4')
|
||||
assert.equal(menu.items[4].label, '5')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Menu.insert', function() {
|
||||
it('should store item in @items by its index', function() {
|
||||
describe('Menu.insert', function () {
|
||||
it('should store item in @items by its index', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '1'
|
||||
|
@ -207,156 +207,156 @@ describe('menu module', function() {
|
|||
}, {
|
||||
label: '3'
|
||||
}
|
||||
]);
|
||||
])
|
||||
var item = new MenuItem({
|
||||
label: 'inserted'
|
||||
});
|
||||
menu.insert(1, item);
|
||||
assert.equal(menu.items[0].label, '1');
|
||||
assert.equal(menu.items[1].label, 'inserted');
|
||||
assert.equal(menu.items[2].label, '2');
|
||||
assert.equal(menu.items[3].label, '3');
|
||||
});
|
||||
});
|
||||
})
|
||||
menu.insert(1, item)
|
||||
assert.equal(menu.items[0].label, '1')
|
||||
assert.equal(menu.items[1].label, 'inserted')
|
||||
assert.equal(menu.items[2].label, '2')
|
||||
assert.equal(menu.items[3].label, '3')
|
||||
})
|
||||
})
|
||||
|
||||
describe('MenuItem.click', function() {
|
||||
it('should be called with the item object passed', function(done) {
|
||||
describe('MenuItem.click', function () {
|
||||
it('should be called with the item object passed', function (done) {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'text',
|
||||
click: function(item) {
|
||||
assert.equal(item.constructor.name, 'MenuItem');
|
||||
assert.equal(item.label, 'text');
|
||||
done();
|
||||
click: function (item) {
|
||||
assert.equal(item.constructor.name, 'MenuItem')
|
||||
assert.equal(item.label, 'text')
|
||||
done()
|
||||
}
|
||||
}
|
||||
]);
|
||||
menu.delegate.executeCommand(menu.items[0].commandId);
|
||||
});
|
||||
});
|
||||
])
|
||||
menu.delegate.executeCommand(menu.items[0].commandId)
|
||||
})
|
||||
})
|
||||
|
||||
describe('MenuItem with checked property', function() {
|
||||
it('clicking an checkbox item should flip the checked property', function() {
|
||||
describe('MenuItem with checked property', function () {
|
||||
it('clicking an checkbox item should flip the checked property', function () {
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'text',
|
||||
type: 'checkbox'
|
||||
}
|
||||
]);
|
||||
assert.equal(menu.items[0].checked, false);
|
||||
menu.delegate.executeCommand(menu.items[0].commandId);
|
||||
assert.equal(menu.items[0].checked, true);
|
||||
});
|
||||
])
|
||||
assert.equal(menu.items[0].checked, false)
|
||||
menu.delegate.executeCommand(menu.items[0].commandId)
|
||||
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 = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'text',
|
||||
type: 'radio'
|
||||
}
|
||||
]);
|
||||
menu.delegate.executeCommand(menu.items[0].commandId);
|
||||
assert.equal(menu.items[0].checked, true);
|
||||
menu.delegate.executeCommand(menu.items[0].commandId);
|
||||
assert.equal(menu.items[0].checked, true);
|
||||
});
|
||||
])
|
||||
menu.delegate.executeCommand(menu.items[0].commandId)
|
||||
assert.equal(menu.items[0].checked, true)
|
||||
menu.delegate.executeCommand(menu.items[0].commandId)
|
||||
assert.equal(menu.items[0].checked, true)
|
||||
})
|
||||
|
||||
it('at least have one item checked in each group', function() {
|
||||
var i, j, k, menu, template;
|
||||
template = [];
|
||||
it('at least have one item checked in each group', function () {
|
||||
var i, j, k, menu, template
|
||||
template = []
|
||||
for (i = j = 0; j <= 10; i = ++j) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
template.push({
|
||||
type: 'separator'
|
||||
});
|
||||
})
|
||||
for (i = k = 12; k <= 20; i = ++k) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
menu.delegate.menuWillShow();
|
||||
assert.equal(menu.items[0].checked, true);
|
||||
assert.equal(menu.items[12].checked, true);
|
||||
});
|
||||
menu = Menu.buildFromTemplate(template)
|
||||
menu.delegate.menuWillShow()
|
||||
assert.equal(menu.items[0].checked, true)
|
||||
assert.equal(menu.items[12].checked, true)
|
||||
})
|
||||
|
||||
it('should assign groupId automatically', function() {
|
||||
var groupId, i, j, k, l, m, menu, template;
|
||||
template = [];
|
||||
it('should assign groupId automatically', function () {
|
||||
var groupId, i, j, k, l, m, menu, template
|
||||
template = []
|
||||
for (i = j = 0; j <= 10; i = ++j) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
template.push({
|
||||
type: 'separator'
|
||||
});
|
||||
})
|
||||
for (i = k = 12; k <= 20; i = ++k) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
groupId = menu.items[0].groupId;
|
||||
menu = Menu.buildFromTemplate(template)
|
||||
groupId = menu.items[0].groupId
|
||||
for (i = l = 0; l <= 10; i = ++l) {
|
||||
assert.equal(menu.items[i].groupId, groupId);
|
||||
assert.equal(menu.items[i].groupId, groupId)
|
||||
}
|
||||
for (i = m = 12; m <= 20; i = ++m) {
|
||||
assert.equal(menu.items[i].groupId, groupId + 1);
|
||||
assert.equal(menu.items[i].groupId, groupId + 1)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
it("setting 'checked' should flip other items' 'checked' property", function() {
|
||||
var i, j, k, l, m, menu, n, o, p, q, template;
|
||||
template = [];
|
||||
it("setting 'checked' should flip other items' 'checked' property", function () {
|
||||
var i, j, k, l, m, menu, n, o, p, q, template
|
||||
template = []
|
||||
for (i = j = 0; j <= 10; i = ++j) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
template.push({
|
||||
type: 'separator'
|
||||
});
|
||||
})
|
||||
for (i = k = 12; k <= 20; i = ++k) {
|
||||
template.push({
|
||||
label: "" + i,
|
||||
label: '' + i,
|
||||
type: 'radio'
|
||||
});
|
||||
})
|
||||
}
|
||||
menu = Menu.buildFromTemplate(template);
|
||||
menu = Menu.buildFromTemplate(template)
|
||||
for (i = l = 0; l <= 10; i = ++l) {
|
||||
assert.equal(menu.items[i].checked, false);
|
||||
assert.equal(menu.items[i].checked, false)
|
||||
}
|
||||
menu.items[0].checked = true;
|
||||
assert.equal(menu.items[0].checked, true);
|
||||
menu.items[0].checked = true
|
||||
assert.equal(menu.items[0].checked, true)
|
||||
for (i = m = 1; m <= 10; i = ++m) {
|
||||
assert.equal(menu.items[i].checked, false);
|
||||
assert.equal(menu.items[i].checked, false)
|
||||
}
|
||||
menu.items[10].checked = true;
|
||||
assert.equal(menu.items[10].checked, true);
|
||||
menu.items[10].checked = true
|
||||
assert.equal(menu.items[10].checked, true)
|
||||
for (i = n = 0; n <= 9; i = ++n) {
|
||||
assert.equal(menu.items[i].checked, false);
|
||||
assert.equal(menu.items[i].checked, false)
|
||||
}
|
||||
for (i = o = 12; o <= 20; i = ++o) {
|
||||
assert.equal(menu.items[i].checked, false);
|
||||
assert.equal(menu.items[i].checked, false)
|
||||
}
|
||||
menu.items[12].checked = true;
|
||||
assert.equal(menu.items[10].checked, true);
|
||||
menu.items[12].checked = true
|
||||
assert.equal(menu.items[10].checked, true)
|
||||
for (i = p = 0; p <= 9; i = ++p) {
|
||||
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)
|
||||
for (i = q = 13; q <= 20; i = ++q) {
|
||||
assert.equal(menu.items[i].checked, false);
|
||||
assert.equal(menu.items[i].checked, false)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert');
|
||||
const nativeImage = require('electron').nativeImage;
|
||||
const path = require('path');
|
||||
const assert = require('assert')
|
||||
const nativeImage = require('electron').nativeImage
|
||||
const path = require('path')
|
||||
|
||||
describe('nativeImage module', () => {
|
||||
describe('createFromPath(path)', () => {
|
||||
it('returns an empty image for invalid paths', () => {
|
||||
assert(nativeImage.createFromPath('').isEmpty());
|
||||
assert(nativeImage.createFromPath('does-not-exist.png').isEmpty());
|
||||
});
|
||||
assert(nativeImage.createFromPath('').isEmpty())
|
||||
assert(nativeImage.createFromPath('does-not-exist.png').isEmpty())
|
||||
})
|
||||
|
||||
it('loads images from paths relative to the current working directory', () => {
|
||||
const imagePath = `.${path.sep}${path.join('spec', 'fixtures', 'assets', 'logo.png')}`;
|
||||
const image = nativeImage.createFromPath(imagePath);
|
||||
assert(!image.isEmpty());
|
||||
assert.equal(image.getSize().height, 190);
|
||||
assert.equal(image.getSize().width, 538);
|
||||
});
|
||||
const imagePath = `.${path.sep}${path.join('spec', 'fixtures', 'assets', 'logo.png')}`
|
||||
const image = nativeImage.createFromPath(imagePath)
|
||||
assert(!image.isEmpty())
|
||||
assert.equal(image.getSize().height, 190)
|
||||
assert.equal(image.getSize().width, 538)
|
||||
})
|
||||
|
||||
it('loads images from paths with `.` segments', () => {
|
||||
const imagePath = `${path.join(__dirname, 'fixtures')}${path.sep}.${path.sep}${path.join('assets', 'logo.png')}`;
|
||||
const image = nativeImage.createFromPath(imagePath);
|
||||
assert(!image.isEmpty());
|
||||
assert.equal(image.getSize().height, 190);
|
||||
assert.equal(image.getSize().width, 538);
|
||||
});
|
||||
const imagePath = `${path.join(__dirname, 'fixtures')}${path.sep}.${path.sep}${path.join('assets', 'logo.png')}`
|
||||
const image = nativeImage.createFromPath(imagePath)
|
||||
assert(!image.isEmpty())
|
||||
assert.equal(image.getSize().height, 190)
|
||||
assert.equal(image.getSize().width, 538)
|
||||
})
|
||||
|
||||
it('loads images from paths with `..` segments', () => {
|
||||
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
||||
const image = nativeImage.createFromPath(imagePath);
|
||||
assert(!image.isEmpty());
|
||||
assert.equal(image.getSize().height, 190);
|
||||
assert.equal(image.getSize().width, 538);
|
||||
});
|
||||
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`
|
||||
const image = nativeImage.createFromPath(imagePath)
|
||||
assert(!image.isEmpty())
|
||||
assert.equal(image.getSize().height, 190)
|
||||
assert.equal(image.getSize().width, 538)
|
||||
})
|
||||
|
||||
it('Gets an NSImage pointer on OS X', () => {
|
||||
if (process.platform !== 'darwin') return;
|
||||
if (process.platform !== 'darwin') return
|
||||
|
||||
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
||||
const image = nativeImage.createFromPath(imagePath);
|
||||
const nsimage = image.getNativeHandle();
|
||||
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`
|
||||
const image = nativeImage.createFromPath(imagePath)
|
||||
const nsimage = image.getNativeHandle()
|
||||
|
||||
assert.equal(nsimage.length, 8);
|
||||
assert.equal(nsimage.length, 8)
|
||||
|
||||
// If all bytes are null, that's Bad
|
||||
assert.equal(nsimage.reduce((acc,x) => acc || (x != 0), false), true);
|
||||
});
|
||||
});
|
||||
});
|
||||
assert.equal(nsimage.reduce((acc, x) => acc || (x != 0), false), true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,21 @@
|
|||
const assert = require('assert');
|
||||
const screen = require('electron').screen;
|
||||
const assert = require('assert')
|
||||
const screen = require('electron').screen
|
||||
|
||||
describe('screen module', function() {
|
||||
describe('screen.getCursorScreenPoint()', function() {
|
||||
it('returns a point object', function() {
|
||||
var point = screen.getCursorScreenPoint();
|
||||
assert.equal(typeof point.x, 'number');
|
||||
assert.equal(typeof point.y, 'number');
|
||||
});
|
||||
});
|
||||
describe('screen module', function () {
|
||||
describe('screen.getCursorScreenPoint()', function () {
|
||||
it('returns a point object', function () {
|
||||
var point = screen.getCursorScreenPoint()
|
||||
assert.equal(typeof point.x, 'number')
|
||||
assert.equal(typeof point.y, 'number')
|
||||
})
|
||||
})
|
||||
|
||||
describe('screen.getPrimaryDisplay()', function() {
|
||||
it('returns a display object', function() {
|
||||
var display = screen.getPrimaryDisplay();
|
||||
assert.equal(typeof display.scaleFactor, 'number');
|
||||
assert(display.size.width > 0);
|
||||
assert(display.size.height > 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('screen.getPrimaryDisplay()', function () {
|
||||
it('returns a display object', function () {
|
||||
var display = screen.getPrimaryDisplay()
|
||||
assert.equal(typeof display.scaleFactor, 'number')
|
||||
assert(display.size.width > 0)
|
||||
assert(display.size.height > 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,265 +1,265 @@
|
|||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const remote = require('electron').remote;
|
||||
const ipcRenderer = require('electron').ipcRenderer
|
||||
const remote = require('electron').remote
|
||||
|
||||
const ipcMain = remote.ipcMain;
|
||||
const session = remote.session;
|
||||
const BrowserWindow = remote.BrowserWindow;
|
||||
const ipcMain = remote.ipcMain
|
||||
const session = remote.session
|
||||
const BrowserWindow = remote.BrowserWindow
|
||||
|
||||
describe('session module', function() {
|
||||
this.timeout(10000);
|
||||
describe('session module', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
var w = null;
|
||||
var url = "http://127.0.0.1";
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
var w = null
|
||||
var url = 'http://127.0.0.1'
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
width: 400,
|
||||
height: 400
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
w.destroy();
|
||||
});
|
||||
afterEach(function () {
|
||||
w.destroy()
|
||||
})
|
||||
|
||||
describe('session.cookies', function() {
|
||||
it('should get cookies', function(done) {
|
||||
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 = server.address().port;
|
||||
w.loadURL(url + ":" + port);
|
||||
w.webContents.on('did-finish-load', function() {
|
||||
describe('session.cookies', function () {
|
||||
it('should get cookies', function (done) {
|
||||
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 = server.address().port
|
||||
w.loadURL(url + ':' + port)
|
||||
w.webContents.on('did-finish-load', function () {
|
||||
w.webContents.session.cookies.get({
|
||||
url: url
|
||||
}, function(error, list) {
|
||||
var cookie, i, len;
|
||||
}, function (error, list) {
|
||||
var cookie, i, len
|
||||
if (error) {
|
||||
return done(error);
|
||||
return done(error)
|
||||
}
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
cookie = list[i];
|
||||
cookie = list[i]
|
||||
if (cookie.name === '0') {
|
||||
if (cookie.value === '0') {
|
||||
return done();
|
||||
return done()
|
||||
} else {
|
||||
return done("cookie value is " + cookie.value + " while expecting 0");
|
||||
return done('cookie value is ' + cookie.value + ' while expecting 0')
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
session.defaultSession.cookies.set({
|
||||
url: url,
|
||||
name: '1',
|
||||
value: '1'
|
||||
}, function(error) {
|
||||
}, function (error) {
|
||||
if (error) {
|
||||
return done(error);
|
||||
return done(error)
|
||||
}
|
||||
session.defaultSession.cookies.get({
|
||||
url: url
|
||||
}, function(error, list) {
|
||||
var cookie, i, len;
|
||||
}, function (error, list) {
|
||||
var cookie, i, len
|
||||
if (error) {
|
||||
return done(error);
|
||||
return done(error)
|
||||
}
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
cookie = list[i];
|
||||
cookie = list[i]
|
||||
if (cookie.name === '1') {
|
||||
if (cookie.value === '1') {
|
||||
return done();
|
||||
return done()
|
||||
} else {
|
||||
return done("cookie value is " + cookie.value + " while expecting 1");
|
||||
return done('cookie value is ' + cookie.value + ' while expecting 1')
|
||||
}
|
||||
}
|
||||
}
|
||||
done('Can not find cookie');
|
||||
});
|
||||
});
|
||||
});
|
||||
done('Can not find cookie')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should remove cookies', function(done) {
|
||||
it('should remove cookies', function (done) {
|
||||
session.defaultSession.cookies.set({
|
||||
url: url,
|
||||
name: '2',
|
||||
value: '2'
|
||||
}, function(error) {
|
||||
}, function (error) {
|
||||
if (error) {
|
||||
return done(error);
|
||||
return done(error)
|
||||
}
|
||||
session.defaultSession.cookies.remove(url, '2', function() {
|
||||
session.defaultSession.cookies.remove(url, '2', function () {
|
||||
session.defaultSession.cookies.get({
|
||||
url: url
|
||||
}, function(error, list) {
|
||||
var cookie, i, len;
|
||||
}, function (error, list) {
|
||||
var cookie, i, len
|
||||
if (error) {
|
||||
return done(error);
|
||||
return done(error)
|
||||
}
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
cookie = list[i];
|
||||
cookie = list[i]
|
||||
if (cookie.name === '2') {
|
||||
return done('Cookie not deleted');
|
||||
return done('Cookie not deleted')
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('session.clearStorageData(options)', function() {
|
||||
fixtures = path.resolve(__dirname, 'fixtures');
|
||||
it('clears localstorage data', function(done) {
|
||||
ipcMain.on('count', function(event, count) {
|
||||
ipcMain.removeAllListeners('count');
|
||||
assert(!count);
|
||||
done();
|
||||
});
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'));
|
||||
w.webContents.on('did-finish-load', function() {
|
||||
describe('session.clearStorageData(options)', function () {
|
||||
fixtures = path.resolve(__dirname, 'fixtures')
|
||||
it('clears localstorage data', function (done) {
|
||||
ipcMain.on('count', function (event, count) {
|
||||
ipcMain.removeAllListeners('count')
|
||||
assert(!count)
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'))
|
||||
w.webContents.on('did-finish-load', function () {
|
||||
var options = {
|
||||
origin: "file://",
|
||||
origin: 'file://',
|
||||
storages: ['localstorage'],
|
||||
quotas: ['persistent']
|
||||
};
|
||||
w.webContents.session.clearStorageData(options, function() {
|
||||
w.webContents.send('getcount');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
w.webContents.session.clearStorageData(options, function () {
|
||||
w.webContents.send('getcount')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('session will-download event', function() {
|
||||
var w = null;
|
||||
describe('session will-download event', function () {
|
||||
var w = null
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
width: 400,
|
||||
height: 400
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
w.destroy();
|
||||
});
|
||||
afterEach(function () {
|
||||
w.destroy()
|
||||
})
|
||||
|
||||
it('can cancel default download behavior', function(done) {
|
||||
const mockFile = new Buffer(1024);
|
||||
const contentDisposition = 'inline; filename="mockFile.txt"';
|
||||
const downloadServer = http.createServer(function(req, res) {
|
||||
it('can cancel default download behavior', function (done) {
|
||||
const mockFile = new Buffer(1024)
|
||||
const contentDisposition = 'inline; filename="mockFile.txt"'
|
||||
const downloadServer = http.createServer(function (req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Length': mockFile.length,
|
||||
'Content-Type': 'application/plain',
|
||||
'Content-Disposition': contentDisposition
|
||||
});
|
||||
res.end(mockFile);
|
||||
downloadServer.close();
|
||||
});
|
||||
})
|
||||
res.end(mockFile)
|
||||
downloadServer.close()
|
||||
})
|
||||
|
||||
downloadServer.listen(0, '127.0.0.1', function() {
|
||||
const port = downloadServer.address().port;
|
||||
const url = "http://127.0.0.1:" + port + '/';
|
||||
downloadServer.listen(0, '127.0.0.1', function () {
|
||||
const port = downloadServer.address().port
|
||||
const url = 'http://127.0.0.1:' + port + '/'
|
||||
|
||||
ipcRenderer.sendSync('set-download-option', false, true);
|
||||
w.loadURL(url);
|
||||
ipcRenderer.once('download-error', function(event, downloadUrl, filename, error) {
|
||||
assert.equal(downloadUrl, url);
|
||||
assert.equal(filename, 'mockFile.txt');
|
||||
assert.equal(error, 'Object has been destroyed');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
ipcRenderer.sendSync('set-download-option', false, true)
|
||||
w.loadURL(url)
|
||||
ipcRenderer.once('download-error', function (event, downloadUrl, filename, error) {
|
||||
assert.equal(downloadUrl, url)
|
||||
assert.equal(filename, 'mockFile.txt')
|
||||
assert.equal(error, 'Object has been destroyed')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('DownloadItem', function() {
|
||||
var mockPDF = new Buffer(1024 * 1024 * 5);
|
||||
var contentDisposition = 'inline; filename="mock.pdf"';
|
||||
var downloadFilePath = path.join(fixtures, 'mock.pdf');
|
||||
var downloadServer = http.createServer(function(req, res) {
|
||||
describe('DownloadItem', function () {
|
||||
var mockPDF = new Buffer(1024 * 1024 * 5)
|
||||
var contentDisposition = 'inline; filename="mock.pdf"'
|
||||
var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||
var downloadServer = http.createServer(function (req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Length': mockPDF.length,
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': contentDisposition
|
||||
});
|
||||
res.end(mockPDF);
|
||||
downloadServer.close();
|
||||
});
|
||||
var assertDownload = function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) {
|
||||
assert.equal(state, 'completed');
|
||||
assert.equal(filename, 'mock.pdf');
|
||||
assert.equal(url, "http://127.0.0.1:" + port + "/");
|
||||
assert.equal(mimeType, 'application/pdf');
|
||||
assert.equal(receivedBytes, mockPDF.length);
|
||||
assert.equal(totalBytes, mockPDF.length);
|
||||
assert.equal(disposition, contentDisposition);
|
||||
assert(fs.existsSync(downloadFilePath));
|
||||
fs.unlinkSync(downloadFilePath);
|
||||
};
|
||||
})
|
||||
res.end(mockPDF)
|
||||
downloadServer.close()
|
||||
})
|
||||
var assertDownload = function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) {
|
||||
assert.equal(state, 'completed')
|
||||
assert.equal(filename, 'mock.pdf')
|
||||
assert.equal(url, 'http://127.0.0.1:' + port + '/')
|
||||
assert.equal(mimeType, 'application/pdf')
|
||||
assert.equal(receivedBytes, mockPDF.length)
|
||||
assert.equal(totalBytes, mockPDF.length)
|
||||
assert.equal(disposition, contentDisposition)
|
||||
assert(fs.existsSync(downloadFilePath))
|
||||
fs.unlinkSync(downloadFilePath)
|
||||
}
|
||||
|
||||
it('can download using BrowserWindow.loadURL', function(done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function() {
|
||||
var port = downloadServer.address().port;
|
||||
ipcRenderer.sendSync('set-download-option', false, false);
|
||||
w.loadURL(url + ":" + port);
|
||||
ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can download using BrowserWindow.loadURL', function (done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function () {
|
||||
var port = downloadServer.address().port
|
||||
ipcRenderer.sendSync('set-download-option', false, false)
|
||||
w.loadURL(url + ':' + port)
|
||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('can download using WebView.downloadURL', function(done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function() {
|
||||
var port = downloadServer.address().port;
|
||||
ipcRenderer.sendSync('set-download-option', false, false);
|
||||
var webview = new WebView;
|
||||
webview.src = "file://" + fixtures + "/api/blank.html";
|
||||
webview.addEventListener('did-finish-load', function() {
|
||||
webview.downloadURL(url + ":" + port + "/");
|
||||
});
|
||||
ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port);
|
||||
document.body.removeChild(webview);
|
||||
done();
|
||||
});
|
||||
document.body.appendChild(webview);
|
||||
});
|
||||
});
|
||||
it('can download using WebView.downloadURL', function (done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function () {
|
||||
var port = downloadServer.address().port
|
||||
ipcRenderer.sendSync('set-download-option', false, false)
|
||||
var webview = new WebView
|
||||
webview.src = 'file://' + fixtures + '/api/blank.html'
|
||||
webview.addEventListener('did-finish-load', function () {
|
||||
webview.downloadURL(url + ':' + port + '/')
|
||||
})
|
||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assertDownload(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port)
|
||||
document.body.removeChild(webview)
|
||||
done()
|
||||
})
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
|
||||
it('can cancel download', function(done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function() {
|
||||
var port = downloadServer.address().port;
|
||||
ipcRenderer.sendSync('set-download-option', true, false);
|
||||
w.loadURL(url + ":" + port + "/");
|
||||
ipcRenderer.once('download-done', function(event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assert.equal(state, 'cancelled');
|
||||
assert.equal(filename, 'mock.pdf');
|
||||
assert.equal(mimeType, 'application/pdf');
|
||||
assert.equal(receivedBytes, 0);
|
||||
assert.equal(totalBytes, mockPDF.length);
|
||||
assert.equal(disposition, contentDisposition);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can cancel download', function (done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function () {
|
||||
var port = downloadServer.address().port
|
||||
ipcRenderer.sendSync('set-download-option', true, false)
|
||||
w.loadURL(url + ':' + port + '/')
|
||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assert.equal(state, 'cancelled')
|
||||
assert.equal(filename, 'mock.pdf')
|
||||
assert.equal(mimeType, 'application/pdf')
|
||||
assert.equal(receivedBytes, 0)
|
||||
assert.equal(totalBytes, mockPDF.length)
|
||||
assert.equal(disposition, contentDisposition)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const webFrame = require('electron').webFrame;
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const webFrame = require('electron').webFrame
|
||||
|
||||
describe('webFrame module', function() {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
describe('webFrame.registerURLSchemeAsPrivileged', function() {
|
||||
it('supports fetch api', function(done) {
|
||||
webFrame.registerURLSchemeAsPrivileged('file');
|
||||
var url = "file://" + fixtures + "/assets/logo.png";
|
||||
fetch(url).then(function(response) {
|
||||
assert(response.ok);
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done('unexpected error : ' + err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('webFrame module', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
describe('webFrame.registerURLSchemeAsPrivileged', function () {
|
||||
it('supports fetch api', function (done) {
|
||||
webFrame.registerURLSchemeAsPrivileged('file')
|
||||
var url = 'file://' + fixtures + '/assets/logo.png'
|
||||
fetch(url).then(function (response) {
|
||||
assert(response.ok)
|
||||
done()
|
||||
}).catch(function (err) {
|
||||
done('unexpected error : ' + err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,413 +1,412 @@
|
|||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const qs = require('querystring');
|
||||
const remote = require('electron').remote;
|
||||
const session = remote.session;
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const qs = require('querystring')
|
||||
const remote = require('electron').remote
|
||||
const session = remote.session
|
||||
|
||||
describe('webRequest module', function() {
|
||||
var ses = session.defaultSession;
|
||||
var server = http.createServer(function(req, res) {
|
||||
res.setHeader('Custom', ['Header']);
|
||||
var content = req.url;
|
||||
describe('webRequest module', function () {
|
||||
var ses = session.defaultSession
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.setHeader('Custom', ['Header'])
|
||||
var content = req.url
|
||||
if (req.headers.accept === '*/*;test/header') {
|
||||
content += 'header/received';
|
||||
content += 'header/received'
|
||||
}
|
||||
res.end(content);
|
||||
});
|
||||
var defaultURL = null;
|
||||
res.end(content)
|
||||
})
|
||||
var defaultURL = null
|
||||
|
||||
before(function(done) {
|
||||
server.listen(0, '127.0.0.1', function() {
|
||||
var port = server.address().port;
|
||||
defaultURL = "http://127.0.0.1:" + port + "/";
|
||||
done();
|
||||
});
|
||||
});
|
||||
before(function (done) {
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
var port = server.address().port
|
||||
defaultURL = 'http://127.0.0.1:' + port + '/'
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
after(function() {
|
||||
server.close();
|
||||
});
|
||||
after(function () {
|
||||
server.close()
|
||||
})
|
||||
|
||||
describe('webRequest.onBeforeRequest', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onBeforeRequest(null);
|
||||
});
|
||||
describe('webRequest.onBeforeRequest', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onBeforeRequest(null)
|
||||
})
|
||||
|
||||
it('can cancel the request', function(done) {
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
it('can cancel the request', function (done) {
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
callback({
|
||||
cancel: true
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function() {
|
||||
done('unexpected success');
|
||||
success: function () {
|
||||
done('unexpected success')
|
||||
},
|
||||
error: function() {
|
||||
done();
|
||||
error: function () {
|
||||
done()
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('can filter URLs', function(done) {
|
||||
it('can filter URLs', function (done) {
|
||||
var filter = {
|
||||
urls: [defaultURL + "filter/*"]
|
||||
};
|
||||
ses.webRequest.onBeforeRequest(filter, function(details, callback) {
|
||||
urls: [defaultURL + 'filter/*']
|
||||
}
|
||||
ses.webRequest.onBeforeRequest(filter, function (details, callback) {
|
||||
callback({
|
||||
cancel: true
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL + "nofilter/test",
|
||||
success: function(data) {
|
||||
assert.equal(data, '/nofilter/test');
|
||||
url: defaultURL + 'nofilter/test',
|
||||
success: function (data) {
|
||||
assert.equal(data, '/nofilter/test')
|
||||
$.ajax({
|
||||
url: defaultURL + "filter/test",
|
||||
success: function() {
|
||||
done('unexpected success');
|
||||
url: defaultURL + 'filter/test',
|
||||
success: function () {
|
||||
done('unexpected success')
|
||||
},
|
||||
error: function() {
|
||||
done();
|
||||
error: function () {
|
||||
done()
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
assert.equal(typeof details.id, 'number');
|
||||
assert.equal(typeof details.timestamp, 'number');
|
||||
assert.equal(details.url, defaultURL);
|
||||
assert.equal(details.method, 'GET');
|
||||
assert.equal(details.resourceType, 'xhr');
|
||||
assert(!details.uploadData);
|
||||
callback({});
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
assert.equal(typeof details.id, 'number')
|
||||
assert.equal(typeof details.timestamp, 'number')
|
||||
assert.equal(details.url, defaultURL)
|
||||
assert.equal(details.method, 'GET')
|
||||
assert.equal(details.resourceType, 'xhr')
|
||||
assert(!details.uploadData)
|
||||
callback({})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('receives post data in details object', function(done) {
|
||||
it('receives post data in details object', function (done) {
|
||||
var postData = {
|
||||
name: 'post test',
|
||||
type: 'string'
|
||||
};
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
assert.equal(details.url, defaultURL);
|
||||
assert.equal(details.method, 'POST');
|
||||
assert.equal(details.uploadData.length, 1);
|
||||
var data = qs.parse(details.uploadData[0].bytes.toString());
|
||||
assert.deepEqual(data, postData);
|
||||
}
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
assert.equal(details.url, defaultURL)
|
||||
assert.equal(details.method, 'POST')
|
||||
assert.equal(details.uploadData.length, 1)
|
||||
var data = qs.parse(details.uploadData[0].bytes.toString())
|
||||
assert.deepEqual(data, postData)
|
||||
callback({
|
||||
cancel: true
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
type: 'POST',
|
||||
data: postData,
|
||||
success: function() {
|
||||
},
|
||||
error: function() {
|
||||
done();
|
||||
success: function () {},
|
||||
error: function () {
|
||||
done()
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('can redirect the request', function(done) {
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
it('can redirect the request', function (done) {
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
if (details.url === defaultURL) {
|
||||
callback({
|
||||
redirectURL: defaultURL + "redirect"
|
||||
});
|
||||
redirectURL: defaultURL + 'redirect'
|
||||
})
|
||||
} else {
|
||||
callback({});
|
||||
callback({})
|
||||
}
|
||||
});
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/redirect');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/redirect')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onBeforeSendHeaders', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onBeforeSendHeaders(null);
|
||||
});
|
||||
describe('webRequest.onBeforeSendHeaders', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onBeforeSendHeaders(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
|
||||
assert.equal(typeof details.requestHeaders, 'object');
|
||||
callback({});
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
||||
assert.equal(typeof details.requestHeaders, 'object')
|
||||
callback({})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('can change the request headers', function(done) {
|
||||
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
|
||||
var requestHeaders = details.requestHeaders;
|
||||
requestHeaders.Accept = '*/*;test/header';
|
||||
it('can change the request headers', function (done) {
|
||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
||||
var requestHeaders = details.requestHeaders
|
||||
requestHeaders.Accept = '*/*;test/header'
|
||||
callback({
|
||||
requestHeaders: requestHeaders
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/header/received');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/header/received')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('resets the whole headers', function(done) {
|
||||
it('resets the whole headers', function (done) {
|
||||
var requestHeaders = {
|
||||
Test: 'header'
|
||||
};
|
||||
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
|
||||
}
|
||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
||||
callback({
|
||||
requestHeaders: requestHeaders
|
||||
});
|
||||
});
|
||||
ses.webRequest.onSendHeaders(function(details) {
|
||||
assert.deepEqual(details.requestHeaders, requestHeaders);
|
||||
done();
|
||||
});
|
||||
})
|
||||
})
|
||||
ses.webRequest.onSendHeaders(function (details) {
|
||||
assert.deepEqual(details.requestHeaders, requestHeaders)
|
||||
done()
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onSendHeaders', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onSendHeaders(null);
|
||||
});
|
||||
describe('webRequest.onSendHeaders', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onSendHeaders(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onSendHeaders(function(details) {
|
||||
assert.equal(typeof details.requestHeaders, 'object');
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onSendHeaders(function (details) {
|
||||
assert.equal(typeof details.requestHeaders, 'object')
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onHeadersReceived', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onHeadersReceived(null);
|
||||
});
|
||||
describe('webRequest.onHeadersReceived', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onHeadersReceived(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onHeadersReceived(function(details, callback) {
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
|
||||
assert.equal(details.statusCode, 200);
|
||||
assert.equal(details.responseHeaders['Custom'], 'Header');
|
||||
callback({});
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||
assert.equal(details.statusCode, 200)
|
||||
assert.equal(details.responseHeaders['Custom'], 'Header')
|
||||
callback({})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('can change the response header', function(done) {
|
||||
ses.webRequest.onHeadersReceived(function(details, callback) {
|
||||
var responseHeaders = details.responseHeaders;
|
||||
responseHeaders['Custom'] = ['Changed'];
|
||||
it('can change the response header', function (done) {
|
||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
||||
var responseHeaders = details.responseHeaders
|
||||
responseHeaders['Custom'] = ['Changed']
|
||||
callback({
|
||||
responseHeaders: responseHeaders
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Changed');
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Changed')
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
it('does not change header by default', function(done) {
|
||||
ses.webRequest.onHeadersReceived(function(details, callback) {
|
||||
callback({});
|
||||
});
|
||||
it('does not change header by default', function (done) {
|
||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
||||
callback({})
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header');
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onResponseStarted', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onResponseStarted(null);
|
||||
});
|
||||
describe('webRequest.onResponseStarted', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onResponseStarted(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onResponseStarted(function(details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean');
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
|
||||
assert.equal(details.statusCode, 200);
|
||||
assert.equal(details.responseHeaders['Custom'], 'Header');
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onResponseStarted(function (details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean')
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||
assert.equal(details.statusCode, 200)
|
||||
assert.equal(details.responseHeaders['Custom'], 'Header')
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header');
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data, status, xhr) {
|
||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onBeforeRedirect', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onBeforeRedirect(null);
|
||||
ses.webRequest.onBeforeRequest(null);
|
||||
});
|
||||
describe('webRequest.onBeforeRedirect', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onBeforeRedirect(null)
|
||||
ses.webRequest.onBeforeRequest(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
var redirectURL = defaultURL + "redirect";
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
it('receives details object', function (done) {
|
||||
var redirectURL = defaultURL + 'redirect'
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
if (details.url === defaultURL) {
|
||||
callback({
|
||||
redirectURL: redirectURL
|
||||
});
|
||||
})
|
||||
} else {
|
||||
callback({});
|
||||
callback({})
|
||||
}
|
||||
});
|
||||
ses.webRequest.onBeforeRedirect(function(details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean');
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect');
|
||||
assert.equal(details.statusCode, 307);
|
||||
assert.equal(details.redirectURL, redirectURL);
|
||||
});
|
||||
})
|
||||
ses.webRequest.onBeforeRedirect(function (details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean')
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect')
|
||||
assert.equal(details.statusCode, 307)
|
||||
assert.equal(details.redirectURL, redirectURL)
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/redirect');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/redirect')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onCompleted', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onCompleted(null);
|
||||
});
|
||||
describe('webRequest.onCompleted', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onCompleted(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onCompleted(function(details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean');
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
|
||||
assert.equal(details.statusCode, 200);
|
||||
});
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onCompleted(function (details) {
|
||||
assert.equal(typeof details.fromCache, 'boolean')
|
||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||
assert.equal(details.statusCode, 200)
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function(data) {
|
||||
assert.equal(data, '/');
|
||||
done();
|
||||
success: function (data) {
|
||||
assert.equal(data, '/')
|
||||
done()
|
||||
},
|
||||
error: function(xhr, errorType) {
|
||||
done(errorType);
|
||||
error: function (xhr, errorType) {
|
||||
done(errorType)
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('webRequest.onErrorOccurred', function() {
|
||||
afterEach(function() {
|
||||
ses.webRequest.onErrorOccurred(null);
|
||||
ses.webRequest.onBeforeRequest(null);
|
||||
});
|
||||
describe('webRequest.onErrorOccurred', function () {
|
||||
afterEach(function () {
|
||||
ses.webRequest.onErrorOccurred(null)
|
||||
ses.webRequest.onBeforeRequest(null)
|
||||
})
|
||||
|
||||
it('receives details object', function(done) {
|
||||
ses.webRequest.onBeforeRequest(function(details, callback) {
|
||||
it('receives details object', function (done) {
|
||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
||||
callback({
|
||||
cancel: true
|
||||
});
|
||||
});
|
||||
ses.webRequest.onErrorOccurred(function(details) {
|
||||
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT');
|
||||
done();
|
||||
});
|
||||
})
|
||||
})
|
||||
ses.webRequest.onErrorOccurred(function (details) {
|
||||
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT')
|
||||
done()
|
||||
})
|
||||
$.ajax({
|
||||
url: defaultURL,
|
||||
success: function() {
|
||||
done('unexpected success');
|
||||
success: function () {
|
||||
done('unexpected success')
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
1368
spec/asar-spec.js
1368
spec/asar-spec.js
File diff suppressed because it is too large
Load diff
|
@ -1,432 +1,432 @@
|
|||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
const ws = require('ws');
|
||||
const remote = require('electron').remote;
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const ws = require('ws')
|
||||
const remote = require('electron').remote
|
||||
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow;
|
||||
const session = remote.require('electron').session;
|
||||
const BrowserWindow = remote.require('electron').BrowserWindow
|
||||
const session = remote.require('electron').session
|
||||
|
||||
const isCI = remote.getGlobal('isCi');
|
||||
const isCI = remote.getGlobal('isCi')
|
||||
|
||||
describe('chromium feature', function() {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||
var listener = null;
|
||||
describe('chromium feature', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
var listener = null
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
if (listener != null) {
|
||||
window.removeEventListener('message', listener);
|
||||
window.removeEventListener('message', listener)
|
||||
}
|
||||
listener = null;
|
||||
});
|
||||
listener = null
|
||||
})
|
||||
|
||||
xdescribe('heap snapshot', function() {
|
||||
it('does not crash', function() {
|
||||
process.atomBinding('v8_util').takeHeapSnapshot();
|
||||
});
|
||||
});
|
||||
xdescribe('heap snapshot', function () {
|
||||
it('does not crash', function () {
|
||||
process.atomBinding('v8_util').takeHeapSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe('sending request of http protocol urls', function() {
|
||||
it('does not crash', function(done) {
|
||||
this.timeout(5000);
|
||||
describe('sending request of http protocol urls', function () {
|
||||
it('does not crash', function (done) {
|
||||
this.timeout(5000)
|
||||
|
||||
var server = http.createServer(function(req, res) {
|
||||
res.end();
|
||||
server.close();
|
||||
done();
|
||||
});
|
||||
server.listen(0, '127.0.0.1', function() {
|
||||
var port = server.address().port;
|
||||
$.get("http://127.0.0.1:" + port);
|
||||
});
|
||||
});
|
||||
});
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.end()
|
||||
server.close()
|
||||
done()
|
||||
})
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
var port = server.address().port
|
||||
$.get('http://127.0.0.1:' + port)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('document.hidden', function() {
|
||||
var url = "file://" + fixtures + "/pages/document-hidden.html";
|
||||
var w = null;
|
||||
describe('document.hidden', function () {
|
||||
var url = 'file://' + fixtures + '/pages/document-hidden.html'
|
||||
var w = null
|
||||
|
||||
afterEach(function() {
|
||||
w != null ? w.destroy() : void 0;
|
||||
});
|
||||
afterEach(function () {
|
||||
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({
|
||||
show: false
|
||||
});
|
||||
w.webContents.on('ipc-message', function(event, args) {
|
||||
assert.deepEqual(args, ['hidden', true]);
|
||||
done();
|
||||
});
|
||||
w.loadURL(url);
|
||||
});
|
||||
})
|
||||
w.webContents.on('ipc-message', function (event, args) {
|
||||
assert.deepEqual(args, ['hidden', true])
|
||||
done()
|
||||
})
|
||||
w.loadURL(url)
|
||||
})
|
||||
|
||||
it('is set correctly when window is inactive', function(done) {
|
||||
it('is set correctly when window is inactive', function (done) {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
});
|
||||
w.webContents.on('ipc-message', function(event, args) {
|
||||
assert.deepEqual(args, ['hidden', false]);
|
||||
done();
|
||||
});
|
||||
w.showInactive();
|
||||
w.loadURL(url);
|
||||
});
|
||||
});
|
||||
})
|
||||
w.webContents.on('ipc-message', function (event, args) {
|
||||
assert.deepEqual(args, ['hidden', false])
|
||||
done()
|
||||
})
|
||||
w.showInactive()
|
||||
w.loadURL(url)
|
||||
})
|
||||
})
|
||||
|
||||
xdescribe('navigator.webkitGetUserMedia', function() {
|
||||
it('calls its callbacks', function(done) {
|
||||
this.timeout(5000);
|
||||
xdescribe('navigator.webkitGetUserMedia', function () {
|
||||
it('calls its callbacks', function (done) {
|
||||
this.timeout(5000)
|
||||
|
||||
navigator.webkitGetUserMedia({
|
||||
audio: true,
|
||||
video: false
|
||||
}, function() {
|
||||
done();
|
||||
}, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, function () {
|
||||
done()
|
||||
}, function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('navigator.mediaDevices', function() {
|
||||
describe('navigator.mediaDevices', function () {
|
||||
if (process.env.TRAVIS === 'true') {
|
||||
return;
|
||||
return
|
||||
}
|
||||
if (isCI && process.platform === 'linux') {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
it('can return labels of enumerated devices', function(done) {
|
||||
it('can return labels of enumerated devices', function (done) {
|
||||
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
||||
const labels = devices.map((device) => device.label);
|
||||
const labelFound = labels.some((label) => !!label);
|
||||
const labels = devices.map((device) => device.label)
|
||||
const labelFound = labels.some((label) => !!label)
|
||||
if (labelFound)
|
||||
done();
|
||||
done()
|
||||
else
|
||||
done('No device labels found: ' + JSON.stringify(labels));
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
done('No device labels found: ' + JSON.stringify(labels))
|
||||
}).catch(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('navigator.language', function() {
|
||||
it('should not be empty', function() {
|
||||
assert.notEqual(navigator.language, '');
|
||||
});
|
||||
});
|
||||
describe('navigator.language', function () {
|
||||
it('should not be empty', function () {
|
||||
assert.notEqual(navigator.language, '')
|
||||
})
|
||||
})
|
||||
|
||||
describe('navigator.serviceWorker', function() {
|
||||
var url = "file://" + fixtures + "/pages/service-worker/index.html";
|
||||
var w = null;
|
||||
describe('navigator.serviceWorker', function () {
|
||||
var url = 'file://' + fixtures + '/pages/service-worker/index.html'
|
||||
var w = null
|
||||
|
||||
afterEach(function() {
|
||||
w != null ? w.destroy() : void 0;
|
||||
});
|
||||
afterEach(function () {
|
||||
w != null ? w.destroy() : void 0
|
||||
})
|
||||
|
||||
it('should register for file scheme', function(done) {
|
||||
it('should register for file scheme', function (done) {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
});
|
||||
w.webContents.on('ipc-message', function(event, args) {
|
||||
})
|
||||
w.webContents.on('ipc-message', function (event, args) {
|
||||
if (args[0] === 'reload') {
|
||||
w.webContents.reload();
|
||||
w.webContents.reload()
|
||||
} else if (args[0] === 'error') {
|
||||
done('unexpected error : ' + args[1]);
|
||||
done('unexpected error : ' + args[1])
|
||||
} else if (args[0] === 'response') {
|
||||
assert.equal(args[1], 'Hello from serviceWorker!');
|
||||
assert.equal(args[1], 'Hello from serviceWorker!')
|
||||
session.defaultSession.clearStorageData({
|
||||
storages: ['serviceworkers']
|
||||
}, function() {
|
||||
done();
|
||||
});
|
||||
}, function () {
|
||||
done()
|
||||
})
|
||||
}
|
||||
});
|
||||
w.loadURL(url);
|
||||
});
|
||||
});
|
||||
})
|
||||
w.loadURL(url)
|
||||
})
|
||||
})
|
||||
|
||||
describe('window.open', function() {
|
||||
this.timeout(20000);
|
||||
describe('window.open', function () {
|
||||
this.timeout(20000)
|
||||
|
||||
it('returns a BrowserWindowProxy object', function() {
|
||||
var b = window.open('about:blank', '', 'show=no');
|
||||
assert.equal(b.closed, false);
|
||||
assert.equal(b.constructor.name, 'BrowserWindowProxy');
|
||||
b.close();
|
||||
});
|
||||
it('returns a BrowserWindowProxy object', function () {
|
||||
var b = window.open('about:blank', '', 'show=no')
|
||||
assert.equal(b.closed, false)
|
||||
assert.equal(b.constructor.name, 'BrowserWindowProxy')
|
||||
b.close()
|
||||
})
|
||||
|
||||
it('accepts "nodeIntegration" as feature', function(done) {
|
||||
var b;
|
||||
listener = function(event) {
|
||||
assert.equal(event.data, 'undefined');
|
||||
b.close();
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open("file://" + fixtures + "/pages/window-opener-node.html", '', 'nodeIntegration=no,show=no');
|
||||
});
|
||||
it('accepts "nodeIntegration" as feature', function (done) {
|
||||
var b
|
||||
listener = function (event) {
|
||||
assert.equal(event.data, 'undefined')
|
||||
b.close()
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-opener-node.html', '', 'nodeIntegration=no,show=no')
|
||||
})
|
||||
|
||||
it('inherit options of parent window', function(done) {
|
||||
var b;
|
||||
listener = function(event) {
|
||||
var height, ref1, width;
|
||||
ref1 = remote.getCurrentWindow().getSize(), width = ref1[0], height = ref1[1];
|
||||
assert.equal(event.data, "size: " + width + " " + height);
|
||||
b.close();
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', 'show=no');
|
||||
});
|
||||
it('inherit options of parent window', function (done) {
|
||||
var b
|
||||
listener = function (event) {
|
||||
var height, ref1, width
|
||||
ref1 = remote.getCurrentWindow().getSize(), width = ref1[0], height = ref1[1]
|
||||
assert.equal(event.data, 'size: ' + width + ' ' + height)
|
||||
b.close()
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-open-size.html', '', 'show=no')
|
||||
})
|
||||
|
||||
it('does not override child options', function(done) {
|
||||
var b, size;
|
||||
it('does not override child options', function (done) {
|
||||
var b, size
|
||||
size = {
|
||||
width: 350,
|
||||
height: 450
|
||||
};
|
||||
listener = function(event) {
|
||||
assert.equal(event.data, "size: " + size.width + " " + size.height);
|
||||
b.close();
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', "show=no,width=" + size.width + ",height=" + size.height);
|
||||
});
|
||||
}
|
||||
listener = function (event) {
|
||||
assert.equal(event.data, 'size: ' + size.width + ' ' + size.height)
|
||||
b.close()
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-open-size.html', '', 'show=no,width=' + size.width + ',height=' + size.height)
|
||||
})
|
||||
|
||||
it('defines a window.location getter', function(done) {
|
||||
var b, targetURL;
|
||||
targetURL = "file://" + fixtures + "/pages/base-page.html";
|
||||
b = window.open(targetURL);
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
|
||||
assert.equal(b.location, targetURL);
|
||||
b.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('defines a window.location getter', function (done) {
|
||||
var b, targetURL
|
||||
targetURL = 'file://' + fixtures + '/pages/base-page.html'
|
||||
b = window.open(targetURL)
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
assert.equal(b.location, targetURL)
|
||||
b.close()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('defines a window.location setter', function(done) {
|
||||
it('defines a window.location setter', function (done) {
|
||||
// Load a page that definitely won't redirect
|
||||
var b;
|
||||
b = window.open("about:blank");
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
|
||||
var b
|
||||
b = window.open('about:blank')
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
// When it loads, redirect
|
||||
b.location = "file://" + fixtures + "/pages/base-page.html";
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
|
||||
b.location = 'file://' + fixtures + '/pages/base-page.html'
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
// After our second redirect, cleanup and callback
|
||||
b.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
b.close()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('window.opener', function() {
|
||||
this.timeout(10000);
|
||||
describe('window.opener', function () {
|
||||
this.timeout(10000)
|
||||
|
||||
var url = "file://" + fixtures + "/pages/window-opener.html";
|
||||
var w = null;
|
||||
var url = 'file://' + fixtures + '/pages/window-opener.html'
|
||||
var w = null
|
||||
|
||||
afterEach(function() {
|
||||
w != null ? w.destroy() : void 0;
|
||||
});
|
||||
afterEach(function () {
|
||||
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({
|
||||
show: false
|
||||
});
|
||||
w.webContents.on('ipc-message', function(event, args) {
|
||||
assert.deepEqual(args, ['opener', null]);
|
||||
done();
|
||||
});
|
||||
w.loadURL(url);
|
||||
});
|
||||
})
|
||||
w.webContents.on('ipc-message', function (event, args) {
|
||||
assert.deepEqual(args, ['opener', null])
|
||||
done()
|
||||
})
|
||||
w.loadURL(url)
|
||||
})
|
||||
|
||||
it('is not null for window opened by window.open', function(done) {
|
||||
var b;
|
||||
listener = function(event) {
|
||||
assert.equal(event.data, 'object');
|
||||
b.close();
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open(url, '', 'show=no');
|
||||
});
|
||||
});
|
||||
|
||||
describe('window.postMessage', function() {
|
||||
it('sets the source and origin correctly', function(done) {
|
||||
var b, sourceId;
|
||||
sourceId = remote.getCurrentWindow().id;
|
||||
listener = function(event) {
|
||||
window.removeEventListener('message', listener);
|
||||
b.close();
|
||||
var message = JSON.parse(event.data);
|
||||
assert.equal(message.data, 'testing');
|
||||
assert.equal(message.origin, 'file://');
|
||||
assert.equal(message.sourceEqualsOpener, true);
|
||||
assert.equal(message.sourceId, sourceId);
|
||||
assert.equal(event.origin, 'file://');
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open("file://" + fixtures + "/pages/window-open-postMessage.html", '', 'show=no');
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function() {
|
||||
b.postMessage('testing', '*');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('window.opener.postMessage', function() {
|
||||
it('sets source and origin correctly', function(done) {
|
||||
var b;
|
||||
listener = function(event) {
|
||||
window.removeEventListener('message', listener);
|
||||
b.close();
|
||||
assert.equal(event.source, b);
|
||||
assert.equal(event.origin, 'file://');
|
||||
done();
|
||||
};
|
||||
window.addEventListener('message', listener);
|
||||
b = window.open("file://" + fixtures + "/pages/window-opener-postMessage.html", '', 'show=no');
|
||||
});
|
||||
});
|
||||
|
||||
describe('creating a Uint8Array under browser side', function() {
|
||||
it('does not crash', function() {
|
||||
var RUint8Array = remote.getGlobal('Uint8Array');
|
||||
new RUint8Array;
|
||||
});
|
||||
});
|
||||
|
||||
describe('webgl', function() {
|
||||
it('can be get as context in canvas', function() {
|
||||
if (process.platform === 'linux') {
|
||||
return;
|
||||
it('is not null for window opened by window.open', function (done) {
|
||||
var b
|
||||
listener = function (event) {
|
||||
assert.equal(event.data, 'object')
|
||||
b.close()
|
||||
done()
|
||||
}
|
||||
var webgl = document.createElement('canvas').getContext('webgl');
|
||||
assert.notEqual(webgl, null);
|
||||
});
|
||||
});
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open(url, '', 'show=no')
|
||||
})
|
||||
})
|
||||
|
||||
describe('web workers', function() {
|
||||
it('Worker can work', function(done) {
|
||||
var worker = new Worker('../fixtures/workers/worker.js');
|
||||
var message = 'ping';
|
||||
worker.onmessage = function(event) {
|
||||
assert.equal(event.data, message);
|
||||
worker.terminate();
|
||||
done();
|
||||
};
|
||||
worker.postMessage(message);
|
||||
});
|
||||
describe('window.postMessage', function () {
|
||||
it('sets the source and origin correctly', function (done) {
|
||||
var b, sourceId
|
||||
sourceId = remote.getCurrentWindow().id
|
||||
listener = function (event) {
|
||||
window.removeEventListener('message', listener)
|
||||
b.close()
|
||||
var message = JSON.parse(event.data)
|
||||
assert.equal(message.data, 'testing')
|
||||
assert.equal(message.origin, 'file://')
|
||||
assert.equal(message.sourceEqualsOpener, true)
|
||||
assert.equal(message.sourceId, sourceId)
|
||||
assert.equal(event.origin, 'file://')
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-open-postMessage.html', '', 'show=no')
|
||||
BrowserWindow.fromId(b.guestId).webContents.once('did-finish-load', function () {
|
||||
b.postMessage('testing', '*')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('SharedWorker can work', function(done) {
|
||||
var worker = new SharedWorker('../fixtures/workers/shared_worker.js');
|
||||
var message = 'ping';
|
||||
worker.port.onmessage = function(event) {
|
||||
assert.equal(event.data, message);
|
||||
done();
|
||||
};
|
||||
worker.port.postMessage(message);
|
||||
});
|
||||
});
|
||||
describe('window.opener.postMessage', function () {
|
||||
it('sets source and origin correctly', function (done) {
|
||||
var b
|
||||
listener = function (event) {
|
||||
window.removeEventListener('message', listener)
|
||||
b.close()
|
||||
assert.equal(event.source, b)
|
||||
assert.equal(event.origin, 'file://')
|
||||
done()
|
||||
}
|
||||
window.addEventListener('message', listener)
|
||||
b = window.open('file://' + fixtures + '/pages/window-opener-postMessage.html', '', 'show=no')
|
||||
})
|
||||
})
|
||||
|
||||
describe('iframe', function() {
|
||||
var iframe = null;
|
||||
describe('creating a Uint8Array under browser side', function () {
|
||||
it('does not crash', function () {
|
||||
var RUint8Array = remote.getGlobal('Uint8Array')
|
||||
new RUint8Array
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
iframe = document.createElement('iframe');
|
||||
});
|
||||
describe('webgl', function () {
|
||||
it('can be get as context in canvas', function () {
|
||||
if (process.platform === 'linux') {
|
||||
return
|
||||
}
|
||||
var webgl = document.createElement('canvas').getContext('webgl')
|
||||
assert.notEqual(webgl, null)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
document.body.removeChild(iframe);
|
||||
});
|
||||
describe('web workers', function () {
|
||||
it('Worker can work', function (done) {
|
||||
var worker = new Worker('../fixtures/workers/worker.js')
|
||||
var message = 'ping'
|
||||
worker.onmessage = function (event) {
|
||||
assert.equal(event.data, message)
|
||||
worker.terminate()
|
||||
done()
|
||||
}
|
||||
worker.postMessage(message)
|
||||
})
|
||||
|
||||
it('does not have node integration', function(done) {
|
||||
iframe.src = "file://" + fixtures + "/pages/set-global.html";
|
||||
document.body.appendChild(iframe);
|
||||
iframe.onload = function() {
|
||||
assert.equal(iframe.contentWindow.test, 'undefined undefined undefined');
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
it('SharedWorker can work', function (done) {
|
||||
var worker = new SharedWorker('../fixtures/workers/shared_worker.js')
|
||||
var message = 'ping'
|
||||
worker.port.onmessage = function (event) {
|
||||
assert.equal(event.data, message)
|
||||
done()
|
||||
}
|
||||
worker.port.postMessage(message)
|
||||
})
|
||||
})
|
||||
|
||||
describe('storage', function() {
|
||||
it('requesting persitent quota works', function(done) {
|
||||
navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) {
|
||||
assert.equal(grantedBytes, 1048576);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('iframe', function () {
|
||||
var iframe = null
|
||||
|
||||
describe('websockets', function() {
|
||||
var wss = null;
|
||||
var server = null;
|
||||
var WebSocketServer = ws.Server;
|
||||
beforeEach(function () {
|
||||
iframe = document.createElement('iframe')
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
wss.close();
|
||||
server.close();
|
||||
});
|
||||
afterEach(function () {
|
||||
document.body.removeChild(iframe)
|
||||
})
|
||||
|
||||
it('has user agent', function(done) {
|
||||
server = http.createServer();
|
||||
server.listen(0, '127.0.0.1', function() {
|
||||
var port = server.address().port;
|
||||
it('does not have node integration', function (done) {
|
||||
iframe.src = 'file://' + fixtures + '/pages/set-global.html'
|
||||
document.body.appendChild(iframe)
|
||||
iframe.onload = function () {
|
||||
assert.equal(iframe.contentWindow.test, 'undefined undefined undefined')
|
||||
done()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('storage', function () {
|
||||
it('requesting persitent quota works', function (done) {
|
||||
navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function (grantedBytes) {
|
||||
assert.equal(grantedBytes, 1048576)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('websockets', function () {
|
||||
var wss = null
|
||||
var server = null
|
||||
var WebSocketServer = ws.Server
|
||||
|
||||
afterEach(function () {
|
||||
wss.close()
|
||||
server.close()
|
||||
})
|
||||
|
||||
it('has user agent', function (done) {
|
||||
server = http.createServer()
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
var port = server.address().port
|
||||
wss = new WebSocketServer({
|
||||
server: server
|
||||
});
|
||||
wss.on('error', done);
|
||||
wss.on('connection', function(ws) {
|
||||
})
|
||||
wss.on('error', done)
|
||||
wss.on('connection', function (ws) {
|
||||
if (ws.upgradeReq.headers['user-agent']) {
|
||||
done();
|
||||
done()
|
||||
} else {
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Promise', function() {
|
||||
it('resolves correctly in Node.js calls', function(done) {
|
||||
describe('Promise', function () {
|
||||
it('resolves correctly in Node.js calls', function (done) {
|
||||
document.registerElement('x-element', {
|
||||
prototype: Object.create(HTMLElement.prototype, {
|
||||
createdCallback: {
|
||||
value: function() {}
|
||||
value: function () {}
|
||||
}
|
||||
})
|
||||
});
|
||||
setImmediate(function() {
|
||||
var called = false;
|
||||
Promise.resolve().then(function() {
|
||||
done(called ? void 0 : new Error('wrong sequence'));
|
||||
});
|
||||
document.createElement('x-element');
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
})
|
||||
setImmediate(function () {
|
||||
var called = false
|
||||
Promise.resolve().then(function () {
|
||||
done(called ? void 0 : new Error('wrong sequence'))
|
||||
})
|
||||
document.createElement('x-element')
|
||||
called = true
|
||||
})
|
||||
})
|
||||
|
||||
it('resolves correctly in Electron calls', function(done) {
|
||||
it('resolves correctly in Electron calls', function (done) {
|
||||
document.registerElement('y-element', {
|
||||
prototype: Object.create(HTMLElement.prototype, {
|
||||
createdCallback: {
|
||||
value: function() {}
|
||||
value: function () {}
|
||||
}
|
||||
})
|
||||
});
|
||||
remote.getGlobal('setImmediate')(function() {
|
||||
var called = false;
|
||||
Promise.resolve().then(function() {
|
||||
done(called ? void 0 : new Error('wrong sequence'));
|
||||
});
|
||||
document.createElement('y-element');
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
remote.getGlobal('setImmediate')(function () {
|
||||
var called = false
|
||||
Promise.resolve().then(function () {
|
||||
done(called ? void 0 : new Error('wrong sequence'))
|
||||
})
|
||||
document.createElement('y-element')
|
||||
called = true
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
12
spec/fixtures/api/quit-app/main.js
vendored
12
spec/fixtures/api/quit-app/main.js
vendored
|
@ -1,12 +1,12 @@
|
|||
var app = require('electron').app;
|
||||
var app = require('electron').app
|
||||
|
||||
app.on('ready', function () {
|
||||
// This setImmediate call gets the spec passing on Linux
|
||||
setImmediate(function () {
|
||||
app.exit(123);
|
||||
});
|
||||
});
|
||||
app.exit(123)
|
||||
})
|
||||
})
|
||||
|
||||
process.on('exit', function (code) {
|
||||
console.log('Exit event with code: ' + code);
|
||||
});
|
||||
console.log('Exit event with code: ' + code)
|
||||
})
|
||||
|
|
8
spec/fixtures/module/asar.js
vendored
8
spec/fixtures/module/asar.js
vendored
|
@ -1,4 +1,4 @@
|
|||
var fs = require('fs');
|
||||
process.on('message', function(file) {
|
||||
process.send(fs.readFileSync(file).toString());
|
||||
});
|
||||
var fs = require('fs')
|
||||
process.on('message', function (file) {
|
||||
process.send(fs.readFileSync(file).toString())
|
||||
})
|
||||
|
|
12
spec/fixtures/module/call.js
vendored
12
spec/fixtures/module/call.js
vendored
|
@ -1,7 +1,7 @@
|
|||
exports.call = function(func) {
|
||||
return func();
|
||||
};
|
||||
exports.call = function (func) {
|
||||
return func()
|
||||
}
|
||||
|
||||
exports.constructor = function() {
|
||||
this.test = 'test';
|
||||
};
|
||||
exports.constructor = function () {
|
||||
this.test = 'test'
|
||||
}
|
||||
|
|
20
spec/fixtures/module/class.js
vendored
20
spec/fixtures/module/class.js
vendored
|
@ -1,22 +1,22 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
let value = 'old';
|
||||
let value = 'old'
|
||||
|
||||
class BaseClass {
|
||||
method() {
|
||||
return 'method';
|
||||
method () {
|
||||
return 'method'
|
||||
}
|
||||
|
||||
get readonly() {
|
||||
return 'readonly';
|
||||
get readonly () {
|
||||
return 'readonly'
|
||||
}
|
||||
|
||||
get value() {
|
||||
return value;
|
||||
get value () {
|
||||
return value
|
||||
}
|
||||
|
||||
set value(val) {
|
||||
value = val;
|
||||
set value (val) {
|
||||
value = val
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
spec/fixtures/module/create_socket.js
vendored
8
spec/fixtures/module/create_socket.js
vendored
|
@ -1,4 +1,4 @@
|
|||
var net = require('net');
|
||||
var server = net.createServer(function() {});
|
||||
server.listen(process.argv[2]);
|
||||
process.exit(0);
|
||||
var net = require('net')
|
||||
var server = net.createServer(function () {})
|
||||
server.listen(process.argv[2])
|
||||
process.exit(0)
|
||||
|
|
24
spec/fixtures/module/fork_ping.js
vendored
24
spec/fixtures/module/fork_ping.js
vendored
|
@ -1,14 +1,14 @@
|
|||
process.on('uncaughtException', function(error) {
|
||||
process.send(error.stack);
|
||||
});
|
||||
process.on('uncaughtException', function (error) {
|
||||
process.send(error.stack)
|
||||
})
|
||||
|
||||
var child = require('child_process').fork(__dirname + '/ping.js');
|
||||
process.on('message', function(msg) {
|
||||
child.send(msg);
|
||||
});
|
||||
var child = require('child_process').fork(__dirname + '/ping.js')
|
||||
process.on('message', function (msg) {
|
||||
child.send(msg)
|
||||
})
|
||||
child.on('message', function (msg) {
|
||||
process.send(msg);
|
||||
});
|
||||
child.on('exit', function(code) {
|
||||
process.exit(code);
|
||||
});
|
||||
process.send(msg)
|
||||
})
|
||||
child.on('exit', function (code) {
|
||||
process.exit(code)
|
||||
})
|
||||
|
|
2
spec/fixtures/module/function.js
vendored
2
spec/fixtures/module/function.js
vendored
|
@ -1 +1 @@
|
|||
exports.aFunction = function() { return 1127; };
|
||||
exports.aFunction = function () { return 1127; }
|
||||
|
|
2
spec/fixtures/module/id.js
vendored
2
spec/fixtures/module/id.js
vendored
|
@ -1 +1 @@
|
|||
exports.id = 1127;
|
||||
exports.id = 1127
|
||||
|
|
4
spec/fixtures/module/locale-compare.js
vendored
4
spec/fixtures/module/locale-compare.js
vendored
|
@ -3,5 +3,5 @@ process.on('message', function () {
|
|||
'a'.localeCompare('a'),
|
||||
'ä'.localeCompare('z', 'de'),
|
||||
'ä'.localeCompare('a', 'sv', { sensitivity: 'base' }),
|
||||
]);
|
||||
});
|
||||
])
|
||||
})
|
||||
|
|
4
spec/fixtures/module/original-fs.js
vendored
4
spec/fixtures/module/original-fs.js
vendored
|
@ -1,3 +1,3 @@
|
|||
process.on('message', function () {
|
||||
process.send(typeof require('original-fs'));
|
||||
});
|
||||
process.send(typeof require('original-fs'))
|
||||
})
|
||||
|
|
8
spec/fixtures/module/ping.js
vendored
8
spec/fixtures/module/ping.js
vendored
|
@ -1,4 +1,4 @@
|
|||
process.on('message', function(msg) {
|
||||
process.send(msg);
|
||||
process.exit(0);
|
||||
});
|
||||
process.on('message', function (msg) {
|
||||
process.send(msg)
|
||||
process.exit(0)
|
||||
})
|
||||
|
|
8
spec/fixtures/module/preload-ipc.js
vendored
8
spec/fixtures/module/preload-ipc.js
vendored
|
@ -1,4 +1,4 @@
|
|||
var ipcRenderer = require('electron').ipcRenderer;
|
||||
ipcRenderer.on('ping', function(event, message) {
|
||||
ipcRenderer.sendToHost('pong', message);
|
||||
});
|
||||
var ipcRenderer = require('electron').ipcRenderer
|
||||
ipcRenderer.on('ping', function (event, message) {
|
||||
ipcRenderer.sendToHost('pong', message)
|
||||
})
|
||||
|
|
8
spec/fixtures/module/preload-node-off.js
vendored
8
spec/fixtures/module/preload-node-off.js
vendored
|
@ -1,7 +1,7 @@
|
|||
setImmediate(function() {
|
||||
setImmediate(function () {
|
||||
try {
|
||||
console.log([typeof process, typeof setImmediate, typeof global].join(' '));
|
||||
console.log([typeof process, typeof setImmediate, typeof global].join(' '))
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
console.log(e.message)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
|
2
spec/fixtures/module/preload.js
vendored
2
spec/fixtures/module/preload.js
vendored
|
@ -1 +1 @@
|
|||
console.log([typeof require, typeof module, typeof process].join(' '));
|
||||
console.log([typeof require, typeof module, typeof process].join(' '))
|
||||
|
|
12
spec/fixtures/module/print_name.js
vendored
12
spec/fixtures/module/print_name.js
vendored
|
@ -1,7 +1,7 @@
|
|||
exports.print = function(obj) {
|
||||
return obj.constructor.name;
|
||||
};
|
||||
exports.print = function (obj) {
|
||||
return obj.constructor.name
|
||||
}
|
||||
|
||||
exports.echo = function(obj) {
|
||||
return obj;
|
||||
};
|
||||
exports.echo = function (obj) {
|
||||
return obj
|
||||
}
|
||||
|
|
8
spec/fixtures/module/process_args.js
vendored
8
spec/fixtures/module/process_args.js
vendored
|
@ -1,4 +1,4 @@
|
|||
process.on('message', function() {
|
||||
process.send(process.argv);
|
||||
process.exit(0);
|
||||
});
|
||||
process.on('message', function () {
|
||||
process.send(process.argv)
|
||||
process.exit(0)
|
||||
})
|
||||
|
|
6
spec/fixtures/module/promise.js
vendored
6
spec/fixtures/module/promise.js
vendored
|
@ -1,5 +1,5 @@
|
|||
exports.twicePromise = function (promise) {
|
||||
return promise.then(function (value) {
|
||||
return value * 2;
|
||||
});
|
||||
};
|
||||
return value * 2
|
||||
})
|
||||
}
|
||||
|
|
2
spec/fixtures/module/property.js
vendored
2
spec/fixtures/module/property.js
vendored
|
@ -1 +1 @@
|
|||
exports.property = 1127;
|
||||
exports.property = 1127
|
||||
|
|
10
spec/fixtures/module/runas.js
vendored
10
spec/fixtures/module/runas.js
vendored
|
@ -1,6 +1,6 @@
|
|||
process.on('uncaughtException', function(err) {
|
||||
process.send(err.message);
|
||||
});
|
||||
process.on('uncaughtException', function (err) {
|
||||
process.send(err.message)
|
||||
})
|
||||
|
||||
require('runas');
|
||||
process.send('ok');
|
||||
require('runas')
|
||||
process.send('ok')
|
||||
|
|
8
spec/fixtures/module/send-later.js
vendored
8
spec/fixtures/module/send-later.js
vendored
|
@ -1,4 +1,4 @@
|
|||
var ipcRenderer = require('electron').ipcRenderer;
|
||||
window.onload = function() {
|
||||
ipcRenderer.send('answer', typeof window.process);
|
||||
};
|
||||
var ipcRenderer = require('electron').ipcRenderer
|
||||
window.onload = function () {
|
||||
ipcRenderer.send('answer', typeof window.process)
|
||||
}
|
||||
|
|
2
spec/fixtures/module/set-global.js
vendored
2
spec/fixtures/module/set-global.js
vendored
|
@ -1 +1 @@
|
|||
window.test = 'preload';
|
||||
window.test = 'preload'
|
||||
|
|
20
spec/fixtures/module/set-immediate.js
vendored
20
spec/fixtures/module/set-immediate.js
vendored
|
@ -1,11 +1,11 @@
|
|||
process.on('uncaughtException', function(error) {
|
||||
process.send(error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
process.on('uncaughtException', function (error) {
|
||||
process.send(error.message)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
process.on('message', function() {
|
||||
setImmediate(function() {
|
||||
process.send('ok');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
process.on('message', function () {
|
||||
setImmediate(function () {
|
||||
process.send('ok')
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
self.addEventListener('fetch', function(event) {
|
||||
var requestUrl = new URL(event.request.url);
|
||||
self.addEventListener('fetch', function (event) {
|
||||
var requestUrl = new URL(event.request.url)
|
||||
|
||||
if (requestUrl.pathname === '/echo' &&
|
||||
event.request.headers.has('X-Mock-Response')) {
|
||||
var mockResponse = new Response('Hello from serviceWorker!');
|
||||
event.respondWith(mockResponse);
|
||||
event.request.headers.has('X-Mock-Response')) {
|
||||
var mockResponse = new Response('Hello from serviceWorker!')
|
||||
event.respondWith(mockResponse)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
|
14
spec/fixtures/workers/shared_worker.js
vendored
14
spec/fixtures/workers/shared_worker.js
vendored
|
@ -1,7 +1,7 @@
|
|||
this.onconnect = function(event) {
|
||||
var port = event.ports[0];
|
||||
port.start();
|
||||
port.onmessage = function(event) {
|
||||
port.postMessage(event.data);
|
||||
};
|
||||
};
|
||||
this.onconnect = function (event) {
|
||||
var port = event.ports[0]
|
||||
port.start()
|
||||
port.onmessage = function (event) {
|
||||
port.postMessage(event.data)
|
||||
}
|
||||
}
|
||||
|
|
6
spec/fixtures/workers/worker.js
vendored
6
spec/fixtures/workers/worker.js
vendored
|
@ -1,3 +1,3 @@
|
|||
this.onmessage = function(msg) {
|
||||
this.postMessage(msg.data);
|
||||
};
|
||||
this.onmessage = function (msg) {
|
||||
this.postMessage(msg.data)
|
||||
}
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const temp = require('temp');
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const temp = require('temp')
|
||||
|
||||
describe('third-party module', function() {
|
||||
var fixtures = path.join(__dirname, 'fixtures');
|
||||
temp.track();
|
||||
describe('third-party module', function () {
|
||||
var fixtures = path.join(__dirname, 'fixtures')
|
||||
temp.track()
|
||||
|
||||
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
|
||||
describe('runas', function() {
|
||||
it('can be required in renderer', function() {
|
||||
require('runas');
|
||||
});
|
||||
describe('runas', function () {
|
||||
it('can be required in renderer', function () {
|
||||
require('runas')
|
||||
})
|
||||
|
||||
it('can be required in node binary', function(done) {
|
||||
var runas = path.join(fixtures, 'module', 'runas.js');
|
||||
var child = require('child_process').fork(runas);
|
||||
child.on('message', function(msg) {
|
||||
assert.equal(msg, 'ok');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can be required in node binary', function (done) {
|
||||
var runas = path.join(fixtures, 'module', 'runas.js')
|
||||
var child = require('child_process').fork(runas)
|
||||
child.on('message', function (msg) {
|
||||
assert.equal(msg, 'ok')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ffi', function() {
|
||||
it('does not crash', function() {
|
||||
var ffi = require('ffi');
|
||||
describe('ffi', function () {
|
||||
it('does not crash', function () {
|
||||
var ffi = require('ffi')
|
||||
var libm = ffi.Library('libm', {
|
||||
ceil: ['double', ['double']]
|
||||
});
|
||||
assert.equal(libm.ceil(1.5), 2);
|
||||
});
|
||||
});
|
||||
})
|
||||
assert.equal(libm.ceil(1.5), 2)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('q', function() {
|
||||
var Q = require('q');
|
||||
describe('Q.when', function() {
|
||||
it('emits the fullfil callback', function(done) {
|
||||
Q(true).then(function(val) {
|
||||
assert.equal(val, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('q', function () {
|
||||
var Q = require('q')
|
||||
describe('Q.when', function () {
|
||||
it('emits the fullfil callback', function (done) {
|
||||
Q(true).then(function (val) {
|
||||
assert.equal(val, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,220 +1,220 @@
|
|||
const assert = require('assert');
|
||||
const child_process = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const remote = require('electron').remote;
|
||||
const assert = require('assert')
|
||||
const child_process = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
const remote = require('electron').remote
|
||||
|
||||
describe('node feature', function() {
|
||||
var fixtures = path.join(__dirname, 'fixtures');
|
||||
describe('node feature', function () {
|
||||
var fixtures = path.join(__dirname, 'fixtures')
|
||||
|
||||
describe('child_process', function() {
|
||||
describe('child_process.fork', function() {
|
||||
it('works in current process', function(done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'ping.js'));
|
||||
child.on('message', function(msg) {
|
||||
assert.equal(msg, 'message');
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
describe('child_process', function () {
|
||||
describe('child_process.fork', function () {
|
||||
it('works in current process', function (done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'ping.js'))
|
||||
child.on('message', function (msg) {
|
||||
assert.equal(msg, 'message')
|
||||
done()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
|
||||
it('preserves args', function(done) {
|
||||
var args = ['--expose_gc', '-test', '1'];
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args);
|
||||
child.on('message', function(msg) {
|
||||
assert.deepEqual(args, msg.slice(2));
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
it('preserves args', function (done) {
|
||||
var args = ['--expose_gc', '-test', '1']
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'process_args.js'), args)
|
||||
child.on('message', function (msg) {
|
||||
assert.deepEqual(args, msg.slice(2))
|
||||
done()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
|
||||
it('works in forked process', function(done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
|
||||
child.on('message', function(msg) {
|
||||
assert.equal(msg, 'message');
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
it('works in forked process', function (done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'))
|
||||
child.on('message', function (msg) {
|
||||
assert.equal(msg, 'message')
|
||||
done()
|
||||
})
|
||||
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 = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
|
||||
path: process.env['PATH']
|
||||
});
|
||||
child.on('message', function(msg) {
|
||||
assert.equal(msg, 'message');
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
})
|
||||
child.on('message', function (msg) {
|
||||
assert.equal(msg, 'message')
|
||||
done()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
|
||||
it('works in browser process', function(done) {
|
||||
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();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
it('works in browser process', function (done) {
|
||||
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()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
|
||||
it('has String::localeCompare working in script', function(done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
|
||||
child.on('message', function(msg) {
|
||||
assert.deepEqual(msg, [0, -1, 1]);
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
it('has String::localeCompare working in script', function (done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'))
|
||||
child.on('message', function (msg) {
|
||||
assert.deepEqual(msg, [0, -1, 1])
|
||||
done()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
|
||||
it('has setImmediate working in script', function(done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
|
||||
child.on('message', function(msg) {
|
||||
assert.equal(msg, 'ok');
|
||||
done();
|
||||
});
|
||||
child.send('message');
|
||||
});
|
||||
});
|
||||
});
|
||||
it('has setImmediate working in script', function (done) {
|
||||
var child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'))
|
||||
child.on('message', function (msg) {
|
||||
assert.equal(msg, 'ok')
|
||||
done()
|
||||
})
|
||||
child.send('message')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('contexts', function() {
|
||||
describe('setTimeout in fs callback', function() {
|
||||
describe('contexts', function () {
|
||||
describe('setTimeout in fs callback', function () {
|
||||
if (process.env.TRAVIS === 'true') {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
it('does not crash', function(done) {
|
||||
fs.readFile(__filename, function() {
|
||||
setTimeout(done, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('does not crash', function (done) {
|
||||
fs.readFile(__filename, function () {
|
||||
setTimeout(done, 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('throw error in node context', function() {
|
||||
it('gets caught', function(done) {
|
||||
var error = new Error('boo!');
|
||||
var lsts = process.listeners('uncaughtException');
|
||||
process.removeAllListeners('uncaughtException');
|
||||
process.on('uncaughtException', function() {
|
||||
var i, len, lst;
|
||||
process.removeAllListeners('uncaughtException');
|
||||
describe('throw error in node context', function () {
|
||||
it('gets caught', function (done) {
|
||||
var error = new Error('boo!')
|
||||
var lsts = process.listeners('uncaughtException')
|
||||
process.removeAllListeners('uncaughtException')
|
||||
process.on('uncaughtException', function () {
|
||||
var i, len, lst
|
||||
process.removeAllListeners('uncaughtException')
|
||||
for (i = 0, len = lsts.length; i < len; i++) {
|
||||
lst = lsts[i];
|
||||
process.on('uncaughtException', lst);
|
||||
lst = lsts[i]
|
||||
process.on('uncaughtException', lst)
|
||||
}
|
||||
done();
|
||||
});
|
||||
fs.readFile(__filename, function() {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
done()
|
||||
})
|
||||
fs.readFile(__filename, function () {
|
||||
throw error
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setTimeout called under Chromium event loop in browser process', function() {
|
||||
it('can be scheduled in time', function(done) {
|
||||
remote.getGlobal('setTimeout')(done, 0);
|
||||
});
|
||||
});
|
||||
describe('setTimeout called under Chromium event loop in browser process', function () {
|
||||
it('can be scheduled in time', function (done) {
|
||||
remote.getGlobal('setTimeout')(done, 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('setInterval called under Chromium event loop in browser process', function() {
|
||||
it('can be scheduled in time', function(done) {
|
||||
var clear, interval;
|
||||
clear = function() {
|
||||
remote.getGlobal('clearInterval')(interval);
|
||||
done();
|
||||
};
|
||||
interval = remote.getGlobal('setInterval')(clear, 10);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('setInterval called under Chromium event loop in browser process', function () {
|
||||
it('can be scheduled in time', function (done) {
|
||||
var clear, interval
|
||||
clear = function () {
|
||||
remote.getGlobal('clearInterval')(interval)
|
||||
done()
|
||||
}
|
||||
interval = remote.getGlobal('setInterval')(clear, 10)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('message loop', function() {
|
||||
describe('process.nextTick', function() {
|
||||
it('emits the callback', function(done) {
|
||||
process.nextTick(done);
|
||||
});
|
||||
describe('message loop', function () {
|
||||
describe('process.nextTick', function () {
|
||||
it('emits the callback', function (done) {
|
||||
process.nextTick(done)
|
||||
})
|
||||
|
||||
it('works in nested calls', function(done) {
|
||||
process.nextTick(function() {
|
||||
process.nextTick(function() {
|
||||
process.nextTick(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('works in nested calls', function (done) {
|
||||
process.nextTick(function () {
|
||||
process.nextTick(function () {
|
||||
process.nextTick(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setImmediate', function() {
|
||||
it('emits the callback', function(done) {
|
||||
setImmediate(done);
|
||||
});
|
||||
describe('setImmediate', function () {
|
||||
it('emits the callback', function (done) {
|
||||
setImmediate(done)
|
||||
})
|
||||
|
||||
it('works in nested calls', function(done) {
|
||||
setImmediate(function() {
|
||||
setImmediate(function() {
|
||||
setImmediate(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('works in nested calls', function (done) {
|
||||
setImmediate(function () {
|
||||
setImmediate(function () {
|
||||
setImmediate(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('net.connect', function() {
|
||||
describe('net.connect', function () {
|
||||
if (process.platform !== 'darwin') {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
it('emit error when connect to a socket path without listeners', function(done) {
|
||||
var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
|
||||
var script = path.join(fixtures, 'module', 'create_socket.js');
|
||||
var child = child_process.fork(script, [socketPath]);
|
||||
child.on('exit', function(code) {
|
||||
assert.equal(code, 0);
|
||||
var client = require('net').connect(socketPath);
|
||||
client.on('error', function(error) {
|
||||
assert.equal(error.code, 'ECONNREFUSED');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('emit error when connect to a socket path without listeners', function (done) {
|
||||
var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
|
||||
var script = path.join(fixtures, 'module', 'create_socket.js')
|
||||
var child = child_process.fork(script, [socketPath])
|
||||
child.on('exit', function (code) {
|
||||
assert.equal(code, 0)
|
||||
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 p = document.createElement('p');
|
||||
p.innerText = '闲云潭影日悠悠,物换星移几度秋';
|
||||
var b = new Buffer(p.innerText);
|
||||
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋');
|
||||
assert.equal(Buffer.byteLength(p.innerText), 45);
|
||||
});
|
||||
describe('Buffer', function () {
|
||||
it('can be created from WebKit external string', function () {
|
||||
var p = document.createElement('p')
|
||||
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 p = document.createElement('p');
|
||||
p.innerText = 'Jøhänñéß';
|
||||
var b = new Buffer(p.innerText);
|
||||
assert.equal(b.toString(), 'Jøhänñéß');
|
||||
assert.equal(Buffer.byteLength(p.innerText), 13);
|
||||
});
|
||||
});
|
||||
it('correctly parses external one-byte UTF8 string', function () {
|
||||
var p = document.createElement('p')
|
||||
p.innerText = 'Jøhänñéß'
|
||||
var b = new Buffer(p.innerText)
|
||||
assert.equal(b.toString(), 'Jøhänñéß')
|
||||
assert.equal(Buffer.byteLength(p.innerText), 13)
|
||||
})
|
||||
})
|
||||
|
||||
describe('process.stdout', function() {
|
||||
it('should not throw exception', function() {
|
||||
process.stdout;
|
||||
});
|
||||
describe('process.stdout', function () {
|
||||
it('should not throw exception', function () {
|
||||
process.stdout
|
||||
})
|
||||
|
||||
it('should not throw exception when calling write()', function() {
|
||||
process.stdout.write('test');
|
||||
});
|
||||
it('should not throw exception when calling write()', function () {
|
||||
process.stdout.write('test')
|
||||
})
|
||||
|
||||
xit('should have isTTY defined', function() {
|
||||
assert.equal(typeof process.stdout.isTTY, 'boolean');
|
||||
});
|
||||
});
|
||||
xit('should have isTTY defined', function () {
|
||||
assert.equal(typeof process.stdout.isTTY, 'boolean')
|
||||
})
|
||||
})
|
||||
|
||||
describe('vm.createContext', function() {
|
||||
it('should not crash', function() {
|
||||
require('vm').runInNewContext('');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('vm.createContext', function () {
|
||||
it('should not crash', function () {
|
||||
require('vm').runInNewContext('')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,81 +1,81 @@
|
|||
// Disable use of deprecated functions.
|
||||
process.throwDeprecation = true;
|
||||
process.throwDeprecation = true
|
||||
|
||||
const electron = require('electron');
|
||||
const app = electron.app;
|
||||
const ipcMain = electron.ipcMain;
|
||||
const dialog = electron.dialog;
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const ipcMain = electron.ipcMain
|
||||
const dialog = electron.dialog
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const path = require('path')
|
||||
const url = require('url')
|
||||
|
||||
var argv = require('yargs')
|
||||
.boolean('ci')
|
||||
.string('g').alias('g', 'grep')
|
||||
.boolean('i').alias('i', 'invert')
|
||||
.argv;
|
||||
.argv
|
||||
|
||||
var window = null;
|
||||
process.port = 0; // will be used by crash-reporter spec.
|
||||
var window = null
|
||||
process.port = 0; // will be used by crash-reporter spec.
|
||||
|
||||
app.commandLine.appendSwitch('js-flags', '--expose_gc');
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors');
|
||||
app.commandLine.appendSwitch('disable-renderer-backgrounding');
|
||||
app.commandLine.appendSwitch('js-flags', '--expose_gc')
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors')
|
||||
app.commandLine.appendSwitch('disable-renderer-backgrounding')
|
||||
|
||||
// Accessing stdout in the main process will result in the process.stdout
|
||||
// throwing UnknownSystemError in renderer process sometimes. This line makes
|
||||
// sure we can reproduce it in renderer process.
|
||||
process.stdout;
|
||||
process.stdout
|
||||
|
||||
// Access console to reproduce #3482.
|
||||
console;
|
||||
console
|
||||
|
||||
ipcMain.on('message', function(event, arg) {
|
||||
event.sender.send('message', arg);
|
||||
});
|
||||
ipcMain.on('message', function (event, arg) {
|
||||
event.sender.send('message', arg)
|
||||
})
|
||||
|
||||
ipcMain.on('console.log', function(event, args) {
|
||||
console.error.apply(console, args);
|
||||
});
|
||||
ipcMain.on('console.log', function (event, args) {
|
||||
console.error.apply(console, args)
|
||||
})
|
||||
|
||||
ipcMain.on('console.error', function(event, args) {
|
||||
console.error.apply(console, args);
|
||||
});
|
||||
ipcMain.on('console.error', function (event, args) {
|
||||
console.error.apply(console, args)
|
||||
})
|
||||
|
||||
ipcMain.on('process.exit', function(event, code) {
|
||||
process.exit(code);
|
||||
});
|
||||
ipcMain.on('process.exit', function (event, code) {
|
||||
process.exit(code)
|
||||
})
|
||||
|
||||
ipcMain.on('eval', function(event, script) {
|
||||
event.returnValue = eval(script);
|
||||
});
|
||||
ipcMain.on('eval', function (event, script) {
|
||||
event.returnValue = eval(script)
|
||||
})
|
||||
|
||||
ipcMain.on('echo', function(event, msg) {
|
||||
event.returnValue = msg;
|
||||
});
|
||||
ipcMain.on('echo', function (event, msg) {
|
||||
event.returnValue = msg
|
||||
})
|
||||
|
||||
global.isCi = !!argv.ci;
|
||||
global.isCi = !!argv.ci
|
||||
if (global.isCi) {
|
||||
process.removeAllListeners('uncaughtException');
|
||||
process.on('uncaughtException', function(error) {
|
||||
console.error(error, error.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
process.removeAllListeners('uncaughtException')
|
||||
process.on('uncaughtException', function (error) {
|
||||
console.error(error, error.stack)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
app.on('window-all-closed', function() {
|
||||
app.quit();
|
||||
});
|
||||
app.on('window-all-closed', function () {
|
||||
app.quit()
|
||||
})
|
||||
|
||||
app.on('ready', function() {
|
||||
app.on('ready', function () {
|
||||
// Test if using protocol module would crash.
|
||||
electron.protocol.registerStringProtocol('test-if-crashes', function() {});
|
||||
electron.protocol.registerStringProtocol('test-if-crashes', function () {})
|
||||
|
||||
// Send auto updater errors to window to be verified in specs
|
||||
electron.autoUpdater.on('error', function (error) {
|
||||
window.send('auto-updater-error', error.message);
|
||||
});
|
||||
window.send('auto-updater-error', error.message)
|
||||
})
|
||||
|
||||
window = new BrowserWindow({
|
||||
title: 'Electron Tests',
|
||||
|
@ -83,70 +83,70 @@ app.on('ready', function() {
|
|||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
javascript: true // Test whether web preferences crashes.
|
||||
javascript: true // Test whether web preferences crashes.
|
||||
},
|
||||
});
|
||||
})
|
||||
window.loadURL(url.format({
|
||||
pathname: __dirname + '/index.html',
|
||||
protocol: 'file',
|
||||
query: {
|
||||
grep: argv.grep,
|
||||
invert: argv.invert ? 'true': ''
|
||||
invert: argv.invert ? 'true' : ''
|
||||
}
|
||||
}));
|
||||
window.on('unresponsive', function() {
|
||||
}))
|
||||
window.on('unresponsive', function () {
|
||||
var chosen = dialog.showMessageBox(window, {
|
||||
type: 'warning',
|
||||
buttons: ['Close', 'Keep Waiting'],
|
||||
message: 'Window is not responsing',
|
||||
detail: 'The window is not responding. Would you like to force close it or just keep waiting?'
|
||||
});
|
||||
if (chosen === 0) window.destroy();
|
||||
});
|
||||
})
|
||||
if (chosen === 0) window.destroy()
|
||||
})
|
||||
|
||||
// For session's download test, listen 'will-download' event in browser, and
|
||||
// reply the result to renderer for verifying
|
||||
var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf');
|
||||
ipcMain.on('set-download-option', function(event, need_cancel, prevent_default) {
|
||||
window.webContents.session.once('will-download', function(e, item) {
|
||||
var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf')
|
||||
ipcMain.on('set-download-option', function (event, need_cancel, prevent_default) {
|
||||
window.webContents.session.once('will-download', function (e, item) {
|
||||
if (prevent_default) {
|
||||
e.preventDefault();
|
||||
const url = item.getURL();
|
||||
const filename = item.getFilename();
|
||||
setImmediate(function() {
|
||||
e.preventDefault()
|
||||
const url = item.getURL()
|
||||
const filename = item.getFilename()
|
||||
setImmediate(function () {
|
||||
try {
|
||||
item.getURL();
|
||||
item.getURL()
|
||||
} catch(err) {
|
||||
window.webContents.send('download-error', url, filename, err.message);
|
||||
window.webContents.send('download-error', url, filename, err.message)
|
||||
}
|
||||
});
|
||||
})
|
||||
} else {
|
||||
item.setSavePath(downloadFilePath);
|
||||
item.on('done', function(e, state) {
|
||||
item.setSavePath(downloadFilePath)
|
||||
item.on('done', function (e, state) {
|
||||
window.webContents.send('download-done',
|
||||
state,
|
||||
item.getURL(),
|
||||
item.getMimeType(),
|
||||
item.getReceivedBytes(),
|
||||
item.getTotalBytes(),
|
||||
item.getContentDisposition(),
|
||||
item.getFilename());
|
||||
});
|
||||
state,
|
||||
item.getURL(),
|
||||
item.getMimeType(),
|
||||
item.getReceivedBytes(),
|
||||
item.getTotalBytes(),
|
||||
item.getContentDisposition(),
|
||||
item.getFilename())
|
||||
})
|
||||
if (need_cancel)
|
||||
item.cancel();
|
||||
item.cancel()
|
||||
}
|
||||
});
|
||||
event.returnValue = "done";
|
||||
});
|
||||
})
|
||||
event.returnValue = 'done'
|
||||
})
|
||||
|
||||
ipcMain.on('executeJavaScript', function(event, code, hasCallback) {
|
||||
ipcMain.on('executeJavaScript', function (event, code, hasCallback) {
|
||||
if (hasCallback) {
|
||||
window.webContents.executeJavaScript(code, (result) => {
|
||||
window.webContents.send('executeJavaScript-response', result);
|
||||
});
|
||||
window.webContents.send('executeJavaScript-response', result)
|
||||
})
|
||||
} else {
|
||||
window.webContents.executeJavaScript(code);
|
||||
event.returnValue = "success";
|
||||
window.webContents.executeJavaScript(code)
|
||||
event.returnValue = 'success'
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
1300
spec/webview-spec.js
1300
spec/webview-spec.js
File diff suppressed because it is too large
Load diff
|
@ -1,31 +1,31 @@
|
|||
var app = require('app');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var request = require('request');
|
||||
var app = require('app')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var request = require('request')
|
||||
|
||||
var TARGET_URL = 'https://atom.io/download/atom-shell/index.json';
|
||||
var TARGET_URL = 'https://atom.io/download/atom-shell/index.json'
|
||||
|
||||
function getDate() {
|
||||
var today = new Date();
|
||||
var year = today.getFullYear();
|
||||
var month = today.getMonth() + 1;
|
||||
function getDate () {
|
||||
var today = new Date()
|
||||
var year = today.getFullYear()
|
||||
var month = today.getMonth() + 1
|
||||
if (month <= 9)
|
||||
month = '0' + month;
|
||||
var day= today.getDate();
|
||||
month = '0' + month
|
||||
var day = today.getDate()
|
||||
if (day <= 9)
|
||||
day = '0' + day;
|
||||
return year + '-' + month + '-' + day;
|
||||
day = '0' + day
|
||||
return year + '-' + month + '-' + day
|
||||
}
|
||||
|
||||
function getInfoForCurrentVersion() {
|
||||
var json = {};
|
||||
json.version = process.versions['atom-shell'];
|
||||
json.date = getDate();
|
||||
function getInfoForCurrentVersion () {
|
||||
var json = {}
|
||||
json.version = process.versions['atom-shell']
|
||||
json.date = getDate()
|
||||
|
||||
var names = ['node', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'chrome']
|
||||
for (var i in names) {
|
||||
var name = names[i];
|
||||
json[name] = process.versions[name];
|
||||
var name = names[i]
|
||||
json[name] = process.versions[name]
|
||||
}
|
||||
|
||||
json.files = [
|
||||
|
@ -39,44 +39,44 @@ function getInfoForCurrentVersion() {
|
|||
'win32-ia32-symbols',
|
||||
'win32-x64',
|
||||
'win32-x64-symbols',
|
||||
];
|
||||
]
|
||||
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
function getIndexJsInServer(callback) {
|
||||
request(TARGET_URL, function(e, res, body) {
|
||||
function getIndexJsInServer (callback) {
|
||||
request(TARGET_URL, function (e, res, body) {
|
||||
if (e)
|
||||
callback(e);
|
||||
callback(e)
|
||||
else if (res.statusCode != 200)
|
||||
callback(new Error('Server returned ' + res.statusCode));
|
||||
callback(new Error('Server returned ' + res.statusCode))
|
||||
else
|
||||
callback(null, JSON.parse(body));
|
||||
});
|
||||
callback(null, JSON.parse(body))
|
||||
})
|
||||
}
|
||||
|
||||
function findObjectByVersion(all, version) {
|
||||
function findObjectByVersion (all, version) {
|
||||
for (var i in all)
|
||||
if (all[i].version == version)
|
||||
return i;
|
||||
return -1;
|
||||
return i
|
||||
return -1
|
||||
}
|
||||
|
||||
app.on('ready', function() {
|
||||
getIndexJsInServer(function(e, all) {
|
||||
app.on('ready', function () {
|
||||
getIndexJsInServer(function (e, all) {
|
||||
if (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var current = getInfoForCurrentVersion();
|
||||
var found = findObjectByVersion(all, current.version);
|
||||
var current = getInfoForCurrentVersion()
|
||||
var found = findObjectByVersion(all, current.version)
|
||||
if (found == -1)
|
||||
all.unshift(current);
|
||||
all.unshift(current)
|
||||
else
|
||||
all[found] = current;
|
||||
all[found] = current
|
||||
|
||||
fs.writeFileSync(process.argv[2], JSON.stringify(all));
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
fs.writeFileSync(process.argv[2], JSON.stringify(all))
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var runas = require('runas');
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var runas = require('runas')
|
||||
|
||||
var source = path.resolve(__dirname, '..', '..', 'vendor', 'breakpad', 'msdia80.dll');
|
||||
var target = 'C:\\Program Files\\Common Files\\Microsoft Shared\\VC\\msdia80.dll';
|
||||
if (fs.existsSync(target))
|
||||
return;
|
||||
var source = path.resolve(__dirname, '..', '..', 'vendor', 'breakpad', 'msdia80.dll')
|
||||
var target = 'C:\\Program Files\\Common Files\\Microsoft Shared\\VC\\msdia80.dll'
|
||||
|
||||
runas('cmd',
|
||||
['/K', 'copy', source, target, '&', 'regsvr32', '/s', target, '&', 'exit'],
|
||||
{admin: true});
|
||||
if (!fs.existsSync(target)) {
|
||||
runas('cmd',
|
||||
['/K', 'copy', source, target, '&', 'regsvr32', '/s', target, '&', 'exit'],
|
||||
{admin: true})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue