Skip to content
Browse files

Bug 817821: Better update download event handling. r=etienne

  • Loading branch information...
1 parent 3b2854f commit 726e800a4d6a20aebc6075031536b811452d7e36 @marshall marshall committed Jan 7, 2013
Showing with 71 additions and 22 deletions.
  1. +15 −6 apps/system/js/updatable.js
  2. +56 −16 apps/system/test/unit/updatable_test.js
View
21 apps/system/js/updatable.js
@@ -111,6 +111,7 @@ function SystemUpdatable() {
this.name = _('systemUpdate');
this.size = 0;
this.downloading = false;
+ this.paused = false;
window.addEventListener('mozChromeEvent', this);
}
@@ -120,6 +121,7 @@ SystemUpdatable.prototype.download = function() {
}
this.downloading = true;
+ this.paused = false;
this._dispatchEvent('update-available-result', 'download');
UpdateManager.addToDownloadsQueue(this);
this.progress = 0;
@@ -129,6 +131,7 @@ SystemUpdatable.prototype.cancelDownload = function() {
this._dispatchEvent('update-download-cancel');
UpdateManager.removeFromDownloadsQueue(this);
this.downloading = false;
+ this.paused = false;
};
SystemUpdatable.prototype.uninit = function() {
@@ -147,17 +150,23 @@ SystemUpdatable.prototype.handleEvent = function(evt) {
case 'update-error':
this.errorCallBack();
break;
- case 'update-progress':
- if (detail.progress === detail.total) {
- UpdateManager.startedUncompressing();
- break;
- }
-
+ case 'update-download-started':
+ // TODO UpdateManager glue
+ this.paused = false;
+ break;
+ case 'update-download-progress':
var delta = detail.progress - this.progress;
this.progress = detail.progress;
UpdateManager.downloadProgressed(delta);
break;
+ case 'update-download-stopped':
+ // TODO UpdateManager glue
+ this.paused = detail.paused;
+ if (!this.paused) {
+ UpdateManager.startedUncompressing();
+ }
+ break;
case 'update-downloaded':
this.downloading = false;
case 'update-prompt-apply':
View
72 apps/system/test/unit/updatable_test.js
@@ -444,40 +444,80 @@ suite('system/Updatable', function() {
});
});
- suite('update-progress', function() {
+ suite('update download events', function() {
var event;
setup(function() {
subject = new SystemUpdatable(98734);
subject.download();
- event = new MockChromeEvent({
- type: 'update-progress',
- progress: 1234,
- total: 98734
+ });
+
+ suite('when the download starts', function() {
+ setup(function() {
+ event = new MockChromeEvent({
+ type: 'update-download-started',
+ total: 98734
+ });
+ });
+
+ test('should clear paused flag', function() {
+ subject.paused = true;
+ subject.handleEvent(event);
+ assert.isFalse(subject.paused);
});
});
- test('should send progress to update manager', function() {
- subject.handleEvent(event);
- assert.equal(1234, MockUpdateManager.mProgressCalledWith);
+ suite('when the download receives progress', function() {
+ setup(function() {
+ event = new MockChromeEvent({
+ type: 'update-download-progress',
+ progress: 1234,
+ total: 98734
+ });
+ })
+
+ test('should send progress to update manager', function() {
+ subject.handleEvent(event);
+ assert.equal(1234, MockUpdateManager.mProgressCalledWith);
+ });
+
+ test('should send progress delta to update manager', function() {
+ subject.handleEvent(event);
+ event.detail.progress = 2234;
+ subject.handleEvent(event);
+ assert.equal(1000, MockUpdateManager.mProgressCalledWith);
+ });
});
- test('should send progress delta to update manager', function() {
- subject.handleEvent(event);
- event.detail.progress = 2234;
- subject.handleEvent(event);
- assert.equal(1000, MockUpdateManager.mProgressCalledWith);
+ suite('when the download is paused', function() {
+ setup(function() {
+ event = new MockChromeEvent({
+ type: 'update-download-stopped',
+ paused: true
+ });
+ subject.handleEvent(event);
+ });
+
+ test('should set the paused flag', function() {
+ assert.isTrue(subject.paused);
+ });
+ test('shouldn\'t signal "started uncompressing"', function() {
+ assert.isFalse(MockUpdateManager.mStartedUncompressingCalled);
+ });
});
suite('when the download is complete', function() {
setup(function() {
event = new MockChromeEvent({
- type: 'update-progress',
- progress: 98734,
- total: 98734
+ type: 'update-download-stopped',
+ paused: false
});
subject.handleEvent(event);
});
+ test('should clear the paused flag', function() {
+ assert.isFalse(subject.paused);
+ });
+
test('should signal the UpdateManager', function() {
assert.isTrue(MockUpdateManager.mStartedUncompressingCalled);
});

0 comments on commit 726e800

Please sign in to comment.
Something went wrong with that request. Please try again.