commit
a2b0e30714
8 changed files with 446 additions and 299 deletions
|
@ -3,60 +3,61 @@
|
||||||
const app = require('electron').app;
|
const app = require('electron').app;
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const squirrelUpdate = require('./squirrel-update-win');
|
const squirrelUpdate = require('./squirrel-update-win');
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
class AutoUpdater extends EventEmitter {
|
function AutoUpdater() {
|
||||||
constructor() {
|
EventEmitter.call(this);
|
||||||
super();
|
}
|
||||||
|
|
||||||
|
util.inherits(AutoUpdater, EventEmitter);
|
||||||
|
|
||||||
|
AutoUpdater.prototype.quitAndInstall = function() {
|
||||||
|
squirrelUpdate.processStart();
|
||||||
|
return app.quit();
|
||||||
|
};
|
||||||
|
|
||||||
|
AutoUpdater.prototype.setFeedURL = function(updateURL) {
|
||||||
|
return this.updateURL = updateURL;
|
||||||
|
};
|
||||||
|
|
||||||
|
AutoUpdater.prototype.checkForUpdates = function() {
|
||||||
|
if (!this.updateURL) {
|
||||||
|
return this.emitError('Update URL is not set');
|
||||||
}
|
}
|
||||||
|
if (!squirrelUpdate.supported()) {
|
||||||
quitAndInstall() {
|
return this.emitError('Can not find Squirrel');
|
||||||
squirrelUpdate.processStart();
|
|
||||||
return app.quit();
|
|
||||||
}
|
}
|
||||||
|
this.emit('checking-for-update');
|
||||||
setFeedURL(updateURL) {
|
return squirrelUpdate.download(this.updateURL, (function(_this) {
|
||||||
return this.updateURL = updateURL;
|
return function(error, update) {
|
||||||
}
|
if (error != null) {
|
||||||
|
return _this.emitError(error);
|
||||||
checkForUpdates() {
|
}
|
||||||
if (!this.updateURL) {
|
if (update == null) {
|
||||||
return this.emitError('Update URL is not set');
|
return _this.emit('update-not-available');
|
||||||
}
|
}
|
||||||
if (!squirrelUpdate.supported()) {
|
_this.emit('update-available');
|
||||||
return this.emitError('Can not find Squirrel');
|
return squirrelUpdate.update(_this.updateURL, function(error) {
|
||||||
}
|
var date, releaseNotes, version;
|
||||||
this.emit('checking-for-update');
|
|
||||||
return squirrelUpdate.download(this.updateURL, (function(_this) {
|
|
||||||
return function(error, update) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return _this.emitError(error);
|
return _this.emitError(error);
|
||||||
}
|
}
|
||||||
if (update == null) {
|
releaseNotes = update.releaseNotes, version = update.version;
|
||||||
return _this.emit('update-not-available');
|
|
||||||
}
|
|
||||||
_this.emit('update-available');
|
|
||||||
return squirrelUpdate.update(_this.updateURL, function(error) {
|
|
||||||
var date, releaseNotes, version;
|
|
||||||
if (error != null) {
|
|
||||||
return _this.emitError(error);
|
|
||||||
}
|
|
||||||
releaseNotes = update.releaseNotes, version = update.version;
|
|
||||||
|
|
||||||
// Following information is not available on Windows, so fake them.
|
// Following information is not available on Windows, so fake them.
|
||||||
date = new Date;
|
date = new Date;
|
||||||
return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() {
|
return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() {
|
||||||
return _this.quitAndInstall();
|
return _this.quitAndInstall();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
})(this));
|
};
|
||||||
}
|
})(this));
|
||||||
|
};
|
||||||
|
|
||||||
// Private: Emit both error object and message, this is to keep compatibility
|
// Private: Emit both error object and message, this is to keep compatibility
|
||||||
// with Old APIs.
|
// with Old APIs.
|
||||||
emitError(message) {
|
AutoUpdater.prototype.emitError = function(message) {
|
||||||
return this.emit('error', new Error(message), message);
|
return this.emit('error', new Error(message), message);
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = new AutoUpdater;
|
module.exports = new AutoUpdater;
|
||||||
|
|
|
@ -76,8 +76,11 @@ let wrapWebContents = function(webContents) {
|
||||||
|
|
||||||
// WebContents::send(channel, args..)
|
// WebContents::send(channel, args..)
|
||||||
webContents.send = function() {
|
webContents.send = function() {
|
||||||
var args, channel;
|
var args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||||
channel = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
var channel = arguments[0];
|
||||||
|
if (channel == null) {
|
||||||
|
throw new Error('Missing required channel argument');
|
||||||
|
}
|
||||||
return this._send(channel, slice.call(args));
|
return this._send(channel, slice.call(args));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -404,10 +404,13 @@ var registerWebViewElement = function() {
|
||||||
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
||||||
createBlockHandler = function(m) {
|
createBlockHandler = function(m) {
|
||||||
return function() {
|
return function() {
|
||||||
var args, internal, ref1;
|
var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||||
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
var internal = v8Util.getHiddenValue(this, 'internal');
|
||||||
internal = v8Util.getHiddenValue(this, 'internal');
|
if (internal.webContents) {
|
||||||
return (ref1 = internal.webContents)[m].apply(ref1, args);
|
return internal.webContents[m].apply(internal.webContents, args);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Cannot call ${m} because the webContents is unavailable. The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
for (i = 0, len = methods.length; i < len; i++) {
|
for (i = 0, len = methods.length; i < len; i++) {
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"bootstrap": "python ./script/bootstrap.py",
|
||||||
|
"build": "python ./script/build.py -c D",
|
||||||
"lint": "python ./script/eslint.py && python ./script/cpplint.py",
|
"lint": "python ./script/eslint.py && python ./script/cpplint.py",
|
||||||
"preinstall": "node -e 'process.exit(0)'",
|
"preinstall": "node -e 'process.exit(0)'",
|
||||||
"start": "python ./script/start.py",
|
"start": "python ./script/start.py",
|
||||||
|
|
34
spec/api-auto-updater-spec.js
Normal file
34
spec/api-auto-updater-spec.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
const assert = require('assert');
|
||||||
|
const autoUpdater = require('electron').remote.autoUpdater;
|
||||||
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
|
|
||||||
|
describe('autoUpdater module', function() {
|
||||||
|
describe('checkForUpdates', function() {
|
||||||
|
it('emits an error on Windows when called the feed URL is not set', function (done) {
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcRenderer.once('auto-updater-error', function(event, message) {
|
||||||
|
assert.equal(message, 'Update URL is not set');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
autoUpdater.setFeedURL('');
|
||||||
|
autoUpdater.checkForUpdates();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setFeedURL', function() {
|
||||||
|
it('emits an error on Mac OS X when the application is unsigned', function (done) {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcRenderer.once('auto-updater-error', function(event, message) {
|
||||||
|
assert.equal(message, 'Could not get code signature for running application');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
autoUpdater.setFeedURL('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -14,29 +14,31 @@ const BrowserWindow = remote.require('electron').BrowserWindow;
|
||||||
const isCI = remote.getGlobal('isCi');
|
const isCI = remote.getGlobal('isCi');
|
||||||
|
|
||||||
describe('browser-window module', function() {
|
describe('browser-window module', function() {
|
||||||
var fixtures, w;
|
var fixtures = path.resolve(__dirname, 'fixtures');
|
||||||
fixtures = path.resolve(__dirname, 'fixtures');
|
var w = null;
|
||||||
w = null;
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
if (w != null) {
|
if (w != null) {
|
||||||
w.destroy();
|
w.destroy();
|
||||||
}
|
}
|
||||||
return w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 400
|
height: 400
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
if (w != null) {
|
if (w != null) {
|
||||||
w.destroy();
|
w.destroy();
|
||||||
}
|
}
|
||||||
return w = null;
|
w = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.close()', function() {
|
describe('BrowserWindow.close()', function() {
|
||||||
it('should emit unload handler', function(done) {
|
it('should emit unload handler', function(done) {
|
||||||
w.webContents.on('did-finish-load', function() {
|
w.webContents.on('did-finish-load', function() {
|
||||||
return w.close();
|
w.close();
|
||||||
});
|
});
|
||||||
w.on('closed', function() {
|
w.on('closed', function() {
|
||||||
var content, test;
|
var content, test;
|
||||||
|
@ -44,20 +46,22 @@ describe('browser-window module', function() {
|
||||||
content = fs.readFileSync(test);
|
content = fs.readFileSync(test);
|
||||||
fs.unlinkSync(test);
|
fs.unlinkSync(test);
|
||||||
assert.equal(String(content), 'unload');
|
assert.equal(String(content), 'unload');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'unload.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'unload.html'));
|
||||||
});
|
});
|
||||||
return it('should emit beforeunload handler', function(done) {
|
|
||||||
|
it('should emit beforeunload handler', function(done) {
|
||||||
w.on('onbeforeunload', function() {
|
w.on('onbeforeunload', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.webContents.on('did-finish-load', function() {
|
w.webContents.on('did-finish-load', function() {
|
||||||
return w.close();
|
w.close();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('window.close()', function() {
|
describe('window.close()', function() {
|
||||||
it('should emit unload handler', function(done) {
|
it('should emit unload handler', function(done) {
|
||||||
w.on('closed', function() {
|
w.on('closed', function() {
|
||||||
|
@ -66,104 +70,113 @@ describe('browser-window module', function() {
|
||||||
content = fs.readFileSync(test);
|
content = fs.readFileSync(test);
|
||||||
fs.unlinkSync(test);
|
fs.unlinkSync(test);
|
||||||
assert.equal(String(content), 'close');
|
assert.equal(String(content), 'close');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close.html'));
|
||||||
});
|
});
|
||||||
return it('should emit beforeunload handler', function(done) {
|
|
||||||
|
it('should emit beforeunload handler', function(done) {
|
||||||
w.on('onbeforeunload', function() {
|
w.on('onbeforeunload', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.destroy()', function() {
|
describe('BrowserWindow.destroy()', function() {
|
||||||
return it('prevents users to access methods of webContents', function() {
|
it('prevents users to access methods of webContents', function() {
|
||||||
var webContents;
|
var webContents;
|
||||||
webContents = w.webContents;
|
webContents = w.webContents;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
return assert.throws((function() {
|
assert.throws((function() {
|
||||||
return webContents.getId();
|
webContents.getId();
|
||||||
}), /Object has been destroyed/);
|
}), /Object has been destroyed/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.loadURL(url)', function() {
|
describe('BrowserWindow.loadURL(url)', function() {
|
||||||
it('should emit did-start-loading event', function(done) {
|
it('should emit did-start-loading event', function(done) {
|
||||||
w.webContents.on('did-start-loading', function() {
|
w.webContents.on('did-start-loading', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('about:blank');
|
w.loadURL('about:blank');
|
||||||
});
|
});
|
||||||
return it('should emit did-fail-load event', function(done) {
|
|
||||||
|
it('should emit did-fail-load event', function(done) {
|
||||||
w.webContents.on('did-fail-load', function() {
|
w.webContents.on('did-fail-load', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://a.txt');
|
w.loadURL('file://a.txt');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.show()', function() {
|
describe('BrowserWindow.show()', function() {
|
||||||
return it('should focus on window', function() {
|
it('should focus on window', function() {
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
w.show();
|
w.show();
|
||||||
return assert(w.isFocused());
|
assert(w.isFocused());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.showInactive()', function() {
|
describe('BrowserWindow.showInactive()', function() {
|
||||||
return it('should not focus on window', function() {
|
it('should not focus on window', function() {
|
||||||
w.showInactive();
|
w.showInactive();
|
||||||
return assert(!w.isFocused());
|
assert(!w.isFocused());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.focus()', function() {
|
describe('BrowserWindow.focus()', function() {
|
||||||
return it('does not make the window become visible', function() {
|
it('does not make the window become visible', function() {
|
||||||
assert.equal(w.isVisible(), false);
|
assert.equal(w.isVisible(), false);
|
||||||
w.focus();
|
w.focus();
|
||||||
return assert.equal(w.isVisible(), false);
|
assert.equal(w.isVisible(), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.capturePage(rect, callback)', function() {
|
describe('BrowserWindow.capturePage(rect, callback)', function() {
|
||||||
return it('calls the callback with a Buffer', function(done) {
|
it('calls the callback with a Buffer', function(done) {
|
||||||
return w.capturePage({
|
w.capturePage({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100
|
height: 100
|
||||||
}, function(image) {
|
}, function(image) {
|
||||||
assert.equal(image.isEmpty(), true);
|
assert.equal(image.isEmpty(), true);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.setSize(width, height)', function() {
|
describe('BrowserWindow.setSize(width, height)', function() {
|
||||||
return it('sets the window size', function(done) {
|
it('sets the window size', function(done) {
|
||||||
var size;
|
var size = [300, 400];
|
||||||
size = [300, 400];
|
|
||||||
w.once('resize', function() {
|
w.once('resize', function() {
|
||||||
var newSize;
|
var newSize = w.getSize();
|
||||||
newSize = w.getSize();
|
|
||||||
assert.equal(newSize[0], size[0]);
|
assert.equal(newSize[0], size[0]);
|
||||||
assert.equal(newSize[1], size[1]);
|
assert.equal(newSize[1], size[1]);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.setSize(size[0], size[1]);
|
w.setSize(size[0], size[1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.setPosition(x, y)', function() {
|
describe('BrowserWindow.setPosition(x, y)', function() {
|
||||||
return it('sets the window position', function(done) {
|
it('sets the window position', function(done) {
|
||||||
var pos;
|
var pos = [10, 10];
|
||||||
pos = [10, 10];
|
|
||||||
w.once('move', function() {
|
w.once('move', function() {
|
||||||
var newPos;
|
var newPos;
|
||||||
newPos = w.getPosition();
|
newPos = w.getPosition();
|
||||||
assert.equal(newPos[0], pos[0]);
|
assert.equal(newPos[0], pos[0]);
|
||||||
assert.equal(newPos[1], pos[1]);
|
assert.equal(newPos[1], pos[1]);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.setPosition(pos[0], pos[1]);
|
w.setPosition(pos[0], pos[1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.setContentSize(width, height)', function() {
|
describe('BrowserWindow.setContentSize(width, height)', function() {
|
||||||
it('sets the content size', function() {
|
it('sets the content size', function() {
|
||||||
var after, size;
|
var after, size;
|
||||||
|
@ -171,9 +184,10 @@ describe('browser-window module', function() {
|
||||||
w.setContentSize(size[0], size[1]);
|
w.setContentSize(size[0], size[1]);
|
||||||
after = w.getContentSize();
|
after = w.getContentSize();
|
||||||
assert.equal(after[0], size[0]);
|
assert.equal(after[0], size[0]);
|
||||||
return assert.equal(after[1], size[1]);
|
assert.equal(after[1], size[1]);
|
||||||
});
|
});
|
||||||
return it('works for framless window', function() {
|
|
||||||
|
it('works for framless window', function() {
|
||||||
var after, size;
|
var after, size;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
@ -186,14 +200,16 @@ describe('browser-window module', function() {
|
||||||
w.setContentSize(size[0], size[1]);
|
w.setContentSize(size[0], size[1]);
|
||||||
after = w.getContentSize();
|
after = w.getContentSize();
|
||||||
assert.equal(after[0], size[0]);
|
assert.equal(after[0], size[0]);
|
||||||
return assert.equal(after[1], size[1]);
|
assert.equal(after[1], size[1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.fromId(id)', function() {
|
describe('BrowserWindow.fromId(id)', function() {
|
||||||
return it('returns the window with id', function() {
|
it('returns the window with id', function() {
|
||||||
return assert.equal(w.id, BrowserWindow.fromId(w.id).id);
|
assert.equal(w.id, BrowserWindow.fromId(w.id).id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('"useContentSize" option', function() {
|
describe('"useContentSize" option', function() {
|
||||||
it('make window created with content size when used', function() {
|
it('make window created with content size when used', function() {
|
||||||
var contentSize;
|
var contentSize;
|
||||||
|
@ -206,15 +222,16 @@ describe('browser-window module', function() {
|
||||||
});
|
});
|
||||||
contentSize = w.getContentSize();
|
contentSize = w.getContentSize();
|
||||||
assert.equal(contentSize[0], 400);
|
assert.equal(contentSize[0], 400);
|
||||||
return assert.equal(contentSize[1], 400);
|
assert.equal(contentSize[1], 400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('make window created with window size when not used', function() {
|
it('make window created with window size when not used', function() {
|
||||||
var size;
|
var size = w.getSize();
|
||||||
size = w.getSize();
|
|
||||||
assert.equal(size[0], 400);
|
assert.equal(size[0], 400);
|
||||||
return assert.equal(size[1], 400);
|
assert.equal(size[1], 400);
|
||||||
});
|
});
|
||||||
return it('works for framless window', function() {
|
|
||||||
|
it('works for framless window', function() {
|
||||||
var contentSize, size;
|
var contentSize, size;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
@ -229,9 +246,10 @@ describe('browser-window module', function() {
|
||||||
assert.equal(contentSize[1], 400);
|
assert.equal(contentSize[1], 400);
|
||||||
size = w.getSize();
|
size = w.getSize();
|
||||||
assert.equal(size[0], 400);
|
assert.equal(size[0], 400);
|
||||||
return assert.equal(size[1], 400);
|
assert.equal(size[1], 400);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('"title-bar-style" option', function() {
|
describe('"title-bar-style" option', function() {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
return;
|
return;
|
||||||
|
@ -239,6 +257,7 @@ describe('browser-window module', function() {
|
||||||
if (parseInt(os.release().split('.')[0]) < 14) {
|
if (parseInt(os.release().split('.')[0]) < 14) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('creates browser window with hidden title bar', function() {
|
it('creates browser window with hidden title bar', function() {
|
||||||
var contentSize;
|
var contentSize;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
|
@ -249,9 +268,10 @@ describe('browser-window module', function() {
|
||||||
titleBarStyle: 'hidden'
|
titleBarStyle: 'hidden'
|
||||||
});
|
});
|
||||||
contentSize = w.getContentSize();
|
contentSize = w.getContentSize();
|
||||||
return assert.equal(contentSize[1], 400);
|
assert.equal(contentSize[1], 400);
|
||||||
});
|
});
|
||||||
return it('creates browser window with hidden inset title bar', function() {
|
|
||||||
|
it('creates browser window with hidden inset title bar', function() {
|
||||||
var contentSize;
|
var contentSize;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
@ -261,30 +281,34 @@ describe('browser-window module', function() {
|
||||||
titleBarStyle: 'hidden-inset'
|
titleBarStyle: 'hidden-inset'
|
||||||
});
|
});
|
||||||
contentSize = w.getContentSize();
|
contentSize = w.getContentSize();
|
||||||
return assert.equal(contentSize[1], 400);
|
assert.equal(contentSize[1], 400);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('"enableLargerThanScreen" option', function() {
|
describe('"enableLargerThanScreen" option', function() {
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
w.destroy();
|
w.destroy();
|
||||||
return w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: true,
|
show: true,
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 400,
|
height: 400,
|
||||||
enableLargerThanScreen: true
|
enableLargerThanScreen: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can move the window out of screen', function() {
|
it('can move the window out of screen', function() {
|
||||||
var after;
|
var after;
|
||||||
w.setPosition(-10, -10);
|
w.setPosition(-10, -10);
|
||||||
after = w.getPosition();
|
after = w.getPosition();
|
||||||
assert.equal(after[0], -10);
|
assert.equal(after[0], -10);
|
||||||
return assert.equal(after[1], -10);
|
assert.equal(after[1], -10);
|
||||||
});
|
});
|
||||||
return it('can set the window larger than screen', function() {
|
|
||||||
|
it('can set the window larger than screen', function() {
|
||||||
var after, size;
|
var after, size;
|
||||||
size = screen.getPrimaryDisplay().size;
|
size = screen.getPrimaryDisplay().size;
|
||||||
size.width += 100;
|
size.width += 100;
|
||||||
|
@ -292,21 +316,22 @@ describe('browser-window module', function() {
|
||||||
w.setSize(size.width, size.height);
|
w.setSize(size.width, size.height);
|
||||||
after = w.getSize();
|
after = w.getSize();
|
||||||
assert.equal(after[0], size.width);
|
assert.equal(after[0], size.width);
|
||||||
return assert.equal(after[1], size.height);
|
assert.equal(after[1], size.height);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('"web-preferences" option', function() {
|
describe('"web-preferences" option', function() {
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
return ipcMain.removeAllListeners('answer');
|
ipcMain.removeAllListeners('answer');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('"preload" option', function() {
|
describe('"preload" option', function() {
|
||||||
return it('loads the script before other scripts in window', function(done) {
|
it('loads the script before other scripts in window', function(done) {
|
||||||
var preload;
|
var preload;
|
||||||
preload = path.join(fixtures, 'module', 'set-global.js');
|
preload = path.join(fixtures, 'module', 'set-global.js');
|
||||||
ipcMain.once('answer', function(event, test) {
|
ipcMain.once('answer', function(event, test) {
|
||||||
assert.equal(test, 'preload');
|
assert.equal(test, 'preload');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
@ -315,16 +340,17 @@ describe('browser-window module', function() {
|
||||||
preload: preload
|
preload: preload
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return describe('"node-integration" option', function() {
|
|
||||||
return it('disables node integration when specified to false', function(done) {
|
describe('"node-integration" option', function() {
|
||||||
|
it('disables node integration when specified to false', function(done) {
|
||||||
var preload;
|
var preload;
|
||||||
preload = path.join(fixtures, 'module', 'send-later.js');
|
preload = path.join(fixtures, 'module', 'send-later.js');
|
||||||
ipcMain.once('answer', function(event, test) {
|
ipcMain.once('answer', function(event, test) {
|
||||||
assert.equal(test, 'undefined');
|
assert.equal(test, 'undefined');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
|
@ -334,107 +360,121 @@ describe('browser-window module', function() {
|
||||||
nodeIntegration: false
|
nodeIntegration: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'blank.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'blank.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('beforeunload handler', function() {
|
describe('beforeunload handler', function() {
|
||||||
it('returning true would not prevent close', function(done) {
|
it('returning true would not prevent close', function(done) {
|
||||||
w.on('closed', function() {
|
w.on('closed', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-true.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-true.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returning non-empty string would not prevent close', function(done) {
|
it('returning non-empty string would not prevent close', function(done) {
|
||||||
w.on('closed', function() {
|
w.on('closed', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-string.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-string.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returning false would prevent close', function(done) {
|
it('returning false would prevent close', function(done) {
|
||||||
w.on('onbeforeunload', function() {
|
w.on('onbeforeunload', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
|
||||||
});
|
});
|
||||||
return it('returning empty string would prevent close', function(done) {
|
|
||||||
|
it('returning empty string would prevent close', function(done) {
|
||||||
w.on('onbeforeunload', function() {
|
w.on('onbeforeunload', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'));
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('new-window event', function() {
|
describe('new-window event', function() {
|
||||||
if (isCI && process.platform === 'darwin') {
|
if (isCI && process.platform === 'darwin') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('emits when window.open is called', function(done) {
|
it('emits when window.open is called', function(done) {
|
||||||
w.webContents.once('new-window', function(e, url, frameName) {
|
w.webContents.once('new-window', function(e, url, frameName) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
assert.equal(url, 'http://host/');
|
assert.equal(url, 'http://host/');
|
||||||
assert.equal(frameName, 'host');
|
assert.equal(frameName, 'host');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL("file://" + fixtures + "/pages/window-open.html");
|
w.loadURL("file://" + fixtures + "/pages/window-open.html");
|
||||||
});
|
});
|
||||||
return it('emits when link with target is called', function(done) {
|
|
||||||
|
it('emits when link with target is called', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
w.webContents.once('new-window', function(e, url, frameName) {
|
w.webContents.once('new-window', function(e, url, frameName) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
assert.equal(url, 'http://host/');
|
assert.equal(url, 'http://host/');
|
||||||
assert.equal(frameName, 'target');
|
assert.equal(frameName, 'target');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return w.loadURL("file://" + fixtures + "/pages/target-name.html");
|
w.loadURL("file://" + fixtures + "/pages/target-name.html");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('maximize event', function() {
|
describe('maximize event', function() {
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return it('emits when window is maximized', function(done) {
|
|
||||||
|
it('emits when window is maximized', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
w.once('maximize', function() {
|
w.once('maximize', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.show();
|
w.show();
|
||||||
return w.maximize();
|
w.maximize();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('unmaximize event', function() {
|
describe('unmaximize event', function() {
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return it('emits when window is unmaximized', function(done) {
|
|
||||||
|
it('emits when window is unmaximized', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
w.once('unmaximize', function() {
|
w.once('unmaximize', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.show();
|
w.show();
|
||||||
w.maximize();
|
w.maximize();
|
||||||
return w.unmaximize();
|
w.unmaximize();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('minimize event', function() {
|
describe('minimize event', function() {
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return it('emits when window is minimized', function(done) {
|
|
||||||
|
it('emits when window is minimized', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
w.once('minimize', function() {
|
w.once('minimize', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
w.show();
|
w.show();
|
||||||
return w.minimize();
|
w.minimize();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
xdescribe('beginFrameSubscription method', function() {
|
xdescribe('beginFrameSubscription method', function() {
|
||||||
return it('subscribes frame updates', function(done) {
|
it('subscribes frame updates', function(done) {
|
||||||
w.loadURL("file://" + fixtures + "/api/blank.html");
|
w.loadURL("file://" + fixtures + "/api/blank.html");
|
||||||
return w.webContents.beginFrameSubscription(function(data) {
|
w.webContents.beginFrameSubscription(function(data) {
|
||||||
assert.notEqual(data.length, 0);
|
assert.notEqual(data.length, 0);
|
||||||
w.webContents.endFrameSubscription();
|
w.webContents.endFrameSubscription();
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -472,13 +512,13 @@ describe('browser-window module', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow options argument is optional', function() {
|
describe('BrowserWindow options argument is optional', function() {
|
||||||
return it('should create a window with default size (800x600)', function() {
|
it('should create a window with default size (800x600)', function() {
|
||||||
var size;
|
var size;
|
||||||
w.destroy();
|
w.destroy();
|
||||||
w = new BrowserWindow();
|
w = new BrowserWindow();
|
||||||
size = w.getSize();
|
size = w.getSize();
|
||||||
assert.equal(size[0], 800);
|
assert.equal(size[0], 800);
|
||||||
return assert.equal(size[1], 600);
|
assert.equal(size[1], 600);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -618,4 +658,16 @@ describe('browser-window module', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('window.webContents.send(channel, args...)', function() {
|
||||||
|
it('throws an error when the channel is missing', function() {
|
||||||
|
assert.throws(function() {
|
||||||
|
w.webContents.send();
|
||||||
|
}, 'Missing required channel argument');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
w.webContents.send(null);
|
||||||
|
}, 'Missing required channel argument');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -72,6 +72,11 @@ app.on('ready', function() {
|
||||||
// Test if using protocol module would crash.
|
// 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 = new BrowserWindow({
|
window = new BrowserWindow({
|
||||||
title: 'Electron Tests',
|
title: 'Electron Tests',
|
||||||
show: false,
|
show: false,
|
||||||
|
|
|
@ -1,166 +1,175 @@
|
||||||
var assert, http, path, url;
|
const assert = require('assert');
|
||||||
|
const path = require('path');
|
||||||
assert = require('assert');
|
const http = require('http');
|
||||||
|
const url = require('url');
|
||||||
path = require('path');
|
|
||||||
|
|
||||||
http = require('http');
|
|
||||||
|
|
||||||
url = require('url');
|
|
||||||
|
|
||||||
describe('<webview> tag', function() {
|
describe('<webview> tag', function() {
|
||||||
var fixtures, webview;
|
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
fixtures = path.join(__dirname, 'fixtures');
|
|
||||||
webview = null;
|
var fixtures = path.join(__dirname, 'fixtures');
|
||||||
|
var webview = null;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return webview = new WebView;
|
webview = new WebView;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
if (document.body.contains(webview)) {
|
if (document.body.contains(webview)) {
|
||||||
return document.body.removeChild(webview);
|
document.body.removeChild(webview);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('src attribute', function() {
|
describe('src attribute', function() {
|
||||||
it('specifies the page to load', function(done) {
|
it('specifies the page to load', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'a');
|
assert.equal(e.message, 'a');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/a.html";
|
webview.src = "file://" + fixtures + "/pages/a.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('navigates to new page when changed', function(done) {
|
|
||||||
|
it('navigates to new page when changed', function(done) {
|
||||||
var listener = function() {
|
var listener = function() {
|
||||||
webview.src = "file://" + fixtures + "/pages/b.html";
|
webview.src = "file://" + fixtures + "/pages/b.html";
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'b');
|
assert.equal(e.message, 'b');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
return webview.removeEventListener('did-finish-load', listener);
|
webview.removeEventListener('did-finish-load', listener);
|
||||||
};
|
};
|
||||||
webview.addEventListener('did-finish-load', listener);
|
webview.addEventListener('did-finish-load', listener);
|
||||||
webview.src = "file://" + fixtures + "/pages/a.html";
|
webview.src = "file://" + fixtures + "/pages/a.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nodeintegration attribute', function() {
|
describe('nodeintegration attribute', function() {
|
||||||
it('inserts no node symbols when not set', function(done) {
|
it('inserts no node symbols when not set', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'undefined undefined undefined undefined');
|
assert.equal(e.message, 'undefined undefined undefined undefined');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/c.html";
|
webview.src = "file://" + fixtures + "/pages/c.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('inserts node symbols when set', function(done) {
|
it('inserts node symbols when set', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'function object object');
|
assert.equal(e.message, 'function object object');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/d.html";
|
webview.src = "file://" + fixtures + "/pages/d.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads node symbols after POST navigation when set', function(done) {
|
it('loads node symbols after POST navigation when set', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'function object object');
|
assert.equal(e.message, 'function object object');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/post.html";
|
webview.src = "file://" + fixtures + "/pages/post.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
|
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
|
||||||
return it('loads native modules when navigation happens', function(done) {
|
it('loads native modules when navigation happens', function(done) {
|
||||||
var listener = function() {
|
var listener = function() {
|
||||||
webview.removeEventListener('did-finish-load', listener);
|
webview.removeEventListener('did-finish-load', listener);
|
||||||
var listener2 = function(e) {
|
var listener2 = function(e) {
|
||||||
assert.equal(e.message, 'function');
|
assert.equal(e.message, 'function');
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener2);
|
webview.addEventListener('console-message', listener2);
|
||||||
return webview.reload();
|
webview.reload();
|
||||||
};
|
};
|
||||||
webview.addEventListener('did-finish-load', listener);
|
webview.addEventListener('did-finish-load', listener);
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/native-module.html";
|
webview.src = "file://" + fixtures + "/pages/native-module.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('preload attribute', function() {
|
describe('preload attribute', function() {
|
||||||
it('loads the script before other scripts in window', function(done) {
|
it('loads the script before other scripts in window', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, 'function object object');
|
assert.equal(e.message, 'function object object');
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.setAttribute('preload', fixtures + "/module/preload.js");
|
webview.setAttribute('preload', fixtures + "/module/preload.js");
|
||||||
webview.src = "file://" + fixtures + "/pages/e.html";
|
webview.src = "file://" + fixtures + "/pages/e.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preload script can still use "process" in required modules when nodeintegration is off', function(done) {
|
it('preload script can still use "process" in required modules when nodeintegration is off', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'object undefined object');
|
assert.equal(e.message, 'object undefined object');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.setAttribute('preload', fixtures + "/module/preload-node-off.js");
|
webview.setAttribute('preload', fixtures + "/module/preload-node-off.js");
|
||||||
webview.src = "file://" + fixtures + "/api/blank.html";
|
webview.src = "file://" + fixtures + "/api/blank.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('receives ipc message in preload script', function(done) {
|
|
||||||
|
it('receives ipc message in preload script', function(done) {
|
||||||
var listener, listener2, message;
|
var listener, listener2, message;
|
||||||
message = 'boom!';
|
message = 'boom!';
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.channel, 'pong');
|
assert.equal(e.channel, 'pong');
|
||||||
assert.deepEqual(e.args, [message]);
|
assert.deepEqual(e.args, [message]);
|
||||||
webview.removeEventListener('ipc-message', listener);
|
webview.removeEventListener('ipc-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
listener2 = function() {
|
listener2 = function() {
|
||||||
webview.send('ping', message);
|
webview.send('ping', message);
|
||||||
return webview.removeEventListener('did-finish-load', listener2);
|
webview.removeEventListener('did-finish-load', listener2);
|
||||||
};
|
};
|
||||||
webview.addEventListener('ipc-message', listener);
|
webview.addEventListener('ipc-message', listener);
|
||||||
webview.addEventListener('did-finish-load', listener2);
|
webview.addEventListener('did-finish-load', listener2);
|
||||||
webview.setAttribute('preload', fixtures + "/module/preload-ipc.js");
|
webview.setAttribute('preload', fixtures + "/module/preload-ipc.js");
|
||||||
webview.src = "file://" + fixtures + "/pages/e.html";
|
webview.src = "file://" + fixtures + "/pages/e.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('httpreferrer attribute', function() {
|
describe('httpreferrer attribute', function() {
|
||||||
return it('sets the referrer url', function(done) {
|
it('sets the referrer url', function(done) {
|
||||||
var listener, referrer;
|
var listener, referrer;
|
||||||
referrer = 'http://github.com/';
|
referrer = 'http://github.com/';
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, referrer);
|
assert.equal(e.message, referrer);
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.setAttribute('httpreferrer', referrer);
|
webview.setAttribute('httpreferrer', referrer);
|
||||||
webview.src = "file://" + fixtures + "/pages/referrer.html";
|
webview.src = "file://" + fixtures + "/pages/referrer.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('useragent attribute', function() {
|
describe('useragent attribute', function() {
|
||||||
return it('sets the user agent', function(done) {
|
it('sets the user agent', function(done) {
|
||||||
var listener, referrer;
|
var listener, referrer;
|
||||||
referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
|
referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, referrer);
|
assert.equal(e.message, referrer);
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.setAttribute('useragent', referrer);
|
webview.setAttribute('useragent', referrer);
|
||||||
webview.src = "file://" + fixtures + "/pages/useragent.html";
|
webview.src = "file://" + fixtures + "/pages/useragent.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('disablewebsecurity attribute', function() {
|
describe('disablewebsecurity attribute', function() {
|
||||||
it('does not disable web security when not set', function(done) {
|
it('does not disable web security when not set', function(done) {
|
||||||
var encoded, listener, src;
|
var encoded, listener, src;
|
||||||
|
@ -169,164 +178,177 @@ describe('<webview> tag', function() {
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert(/Not allowed to load local resource/.test(e.message));
|
assert(/Not allowed to load local resource/.test(e.message));
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.src = "data:text/html;base64," + encoded;
|
webview.src = "data:text/html;base64," + encoded;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('disables web security when set', function(done) {
|
|
||||||
|
it('disables web security when set', function(done) {
|
||||||
var encoded, listener, src;
|
var encoded, listener, src;
|
||||||
src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
|
src = "<script src='file://" + __dirname + "/static/jquery-2.0.3.min.js'></script> <script>console.log('ok');</script>";
|
||||||
encoded = btoa(unescape(encodeURIComponent(src)));
|
encoded = btoa(unescape(encodeURIComponent(src)));
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, 'ok');
|
assert.equal(e.message, 'ok');
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.setAttribute('disablewebsecurity', '');
|
webview.setAttribute('disablewebsecurity', '');
|
||||||
webview.src = "data:text/html;base64," + encoded;
|
webview.src = "data:text/html;base64," + encoded;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('partition attribute', function() {
|
describe('partition attribute', function() {
|
||||||
it('inserts no node symbols when not set', function(done) {
|
it('inserts no node symbols when not set', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'undefined undefined undefined undefined');
|
assert.equal(e.message, 'undefined undefined undefined undefined');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/c.html";
|
webview.src = "file://" + fixtures + "/pages/c.html";
|
||||||
webview.partition = 'test1';
|
webview.partition = 'test1';
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('inserts node symbols when set', function(done) {
|
it('inserts node symbols when set', function(done) {
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', function(e) {
|
||||||
assert.equal(e.message, 'function object object');
|
assert.equal(e.message, 'function object object');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/d.html";
|
webview.src = "file://" + fixtures + "/pages/d.html";
|
||||||
webview.partition = 'test2';
|
webview.partition = 'test2';
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isolates storage for different id', function(done) {
|
it('isolates storage for different id', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, " 0");
|
assert.equal(e.message, " 0");
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
window.localStorage.setItem('test', 'one');
|
window.localStorage.setItem('test', 'one');
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.src = "file://" + fixtures + "/pages/partition/one.html";
|
webview.src = "file://" + fixtures + "/pages/partition/one.html";
|
||||||
webview.partition = 'test3';
|
webview.partition = 'test3';
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('uses current session storage when no id is provided', function(done) {
|
|
||||||
|
it('uses current session storage when no id is provided', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, "one 1");
|
assert.equal(e.message, "one 1");
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
window.localStorage.setItem('test', 'one');
|
window.localStorage.setItem('test', 'one');
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.src = "file://" + fixtures + "/pages/partition/one.html";
|
webview.src = "file://" + fixtures + "/pages/partition/one.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('allowpopups attribute', function() {
|
describe('allowpopups attribute', function() {
|
||||||
it('can not open new window when not set', function(done) {
|
it('can not open new window when not set', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, 'null');
|
assert.equal(e.message, 'null');
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.src = "file://" + fixtures + "/pages/window-open-hide.html";
|
webview.src = "file://" + fixtures + "/pages/window-open-hide.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('can open new window when set', function(done) {
|
|
||||||
|
it('can open new window when set', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.message, 'window');
|
assert.equal(e.message, 'window');
|
||||||
webview.removeEventListener('console-message', listener);
|
webview.removeEventListener('console-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('console-message', listener);
|
webview.addEventListener('console-message', listener);
|
||||||
webview.setAttribute('allowpopups', 'on');
|
webview.setAttribute('allowpopups', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/window-open-hide.html";
|
webview.src = "file://" + fixtures + "/pages/window-open-hide.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('new-window event', function() {
|
describe('new-window event', function() {
|
||||||
it('emits when window.open is called', function(done) {
|
it('emits when window.open is called', function(done) {
|
||||||
webview.addEventListener('new-window', function(e) {
|
webview.addEventListener('new-window', function(e) {
|
||||||
assert.equal(e.url, 'http://host/');
|
assert.equal(e.url, 'http://host/');
|
||||||
assert.equal(e.frameName, 'host');
|
assert.equal(e.frameName, 'host');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/window-open.html";
|
webview.src = "file://" + fixtures + "/pages/window-open.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('emits when link with target is called', function(done) {
|
|
||||||
|
it('emits when link with target is called', function(done) {
|
||||||
webview.addEventListener('new-window', function(e) {
|
webview.addEventListener('new-window', function(e) {
|
||||||
assert.equal(e.url, 'http://host/');
|
assert.equal(e.url, 'http://host/');
|
||||||
assert.equal(e.frameName, 'target');
|
assert.equal(e.frameName, 'target');
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/target-name.html";
|
webview.src = "file://" + fixtures + "/pages/target-name.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ipc-message event', function() {
|
describe('ipc-message event', function() {
|
||||||
return it('emits when guest sends a ipc message to browser', function(done) {
|
it('emits when guest sends a ipc message to browser', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert.equal(e.channel, 'channel');
|
assert.equal(e.channel, 'channel');
|
||||||
assert.deepEqual(e.args, ['arg1', 'arg2']);
|
assert.deepEqual(e.args, ['arg1', 'arg2']);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/ipc-message.html";
|
webview.src = "file://" + fixtures + "/pages/ipc-message.html";
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('page-title-set event', function() {
|
describe('page-title-set event', function() {
|
||||||
return it('emits when title is set', function(done) {
|
it('emits when title is set', function(done) {
|
||||||
webview.addEventListener('page-title-set', function(e) {
|
webview.addEventListener('page-title-set', function(e) {
|
||||||
assert.equal(e.title, 'test');
|
assert.equal(e.title, 'test');
|
||||||
assert(e.explicitSet);
|
assert(e.explicitSet);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/a.html";
|
webview.src = "file://" + fixtures + "/pages/a.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('page-favicon-updated event', function() {
|
describe('page-favicon-updated event', function() {
|
||||||
return it('emits when favicon urls are received', function(done) {
|
it('emits when favicon urls are received', function(done) {
|
||||||
webview.addEventListener('page-favicon-updated', function(e) {
|
webview.addEventListener('page-favicon-updated', function(e) {
|
||||||
var pageUrl;
|
var pageUrl;
|
||||||
assert.equal(e.favicons.length, 2);
|
assert.equal(e.favicons.length, 2);
|
||||||
pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
|
pageUrl = process.platform === 'win32' ? 'file:///C:/favicon.png' : 'file:///favicon.png';
|
||||||
assert.equal(e.favicons[0], pageUrl);
|
assert.equal(e.favicons[0], pageUrl);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/a.html";
|
webview.src = "file://" + fixtures + "/pages/a.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('will-navigate event', function() {
|
describe('will-navigate event', function() {
|
||||||
return it('emits when a url that leads to oustide of the page is clicked', function(done) {
|
it('emits when a url that leads to oustide of the page is clicked', function(done) {
|
||||||
webview.addEventListener('will-navigate', function(e) {
|
webview.addEventListener('will-navigate', function(e) {
|
||||||
assert.equal(e.url, "http://host/");
|
assert.equal(e.url, "http://host/");
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/webview-will-navigate.html";
|
webview.src = "file://" + fixtures + "/pages/webview-will-navigate.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('did-navigate event', function() {
|
describe('did-navigate event', function() {
|
||||||
var p, pageUrl;
|
var p, pageUrl;
|
||||||
p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
|
p = path.join(fixtures, 'pages', 'webview-will-navigate.html');
|
||||||
|
@ -336,13 +358,14 @@ describe('<webview> tag', function() {
|
||||||
slashes: true,
|
slashes: true,
|
||||||
pathname: p
|
pathname: p
|
||||||
});
|
});
|
||||||
return it('emits when a url that leads to outside of the page is clicked', function(done) {
|
|
||||||
|
it('emits when a url that leads to outside of the page is clicked', function(done) {
|
||||||
webview.addEventListener('did-navigate', function(e) {
|
webview.addEventListener('did-navigate', function(e) {
|
||||||
assert.equal(e.url, pageUrl);
|
assert.equal(e.url, pageUrl);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = pageUrl;
|
webview.src = pageUrl;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('did-navigate-in-page event', function() {
|
describe('did-navigate-in-page event', function() {
|
||||||
|
@ -357,20 +380,22 @@ describe('<webview> tag', function() {
|
||||||
});
|
});
|
||||||
webview.addEventListener('did-navigate-in-page', function(e) {
|
webview.addEventListener('did-navigate-in-page', function(e) {
|
||||||
assert.equal(e.url, pageUrl + "#test_content");
|
assert.equal(e.url, pageUrl + "#test_content");
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = pageUrl;
|
webview.src = pageUrl;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits when window.history.replaceState is called', function(done) {
|
it('emits when window.history.replaceState is called', function(done) {
|
||||||
webview.addEventListener('did-navigate-in-page', function(e) {
|
webview.addEventListener('did-navigate-in-page', function(e) {
|
||||||
assert.equal(e.url, "http://host/");
|
assert.equal(e.url, "http://host/");
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/webview-did-navigate-in-page-with-history.html";
|
webview.src = "file://" + fixtures + "/pages/webview-did-navigate-in-page-with-history.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('emits when window.location.hash is changed', function(done) {
|
|
||||||
|
it('emits when window.location.hash is changed', function(done) {
|
||||||
var p, pageUrl;
|
var p, pageUrl;
|
||||||
p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
|
p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html');
|
||||||
p = p.replace(/\\/g, '/');
|
p = p.replace(/\\/g, '/');
|
||||||
|
@ -381,94 +406,100 @@ describe('<webview> tag', function() {
|
||||||
});
|
});
|
||||||
webview.addEventListener('did-navigate-in-page', function(e) {
|
webview.addEventListener('did-navigate-in-page', function(e) {
|
||||||
assert.equal(e.url, pageUrl + "#test");
|
assert.equal(e.url, pageUrl + "#test");
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = pageUrl;
|
webview.src = pageUrl;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('close event', function() {
|
describe('close event', function() {
|
||||||
return it('should fire when interior page calls window.close', function(done) {
|
it('should fire when interior page calls window.close', function(done) {
|
||||||
webview.addEventListener('close', function() {
|
webview.addEventListener('close', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/close.html";
|
webview.src = "file://" + fixtures + "/pages/close.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('devtools-opened event', function() {
|
describe('devtools-opened event', function() {
|
||||||
return it('should fire when webview.openDevTools() is called', function(done) {
|
it('should fire when webview.openDevTools() is called', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function() {
|
listener = function() {
|
||||||
webview.removeEventListener('devtools-opened', listener);
|
webview.removeEventListener('devtools-opened', listener);
|
||||||
webview.closeDevTools();
|
webview.closeDevTools();
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('devtools-opened', listener);
|
webview.addEventListener('devtools-opened', listener);
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return webview.openDevTools();
|
webview.openDevTools();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('devtools-closed event', function() {
|
describe('devtools-closed event', function() {
|
||||||
return it('should fire when webview.closeDevTools() is called', function(done) {
|
it('should fire when webview.closeDevTools() is called', function(done) {
|
||||||
var listener, listener2;
|
var listener, listener2;
|
||||||
listener2 = function() {
|
listener2 = function() {
|
||||||
webview.removeEventListener('devtools-closed', listener2);
|
webview.removeEventListener('devtools-closed', listener2);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
listener = function() {
|
listener = function() {
|
||||||
webview.removeEventListener('devtools-opened', listener);
|
webview.removeEventListener('devtools-opened', listener);
|
||||||
return webview.closeDevTools();
|
webview.closeDevTools();
|
||||||
};
|
};
|
||||||
webview.addEventListener('devtools-opened', listener);
|
webview.addEventListener('devtools-opened', listener);
|
||||||
webview.addEventListener('devtools-closed', listener2);
|
webview.addEventListener('devtools-closed', listener2);
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return webview.openDevTools();
|
webview.openDevTools();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('devtools-focused event', function() {
|
describe('devtools-focused event', function() {
|
||||||
return it('should fire when webview.openDevTools() is called', function(done) {
|
it('should fire when webview.openDevTools() is called', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function() {
|
listener = function() {
|
||||||
webview.removeEventListener('devtools-focused', listener);
|
webview.removeEventListener('devtools-focused', listener);
|
||||||
webview.closeDevTools();
|
webview.closeDevTools();
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('devtools-focused', listener);
|
webview.addEventListener('devtools-focused', listener);
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return webview.openDevTools();
|
webview.openDevTools();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
webview.src = "file://" + fixtures + "/pages/base-page.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<webview>.reload()', function() {
|
describe('<webview>.reload()', function() {
|
||||||
return it('should emit beforeunload handler', function(done) {
|
it('should emit beforeunload handler', function(done) {
|
||||||
var listener, listener2;
|
var listener, listener2;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.channel, 'onbeforeunload');
|
assert.equal(e.channel, 'onbeforeunload');
|
||||||
webview.removeEventListener('ipc-message', listener);
|
webview.removeEventListener('ipc-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
listener2 = function() {
|
listener2 = function() {
|
||||||
webview.reload();
|
webview.reload();
|
||||||
return webview.removeEventListener('did-finish-load', listener2);
|
webview.removeEventListener('did-finish-load', listener2);
|
||||||
};
|
};
|
||||||
webview.addEventListener('ipc-message', listener);
|
webview.addEventListener('ipc-message', listener);
|
||||||
webview.addEventListener('did-finish-load', listener2);
|
webview.addEventListener('did-finish-load', listener2);
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/beforeunload-false.html";
|
webview.src = "file://" + fixtures + "/pages/beforeunload-false.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<webview>.clearHistory()', function() {
|
describe('<webview>.clearHistory()', function() {
|
||||||
return it('should clear the navigation history', function(done) {
|
it('should clear the navigation history', function(done) {
|
||||||
var listener;
|
var listener;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
assert.equal(e.channel, 'history');
|
assert.equal(e.channel, 'history');
|
||||||
|
@ -477,18 +508,19 @@ describe('<webview> tag', function() {
|
||||||
webview.clearHistory();
|
webview.clearHistory();
|
||||||
assert(!webview.canGoBack());
|
assert(!webview.canGoBack());
|
||||||
webview.removeEventListener('ipc-message', listener);
|
webview.removeEventListener('ipc-message', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
webview.addEventListener('ipc-message', listener);
|
webview.addEventListener('ipc-message', listener);
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
webview.src = "file://" + fixtures + "/pages/history.html";
|
webview.src = "file://" + fixtures + "/pages/history.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('basic auth', function() {
|
describe('basic auth', function() {
|
||||||
var auth;
|
var auth;
|
||||||
auth = require('basic-auth');
|
auth = require('basic-auth');
|
||||||
return it('should authenticate with correct credentials', function(done) {
|
it('should authenticate with correct credentials', function(done) {
|
||||||
var message, server;
|
var message, server;
|
||||||
message = 'Authenticated';
|
message = 'Authenticated';
|
||||||
server = http.createServer(function(req, res) {
|
server = http.createServer(function(req, res) {
|
||||||
|
@ -499,67 +531,77 @@ describe('<webview> tag', function() {
|
||||||
} else {
|
} else {
|
||||||
res.end('failed');
|
res.end('failed');
|
||||||
}
|
}
|
||||||
return server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
return server.listen(0, '127.0.0.1', function() {
|
server.listen(0, '127.0.0.1', function() {
|
||||||
var port;
|
var port;
|
||||||
port = server.address().port;
|
port = server.address().port;
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert.equal(e.channel, message);
|
assert.equal(e.channel, message);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/basic-auth.html?port=" + port;
|
webview.src = "file://" + fixtures + "/pages/basic-auth.html?port=" + port;
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dom-ready event', function() {
|
describe('dom-ready event', function() {
|
||||||
return it('emits when document is loaded', function(done) {
|
it('emits when document is loaded', function(done) {
|
||||||
var server;
|
var server;
|
||||||
server = http.createServer(function() {});
|
server = http.createServer(function() {});
|
||||||
return server.listen(0, '127.0.0.1', function() {
|
server.listen(0, '127.0.0.1', function() {
|
||||||
var port;
|
var port;
|
||||||
port = server.address().port;
|
port = server.address().port;
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/dom-ready.html?port=" + port;
|
webview.src = "file://" + fixtures + "/pages/dom-ready.html?port=" + port;
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws a custom error when an API method is called before the event is emitted', function() {
|
||||||
|
assert.throws(function () {
|
||||||
|
webview.stop();
|
||||||
|
}, 'Cannot call stop because the webContents is unavailable. The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('executeJavaScript', function() {
|
describe('executeJavaScript', function() {
|
||||||
if (process.env.TRAVIS !== 'true') {
|
if (process.env.TRAVIS !== 'true') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return it('should support user gesture', function(done) {
|
|
||||||
|
it('should support user gesture', function(done) {
|
||||||
var listener, listener2;
|
var listener, listener2;
|
||||||
listener = function() {
|
listener = function() {
|
||||||
webview.removeEventListener('enter-html-full-screen', listener);
|
webview.removeEventListener('enter-html-full-screen', listener);
|
||||||
return done();
|
done();
|
||||||
};
|
};
|
||||||
listener2 = function() {
|
listener2 = function() {
|
||||||
var jsScript;
|
var jsScript;
|
||||||
jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
|
jsScript = 'document.getElementsByTagName("video")[0].webkitRequestFullScreen()';
|
||||||
webview.executeJavaScript(jsScript, true);
|
webview.executeJavaScript(jsScript, true);
|
||||||
return webview.removeEventListener('did-finish-load', listener2);
|
webview.removeEventListener('did-finish-load', listener2);
|
||||||
};
|
};
|
||||||
webview.addEventListener('enter-html-full-screen', listener);
|
webview.addEventListener('enter-html-full-screen', listener);
|
||||||
webview.addEventListener('did-finish-load', listener2);
|
webview.addEventListener('did-finish-load', listener2);
|
||||||
webview.src = "file://" + fixtures + "/pages/fullscreen.html";
|
webview.src = "file://" + fixtures + "/pages/fullscreen.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sendInputEvent', function() {
|
describe('sendInputEvent', function() {
|
||||||
it('can send keyboard event', function(done) {
|
it('can send keyboard event', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert.equal(e.channel, 'keyup');
|
assert.equal(e.channel, 'keyup');
|
||||||
assert.deepEqual(e.args, [67, true, false]);
|
assert.deepEqual(e.args, [67, true, false]);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return webview.sendInputEvent({
|
webview.sendInputEvent({
|
||||||
type: 'keyup',
|
type: 'keyup',
|
||||||
keyCode: 'c',
|
keyCode: 'c',
|
||||||
modifiers: ['shift']
|
modifiers: ['shift']
|
||||||
|
@ -567,16 +609,17 @@ describe('<webview> tag', function() {
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/onkeyup.html";
|
webview.src = "file://" + fixtures + "/pages/onkeyup.html";
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
return it('can send mouse event', function(done) {
|
|
||||||
|
it('can send mouse event', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert.equal(e.channel, 'mouseup');
|
assert.equal(e.channel, 'mouseup');
|
||||||
assert.deepEqual(e.args, [10, 20, false, true]);
|
assert.deepEqual(e.args, [10, 20, false, true]);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.addEventListener('dom-ready', function() {
|
webview.addEventListener('dom-ready', function() {
|
||||||
return webview.sendInputEvent({
|
webview.sendInputEvent({
|
||||||
type: 'mouseup',
|
type: 'mouseup',
|
||||||
modifiers: ['ctrl'],
|
modifiers: ['ctrl'],
|
||||||
x: 10,
|
x: 10,
|
||||||
|
@ -585,26 +628,28 @@ describe('<webview> tag', function() {
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/onmouseup.html";
|
webview.src = "file://" + fixtures + "/pages/onmouseup.html";
|
||||||
webview.setAttribute('nodeintegration', 'on');
|
webview.setAttribute('nodeintegration', 'on');
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('media-started-playing media-paused events', function() {
|
describe('media-started-playing media-paused events', function() {
|
||||||
return it('emits when audio starts and stops playing', function(done) {
|
it('emits when audio starts and stops playing', function(done) {
|
||||||
var audioPlayed;
|
var audioPlayed;
|
||||||
audioPlayed = false;
|
audioPlayed = false;
|
||||||
webview.addEventListener('media-started-playing', function() {
|
webview.addEventListener('media-started-playing', function() {
|
||||||
return audioPlayed = true;
|
audioPlayed = true;
|
||||||
});
|
});
|
||||||
webview.addEventListener('media-paused', function() {
|
webview.addEventListener('media-paused', function() {
|
||||||
assert(audioPlayed);
|
assert(audioPlayed);
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/audio.html";
|
webview.src = "file://" + fixtures + "/pages/audio.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('found-in-page event', function() {
|
describe('found-in-page event', function() {
|
||||||
return it('emits when a request is made', function(done) {
|
it('emits when a request is made', function(done) {
|
||||||
var listener, listener2, requestId;
|
var listener, listener2, requestId;
|
||||||
requestId = null;
|
requestId = null;
|
||||||
listener = function(e) {
|
listener = function(e) {
|
||||||
|
@ -612,27 +657,29 @@ describe('<webview> tag', function() {
|
||||||
if (e.result.finalUpdate) {
|
if (e.result.finalUpdate) {
|
||||||
assert.equal(e.result.matches, 3);
|
assert.equal(e.result.matches, 3);
|
||||||
webview.stopFindInPage("clearSelection");
|
webview.stopFindInPage("clearSelection");
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
listener2 = function() {
|
listener2 = function() {
|
||||||
return requestId = webview.findInPage("virtual");
|
requestId = webview.findInPage("virtual");
|
||||||
};
|
};
|
||||||
webview.addEventListener('found-in-page', listener);
|
webview.addEventListener('found-in-page', listener);
|
||||||
webview.addEventListener('did-finish-load', listener2);
|
webview.addEventListener('did-finish-load', listener2);
|
||||||
webview.src = "file://" + fixtures + "/pages/content.html";
|
webview.src = "file://" + fixtures + "/pages/content.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
xdescribe('did-change-theme-color event', function() {
|
xdescribe('did-change-theme-color event', function() {
|
||||||
return it('emits when theme color changes', function(done) {
|
it('emits when theme color changes', function(done) {
|
||||||
webview.addEventListener('did-change-theme-color', function() {
|
webview.addEventListener('did-change-theme-color', function() {
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
webview.src = "file://" + fixtures + "/pages/theme-color.html";
|
webview.src = "file://" + fixtures + "/pages/theme-color.html";
|
||||||
return document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('permission-request event', function() {
|
describe('permission-request event', function() {
|
||||||
function setUpRequestHandler(webview, requested_permission) {
|
function setUpRequestHandler(webview, requested_permission) {
|
||||||
const session = require('electron').remote.session;
|
const session = require('electron').remote.session;
|
||||||
|
@ -645,7 +692,7 @@ describe('<webview> tag', function() {
|
||||||
session.fromPartition(webview.partition).setPermissionRequestHandler(listener);
|
session.fromPartition(webview.partition).setPermissionRequestHandler(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
it ('emits when using navigator.getUserMedia api', function(done) {
|
it('emits when using navigator.getUserMedia api', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert(e.channel, 'message');
|
assert(e.channel, 'message');
|
||||||
assert(e.args, ['PermissionDeniedError']);
|
assert(e.args, ['PermissionDeniedError']);
|
||||||
|
@ -658,7 +705,7 @@ describe('<webview> tag', function() {
|
||||||
document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('emits when using navigator.geolocation api', function(done) {
|
it('emits when using navigator.geolocation api', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert(e.channel, 'message');
|
assert(e.channel, 'message');
|
||||||
assert(e.args, ['ERROR(1): User denied Geolocation']);
|
assert(e.args, ['ERROR(1): User denied Geolocation']);
|
||||||
|
@ -671,7 +718,7 @@ describe('<webview> tag', function() {
|
||||||
document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('emits when using navigator.requestMIDIAccess api', function(done) {
|
it('emits when using navigator.requestMIDIAccess api', function(done) {
|
||||||
webview.addEventListener('ipc-message', function(e) {
|
webview.addEventListener('ipc-message', function(e) {
|
||||||
assert(e.channel, 'message');
|
assert(e.channel, 'message');
|
||||||
assert(e.args, ['SecurityError']);
|
assert(e.args, ['SecurityError']);
|
||||||
|
|
Loading…
Reference in a new issue