Bug 562518: Update nsAddonRepository to use the new API. r=robstrong

--HG--
rename : toolkit/mozapps/extensions/test/unit/data/test_bug404024.xml => toolkit/mozapps/extensions/test/xpcshell/data/test_bug404024.xml
rename : toolkit/mozapps/extensions/test/unit/data/test_bug417606.xml => toolkit/mozapps/extensions/test/xpcshell/data/test_bug417606.xml
rename : toolkit/mozapps/extensions/test/unit/data/test_bug424262.xml => toolkit/mozapps/extensions/test/xpcshell/data/test_bug424262.xml
rename : toolkit/mozapps/extensions/test/unit/test_bug404024.js => toolkit/mozapps/extensions/test/xpcshell/test_bug404024.js
rename : toolkit/mozapps/extensions/test/unit/test_bug417606.js => toolkit/mozapps/extensions/test/xpcshell/test_bug417606.js
rename : toolkit/mozapps/extensions/test/unit/test_bug424262.js => toolkit/mozapps/extensions/test/xpcshell/test_bug424262.js
This commit is contained in:
Dave Townsend 2010-04-29 10:41:24 -07:00
Родитель 8fef83b023
Коммит ea1981e4a0
8 изменённых файлов: 108 добавлений и 95 удалений

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

