зеркало из https://github.com/mozilla/gecko-dev.git
Bug 581065 - Allow searching for incompatible add-ons if compatibility checks are disabled. r=dtownsend
This commit is contained in:
Родитель
2091e7ce9a
Коммит
f7de091224
|
@ -60,6 +60,15 @@ const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url
|
|||
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
|
||||
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
|
||||
|
||||
const PREF_CHECK_COMPATIBILITY_BASE = "extensions.checkCompatibility";
|
||||
#ifdef MOZ_COMPATIBILITY_NIGHTLY
|
||||
const PREF_CHECK_COMPATIBILITY = PREF_CHECK_COMPATIBILITY_BASE +
|
||||
".nightly";
|
||||
#else
|
||||
const PREF_CHECK_COMPATIBILITY = PREF_CHECK_COMPATIBILITY_BASE + "." +
|
||||
Services.appinfo.version.replace(BRANCH_REGEXP, "$1");
|
||||
#endif
|
||||
|
||||
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml";
|
||||
|
||||
const API_VERSION = "1.5";
|
||||
|
@ -810,13 +819,23 @@ var AddonRepository = {
|
|||
* The callback to pass results to
|
||||
*/
|
||||
searchAddons: function(aSearchTerms, aMaxResults, aCallback) {
|
||||
let url = this._formatURLPref(PREF_GETADDONS_GETSEARCHRESULTS, {
|
||||
let substitutions = {
|
||||
API_VERSION : API_VERSION,
|
||||
TERMS : encodeURIComponent(aSearchTerms),
|
||||
|
||||
// Get twice as many results to account for potential filtering
|
||||
MAX_RESULTS : 2 * aMaxResults
|
||||
});
|
||||
};
|
||||
|
||||
let checkCompatibility = true;
|
||||
try {
|
||||
checkCompatibility = Services.prefs.getBoolPref(PREF_CHECK_COMPATIBILITY);
|
||||
} catch(e) { }
|
||||
|
||||
if (!checkCompatibility)
|
||||
substitutions.VERSION = "";
|
||||
|
||||
let url = this._formatURLPref(PREF_GETADDONS_GETSEARCHRESULTS, substitutions);
|
||||
|
||||
let self = this;
|
||||
function handleResults(aElements, aTotalResults) {
|
||||
|
@ -1079,17 +1098,26 @@ var AddonRepository = {
|
|||
_parseAddons: function(aElements, aTotalResults, aSkip) {
|
||||
let self = this;
|
||||
let results = [];
|
||||
|
||||
let checkCompatibility = true;
|
||||
try {
|
||||
checkCompatibility = Services.prefs.getBoolPref(PREF_CHECK_COMPATIBILITY);
|
||||
} catch(e) { }
|
||||
|
||||
function isSameApplication(aAppNode) {
|
||||
return self._getTextContent(aAppNode) == Services.appinfo.ID;
|
||||
}
|
||||
|
||||
for (let i = 0; i < aElements.length && results.length < this._maxResults; i++) {
|
||||
let element = aElements[i];
|
||||
|
||||
// Ignore add-ons not compatible with this Application
|
||||
let tags = this._getUniqueDescendant(element, "compatible_applications");
|
||||
if (tags == null)
|
||||
continue;
|
||||
|
||||
let applications = tags.getElementsByTagName("appID");
|
||||
let compatible = Array.some(applications, function(aAppNode) {
|
||||
if (self._getTextContent(aAppNode) != Services.appinfo.ID)
|
||||
if (!isSameApplication(aAppNode))
|
||||
return false;
|
||||
|
||||
let parent = aAppNode.parentNode;
|
||||
|
@ -1103,8 +1131,14 @@ var AddonRepository = {
|
|||
Services.vc.compare(currentVersion, maxVersion) <= 0);
|
||||
});
|
||||
|
||||
if (!compatible)
|
||||
continue;
|
||||
// Ignore add-ons not compatible with this Application
|
||||
if (!compatible) {
|
||||
if (checkCompatibility)
|
||||
continue;
|
||||
|
||||
if (!Array.some(applications, isSameApplication))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add-on meets all requirements, so parse out data
|
||||
let result = this._parseAddon(element, aSkip);
|
||||
|
@ -1125,6 +1159,8 @@ var AddonRepository = {
|
|||
if (!result.xpiURL && !result.addon.purchaseURL)
|
||||
continue;
|
||||
|
||||
result.addon.isCompatible = compatible;
|
||||
|
||||
results.push(result);
|
||||
// Ignore this add-on from now on by adding it to the skip array
|
||||
aSkip.ids.push(result.addon.id);
|
||||
|
|
|
@ -589,6 +589,22 @@ add_test(function() {
|
|||
});
|
||||
});
|
||||
|
||||
// Tests that incompatible add-ons are shown with a warning if compatibility checking is disabled
|
||||
add_test(function() {
|
||||
Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
|
||||
search("incompatible", false, function() {
|
||||
var item = get_addon_item("remote5");
|
||||
is_element_visible(item, "Incompatible addon should be visible");
|
||||
is(item.getAttribute("notification"), "warning", "Compatibility warning should be shown");
|
||||
|
||||
var item = get_addon_item("remote6");
|
||||
is(item, null, "Addon incompatible with the product should not be visible");
|
||||
|
||||
Services.prefs.clearUserPref("extensions.checkCompatibility.nightly");
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
// Tests that restarting the manager doesn't change search results
|
||||
add_test(function() {
|
||||
restart_manager(gManagerWindow, null, function(aWindow) {
|
||||
|
|
|
@ -186,5 +186,61 @@
|
|||
<compatible_os>ALL</compatible_os>
|
||||
<install size="4">http://example.com/remote4.xpi</install>
|
||||
</addon>
|
||||
<addon>
|
||||
<name>PASS - i</name>
|
||||
<type id='1'>Extension</type>
|
||||
<guid>remote5@tests.mozilla.org</guid>
|
||||
<version>6.0</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>Test Creator</name>
|
||||
<link>http://example.com/creator.html</link>
|
||||
</author>
|
||||
</authors>
|
||||
<status id='4'>Public</status>
|
||||
<summary>Incompatible test</summary>
|
||||
<description>Test description</description>
|
||||
<compatible_applications>
|
||||
<application>
|
||||
<name>Firefox</name>
|
||||
<appID>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</appID>
|
||||
<min_version>0</min_version>
|
||||
<max_version>1</max_version>
|
||||
</application>
|
||||
<application>
|
||||
<name>SeaMonkey</name>
|
||||
<appID>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</appID>
|
||||
<min_version>0</min_version>
|
||||
<max_version>1</max_version>
|
||||
</application>
|
||||
</compatible_applications>
|
||||
<compatible_os>ALL</compatible_os>
|
||||
<install size="1">http://example.com/addon1.xpi</install>
|
||||
</addon>
|
||||
<addon>
|
||||
<name>FAIL - j</name>
|
||||
<type id='1'>Extension</type>
|
||||
<guid>remote6@tests.mozilla.org</guid>
|
||||
<version>6.0</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>Test Creator</name>
|
||||
<link>http://example.com/creator.html</link>
|
||||
</author>
|
||||
</authors>
|
||||
<status id='4'>Public</status>
|
||||
<summary>Incompatible test</summary>
|
||||
<description>Test description</description>
|
||||
<compatible_applications>
|
||||
<application>
|
||||
<name>Fake Product</name>
|
||||
<appID>fakeproduct@mozilla.org</appID>
|
||||
<min_version>0</min_version>
|
||||
<max_version>1</max_version>
|
||||
</application>
|
||||
</compatible_applications>
|
||||
<compatible_os>ALL</compatible_os>
|
||||
<install size="1">http://example.com/addon1.xpi</install>
|
||||
</addon>
|
||||
</searchresults>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче