From 1d47415833062e328741d6d6b0bbba2382c5a233 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Wed, 19 Oct 2011 11:38:58 +1300 Subject: [PATCH] Bug 581065 - Allow searching for incompatible add-ons if compatibility checks are disabled. r=dtownsend --- .../mozapps/extensions/AddonRepository.jsm | 48 ++++++++++++++-- .../test/browser/browser_searching.js | 16 ++++++ .../test/browser/browser_searching.xml | 56 +++++++++++++++++++ 3 files changed, 114 insertions(+), 6 deletions(-) diff --git a/toolkit/mozapps/extensions/AddonRepository.jsm b/toolkit/mozapps/extensions/AddonRepository.jsm index 826ce24278b..1f6b4d9e01c 100644 --- a/toolkit/mozapps/extensions/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/AddonRepository.jsm @@ -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); diff --git a/toolkit/mozapps/extensions/test/browser/browser_searching.js b/toolkit/mozapps/extensions/test/browser/browser_searching.js index 960d8b4225a..4588543f227 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_searching.js +++ b/toolkit/mozapps/extensions/test/browser/browser_searching.js @@ -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) { diff --git a/toolkit/mozapps/extensions/test/browser/browser_searching.xml b/toolkit/mozapps/extensions/test/browser/browser_searching.xml index 198013b5b3e..b050443b3dc 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_searching.xml +++ b/toolkit/mozapps/extensions/test/browser/browser_searching.xml @@ -186,5 +186,61 @@ ALL http://example.com/remote4.xpi + + PASS - i + Extension + remote5@tests.mozilla.org + 6.0 + + + Test Creator + http://example.com/creator.html + + + Public + Incompatible test + Test description + + + Firefox + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 0 + 1 + + + SeaMonkey + {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} + 0 + 1 + + + ALL + http://example.com/addon1.xpi + + + FAIL - j + Extension + remote6@tests.mozilla.org + 6.0 + + + Test Creator + http://example.com/creator.html + + + Public + Incompatible test + Test description + + + Fake Product + fakeproduct@mozilla.org + 0 + 1 + + + ALL + http://example.com/addon1.xpi +