@ -42,6 +42,7 @@ const Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/AddonManager.jsm");
const PREF_GETADDONS_BROWSEADDONS = "extensions.getAddons.browseAddons";
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
@ -202,9 +203,7 @@ AddonRepository.prototype = {
},
// Parses an add-on entry from an <addon> element
_parseAddon: function(element) {
var em = Cc["@mozilla.org/extensions/manager;1"].
getService(Ci.nsIExtensionManager);
_parseAddon: function(element, known_ids) {
var app = Cc["@mozilla.org/xre/app-info;1"].
getService(Ci.nsIXULAppInfo).
QueryInterface(Ci.nsIXULRuntime);
@ -219,7 +218,7 @@ AddonRepository.prototype = {
return;
// Ignore installed add-ons
if (em.getItemForID(guid[0].textContent) != null)
if (known_ids.indexOf(guid[0].textContent) != -1)
return;
// Ignore sandboxed add-ons
@ -304,9 +303,9 @@ AddonRepository.prototype = {
// The type element has an id attribute that is the id from AMO's
// database. This doesn't match our type values to perform a mapping
if (node.getAttribute("id") == 2)
addon.type = Ci.nsIUpdateItem.TYPE_THEME;
addon.type = Ci.nsIAddonSearchResult.TYPE_THEME;
else
addon.type = Ci.nsIUpdateItem.TYPE_EXTENSION;
addon.type = Ci.nsIAddonSearchResult.TYPE_EXTENSION;
break;
case "install":
// No os attribute means the xpi is compatible with any os
@ -341,22 +340,28 @@ AddonRepository.prototype = {
this._reportFailure();
return;
}
var self = this;
AddonManager.getAllAddons(function(addons) {
var known_ids = [a.id for each(a in addons)];
var elements = responseXML.documentElement.getElementsByTagName("addon");
for (var i = 0; i < elements.length; i++) {
this._parseAddon(elements[i]);
self._parseAddon(elements[i], known_ids);
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (this._addons.length == this._maxResults) {
this._reportSuccess(elements.length);
if (self._addons.length == self._maxResults) {
self._reportSuccess(elements.length);
return;
}
}
if (responseXML.documentElement.hasAttribute("total_results"))
this._reportSuccess(responseXML.documentElement.getAttribute("total_results"));
self._reportSuccess(responseXML.documentElement.getAttribute("total_results"));
else
this._reportSuccess(elements.length);
self._reportSuccess(elements.length);
});
},
// Performs a new request for results

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

@ -38,9 +38,15 @@
#include "nsISupports.idl"
[scriptable, uuid(a549a714-2ada-4bb9-8a47-be26e73d49a5)]
[scriptable, uuid(f81ed0bc-ee98-4edd-bf2d-751b47bf665d)]
interface nsIAddonSearchResult : nsISupports
{
/**
* Values for the type attribute
*/
const unsigned long TYPE_EXTENSION = 0x02;
const unsigned long TYPE_THEME = 0x04;
/**
* The ID of the add-on
*/

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

@ -69,7 +69,7 @@ var RESULTS = [
thumbnailURL: null,
homepageURL: "https://addons.mozilla.org/addon/5992",
eula: null,
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
type: Ci.nsIAddonSearchResult.TYPE_EXTENSION,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
},
@ -84,7 +84,7 @@ var RESULTS = [
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
homepageURL: null,
eula: "EULA should be confirmed",
type: Ci.nsIUpdateItem.TYPE_THEME,
type: Ci.nsIAddonSearchResult.TYPE_THEME,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: null
}
@ -158,23 +158,24 @@ var FailCallback = {
function run_test()
{
// Setup for test
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
// Install an add-on so we can check the same add-on isn't returns in the results
startupEM();
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
restartEM();
startupManager();
installAllFiles([do_get_addon("test_bug397778")], function() {
restartManager();
server = new nsHttpServer();
server.registerDirectory("/", do_get_file("data"));
server.start(4444);
// Point the addons repository to the test server
gPrefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
gPrefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug404024.xml");
gPrefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
gPrefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
Services.prefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug404024.xml");
Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
.getService(Components.interfaces.nsIAddonRepository);
@ -191,7 +192,6 @@ function run_test()
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
}
do_test_pending();
// This should fail because we cancel it immediately.
addonRepo.retrieveRecommendedAddons(10, FailCallback);
addonRepo.cancelSearch();
@ -200,5 +200,6 @@ function run_test()
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.retrieveRecommendedAddons(10, FailCallback);
});
}

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

@ -69,7 +69,7 @@ var RESULTS = [
thumbnailURL: null,
homepageURL: "https://addons.mozilla.org/addon/5992",
eula: null,
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
type: Ci.nsIAddonSearchResult.TYPE_EXTENSION,
xpiURL: "http://localhost:4444/test.xpi",
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
},
@ -84,7 +84,7 @@ var RESULTS = [
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
homepageURL: null,
eula: "EULA should be confirmed",
type: Ci.nsIUpdateItem.TYPE_THEME,
type: Ci.nsIAddonSearchResult.TYPE_THEME,
xpiURL: "http://localhost:4444/XPCShell.xpi",
xpiHash: null
}
@ -158,23 +158,24 @@ var FailCallback = {
function run_test()
{
// Setup for test
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
// Install an add-on so we can check the same add-on isn't returns in the results
startupEM();
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
restartEM();
startupManager();
installAllFiles([do_get_addon("test_bug397778")], function() {
restartManager();
server = new nsHttpServer();
server.registerDirectory("/", do_get_file("data"));
server.start(4444);
// Point the addons repository to the test server
gPrefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
gPrefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug417606.xml");
gPrefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
gPrefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
Services.prefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug417606.xml");
Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
.getService(Components.interfaces.nsIAddonRepository);
@ -191,7 +192,6 @@ function run_test()
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
}
do_test_pending();
// This should fail because we cancel it immediately.
addonRepo.retrieveRecommendedAddons(10, FailCallback);
addonRepo.cancelSearch();
@ -200,5 +200,6 @@ function run_test()
// Should be searching now and any attempt to retrieve again should be ignored
do_check_true(addonRepo.isSearching);
addonRepo.retrieveRecommendedAddons(10, FailCallback);
});
}

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

@ -76,14 +76,14 @@ function run_test()
{
// EM needs to be running.
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
startupEM();
startupManager();
server = new nsHttpServer();
server.registerDirectory("/", do_get_file("data"));
server.start(4444);
// Point the addons repository to the test server
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug424262.xml");
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug424262.xml");
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
.getService(Components.interfaces.nsIAddonRepository);