Bug 758950 - Part 2b: Use more for...of loops in Add-ons Manager frontend and backend code. r=Unfocused

This commit is contained in:
Marcos S. 2012-09-17 15:14:00 +12:00
parent d53801e41f
commit 3665bcb073
11 changed files with 135 additions and 140 deletions

View File

@ -14,10 +14,10 @@ var gProvider;
function parseParams(aQuery) {
let params = {};
aQuery.split("&").forEach(function(aParam) {
let [key, value] = aParam.split("=");
for (let param of aQuery.split("&")) {
let [key, value] = param.split("=");
params[key] = value;
});
}
return params;
}

View File

@ -37,9 +37,8 @@ function test() {
function end_test() {
// Test generates a lot of available installs so just cancel them all
AddonManager.getAllInstalls(function(aInstalls) {
aInstalls.forEach(function(aInstall) {
aInstall.cancel();
});
for (let install of aInstalls)
install.cancel();
finish();
});
@ -51,20 +50,21 @@ function install_test_addons(aCallback) {
// Use a blank update URL
Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "missing.rdf");
["browser_bug557956_1",
"browser_bug557956_2",
"browser_bug557956_3",
"browser_bug557956_4",
"browser_bug557956_5",
"browser_bug557956_6",
"browser_bug557956_7",
"browser_bug557956_8_1",
"browser_bug557956_9_1",
"browser_bug557956_10"].forEach(function(aName) {
AddonManager.getInstallForURL(TESTROOT + "addons/" + aName + ".xpi", function(aInstall) {
let names = ["browser_bug557956_1",
"browser_bug557956_2",
"browser_bug557956_3",
"browser_bug557956_4",
"browser_bug557956_5",
"browser_bug557956_6",
"browser_bug557956_7",
"browser_bug557956_8_1",
"browser_bug557956_9_1",
"browser_bug557956_10"];
for (let name of names) {
AddonManager.getInstallForURL(TESTROOT + "addons/" + name + ".xpi", function(aInstall) {
installs.push(aInstall);
}, "application/x-xpinstall");
});
}
var listener = {
installCount: 0,
@ -80,10 +80,10 @@ function install_test_addons(aCallback) {
}
};
installs.forEach(function(aInstall) {
aInstall.addListener(listener);
aInstall.install();
});
for (let install of installs) {
install.addListener(listener);
install.install();
}
}
function uninstall_test_addons(aCallback) {
@ -98,10 +98,10 @@ function uninstall_test_addons(aCallback) {
"addon9@tests.mozilla.org",
"addon10@tests.mozilla.org"],
function(aAddons) {
aAddons.forEach(function(aAddon) {
if (aAddon)
aAddon.uninstall();
});
for (let addon of aAddons) {
if (addon)
addon.uninstall();
}
aCallback();
});
}
@ -353,9 +353,8 @@ add_test(function() {
"addon9@tests.mozilla.org",
"addon10@tests.mozilla.org"],
function(aAddons) {
aAddons.forEach(function(aAddon) {
aAddon.userDisabled = true;
});
for (let addon of aAddons)
addon.userDisabled = true;
// These add-ons were inactive in the old application
var inactiveAddonIds = [
@ -389,9 +388,8 @@ add_test(function() {
"addon9@tests.mozilla.org",
"addon10@tests.mozilla.org"],
function(aAddons) {
aAddons.forEach(function(aAddon) {
aAddon.uninstall();
});
for (let addon of aAddons)
addon.uninstall();
// These add-ons were inactive in the old application
var inactiveAddonIds = [
@ -450,12 +448,13 @@ add_test(function() {
"addon9@tests.mozilla.org",
"addon10@tests.mozilla.org"],
function(aAddons) {
aAddons.forEach(function(aAddon) {
if (aAddon.id == "addon10@tests.mozilla.org")
is(aAddon.isCompatible, true, "Addon10 should be compatible before compat overrides are refreshed");
for (let addon of aAddons) {
if (addon.id == "addon10@tests.mozilla.org")
is(addon.isCompatible, true, "Addon10 should be compatible before compat overrides are refreshed");
else
aAddon.uninstall();
});
addon.uninstall();
}
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, TESTROOT + "browser_bug557956.xml");
Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);

View File

@ -84,17 +84,16 @@ function test_confirmation(aWindow, aExpectedURLs) {
var list = aWindow.document.getElementById("itemList");
is(list.childNodes.length, aExpectedURLs.length, "Should be the right number of installs");
aExpectedURLs.forEach(function(aURL) {
var node = list.firstChild;
while (node) {
if (node.url == aURL) {
ok(true, "Should have seen " + aURL + " in the list");
return;
for (let url of aExpectedURLs) {
let found = false;
for (let node of list.children) {
if (node.url == url) {
found = true;
break;
}
node = node.nextSibling;
}
ok(false, "Should have seen " + aURL + " in the list");
});
ok(found, "Should have seen " + url + " in the list");
}
aWindow.document.documentElement.cancelDialog();
}

View File

@ -29,9 +29,8 @@ function test() {
function end_test() {
// Test generates a lot of available installs so just cancel them all
AddonManager.getAllInstalls(function(aInstalls) {
aInstalls.forEach(function(aInstall) {
aInstall.cancel();
});
for (let install of aInstalls)
install.cancel();
close_manager(gManagerWindow, finish);
});

View File

@ -17,14 +17,14 @@ function test() {
});
let allCompatible = true;
aAddons.forEach(function checkCompatibility(a) {
for (let a of aAddons) {
// Ignore plugins.
if (a.type == "plugin")
return;
continue;
ok(a.isCompatible, a.type + " " + a.name + " " + a.version + " should be compatible");
allCompatible = allCompatible && a.isCompatible;
});
}
// Add a reminder.
if (!allCompatible)
ok(false, "As this test failed, test browser_bug557956.js should have failed, too.");

View File

@ -130,24 +130,23 @@ function testHash(aBrowser, aTestAddonVisible, aCallback) {
// Test against all the add-ons the manager knows about since plugins and
// app extensions may exist
AddonManager.getAllAddons(function(aAddons) {
aAddons.forEach(function(aAddon) {
if (!(aAddon.id in data)) {
for (let addon of aAddons) {
if (!(addon.id in data)) {
// Test add-ons will have shown an error if necessary above
if (aAddon.id.substring(6) != "@tests.mozilla.org")
ok(false, "Add-on " + aAddon.id + " was not included in the data");
return;
if (addon.id.substring(6) != "@tests.mozilla.org")
ok(false, "Add-on " + addon.id + " was not included in the data");
continue;
}
info("Testing data for add-on " + aAddon.id);
var addonData = data[aAddon.id];
is(addonData.name, aAddon.name, "Name should be correct");
is(addonData.version, aAddon.version, "Version should be correct");
is(addonData.type, aAddon.type, "Type should be correct");
is(addonData.userDisabled, aAddon.userDisabled, "userDisabled should be correct");
is(addonData.isBlocklisted, aAddon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED, "blocklisted should be correct");
is(addonData.isCompatible, aAddon.isCompatible, "isCompatible should be correct");
});
info("Testing data for add-on " + addon.id);
var addonData = data[addon.id];
is(addonData.name, addon.name, "Name should be correct");
is(addonData.version, addon.version, "Version should be correct");
is(addonData.type, addon.type, "Type should be correct");
is(addonData.userDisabled, addon.userDisabled, "userDisabled should be correct");
is(addonData.isBlocklisted, addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED, "blocklisted should be correct");
is(addonData.isCompatible, addon.isCompatible, "isCompatible should be correct");
}
aCallback();
});
}

View File

@ -105,17 +105,16 @@ function test_confirmation(aWindow, aExpectedURLs) {
var list = aWindow.document.getElementById("itemList");
is(list.childNodes.length, aExpectedURLs.length, "Should be the right number of installs");
aExpectedURLs.forEach(function(aURL) {
var node = list.firstChild;
while (node) {
if (node.url == aURL) {
ok(true, "Should have seen " + aURL + " in the list");
return;
for (let url of aExpectedURLs) {
let found = false;
for (let node of list.children) {
if (node.url == url) {
found = true;
break;
}
node = node.nextSibling;
}
ok(false, "Should have seen " + aURL + " in the list");
});
ok(found, "Should have seen " + url + " in the list");
}
aWindow.document.documentElement.cancelDialog();
}

View File

@ -61,7 +61,8 @@ function test() {
sourceURI: "http://example.com/fail-install1.xpi"
}]);
installs.forEach(function(aInstall) { aInstall.install(); });
for (let install of installs )
install.install();
open_manager("addons://list/extension", function(aWindow) {
gManagerWindow = aWindow;

View File

@ -103,26 +103,27 @@ function test() {
Services.prefs.setBoolPref("extensions.installedDistroAddon.test12@tests.mozilla.org", true);
Services.prefs.setBoolPref("extensions.installedDistroAddon.test15@tests.mozilla.org", true);
ADDONS.forEach(function(aAddon, aPos) {
var addon = new MockAddon("test" + aPos + "@tests.mozilla.org",
"Test Add-on " + aPos, "extension");
for (let pos in ADDONS) {
let addonItem = ADDONS[pos];
let addon = new MockAddon("test" + pos + "@tests.mozilla.org",
"Test Add-on " + pos, "extension");
addon.version = "1.0";
addon.userDisabled = aAddon[0];
addon.appDisabled = aAddon[1];
addon.isActive = aAddon[3];
addon.applyBackgroundUpdates = aAddon[5] ? AddonManager.AUTOUPDATE_ENABLE
addon.userDisabled = addonItem[0];
addon.appDisabled = addonItem[1];
addon.isActive = addonItem[3];
addon.applyBackgroundUpdates = addonItem[5] ? AddonManager.AUTOUPDATE_ENABLE
: AddonManager.AUTOUPDATE_DISABLE;
addon.scope = aAddon[6];
addon.scope = addonItem[6];
// Remove the upgrade permission from non-profile add-ons
if (addon.scope != AddonManager.SCOPE_PROFILE)
addon._permissions -= AddonManager.PERM_CAN_UPGRADE;
addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) {
addon.appDisabled = aAddon[2];
addon.appDisabled = addonItem[2];
addon.isActive = addon.shouldBeActive;
if (aAddon[4]) {
if (addonItem[4]) {
var newAddon = new MockAddon(this.id, this.name, "extension");
newAddon.version = "2.0";
var install = new MockInstall(this.name, this.type, newAddon);
@ -134,7 +135,7 @@ function test() {
};
gProvider.addAddon(addon);
});
}
gWin = Services.ww.openWindow(null,
"chrome://mozapps/content/extensions/selectAddons.xul",

View File

@ -212,9 +212,8 @@ function set_order(aSortBy, aAscending) {
node = node.nextSibling;
}
gManagerWindow.sortElements(elements, ["uiState", aSortBy], aAscending);
elements.forEach(function(aElement) {
list.appendChild(aElement);
});
for (let element of elements)
list.appendChild(element);
}
function check_order(aExpectedOrder) {

View File

@ -69,35 +69,35 @@ var gRestorePrefs = [{name: PREF_LOGGING_ENABLED},
{name: PREF_STRICT_COMPAT},
{name: PREF_CHECK_COMPATIBILITY}];
gRestorePrefs.forEach(function(aPref) {
if (!Services.prefs.prefHasUserValue(aPref.name)) {
aPref.type = "clear";
return;
for (let pref of gRestorePrefs) {
if (!Services.prefs.prefHasUserValue(pref.name)) {
pref.type = "clear";
continue;
}
aPref.type = Services.prefs.getPrefType(aPref.name);
if (aPref.type == Services.prefs.PREF_BOOL)
aPref.value = Services.prefs.getBoolPref(aPref.name);
else if (aPref.type == Services.prefs.PREF_INT)
aPref.value = Services.prefs.getIntPref(aPref.name);
else if (aPref.type == Services.prefs.PREF_STRING)
aPref.value = Services.prefs.getCharPref(aPref.name);
});
pref.type = Services.prefs.getPrefType(pref.name);
if (pref.type == Services.prefs.PREF_BOOL)
pref.value = Services.prefs.getBoolPref(pref.name);
else if (pref.type == Services.prefs.PREF_INT)
pref.value = Services.prefs.getIntPref(pref.name);
else if (pref.type == Services.prefs.PREF_STRING)
pref.value = Services.prefs.getCharPref(pref.name);
}
// Turn logging on for all tests
Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true);
registerCleanupFunction(function() {
// Restore prefs
gRestorePrefs.forEach(function(aPref) {
if (aPref.type == "clear")
Services.prefs.clearUserPref(aPref.name);
else if (aPref.type == Services.prefs.PREF_BOOL)
Services.prefs.setBoolPref(aPref.name, aPref.value);
else if (aPref.type == Services.prefs.PREF_INT)
Services.prefs.setIntPref(aPref.name, aPref.value);
else if (aPref.type == Services.prefs.PREF_STRING)
Services.prefs.setCharPref(aPref.name, aPref.value);
});
for (let pref of gRestorePrefs) {
if (pref.type == "clear")
Services.prefs.clearUserPref(pref.name);
else if (pref.type == Services.prefs.PREF_BOOL)
Services.prefs.setBoolPref(pref.name, pref.value);
else if (pref.type == Services.prefs.PREF_INT)
Services.prefs.setIntPref(pref.name, pref.value);
else if (pref.type == Services.prefs.PREF_STRING)
Services.prefs.setCharPref(pref.name, pref.value);
}
// Throw an error if the add-ons manager window is open anywhere
var windows = Services.wm.getEnumerator("Addons:Manager");
@ -122,13 +122,13 @@ registerCleanupFunction(function() {
// We can for now know that getAllInstalls actually calls its callback before
// it returns so this will complete before the next test start.
AddonManager.getAllInstalls(function(aInstalls) {
aInstalls.forEach(function(aInstall) {
if (aInstall instanceof MockInstall)
return;
for (let install of aInstalls) {
if (install instanceof MockInstall)
continue;
ok(false, "Should not have seen an install of " + aInstall.sourceURI.spec + " in state " + aInstall.state);
aInstall.cancel();
});
ok(false, "Should not have seen an install of " + install.sourceURI.spec + " in state " + install.state);
install.cancel();
}
});
});
@ -663,20 +663,20 @@ MockProvider.prototype = {
*/
createAddons: function MP_createAddons(aAddonProperties) {
var newAddons = [];
aAddonProperties.forEach(function(aAddonProp) {
var addon = new MockAddon(aAddonProp.id);
for (var prop in aAddonProp) {
for (let addonProp of aAddonProperties) {
let addon = new MockAddon(addonProp.id);
for (let prop in addonProp) {
if (prop == "id")
continue;
if (prop == "applyBackgroundUpdates") {
addon._applyBackgroundUpdates = aAddonProp[prop];
addon._applyBackgroundUpdates = addonProp[prop];
continue;
}
if (prop == "appDisabled") {
addon._appDisabled = aAddonProp[prop];
addon._appDisabled = addonProp[prop];
continue;
}
addon[prop] = aAddonProp[prop];
addon[prop] = addonProp[prop];
}
if (!addon.optionsType && !!addon.optionsURL)
addon.optionsType = AddonManager.OPTIONS_TYPE_DIALOG;
@ -686,7 +686,7 @@ MockProvider.prototype = {
this.addAddon(addon);
newAddons.push(addon);
}, this);
}
return newAddons;
},
@ -701,25 +701,25 @@ MockProvider.prototype = {
*/
createInstalls: function MP_createInstalls(aInstallProperties) {
var newInstalls = [];
aInstallProperties.forEach(function(aInstallProp) {
var install = new MockInstall(aInstallProp.name || null,
aInstallProp.type || null,
for (let installProp of aInstallProperties) {
let install = new MockInstall(installProp.name || null,
installProp.type || null,
null);
for (var prop in aInstallProp) {
for (let prop in installProp) {
switch (prop) {
case "name":
case "type":
break;
case "sourceURI":
install[prop] = NetUtil.newURI(aInstallProp[prop]);
install[prop] = NetUtil.newURI(installProp[prop]);
break;
default:
install[prop] = aInstallProp[prop];
install[prop] = installProp[prop];
}
}
this.addInstall(install);
newInstalls.push(install);
}, this);
}
return newInstalls;
},
@ -737,9 +737,8 @@ MockProvider.prototype = {
* Called when the provider should shutdown.
*/
shutdown: function MP_shutdown() {
this.callbackTimers.forEach(function(aTimer) {
aTimer.cancel();
});
for (let timer of this.callbackTimers)
timer.cancel();
this.callbackTimers = [];
this.started = false;
@ -1218,16 +1217,16 @@ MockInstall.prototype = {
// Call test listeners after standard listeners to remove race condition
// between standard and test listeners
this.testListeners.forEach(function(aListener) {
for (let listener of this.testListeners) {
try {
if (aMethod in aListener)
if (aListener[aMethod].call(aListener, this, this.addon) === false)
if (aMethod in listener)
if (listener[aMethod].call(listener, this, this.addon) === false)
result = false;
}
catch (e) {
ok(false, "Test listener threw exception: " + e);
}
}, this);
}
return result;
}