Bug 705530 - Support strictCompatibility option in update.rdf. r=dtownsend

This commit is contained in:
Blair McBride 2011-12-02 15:28:16 +13:00
Родитель f503ccea10
Коммит 156e5ad6e2
8 изменённых файлов: 198 добавлений и 10 удалений

Просмотреть файл

@ -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];
}
}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -226,4 +226,25 @@
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:addon11@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>0.1</em:minVersion>
<em:maxVersion>0.2</em:maxVersion>
<em:strictCompatibility>true</em:strictCompatibility>
<em:updateLink>http://localhost:4444/addons/test_update11.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
</RDF>

Просмотреть файл

@ -394,4 +394,26 @@
</Seq>
</em:updates>
</Description>
<!-- Opt-in to strict compatibility checking -->
<Description about="urn:mozilla:extension:compat-strict-optin@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>1.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>0.1</em:minVersion>
<em:maxVersion>0.2</em:maxVersion>
<em:strictCompatibility>true</em:strictCompatibility>
<em:updateLink>https://localhost:4444/addons/test1.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
</RDF>

Просмотреть файл

@ -1130,8 +1130,43 @@ function run_test_18() {
},
onUpdateFinished: function() {
end_test();
run_test_19();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
}
// 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);
});
}

Просмотреть файл

@ -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);
});
}

Просмотреть файл

@ -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);
});
}

Просмотреть файл

@ -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();
},