2016-02-17 00:46:49 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const ChildProcess = require('child_process');
|
|
|
|
const path = require('path');
|
|
|
|
const remote = require('electron').remote;
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-02-17 00:46:49 +00:00
|
|
|
const app = remote.require('electron').app;
|
|
|
|
const BrowserWindow = remote.require('electron').BrowserWindow;
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-27 08:44:10 +00:00
|
|
|
describe('electron module', function() {
|
2016-03-14 05:54:45 +00:00
|
|
|
it('allows old style require by default', function() {
|
|
|
|
require('shell');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can prevent exposing internal modules to require', function(done) {
|
2016-01-27 08:44:10 +00:00
|
|
|
const electron = require('electron');
|
|
|
|
const clipboard = require('clipboard');
|
|
|
|
assert.equal(typeof clipboard, 'object');
|
|
|
|
electron.hideInternalModules();
|
|
|
|
try {
|
|
|
|
require('clipboard');
|
|
|
|
} catch(err) {
|
|
|
|
assert.equal(err.message, 'Cannot find module \'clipboard\'');
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app module', function() {
|
|
|
|
describe('app.getVersion()', function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
it('returns the version field of package.json', function() {
|
|
|
|
assert.equal(app.getVersion(), '0.1.0');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app.setVersion(version)', function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
it('overrides the version', function() {
|
2016-01-12 02:40:23 +00:00
|
|
|
assert.equal(app.getVersion(), '0.1.0');
|
|
|
|
app.setVersion('test-version');
|
|
|
|
assert.equal(app.getVersion(), 'test-version');
|
2016-02-17 01:39:11 +00:00
|
|
|
app.setVersion('0.1.0');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app.getName()', function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
it('returns the name field of package.json', function() {
|
|
|
|
assert.equal(app.getName(), 'Electron Test');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app.setName(name)', function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
it('overrides the name', function() {
|
2016-01-12 02:40:23 +00:00
|
|
|
assert.equal(app.getName(), 'Electron Test');
|
|
|
|
app.setName('test-name');
|
|
|
|
assert.equal(app.getName(), 'test-name');
|
2016-02-17 01:39:11 +00:00
|
|
|
app.setName('Electron Test');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app.getLocale()', function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
it('should not be empty', function() {
|
|
|
|
assert.notEqual(app.getLocale(), '');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
describe('app.exit(exitCode)', function() {
|
2016-02-17 01:09:41 +00:00
|
|
|
var appProcess = null;
|
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
afterEach(function() {
|
2016-02-17 01:39:11 +00:00
|
|
|
appProcess != null ? appProcess.kill() : void 0;
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-02-17 01:39:11 +00:00
|
|
|
it('emits a process exit event with the code', function(done) {
|
2016-02-17 17:27:25 +00:00
|
|
|
var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
|
|
|
|
var electronPath = remote.getGlobal('process').execPath;
|
|
|
|
var output = '';
|
2016-01-12 02:40:23 +00:00
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath]);
|
|
|
|
appProcess.stdout.on('data', function(data) {
|
2016-02-17 01:39:11 +00:00
|
|
|
output += data;
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-02-17 01:39:11 +00:00
|
|
|
appProcess.on('close', function(code) {
|
2016-01-12 02:40:23 +00:00
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
assert.notEqual(output.indexOf('Exit event with code: 123'), -1);
|
|
|
|
}
|
|
|
|
assert.equal(code, 123);
|
2016-02-17 01:39:11 +00:00
|
|
|
done();
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-02-17 01:39:11 +00:00
|
|
|
describe('BrowserWindow events', function() {
|
2016-02-17 01:09:41 +00:00
|
|
|
var w = null;
|
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
afterEach(function() {
|
|
|
|
if (w != null) {
|
|
|
|
w.destroy();
|
|
|
|
}
|
2016-02-17 01:39:11 +00:00
|
|
|
w = null;
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
it('should emit browser-window-focus event when window is focused', function(done) {
|
|
|
|
app.once('browser-window-focus', function(e, window) {
|
|
|
|
assert.equal(w.id, window.id);
|
2016-02-17 01:39:11 +00:00
|
|
|
done();
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false
|
|
|
|
});
|
2016-02-17 01:39:11 +00:00
|
|
|
w.emit('focus');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
it('should emit browser-window-blur event when window is blured', function(done) {
|
|
|
|
app.once('browser-window-blur', function(e, window) {
|
|
|
|
assert.equal(w.id, window.id);
|
2016-02-17 01:39:11 +00:00
|
|
|
done();
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false
|
|
|
|
});
|
2016-02-17 01:39:11 +00:00
|
|
|
w.emit('blur');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2016-02-17 01:39:11 +00:00
|
|
|
it('should emit browser-window-created event when window is created', function(done) {
|
2016-01-12 02:40:23 +00:00
|
|
|
app.once('browser-window-created', function(e, window) {
|
2016-02-17 01:39:11 +00:00
|
|
|
setImmediate(function() {
|
2016-01-12 02:40:23 +00:00
|
|
|
assert.equal(w.id, window.id);
|
2016-02-17 01:39:11 +00:00
|
|
|
done();
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false
|
|
|
|
});
|
2016-02-17 01:39:11 +00:00
|
|
|
w.emit('blur');
|
2016-01-12 02:40:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|