mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1135319 - Fix several javascript warnings when for mochitest-chrome app update tests and cleanup style. r=spohl
This commit is contained in:
parent
7f6c9d55b4
commit
dfdd36c714
@ -3,6 +3,8 @@
|
||||
* 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/. */
|
||||
|
||||
'use strict';
|
||||
|
||||
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
@ -344,7 +346,7 @@ var gUpdates = {
|
||||
onLoad: function() {
|
||||
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");
|
||||
var brandStrings = document.getElementById("brandStrings");
|
||||
@ -427,13 +429,8 @@ var gUpdates = {
|
||||
|
||||
var p = this.update.selectedPatch;
|
||||
if (p) {
|
||||
var state = p.state;
|
||||
var patchFailed;
|
||||
try {
|
||||
patchFailed = this.update.getProperty("patchingFailed");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
let state = p.state;
|
||||
let patchFailed = this.update.getProperty("patchingFailed");
|
||||
if (patchFailed) {
|
||||
if (patchFailed == "partial" && this.update.patchCount == 2) {
|
||||
// If the system failed to apply the partial patch, show the
|
||||
@ -1642,7 +1639,7 @@ var gDownloadingPage = {
|
||||
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"].
|
||||
let aus = CoC["@mozilla.org/updates/update-service;1"].
|
||||
getService(CoI.nsIApplicationUpdateService);
|
||||
if (aus.canStageUpdates) {
|
||||
this._setUpdateApplying();
|
||||
|
@ -1610,7 +1610,7 @@ function UpdatePatch(patch) {
|
||||
default:
|
||||
this[attr.name] = attr.value;
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdatePatch.prototype = {
|
||||
@ -1622,18 +1622,22 @@ UpdatePatch.prototype = {
|
||||
patch.setAttribute("type", this.type);
|
||||
patch.setAttribute("URL", this.URL);
|
||||
// finalURL is not available until after the download has started
|
||||
if (this.finalURL)
|
||||
if (this.finalURL) {
|
||||
patch.setAttribute("finalURL", this.finalURL);
|
||||
}
|
||||
patch.setAttribute("hashFunction", this.hashFunction);
|
||||
patch.setAttribute("hashValue", this.hashValue);
|
||||
patch.setAttribute("size", this.size);
|
||||
if (this.selected) {
|
||||
patch.setAttribute("selected", this.selected);
|
||||
}
|
||||
patch.setAttribute("state", this.state);
|
||||
|
||||
for (var p in this._properties) {
|
||||
if (this._properties[p].present)
|
||||
if (this._properties[p].present) {
|
||||
patch.setAttribute(p, this._properties[p].data);
|
||||
}
|
||||
}
|
||||
|
||||
return patch;
|
||||
},
|
||||
@ -1672,12 +1676,15 @@ UpdatePatch.prototype = {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (name in this._properties &&
|
||||
this._properties[name].present)
|
||||
this._properties[name].present) {
|
||||
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
|
||||
// further initialization
|
||||
if (!update)
|
||||
if (!update) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ELEMENT_NODE = Ci.nsIDOMNode.ELEMENT_NODE;
|
||||
for (var i = 0; i < update.childNodes.length; ++i) {
|
||||
var patchElement = update.childNodes.item(i);
|
||||
if (patchElement.nodeType != ELEMENT_NODE ||
|
||||
patchElement.localName != "patch")
|
||||
patchElement.localName != "patch") {
|
||||
continue;
|
||||
}
|
||||
|
||||
patchElement.QueryInterface(Ci.nsIDOMElement);
|
||||
try {
|
||||
@ -1747,8 +1756,9 @@ function Update(update) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Fallback to the behavior prior to bug 530872 if the update does not have an
|
||||
// appVersion attribute.
|
||||
@ -1762,45 +1772,52 @@ 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) {
|
||||
var attr = update.attributes.item(i);
|
||||
attr.QueryInterface(Ci.nsIDOMAttr);
|
||||
if (attr.value == "undefined")
|
||||
if (attr.value == "undefined") {
|
||||
continue;
|
||||
else if (attr.name == "detailsURL")
|
||||
} else if (attr.name == "detailsURL") {
|
||||
this._detailsURL = attr.value;
|
||||
else if (attr.name == "extensionVersion") {
|
||||
} else if (attr.name == "extensionVersion") {
|
||||
// Prevent extensionVersion from replacing appVersion if appVersion is
|
||||
// present in the update xml.
|
||||
if (!this.appVersion)
|
||||
if (!this.appVersion) {
|
||||
this.appVersion = attr.value;
|
||||
}
|
||||
else if (attr.name == "installDate" && attr.value)
|
||||
this.installDate = parseInt(attr.value);
|
||||
else if (attr.name == "isCompleteUpdate")
|
||||
} else if (attr.name == "installDate" && attr.value) {
|
||||
let val = parseInt(attr.value);
|
||||
if (val) {
|
||||
this.installDate = val;
|
||||
}
|
||||
} else if (attr.name == "isCompleteUpdate") {
|
||||
this.isCompleteUpdate = attr.value == "true";
|
||||
else if (attr.name == "isSecurityUpdate")
|
||||
} else if (attr.name == "isSecurityUpdate") {
|
||||
this.isSecurityUpdate = attr.value == "true";
|
||||
else if (attr.name == "isOSUpdate")
|
||||
} else if (attr.name == "isOSUpdate") {
|
||||
this.isOSUpdate = attr.value == "true";
|
||||
else if (attr.name == "showNeverForVersion")
|
||||
} else if (attr.name == "showNeverForVersion") {
|
||||
this.showNeverForVersion = attr.value == "true";
|
||||
else if (attr.name == "showPrompt")
|
||||
} else if (attr.name == "showPrompt") {
|
||||
this.showPrompt = attr.value == "true";
|
||||
else if (attr.name == "promptWaitTime")
|
||||
{
|
||||
if(!isNaN(attr.value))
|
||||
} else if (attr.name == "promptWaitTime") {
|
||||
if(!isNaN(attr.value)) {
|
||||
this.promptWaitTime = parseInt(attr.value);
|
||||
}
|
||||
else if (attr.name == "unsupported")
|
||||
} else if (attr.name == "unsupported") {
|
||||
this.unsupported = attr.value == "true";
|
||||
else if (attr.name == "version") {
|
||||
} else if (attr.name == "version") {
|
||||
// Prevent version from replacing displayVersion if displayVersion is
|
||||
// present in the update xml.
|
||||
if (!this.displayVersion)
|
||||
if (!this.displayVersion) {
|
||||
this.displayVersion = attr.value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this[attr.name] = attr.value;
|
||||
|
||||
switch (attr.name) {
|
||||
@ -1823,21 +1840,16 @@ function Update(update) {
|
||||
// handled in serialize.
|
||||
this.setProperty(attr.name, attr.value);
|
||||
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 string: "<App Name> <Update App Version>"
|
||||
var name = "";
|
||||
if (update.hasAttribute("name"))
|
||||
if (update.hasAttribute("name")) {
|
||||
name = update.getAttribute("name");
|
||||
else {
|
||||
} else {
|
||||
var brandBundle = Services.strings.createBundle(URI_BRAND_PROPERTIES);
|
||||
var appName = brandBundle.GetStringFromName("brandShortName");
|
||||
name = gUpdateBundle.formatStringFromName("updateName",
|
||||
@ -1917,6 +1929,12 @@ Update.prototype = {
|
||||
* See nsIUpdateService.idl
|
||||
*/
|
||||
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");
|
||||
update.setAttribute("appVersion", this.appVersion);
|
||||
update.setAttribute("buildID", this.buildID);
|
||||
@ -1937,29 +1955,38 @@ Update.prototype = {
|
||||
update.setAttribute("version", this.displayVersion);
|
||||
|
||||
// Optional attributes
|
||||
if (this.billboardURL)
|
||||
if (this.billboardURL) {
|
||||
update.setAttribute("billboardURL", this.billboardURL);
|
||||
if (this.detailsURL)
|
||||
}
|
||||
if (this.detailsURL) {
|
||||
update.setAttribute("detailsURL", this.detailsURL);
|
||||
if (this.licenseURL)
|
||||
}
|
||||
if (this.licenseURL) {
|
||||
update.setAttribute("licenseURL", this.licenseURL);
|
||||
if (this.platformVersion)
|
||||
}
|
||||
if (this.platformVersion) {
|
||||
update.setAttribute("platformVersion", this.platformVersion);
|
||||
if (this.previousAppVersion)
|
||||
}
|
||||
if (this.previousAppVersion) {
|
||||
update.setAttribute("previousAppVersion", this.previousAppVersion);
|
||||
if (this.statusText)
|
||||
}
|
||||
if (this.statusText) {
|
||||
update.setAttribute("statusText", this.statusText);
|
||||
if (this.unsupported)
|
||||
}
|
||||
if (this.unsupported) {
|
||||
update.setAttribute("unsupported", this.unsupported);
|
||||
}
|
||||
updates.documentElement.appendChild(update);
|
||||
|
||||
for (var p in this._properties) {
|
||||
if (this._properties[p].present)
|
||||
if (this._properties[p].present) {
|
||||
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));
|
||||
}
|
||||
|
||||
return update;
|
||||
},
|
||||
@ -1998,11 +2025,14 @@ Update.prototype = {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (name in this._properties && this._properties[name].present)
|
||||
if (name in this._properties && this._properties[name].present) {
|
||||
return this._properties[name].data;
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdate,
|
||||
@ -3217,11 +3247,8 @@ UpdateService.prototype = {
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
let osApplyToDir;
|
||||
try {
|
||||
aUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
|
||||
osApplyToDir = aUpdate.getProperty("osApplyToDir");
|
||||
} catch (e) {}
|
||||
let osApplyToDir = aUpdate.getProperty("osApplyToDir");
|
||||
|
||||
if (!osApplyToDir) {
|
||||
LOG("UpdateService:applyOsUpdate - Error: osApplyToDir is not defined" +
|
||||
@ -3478,8 +3505,9 @@ UpdateManager.prototype = {
|
||||
createInstance(Ci.nsIFileOutputStream);
|
||||
var modeFlags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
|
||||
FileUtils.MODE_TRUNCATE;
|
||||
if (!file.exists())
|
||||
if (!file.exists()) {
|
||||
file.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
|
||||
}
|
||||
fos.init(file, modeFlags, FileUtils.PERMS_FILE, 0);
|
||||
|
||||
try {
|
||||
@ -3489,15 +3517,18 @@ UpdateManager.prototype = {
|
||||
var doc = parser.parseFromString(EMPTY_UPDATES_DOCUMENT, "text/xml");
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
var serializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].
|
||||
createInstance(Ci.nsIDOMSerializer);
|
||||
serializer.serializeToStream(doc.documentElement, fos, null);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
FileUtils.closeSafeFileOutputStream(fos);
|
||||
@ -3829,7 +3860,7 @@ Checker.prototype = {
|
||||
if (this._isHttpStatusCode(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
|
||||
: CERT_ATTR_CHECK_FAILED_NO_UPDATE;
|
||||
}
|
||||
@ -3981,10 +4012,11 @@ Downloader.prototype = {
|
||||
*/
|
||||
_verifyDownload: function Downloader__verifyDownload() {
|
||||
LOG("Downloader:_verifyDownload called");
|
||||
if (!this._request)
|
||||
if (!this._request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var destination = this._request.destination;
|
||||
let destination = this._request.destination;
|
||||
|
||||
// Ensure that the file size matches the expected file size.
|
||||
if (destination.fileSize != this._patch.size) {
|
||||
@ -3993,16 +4025,18 @@ Downloader.prototype = {
|
||||
}
|
||||
|
||||
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);
|
||||
fileStream.init(destination, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
|
||||
|
||||
let digest;
|
||||
try {
|
||||
var hash = Cc["@mozilla.org/security/hash;1"].
|
||||
let hash = Cc["@mozilla.org/security/hash;1"].
|
||||
createInstance(Ci.nsICryptoHash);
|
||||
var hashFunction = Ci.nsICryptoHash[this._patch.hashFunction.toUpperCase()];
|
||||
if (hashFunction == undefined)
|
||||
if (hashFunction == undefined) {
|
||||
throw Cr.NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
hash.init(hashFunction);
|
||||
hash.updateFromStream(fileStream, -1);
|
||||
// NOTE: For now, we assume that the format of _patch.hashValue is hex
|
||||
@ -4571,14 +4605,8 @@ Downloader.prototype = {
|
||||
// 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.
|
||||
if (!Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME)) {
|
||||
try {
|
||||
this._update.QueryInterface(Ci.nsIWritablePropertyBag);
|
||||
var fgdl = this._update.getProperty("foregroundDownload");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
if (fgdl == "true") {
|
||||
if (this._update.getProperty("foregroundDownload") == "true") {
|
||||
var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
|
||||
createInstance(Ci.nsIUpdatePrompt);
|
||||
prompter.showUpdateError(this._update);
|
||||
|
@ -114,6 +114,8 @@
|
||||
* install completes.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
// 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.
|
||||
const PREF_DISABLEDADDONS = "app.update.test.disabledAddons";
|
||||
const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
|
||||
const PREF_EM_SILENT = "app.update.silent";
|
||||
const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2",
|
||||
"compatible_1", "compatible_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_PROMPTWAITTIME, 0);
|
||||
Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
|
||||
Services.prefs.setBoolPref(PREF_EXTENSIONS_STRICT_COMPAT, true);
|
||||
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) {
|
||||
}
|
||||
|
||||
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_SILENT)) {
|
||||
Services.prefs.clearUserPref(PREF_APP_UPDATE_SILENT);
|
||||
}
|
||||
|
||||
if (Services.prefs.prefHasUserValue(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)) {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_ID);
|
||||
}
|
||||
|
||||
if (Services.prefs.prefHasUserValue(PREF_EM_SILENT)) {
|
||||
Services.prefs.clearUserPref(PREF_EM_SILENT);
|
||||
}
|
||||
}
|
||||
|
||||
function setupTimer(aTestTimeout) {
|
||||
@ -1187,7 +1188,7 @@ function setupAddons(aCallback) {
|
||||
|
||||
if (--xpiCount == 0) {
|
||||
let installCount = installs.length;
|
||||
function installCompleted(aInstall) {
|
||||
let installCompleted = function(aInstall) {
|
||||
aInstall.removeListener(listener);
|
||||
|
||||
if (getAddonTestType(aInstall.addon.name) == "userdisabled") {
|
||||
@ -1196,7 +1197,7 @@ function setupAddons(aCallback) {
|
||||
if (--installCount == 0) {
|
||||
setNoUpdateAddonsDisabledState();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let listener = {
|
||||
onDownloadFailed: installCompleted,
|
||||
|
Loading…
Reference in New Issue
Block a user