Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Bug 833708: Correctly handle update errors that happen in-stack while sending a download event #8303

Open
wants to merge 1 commit into from

1 participant

Marshall Culpepper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 25, 2013
Marshall Culpepper marshall Bug 833708: Correctly handle update errors that happen in-stack while…
… sending a download event. r=etienne
afb3ef9
This page is out of date. Refresh to see the latest.
2  apps/system/js/updatable.js
@@ -146,9 +146,9 @@ SystemUpdatable.prototype.download = function() {
146 146
147 147 this.downloading = true;
148 148 this.paused = false;
149   - this._dispatchEvent('update-available-result', 'download');
150 149 UpdateManager.addToDownloadsQueue(this);
151 150 this.progress = 0;
  151 + this._dispatchEvent('update-available-result', 'download');
152 152 };
153 153
154 154 SystemUpdatable.prototype.cancelDownload = function() {
14 apps/system/test/unit/mock_update_manager.js
@@ -3,6 +3,7 @@
3 3 var MockUpdateManager = {
4 4 addToUpdatesQueue: function mum_addtoUpdateQueue(updatable) {
5 5 this.mLastUpdatesAdd = updatable;
  6 + this.mUpdates.push(updatable);
6 7 },
7 8 addToUpdatableApps: function mum_addToUpdatableApps(updatable) {
8 9 this.mLastUpdatableAdd = updatable;
@@ -10,15 +11,24 @@ var MockUpdateManager = {
10 11
11 12 removeFromUpdatesQueue: function mum_removeFromUpdateQueue(updatable) {
12 13 this.mLastUpdatesRemoval = updatable;
  14 + var index = this.mUpdates.indexOf(updatable);
  15 + if (index >= 0) {
  16 + this.mUpdates.splice(index, 1);
  17 + }
13 18 },
14 19
15 20 addToDownloadsQueue: function mum_addtoActiveDownloads(updatable) {
16 21 this.mLastDownloadsAdd = updatable;
  22 + this.mDownloads.push(updatable);
17 23 },
18 24 removeFromDownloadsQueue:
19 25 function mum_removeFromActiveDownloads(updatable) {
20 26
21 27 this.mLastDownloadsRemoval = updatable;
  28 + var index = this.mDownloads.indexOf(updatable);
  29 + if (index >= 0) {
  30 + this.mDownloads.splice(index, 1);
  31 + }
22 32 },
23 33
24 34 downloadProgressed: function mum_downloadProgressed(bytes) {
@@ -38,6 +48,8 @@ var MockUpdateManager = {
38 48 },
39 49
40 50 mErrorBannerRequested: false,
  51 + mUpdates: [],
  52 + mDownloads: [],
41 53 mLastUpdatesAdd: null,
42 54 mLastUpdatableAdd: null,
43 55 mLastUpdatesRemoval: null,
@@ -56,5 +68,7 @@ var MockUpdateManager = {
56 68 this.mProgressCalledWith = null;
57 69 this.mCheckForUpdatesCalledWith = null;
58 70 this.mStartedUncompressingCalled = false;
  71 + this.mUpdates = [];
  72 + this.mDownloads = [];
59 73 }
60 74 };
31 apps/system/test/unit/updatable_test.js
@@ -584,11 +584,39 @@ suite('system/Updatable', function() {
584 584 assert.isTrue(asyncStorage.mItems[SystemUpdatable.KNOWN_UPDATE_FLAG]);
585 585 });
586 586 });
  587 +
  588 + suite('when an error occurs', function() {
  589 + setup(function() {
  590 + MockUpdateManager.mTeardown();
  591 + subject = new SystemUpdatable(98734);
  592 + subject._dispatchEvent = function errorDuringDispatch(type, result) {
  593 + fakeDispatchEvent.call(subject, type, result);
  594 + subject.handleEvent(new MockChromeEvent({
  595 + type: 'update-error'
  596 + }));
  597 + };
  598 + subject.download();
  599 + subject._dispatchEvent = fakeDispatchEvent;
  600 + });
  601 +
  602 + test('should request error banner', function() {
  603 + assert.isTrue(MockUpdateManager.mErrorBannerRequested);
  604 + });
  605 +
  606 + test('should remove self from active downloads', function() {
  607 + assert.isNotNull(MockUpdateManager.mLastDownloadsRemoval);
  608 + assert.equal(subject, MockUpdateManager.mLastDownloadsRemoval);
  609 + assert.equal(MockUpdateManager.mDownloads.length, 0);
  610 + });
  611 +
  612 + test('should remove the downloading flag', function() {
  613 + assert.isFalse(subject.downloading);
  614 + });
  615 + });
587 616 });
588 617 });
589 618 });
590 619
591   -
592 620 function testSystemApplyPrompt() {
593 621 test('apply prompt shown', function() {
594 622 assert.isTrue(MockCustomDialog.mShown);
@@ -619,6 +647,7 @@ suite('system/Updatable', function() {
619 647
620 648 assert.isNotNull(MockUpdateManager.mLastDownloadsRemoval);
621 649 assert.equal(subject, MockUpdateManager.mLastDownloadsRemoval);
  650 + assert.equal(MockUpdateManager.mDownloads.length, 0);
622 651 });
623 652
624 653 test('apply prompt confirm callback', function() {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.