diff --git a/atom/browser/api/lib/auto-updater/auto-updater-win.js b/atom/browser/api/lib/auto-updater/auto-updater-win.js index f8a07902f21..1270f8f2bdb 100644 --- a/atom/browser/api/lib/auto-updater/auto-updater-win.js +++ b/atom/browser/api/lib/auto-updater/auto-updater-win.js @@ -3,60 +3,61 @@ const app = require('electron').app; const EventEmitter = require('events').EventEmitter; const squirrelUpdate = require('./squirrel-update-win'); +const util = require('util'); -class AutoUpdater extends EventEmitter { - constructor() { - super(); +function AutoUpdater() { + EventEmitter.call(this); +} + +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'); } - - quitAndInstall() { - squirrelUpdate.processStart(); - return app.quit(); + if (!squirrelUpdate.supported()) { + return this.emitError('Can not find Squirrel'); } - - setFeedURL(updateURL) { - return this.updateURL = updateURL; - } - - checkForUpdates() { - if (!this.updateURL) { - return this.emitError('Update URL is not set'); - } - if (!squirrelUpdate.supported()) { - return this.emitError('Can not find Squirrel'); - } - this.emit('checking-for-update'); - return squirrelUpdate.download(this.updateURL, (function(_this) { - return function(error, update) { + this.emit('checking-for-update'); + return squirrelUpdate.download(this.updateURL, (function(_this) { + return function(error, update) { + if (error != null) { + return _this.emitError(error); + } + if (update == null) { + 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); } - if (update == null) { - 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; + releaseNotes = update.releaseNotes, version = update.version; - // Following information is not available on Windows, so fake them. - date = new Date; - return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { - return _this.quitAndInstall(); - }); + // Following information is not available on Windows, so fake them. + date = new Date; + return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { + return _this.quitAndInstall(); }); - }; - })(this)); - } + }); + }; + })(this)); +}; - // Private: Emit both error object and message, this is to keep compatibility - // with Old APIs. - emitError(message) { - return this.emit('error', new Error(message), message); - } -} +// Private: Emit both error object and message, this is to keep compatibility +// with Old APIs. +AutoUpdater.prototype.emitError = function(message) { + return this.emit('error', new Error(message), message); +}; module.exports = new AutoUpdater; diff --git a/spec/api-auto-updater-spec.js b/spec/api-auto-updater-spec.js new file mode 100644 index 00000000000..72a1d90a7fe --- /dev/null +++ b/spec/api-auto-updater-spec.js @@ -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(''); + }); + }); +}); diff --git a/spec/static/main.js b/spec/static/main.js index 13d2dd6a6e1..125ef72f609 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -72,6 +72,11 @@ app.on('ready', function() { // Test if using protocol module would crash. 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({ title: 'Electron Tests', show: false,