From 156e5ad6e2fb261a2c6e41482e82907554daa032 Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Fri, 2 Dec 2011 15:28:16 +1300 Subject: [PATCH] Bug 705530 - Support strictCompatibility option in update.rdf. r=dtownsend --- .../mozapps/extensions/AddonUpdateChecker.jsm | 22 +++++++++-- toolkit/mozapps/extensions/XPIProvider.jsm | 9 ++++- .../test/xpcshell/data/test_update.rdf | 21 ++++++++++ .../test/xpcshell/data/test_updatecheck.rdf | 22 +++++++++++ .../extensions/test/xpcshell/test_update.js | 39 ++++++++++++++++++- .../test/xpcshell/test_update_ignorecompat.js | 36 ++++++++++++++++- .../test/xpcshell/test_update_strictcompat.js | 37 +++++++++++++++++- .../test/xpcshell/test_updatecheck.js | 22 +++++++++++ 8 files changed, 198 insertions(+), 10 deletions(-) diff --git a/toolkit/mozapps/extensions/AddonUpdateChecker.jsm b/toolkit/mozapps/extensions/AddonUpdateChecker.jsm index eea0fefd294..a60636ecbaa 100644 --- a/toolkit/mozapps/extensions/AddonUpdateChecker.jsm +++ b/toolkit/mozapps/extensions/AddonUpdateChecker.jsm @@ -395,6 +395,7 @@ function parseRDFManifest(aId, aType, aUpdateKey, aRequest) { updateURL: getProperty(ds, targetApp, "updateLink"), updateHash: getProperty(ds, targetApp, "updateHash"), updateInfoURL: getProperty(ds, targetApp, "updateInfoURL"), + strictCompatibility: getProperty(ds, targetApp, "strictCompatibility") == "true", targetApplications: [appEntry] }; @@ -598,12 +599,15 @@ UpdateParser.prototype = { * The platform version to use * @param aIgnoreMaxVersion * Ignore maxVersion when testing if an update matches. Optional. + * @param aIgnoreStrictCompat + * Ignore strictCompatibility when testing if an update matches. Optional. * @param aCompatOverrides * AddonCompatibilityOverride objects to match against. Optional. * @return true if the update is compatible with the application/platform */ function matchesVersions(aUpdate, aAppVersion, aPlatformVersion, - aIgnoreMaxVersion, aCompatOverrides) { + aIgnoreMaxVersion, aIgnoreStrictCompat, + aCompatOverrides) { if (aCompatOverrides) { let override = AddonRepository.findMatchingCompatOverride(aUpdate.version, aCompatOverrides, @@ -613,6 +617,9 @@ function matchesVersions(aUpdate, aAppVersion, aPlatformVersion, return false; } + if (aUpdate.strictCompatibility && !aIgnoreStrictCompat) + aIgnoreMaxVersion = false; + let result = false; for (let i = 0; i < aUpdate.targetApplications.length; i++) { let app = aUpdate.targetApplications[i]; @@ -658,13 +665,16 @@ var AddonUpdateChecker = { * The version of the platform or null to use the current version * @param aIgnoreMaxVersion * Ignore maxVersion when testing if an update matches. Optional. + * @param aIgnoreStrictCompat + * Ignore strictCompatibility when testing if an update matches. Optional. * @return an update object if one matches or null if not */ getCompatibilityUpdate: function AUC_getCompatibilityUpdate(aUpdates, aVersion, aIgnoreCompatibility, aAppVersion, aPlatformVersion, - aIgnoreMaxVersion) { + aIgnoreMaxVersion, + aIgnoreStrictCompat) { if (!aAppVersion) aAppVersion = Services.appinfo.version; if (!aPlatformVersion) @@ -680,7 +690,7 @@ var AddonUpdateChecker = { } } else if (matchesVersions(aUpdates[i], aAppVersion, aPlatformVersion, - aIgnoreMaxVersion)) { + aIgnoreMaxVersion, aIgnoreStrictCompat)) { return aUpdates[i]; } } @@ -699,6 +709,8 @@ var AddonUpdateChecker = { * The version of the platform or null to use the current version * @param aIgnoreMaxVersion * When determining compatible updates, ignore maxVersion. Optional. + * @param aIgnoreMaxVersion + * When determining compatible updates, ignore strictCompatibility. Optional. * @param aCompatOverrides * Array of AddonCompatibilityOverride to take into account. Optional. * @return an update object if one matches or null if not @@ -707,6 +719,7 @@ var AddonUpdateChecker = { aAppVersion, aPlatformVersion, aIgnoreMaxVersion, + aIgnoreStrictCompat, aCompatOverrides) { if (!aAppVersion) aAppVersion = Services.appinfo.version; @@ -726,7 +739,8 @@ var AddonUpdateChecker = { continue; if ((newest == null || (Services.vc.compare(newest.version, aUpdates[i].version) < 0)) && matchesVersions(aUpdates[i], aAppVersion, aPlatformVersion, - aIgnoreMaxVersion, aCompatOverrides)) { + aIgnoreMaxVersion, aIgnoreStrictCompat, + aCompatOverrides)) { newest = aUpdates[i]; } } diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index edc25887500..823570c7158 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -7015,8 +7015,10 @@ UpdateChecker.prototype = { let AUC = AddonUpdateChecker; let ignoreMaxVersion = false; + let ignoreStrictCompat = false; if (!XPIProvider.checkCompatibility) { ignoreMaxVersion = true; + ignoreStrictCompat = true; } else if (this.addon.type == "extension" && !AddonManager.strictCompatibility && !this.addon.strictCompatibility && @@ -7028,7 +7030,8 @@ UpdateChecker.prototype = { let compatUpdate = AUC.getCompatibilityUpdate(aUpdates, this.addon.version, this.syncCompatibility, null, null, - ignoreMaxVersion); + ignoreMaxVersion, + ignoreStrictCompat); // Apply the compatibility update to the database if (compatUpdate) this.addon.applyCompatibilityUpdate(compatUpdate, this.syncCompatibility); @@ -7043,7 +7046,8 @@ UpdateChecker.prototype = { compatUpdate = AUC.getCompatibilityUpdate(aUpdates, this.addon.version, false, this.appVersion, this.platformVersion, - ignoreMaxVersion); + ignoreMaxVersion, + ignoreStrictCompat); } if (compatUpdate) @@ -7071,6 +7075,7 @@ UpdateChecker.prototype = { this.appVersion, this.platformVersion, ignoreMaxVersion, + ignoreStrictCompat, compatOverrides); if (update && Services.vc.compare(this.addon.version, update.version) < 0) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_update.rdf b/toolkit/mozapps/extensions/test/xpcshell/data/test_update.rdf index 424d56ef69b..bcf8fae8c07 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/data/test_update.rdf +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_update.rdf @@ -226,4 +226,25 @@ + + + + +
  • + + 2.0 + + + xpcshell@tests.mozilla.org + 0.1 + 0.2 + true + http://localhost:4444/addons/test_update11.xpi + + + +
  • +
    +
    +
    diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecheck.rdf b/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecheck.rdf index 909c862d1be..93c82886a65 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecheck.rdf +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_updatecheck.rdf @@ -394,4 +394,26 @@ + + + + + +
  • + + 1.0 + + + xpcshell@tests.mozilla.org + 0.1 + 0.2 + true + https://localhost:4444/addons/test1.xpi + + + +
  • +
    +
    +
    diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update.js b/toolkit/mozapps/extensions/test/xpcshell/test_update.js index f44b0e187ca..8b13a5045e8 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_update.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update.js @@ -1130,8 +1130,43 @@ function run_test_18() { }, onUpdateFinished: function() { - end_test(); + run_test_19(); } }, AddonManager.UPDATE_WHEN_USER_REQUESTED); }); -} \ No newline at end of file +} + +// Test that the update check correctly observes when an addon opts-in to +// strict compatibility checking. +function run_test_19() { + writeInstallRDFForExtension({ + id: "addon11@tests.mozilla.org", + version: "1.0", + updateURL: "http://localhost:4444/data/test_update.rdf", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "0.1", + maxVersion: "0.2" + }], + name: "Test Addon 11", + }, profileDir); + restartManager(); + + AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { + do_check_neq(a11, null); + + a11.findUpdates({ + onCompatibilityUpdateAvailable: function() { + do_throw("Should have not have seen compatibility information"); + }, + + onUpdateAvailable: function() { + do_throw("Should not have seen an available update"); + }, + + onUpdateFinished: function() { + end_test(); + } + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); + }); +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js b/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js index 050f3016722..51dce18dca2 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js @@ -53,7 +53,7 @@ function run_test_1() { do_check_eq(aInstall.version, "4.0"); }, onDownloadFailed: function(aInstall) { - end_test(); + do_execute_soon(run_test_2); } }); @@ -63,3 +63,37 @@ function run_test_1() { gInternalManager.notify(null); } +// Test that the update check correctly observes when an addon opts-in to +// strict compatibility checking. +function run_test_2() { + writeInstallRDFForExtension({ + id: "addon11@tests.mozilla.org", + version: "1.0", + updateURL: "http://localhost:4444/data/test_update.rdf", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "0.1", + maxVersion: "0.2" + }], + name: "Test Addon 11", + }, profileDir); + restartManager(); + + AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { + do_check_neq(a11, null); + + a11.findUpdates({ + onCompatibilityUpdateAvailable: function() { + do_throw("Should have not have seen compatibility information"); + }, + + onNoUpdateAvailable: function() { + do_throw("Should have seen an available update"); + }, + + onUpdateFinished: function() { + end_test(); + } + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); + }); +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js b/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js index 5be83c12e75..d71ca792ddd 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_strictcompat.js @@ -1045,7 +1045,7 @@ function run_test_16() { do_check_eq(aInstall.version, "2.0"); }, onDownloadFailed: function(aInstall) { - end_test(); + do_execute_soon(run_test_17); } }); @@ -1055,3 +1055,38 @@ function run_test_16() { gInternalManager.notify(null); } +// Test that the update check correctly observes when an addon opts-in to +// strict compatibility checking. +function run_test_17() { + + writeInstallRDFForExtension({ + id: "addon11@tests.mozilla.org", + version: "1.0", + updateURL: "http://localhost:4444/data/test_update.rdf", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "0.1", + maxVersion: "0.2" + }], + name: "Test Addon 11", + }, profileDir); + restartManager(); + + AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { + do_check_neq(a11, null); + + a11.findUpdates({ + onCompatibilityUpdateAvailable: function() { + do_throw("Should have not have seen compatibility information"); + }, + + onUpdateAvailable: function() { + do_throw("Should not have seen an available update"); + }, + + onUpdateFinished: function() { + end_test(); + } + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); + }); +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js b/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js index cf63b6d63ad..b792145909a 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js @@ -289,9 +289,31 @@ function run_test_13() { null, null, true, + false, overrides); do_check_neq(update, null); do_check_eq(update.version, 1); + run_test_14(); + }, + + onUpdateCheckError: function(status) { + do_throw("Update check failed with status " + status); + } + }); +} + +function run_test_14() { + AddonUpdateChecker.checkForUpdates("compat-strict-optin@tests.mozilla.org", + "extension", null, + "http://localhost:4444/data/test_updatecheck.rdf", { + onUpdateCheckComplete: function(updates) { + do_check_eq(updates.length, 1); + let update = AddonUpdateChecker.getNewestCompatibleUpdate(updates, + null, + null, + true, + false); + do_check_eq(update, null); end_test(); },