Bug 1135319 - Fix several javascript warnings when for mochitest-chrome app update tests and cleanup style. r=spohl

This commit is contained in:
Robert Strong 2015-02-23 09:45:03 -08:00
parent 7f6c9d55b4
commit dfdd36c714
3 changed files with 275 additions and 249 deletions

View File

@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
Components.utils.import("resource://gre/modules/DownloadUtils.jsm"); Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
Components.utils.import("resource://gre/modules/AddonManager.jsm"); Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/Services.jsm");
@ -344,7 +346,7 @@ var gUpdates = {
onLoad: function() { onLoad: function() {
this.wiz = document.documentElement; this.wiz = document.documentElement;
gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false) gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false);
this.strings = document.getElementById("updateStrings"); this.strings = document.getElementById("updateStrings");
var brandStrings = document.getElementById("brandStrings"); var brandStrings = document.getElementById("brandStrings");
@ -427,13 +429,8 @@ var gUpdates = {
var p = this.update.selectedPatch; var p = this.update.selectedPatch;
if (p) { if (p) {
var state = p.state; let state = p.state;
var patchFailed; let patchFailed = this.update.getProperty("patchingFailed");
try {
patchFailed = this.update.getProperty("patchingFailed");
}
catch (e) {
}
if (patchFailed) { if (patchFailed) {
if (patchFailed == "partial" && this.update.patchCount == 2) { if (patchFailed == "partial" && this.update.patchCount == 2) {
// If the system failed to apply the partial patch, show the // If the system failed to apply the partial patch, show the
@ -453,24 +450,24 @@ var gUpdates = {
// Now select the best page to start with, given the current state of // Now select the best page to start with, given the current state of
// the Update. // the Update.
switch (state) { switch (state) {
case STATE_PENDING: case STATE_PENDING:
case STATE_PENDING_SVC: case STATE_PENDING_SVC:
case STATE_APPLIED: case STATE_APPLIED:
case STATE_APPLIED_SVC: case STATE_APPLIED_SVC:
this.sourceEvent = SRCEVT_BACKGROUND; this.sourceEvent = SRCEVT_BACKGROUND;
aCallback("finishedBackground"); aCallback("finishedBackground");
return; return;
case STATE_DOWNLOADING: case STATE_DOWNLOADING:
aCallback("downloading"); aCallback("downloading");
return; return;
case STATE_FAILED: case STATE_FAILED:
window.getAttention(); window.getAttention();
aCallback("errorpatching"); aCallback("errorpatching");
return; return;
case STATE_DOWNLOAD_FAILED: case STATE_DOWNLOAD_FAILED:
case STATE_APPLYING: case STATE_APPLYING:
aCallback("errors"); aCallback("errors");
return; return;
} }
} }
if (this.update.licenseURL) if (this.update.licenseURL)
@ -1615,48 +1612,48 @@ var gDownloadingPage = {
var u = gUpdates.update; var u = gUpdates.update;
switch (status) { switch (status) {
case CoR.NS_ERROR_CORRUPTED_CONTENT: case CoR.NS_ERROR_CORRUPTED_CONTENT:
case CoR.NS_ERROR_UNEXPECTED: case CoR.NS_ERROR_UNEXPECTED:
if (u.selectedPatch.state == STATE_DOWNLOAD_FAILED && if (u.selectedPatch.state == STATE_DOWNLOAD_FAILED &&
(u.isCompleteUpdate || u.patchCount != 2)) { (u.isCompleteUpdate || u.patchCount != 2)) {
// Verification error of complete patch, informational text is held in // Verification error of complete patch, informational text is held in
// the update object. // the update object.
this.cleanUp();
gUpdates.wiz.goTo("errors");
break;
}
// Verification failed for a partial patch, complete patch is now
// downloading so return early and do NOT remove the download listener!
// Reset the progress meter to "undertermined" mode so that we don't
// show old progress for the new download of the "complete" patch.
this._downloadProgress.mode = "undetermined";
this._pauseButton.disabled = true;
document.getElementById("verificationFailed").hidden = false;
break;
case CoR.NS_BINDING_ABORTED:
LOG("gDownloadingPage", "onStopRequest - pausing download");
// Do not remove UI listener since the user may resume downloading again.
break;
case CoR.NS_OK:
LOG("gDownloadingPage", "onStopRequest - patch verification succeeded");
// If the background update pref is set, we should wait until the update
// is actually staged in the background.
let aus = CoC["@mozilla.org/updates/update-service;1"].
getService(CoI.nsIApplicationUpdateService);
if (aus.canStageUpdates) {
this._setUpdateApplying();
} else {
this.cleanUp();
gUpdates.wiz.goTo("finished");
}
break;
default:
LOG("gDownloadingPage", "onStopRequest - transfer failed");
// Some kind of transfer error, die.
this.cleanUp(); this.cleanUp();
gUpdates.wiz.goTo("errors"); gUpdates.wiz.goTo("errors");
break; break;
}
// Verification failed for a partial patch, complete patch is now
// downloading so return early and do NOT remove the download listener!
// Reset the progress meter to "undertermined" mode so that we don't
// show old progress for the new download of the "complete" patch.
this._downloadProgress.mode = "undetermined";
this._pauseButton.disabled = true;
document.getElementById("verificationFailed").hidden = false;
break;
case CoR.NS_BINDING_ABORTED:
LOG("gDownloadingPage", "onStopRequest - pausing download");
// Do not remove UI listener since the user may resume downloading again.
break;
case CoR.NS_OK:
LOG("gDownloadingPage", "onStopRequest - patch verification succeeded");
// If the background update pref is set, we should wait until the update
// is actually staged in the background.
var aus = CoC["@mozilla.org/updates/update-service;1"].
getService(CoI.nsIApplicationUpdateService);
if (aus.canStageUpdates) {
this._setUpdateApplying();
} else {
this.cleanUp();
gUpdates.wiz.goTo("finished");
}
break;
default:
LOG("gDownloadingPage", "onStopRequest - transfer failed");
// Some kind of transfer error, die.
this.cleanUp();
gUpdates.wiz.goTo("errors");
break;
} }
}, },
@ -1775,16 +1772,16 @@ var gErrorPatchingPage = {
onWizardNext: function() { onWizardNext: function() {
switch (gUpdates.update.selectedPatch.state) { switch (gUpdates.update.selectedPatch.state) {
case STATE_PENDING: case STATE_PENDING:
case STATE_PENDING_SVC: case STATE_PENDING_SVC:
gUpdates.wiz.goTo("finished"); gUpdates.wiz.goTo("finished");
break; break;
case STATE_DOWNLOADING: case STATE_DOWNLOADING:
gUpdates.wiz.goTo("downloading"); gUpdates.wiz.goTo("downloading");
break; break;
case STATE_DOWNLOAD_FAILED: case STATE_DOWNLOAD_FAILED:
gUpdates.wiz.goTo("errors"); gUpdates.wiz.goTo("errors");
break; break;
} }
} }
}; };

View File

@ -1598,19 +1598,19 @@ function UpdatePatch(patch) {
var attr = patch.attributes.item(i); var attr = patch.attributes.item(i);
attr.QueryInterface(Ci.nsIDOMAttr); attr.QueryInterface(Ci.nsIDOMAttr);
switch (attr.name) { switch (attr.name) {
case "selected": case "selected":
this.selected = attr.value == "true"; this.selected = attr.value == "true";
break; break;
case "size": case "size":
if (0 == parseInt(attr.value)) { if (0 == parseInt(attr.value)) {
LOG("UpdatePatch:init - 0-sized patch!"); LOG("UpdatePatch:init - 0-sized patch!");
throw Cr.NS_ERROR_ILLEGAL_VALUE; throw Cr.NS_ERROR_ILLEGAL_VALUE;
} }
// fall through // fall through
default: default:
this[attr.name] = attr.value; this[attr.name] = attr.value;
break; break;
}; }
} }
} }
UpdatePatch.prototype = { UpdatePatch.prototype = {
@ -1622,17 +1622,21 @@ UpdatePatch.prototype = {
patch.setAttribute("type", this.type); patch.setAttribute("type", this.type);
patch.setAttribute("URL", this.URL); patch.setAttribute("URL", this.URL);
// finalURL is not available until after the download has started // finalURL is not available until after the download has started
if (this.finalURL) if (this.finalURL) {
patch.setAttribute("finalURL", this.finalURL); patch.setAttribute("finalURL", this.finalURL);
}
patch.setAttribute("hashFunction", this.hashFunction); patch.setAttribute("hashFunction", this.hashFunction);
patch.setAttribute("hashValue", this.hashValue); patch.setAttribute("hashValue", this.hashValue);
patch.setAttribute("size", this.size); patch.setAttribute("size", this.size);
patch.setAttribute("selected", this.selected); if (this.selected) {
patch.setAttribute("selected", this.selected);
}
patch.setAttribute("state", this.state); patch.setAttribute("state", this.state);
for (var p in this._properties) { for (var p in this._properties) {
if (this._properties[p].present) if (this._properties[p].present) {
patch.setAttribute(p, this._properties[p].data); patch.setAttribute(p, this._properties[p].data);
}
} }
return patch; return patch;
@ -1672,12 +1676,15 @@ UpdatePatch.prototype = {
/** /**
* See nsIPropertyBag.idl * See nsIPropertyBag.idl
* Note: returns null instead of throwing when the property doesn't exist to
* simplify code and to silence warnings in debug builds.
*/ */
getProperty: function UpdatePatch_getProperty(name) { getProperty: function UpdatePatch_getProperty(name) {
if (name in this._properties && if (name in this._properties &&
this._properties[name].present) this._properties[name].present) {
return this._properties[name].data; return this._properties[name].data;
throw Cr.NS_ERROR_FAILURE; }
return null;
}, },
/** /**
@ -1728,15 +1735,17 @@ function Update(update) {
// Null <update>, assume this is a message container and do no // Null <update>, assume this is a message container and do no
// further initialization // further initialization
if (!update) if (!update) {
return; return;
}
const ELEMENT_NODE = Ci.nsIDOMNode.ELEMENT_NODE; const ELEMENT_NODE = Ci.nsIDOMNode.ELEMENT_NODE;
for (var i = 0; i < update.childNodes.length; ++i) { for (var i = 0; i < update.childNodes.length; ++i) {
var patchElement = update.childNodes.item(i); var patchElement = update.childNodes.item(i);
if (patchElement.nodeType != ELEMENT_NODE || if (patchElement.nodeType != ELEMENT_NODE ||
patchElement.localName != "patch") patchElement.localName != "patch") {
continue; continue;
}
patchElement.QueryInterface(Ci.nsIDOMElement); patchElement.QueryInterface(Ci.nsIDOMElement);
try { try {
@ -1747,8 +1756,9 @@ function Update(update) {
this._patches.push(patch); this._patches.push(patch);
} }
if (this._patches.length == 0 && !update.hasAttribute("unsupported")) if (this._patches.length == 0 && !update.hasAttribute("unsupported")) {
throw Cr.NS_ERROR_ILLEGAL_VALUE; throw Cr.NS_ERROR_ILLEGAL_VALUE;
}
// Fallback to the behavior prior to bug 530872 if the update does not have an // Fallback to the behavior prior to bug 530872 if the update does not have an
// appVersion attribute. // appVersion attribute.
@ -1762,82 +1772,84 @@ function Update(update) {
} }
} }
// Set the installDate value with the current time. If the update has an
// installDate attribute this will be replaced with that value if it doesn't
// equal 0.
this.installDate = (new Date()).getTime();
for (var i = 0; i < update.attributes.length; ++i) { for (var i = 0; i < update.attributes.length; ++i) {
var attr = update.attributes.item(i); var attr = update.attributes.item(i);
attr.QueryInterface(Ci.nsIDOMAttr); attr.QueryInterface(Ci.nsIDOMAttr);
if (attr.value == "undefined") if (attr.value == "undefined") {
continue; continue;
else if (attr.name == "detailsURL") } else if (attr.name == "detailsURL") {
this._detailsURL = attr.value; this._detailsURL = attr.value;
else if (attr.name == "extensionVersion") { } else if (attr.name == "extensionVersion") {
// Prevent extensionVersion from replacing appVersion if appVersion is // Prevent extensionVersion from replacing appVersion if appVersion is
// present in the update xml. // present in the update xml.
if (!this.appVersion) if (!this.appVersion) {
this.appVersion = attr.value; this.appVersion = attr.value;
} }
else if (attr.name == "installDate" && attr.value) } else if (attr.name == "installDate" && attr.value) {
this.installDate = parseInt(attr.value); let val = parseInt(attr.value);
else if (attr.name == "isCompleteUpdate") if (val) {
this.installDate = val;
}
} else if (attr.name == "isCompleteUpdate") {
this.isCompleteUpdate = attr.value == "true"; this.isCompleteUpdate = attr.value == "true";
else if (attr.name == "isSecurityUpdate") } else if (attr.name == "isSecurityUpdate") {
this.isSecurityUpdate = attr.value == "true"; this.isSecurityUpdate = attr.value == "true";
else if (attr.name == "isOSUpdate") } else if (attr.name == "isOSUpdate") {
this.isOSUpdate = attr.value == "true"; this.isOSUpdate = attr.value == "true";
else if (attr.name == "showNeverForVersion") } else if (attr.name == "showNeverForVersion") {
this.showNeverForVersion = attr.value == "true"; this.showNeverForVersion = attr.value == "true";
else if (attr.name == "showPrompt") } else if (attr.name == "showPrompt") {
this.showPrompt = attr.value == "true"; this.showPrompt = attr.value == "true";
else if (attr.name == "promptWaitTime") } else if (attr.name == "promptWaitTime") {
{ if(!isNaN(attr.value)) {
if(!isNaN(attr.value))
this.promptWaitTime = parseInt(attr.value); this.promptWaitTime = parseInt(attr.value);
} }
else if (attr.name == "unsupported") } else if (attr.name == "unsupported") {
this.unsupported = attr.value == "true"; this.unsupported = attr.value == "true";
else if (attr.name == "version") { } else if (attr.name == "version") {
// Prevent version from replacing displayVersion if displayVersion is // Prevent version from replacing displayVersion if displayVersion is
// present in the update xml. // present in the update xml.
if (!this.displayVersion) if (!this.displayVersion) {
this.displayVersion = attr.value; this.displayVersion = attr.value;
} }
else { } else {
this[attr.name] = attr.value; this[attr.name] = attr.value;
switch (attr.name) { switch (attr.name) {
case "appVersion": case "appVersion":
case "billboardURL": case "billboardURL":
case "buildID": case "buildID":
case "channel": case "channel":
case "displayVersion": case "displayVersion":
case "licenseURL": case "licenseURL":
case "name": case "name":
case "platformVersion": case "platformVersion":
case "previousAppVersion": case "previousAppVersion":
case "serviceURL": case "serviceURL":
case "statusText": case "statusText":
case "type": case "type":
break; break;
default: default:
// Save custom attributes when serializing to the local xml file but // Save custom attributes when serializing to the local xml file but
// don't use this method for the expected attributes which are already // don't use this method for the expected attributes which are already
// handled in serialize. // handled in serialize.
this.setProperty(attr.name, attr.value); this.setProperty(attr.name, attr.value);
break; break;
}; }
} }
} }
// Set the initial value with the current time when it doesn't already have a
// value or the value is already set to 0 (bug 316328).
if (!this.installDate && this.installDate != 0)
this.installDate = (new Date()).getTime();
// The Update Name is either the string provided by the <update> element, or // The Update Name is either the string provided by the <update> element, or
// the string: "<App Name> <Update App Version>" // the string: "<App Name> <Update App Version>"
var name = ""; var name = "";
if (update.hasAttribute("name")) if (update.hasAttribute("name")) {
name = update.getAttribute("name"); name = update.getAttribute("name");
else { } else {
var brandBundle = Services.strings.createBundle(URI_BRAND_PROPERTIES); var brandBundle = Services.strings.createBundle(URI_BRAND_PROPERTIES);
var appName = brandBundle.GetStringFromName("brandShortName"); var appName = brandBundle.GetStringFromName("brandShortName");
name = gUpdateBundle.formatStringFromName("updateName", name = gUpdateBundle.formatStringFromName("updateName",
@ -1917,6 +1929,12 @@ Update.prototype = {
* See nsIUpdateService.idl * See nsIUpdateService.idl
*/ */
serialize: function Update_serialize(updates) { serialize: function Update_serialize(updates) {
// If appVersion isn't defined just return null. This happens when a
// temporary nsIUpdate is passed to the UI when the
// app.update.showInstalledUI prefence is set to true.
if (!this.appVersion) {
return null;
}
var update = updates.createElementNS(URI_UPDATE_NS, "update"); var update = updates.createElementNS(URI_UPDATE_NS, "update");
update.setAttribute("appVersion", this.appVersion); update.setAttribute("appVersion", this.appVersion);
update.setAttribute("buildID", this.buildID); update.setAttribute("buildID", this.buildID);
@ -1937,29 +1955,38 @@ Update.prototype = {
update.setAttribute("version", this.displayVersion); update.setAttribute("version", this.displayVersion);
// Optional attributes // Optional attributes
if (this.billboardURL) if (this.billboardURL) {
update.setAttribute("billboardURL", this.billboardURL); update.setAttribute("billboardURL", this.billboardURL);
if (this.detailsURL) }
if (this.detailsURL) {
update.setAttribute("detailsURL", this.detailsURL); update.setAttribute("detailsURL", this.detailsURL);
if (this.licenseURL) }
if (this.licenseURL) {
update.setAttribute("licenseURL", this.licenseURL); update.setAttribute("licenseURL", this.licenseURL);
if (this.platformVersion) }
if (this.platformVersion) {
update.setAttribute("platformVersion", this.platformVersion); update.setAttribute("platformVersion", this.platformVersion);
if (this.previousAppVersion) }
if (this.previousAppVersion) {
update.setAttribute("previousAppVersion", this.previousAppVersion); update.setAttribute("previousAppVersion", this.previousAppVersion);
if (this.statusText) }
if (this.statusText) {
update.setAttribute("statusText", this.statusText); update.setAttribute("statusText", this.statusText);
if (this.unsupported) }
if (this.unsupported) {
update.setAttribute("unsupported", this.unsupported); update.setAttribute("unsupported", this.unsupported);
}
updates.documentElement.appendChild(update); updates.documentElement.appendChild(update);
for (var p in this._properties) { for (var p in this._properties) {
if (this._properties[p].present) if (this._properties[p].present) {
update.setAttribute(p, this._properties[p].data); update.setAttribute(p, this._properties[p].data);
}
} }
for (var i = 0; i < this.patchCount; ++i) for (let i = 0; i < this.patchCount; ++i) {
update.appendChild(this.getPatchAt(i).serialize(updates)); update.appendChild(this.getPatchAt(i).serialize(updates));
}
return update; return update;
}, },
@ -1998,11 +2025,14 @@ Update.prototype = {
/** /**
* See nsIPropertyBag.idl * See nsIPropertyBag.idl
* Note: returns null instead of throwing when the property doesn't exist to
* simplify code and to silence warnings in debug builds.
*/ */
getProperty: function Update_getProperty(name) { getProperty: function Update_getProperty(name) {
if (name in this._properties && this._properties[name].present) if (name in this._properties && this._properties[name].present) {
return this._properties[name].data; return this._properties[name].data;
throw Cr.NS_ERROR_FAILURE; }
return null;
}, },
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdate, QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdate,
@ -2081,41 +2111,41 @@ UpdateService.prototype = {
*/ */
observe: function AUS_observe(subject, topic, data) { observe: function AUS_observe(subject, topic, data) {
switch (topic) { switch (topic) {
case "post-update-processing": case "post-update-processing":
// Clean up any extant updates // Clean up any extant updates
this._postUpdateProcessing(); this._postUpdateProcessing();
break; break;
case "network:offline-status-changed": case "network:offline-status-changed":
this._offlineStatusChanged(data); this._offlineStatusChanged(data);
break; break;
case "nsPref:changed": case "nsPref:changed":
if (data == PREF_APP_UPDATE_LOG) { if (data == PREF_APP_UPDATE_LOG) {
gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false); gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false);
} }
break; break;
#ifdef MOZ_WIDGET_GONK #ifdef MOZ_WIDGET_GONK
case "profile-change-net-teardown": // fall thru case "profile-change-net-teardown": // fall thru
#endif #endif
case "xpcom-shutdown": case "xpcom-shutdown":
Services.obs.removeObserver(this, topic); Services.obs.removeObserver(this, topic);
Services.prefs.removeObserver(PREF_APP_UPDATE_LOG, this); Services.prefs.removeObserver(PREF_APP_UPDATE_LOG, this);
#ifdef XP_WIN #ifdef XP_WIN
// If we hold the update mutex, let it go! // If we hold the update mutex, let it go!
// The OS would clean this up sometime after shutdown, // The OS would clean this up sometime after shutdown,
// but that would have no guarantee on timing. // but that would have no guarantee on timing.
if (gUpdateMutexHandle) { if (gUpdateMutexHandle) {
closeHandle(gUpdateMutexHandle); closeHandle(gUpdateMutexHandle);
} }
#endif #endif
if (this._retryTimer) { if (this._retryTimer) {
this._retryTimer.cancel(); this._retryTimer.cancel();
} }
this.pauseDownload(); this.pauseDownload();
// Prevent leaking the downloader (bug 454964) // Prevent leaking the downloader (bug 454964)
this._downloader = null; this._downloader = null;
break; break;
} }
}, },
@ -3217,11 +3247,8 @@ UpdateService.prototype = {
throw Cr.NS_ERROR_FAILURE; throw Cr.NS_ERROR_FAILURE;
} }
let osApplyToDir; aUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
try { let osApplyToDir = aUpdate.getProperty("osApplyToDir");
aUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
osApplyToDir = aUpdate.getProperty("osApplyToDir");
} catch (e) {}
if (!osApplyToDir) { if (!osApplyToDir) {
LOG("UpdateService:applyOsUpdate - Error: osApplyToDir is not defined" + LOG("UpdateService:applyOsUpdate - Error: osApplyToDir is not defined" +
@ -3478,8 +3505,9 @@ UpdateManager.prototype = {
createInstance(Ci.nsIFileOutputStream); createInstance(Ci.nsIFileOutputStream);
var modeFlags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | var modeFlags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
FileUtils.MODE_TRUNCATE; FileUtils.MODE_TRUNCATE;
if (!file.exists()) if (!file.exists()) {
file.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); file.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
}
fos.init(file, modeFlags, FileUtils.PERMS_FILE, 0); fos.init(file, modeFlags, FileUtils.PERMS_FILE, 0);
try { try {
@ -3489,15 +3517,18 @@ UpdateManager.prototype = {
var doc = parser.parseFromString(EMPTY_UPDATES_DOCUMENT, "text/xml"); var doc = parser.parseFromString(EMPTY_UPDATES_DOCUMENT, "text/xml");
for (var i = 0; i < updates.length; ++i) { for (var i = 0; i < updates.length; ++i) {
if (updates[i]) // If appVersion isn't defined don't add the update. This happens when a
// temporary nsIUpdate is passed to the UI when the
// app.update.showInstalledUI prefence is set to true.
if (updates[i] && updates[i].appVersion) {
doc.documentElement.appendChild(updates[i].serialize(doc)); doc.documentElement.appendChild(updates[i].serialize(doc));
}
} }
var serializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"]. var serializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].
createInstance(Ci.nsIDOMSerializer); createInstance(Ci.nsIDOMSerializer);
serializer.serializeToStream(doc.documentElement, fos, null); serializer.serializeToStream(doc.documentElement, fos, null);
} } catch (e) {
catch (e) {
} }
FileUtils.closeSafeFileOutputStream(fos); FileUtils.closeSafeFileOutputStream(fos);
@ -3829,7 +3860,7 @@ Checker.prototype = {
if (this._isHttpStatusCode(status)) { if (this._isHttpStatusCode(status)) {
update.errorCode = HTTP_ERROR_OFFSET + status; update.errorCode = HTTP_ERROR_OFFSET + status;
} }
if (e.result == Cr.NS_ERROR_ILLEGAL_VALUE) { if (e.result && e.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
update.errorCode = updates[0] ? CERT_ATTR_CHECK_FAILED_HAS_UPDATE update.errorCode = updates[0] ? CERT_ATTR_CHECK_FAILED_HAS_UPDATE
: CERT_ATTR_CHECK_FAILED_NO_UPDATE; : CERT_ATTR_CHECK_FAILED_NO_UPDATE;
} }
@ -3896,13 +3927,13 @@ Checker.prototype = {
this._request.abort(); this._request.abort();
switch (duration) { switch (duration) {
case Ci.nsIUpdateChecker.CURRENT_SESSION: case Ci.nsIUpdateChecker.CURRENT_SESSION:
this._enabled = false; this._enabled = false;
break; break;
case Ci.nsIUpdateChecker.ANY_CHECKS: case Ci.nsIUpdateChecker.ANY_CHECKS:
this._enabled = false; this._enabled = false;
Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, this._enabled); Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, this._enabled);
break; break;
} }
this._callback = null; this._callback = null;
@ -3981,10 +4012,11 @@ Downloader.prototype = {
*/ */
_verifyDownload: function Downloader__verifyDownload() { _verifyDownload: function Downloader__verifyDownload() {
LOG("Downloader:_verifyDownload called"); LOG("Downloader:_verifyDownload called");
if (!this._request) if (!this._request) {
return false; return false;
}
var destination = this._request.destination; let destination = this._request.destination;
// Ensure that the file size matches the expected file size. // Ensure that the file size matches the expected file size.
if (destination.fileSize != this._patch.size) { if (destination.fileSize != this._patch.size) {
@ -3993,16 +4025,18 @@ Downloader.prototype = {
} }
LOG("Downloader:_verifyDownload downloaded size == expected size."); LOG("Downloader:_verifyDownload downloaded size == expected size.");
var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]. let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream); createInstance(Ci.nsIFileInputStream);
fileStream.init(destination, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0); fileStream.init(destination, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
let digest;
try { try {
var hash = Cc["@mozilla.org/security/hash;1"]. let hash = Cc["@mozilla.org/security/hash;1"].
createInstance(Ci.nsICryptoHash); createInstance(Ci.nsICryptoHash);
var hashFunction = Ci.nsICryptoHash[this._patch.hashFunction.toUpperCase()]; var hashFunction = Ci.nsICryptoHash[this._patch.hashFunction.toUpperCase()];
if (hashFunction == undefined) if (hashFunction == undefined) {
throw Cr.NS_ERROR_UNEXPECTED; throw Cr.NS_ERROR_UNEXPECTED;
}
hash.init(hashFunction); hash.init(hashFunction);
hash.updateFromStream(fileStream, -1); hash.updateFromStream(fileStream, -1);
// NOTE: For now, we assume that the format of _patch.hashValue is hex // NOTE: For now, we assume that the format of _patch.hashValue is hex
@ -4069,35 +4103,35 @@ Downloader.prototype = {
LOG("Downloader:_selectPatch - found existing patch with state: " + LOG("Downloader:_selectPatch - found existing patch with state: " +
state); state);
switch (state) { switch (state) {
case STATE_DOWNLOADING: case STATE_DOWNLOADING:
LOG("Downloader:_selectPatch - resuming download"); LOG("Downloader:_selectPatch - resuming download");
return selectedPatch; return selectedPatch;
#ifdef MOZ_WIDGET_GONK #ifdef MOZ_WIDGET_GONK
case STATE_PENDING: case STATE_PENDING:
case STATE_APPLYING: case STATE_APPLYING:
LOG("Downloader:_selectPatch - resuming interrupted apply"); LOG("Downloader:_selectPatch - resuming interrupted apply");
return selectedPatch; return selectedPatch;
case STATE_APPLIED: case STATE_APPLIED:
LOG("Downloader:_selectPatch - already downloaded and staged"); LOG("Downloader:_selectPatch - already downloaded and staged");
return null;
#else
case STATE_PENDING_SVC:
case STATE_PENDING:
LOG("Downloader:_selectPatch - already downloaded and staged");
return null;
#endif
default:
// Something went wrong when we tried to apply the previous patch.
// Try the complete patch next time.
if (update && selectedPatch.type == "partial") {
useComplete = true;
} else {
// This is a pretty fatal error. Just bail.
LOG("Downloader:_selectPatch - failed to apply complete patch!");
writeStatusFile(updateDir, STATE_NONE);
writeVersionFile(getUpdatesDir(), null);
return null; return null;
} #else
case STATE_PENDING_SVC:
case STATE_PENDING:
LOG("Downloader:_selectPatch - already downloaded and staged");
return null;
#endif
default:
// Something went wrong when we tried to apply the previous patch.
// Try the complete patch next time.
if (update && selectedPatch.type == "partial") {
useComplete = true;
} else {
// This is a pretty fatal error. Just bail.
LOG("Downloader:_selectPatch - failed to apply complete patch!");
writeStatusFile(updateDir, STATE_NONE);
writeVersionFile(getUpdatesDir(), null);
return null;
}
} }
selectedPatch = null; selectedPatch = null;
@ -4571,14 +4605,8 @@ Downloader.prototype = {
// notify the user about the error. If the update was a background // notify the user about the error. If the update was a background
// update there is no notification since the user won't be expecting it. // update there is no notification since the user won't be expecting it.
if (!Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME)) { if (!Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME)) {
try { this._update.QueryInterface(Ci.nsIWritablePropertyBag);
this._update.QueryInterface(Ci.nsIWritablePropertyBag); if (this._update.getProperty("foregroundDownload") == "true") {
var fgdl = this._update.getProperty("foregroundDownload");
}
catch (e) {
}
if (fgdl == "true") {
var prompter = Cc["@mozilla.org/updates/update-prompt;1"]. var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
createInstance(Ci.nsIUpdatePrompt); createInstance(Ci.nsIUpdatePrompt);
prompter.showUpdateError(this._update); prompter.showUpdateError(this._update);

View File

@ -114,6 +114,8 @@
* install completes. * install completes.
*/ */
'use strict';
Components.utils.import("resource://gre/modules/AddonManager.jsm"); Components.utils.import("resource://gre/modules/AddonManager.jsm");
// The tests have to use the pageid instead of the pageIndex due to the // The tests have to use the pageid instead of the pageIndex due to the
@ -158,7 +160,6 @@ const PREF_APP_UPDATE_LASTUPDATETIME = "app.update.lastUpdateTime.background-upd
// from interefering with the tests. // from interefering with the tests.
const PREF_DISABLEDADDONS = "app.update.test.disabledAddons"; const PREF_DISABLEDADDONS = "app.update.test.disabledAddons";
const PREF_EM_HOTFIX_ID = "extensions.hotfix.id"; const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
const PREF_EM_SILENT = "app.update.silent";
const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2", const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2",
"compatible_1", "compatible_2", "compatible_1", "compatible_2",
"noupdate_1", "noupdate_2", "noupdate_1", "noupdate_2",
@ -922,9 +923,9 @@ function setupPrefs() {
Services.prefs.setIntPref(PREF_APP_UPDATE_IDLETIME, 0); Services.prefs.setIntPref(PREF_APP_UPDATE_IDLETIME, 0);
Services.prefs.setIntPref(PREF_APP_UPDATE_PROMPTWAITTIME, 0); Services.prefs.setIntPref(PREF_APP_UPDATE_PROMPTWAITTIME, 0);
Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
Services.prefs.setBoolPref(PREF_EXTENSIONS_STRICT_COMPAT, true); Services.prefs.setBoolPref(PREF_EXTENSIONS_STRICT_COMPAT, true);
Services.prefs.setCharPref(PREF_EM_HOTFIX_ID, "hotfix" + ADDON_ID_SUFFIX); Services.prefs.setCharPref(PREF_EM_HOTFIX_ID, "hotfix" + ADDON_ID_SUFFIX);
Services.prefs.setBoolPref(PREF_EM_SILENT, false);
} }
/** /**
@ -1078,6 +1079,10 @@ function resetPrefs() {
catch(e) { catch(e) {
} }
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_SILENT)) {
Services.prefs.clearUserPref(PREF_APP_UPDATE_SILENT);
}
if (Services.prefs.prefHasUserValue(PREF_EXTENSIONS_STRICT_COMPAT)) { if (Services.prefs.prefHasUserValue(PREF_EXTENSIONS_STRICT_COMPAT)) {
Services.prefs.clearUserPref(PREF_EXTENSIONS_STRICT_COMPAT); Services.prefs.clearUserPref(PREF_EXTENSIONS_STRICT_COMPAT);
} }
@ -1085,10 +1090,6 @@ function resetPrefs() {
if (Services.prefs.prefHasUserValue(PREF_EM_HOTFIX_ID)) { if (Services.prefs.prefHasUserValue(PREF_EM_HOTFIX_ID)) {
Services.prefs.clearUserPref(PREF_EM_HOTFIX_ID); Services.prefs.clearUserPref(PREF_EM_HOTFIX_ID);
} }
if (Services.prefs.prefHasUserValue(PREF_EM_SILENT)) {
Services.prefs.clearUserPref(PREF_EM_SILENT);
}
} }
function setupTimer(aTestTimeout) { function setupTimer(aTestTimeout) {
@ -1187,7 +1188,7 @@ function setupAddons(aCallback) {
if (--xpiCount == 0) { if (--xpiCount == 0) {
let installCount = installs.length; let installCount = installs.length;
function installCompleted(aInstall) { let installCompleted = function(aInstall) {
aInstall.removeListener(listener); aInstall.removeListener(listener);
if (getAddonTestType(aInstall.addon.name) == "userdisabled") { if (getAddonTestType(aInstall.addon.name) == "userdisabled") {
@ -1196,7 +1197,7 @@ function setupAddons(aCallback) {
if (--installCount == 0) { if (--installCount == 0) {
setNoUpdateAddonsDisabledState(); setNoUpdateAddonsDisabledState();
} }
} };
let listener = { let listener = {
onDownloadFailed: installCompleted, onDownloadFailed: installCompleted,