зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
8fef83b023
Коммит
ea1981e4a0
|
@ -42,6 +42,7 @@ const Ci = Components.interfaces;
|
||||||
const Cr = Components.results;
|
const Cr = Components.results;
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
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_BROWSEADDONS = "extensions.getAddons.browseAddons";
|
||||||
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
|
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
|
||||||
|
@ -202,9 +203,7 @@ AddonRepository.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Parses an add-on entry from an <addon> element
|
// Parses an add-on entry from an <addon> element
|
||||||
_parseAddon: function(element) {
|
_parseAddon: function(element, known_ids) {
|
||||||
var em = Cc["@mozilla.org/extensions/manager;1"].
|
|
||||||
getService(Ci.nsIExtensionManager);
|
|
||||||
var app = Cc["@mozilla.org/xre/app-info;1"].
|
var app = Cc["@mozilla.org/xre/app-info;1"].
|
||||||
getService(Ci.nsIXULAppInfo).
|
getService(Ci.nsIXULAppInfo).
|
||||||
QueryInterface(Ci.nsIXULRuntime);
|
QueryInterface(Ci.nsIXULRuntime);
|
||||||
|
@ -219,7 +218,7 @@ AddonRepository.prototype = {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Ignore installed add-ons
|
// Ignore installed add-ons
|
||||||
if (em.getItemForID(guid[0].textContent) != null)
|
if (known_ids.indexOf(guid[0].textContent) != -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Ignore sandboxed add-ons
|
// Ignore sandboxed add-ons
|
||||||
|
@ -304,9 +303,9 @@ AddonRepository.prototype = {
|
||||||
// The type element has an id attribute that is the id from AMO's
|
// 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
|
// database. This doesn't match our type values to perform a mapping
|
||||||
if (node.getAttribute("id") == 2)
|
if (node.getAttribute("id") == 2)
|
||||||
addon.type = Ci.nsIUpdateItem.TYPE_THEME;
|
addon.type = Ci.nsIAddonSearchResult.TYPE_THEME;
|
||||||
else
|
else
|
||||||
addon.type = Ci.nsIUpdateItem.TYPE_EXTENSION;
|
addon.type = Ci.nsIAddonSearchResult.TYPE_EXTENSION;
|
||||||
break;
|
break;
|
||||||
case "install":
|
case "install":
|
||||||
// No os attribute means the xpi is compatible with any os
|
// No os attribute means the xpi is compatible with any os
|
||||||
|
@ -341,22 +340,28 @@ AddonRepository.prototype = {
|
||||||
this._reportFailure();
|
this._reportFailure();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var elements = responseXML.documentElement.getElementsByTagName("addon");
|
|
||||||
for (var i = 0; i < elements.length; i++) {
|
|
||||||
this._parseAddon(elements[i]);
|
|
||||||
|
|
||||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
var self = this;
|
||||||
.getService(Components.interfaces.nsIPrefBranch);
|
AddonManager.getAllAddons(function(addons) {
|
||||||
if (this._addons.length == this._maxResults) {
|
var known_ids = [a.id for each(a in addons)];
|
||||||
this._reportSuccess(elements.length);
|
|
||||||
return;
|
var elements = responseXML.documentElement.getElementsByTagName("addon");
|
||||||
|
for (var i = 0; i < elements.length; i++) {
|
||||||
|
self._parseAddon(elements[i], known_ids);
|
||||||
|
|
||||||
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
|
if (self._addons.length == self._maxResults) {
|
||||||
|
self._reportSuccess(elements.length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (responseXML.documentElement.hasAttribute("total_results"))
|
if (responseXML.documentElement.hasAttribute("total_results"))
|
||||||
this._reportSuccess(responseXML.documentElement.getAttribute("total_results"));
|
self._reportSuccess(responseXML.documentElement.getAttribute("total_results"));
|
||||||
else
|
else
|
||||||
this._reportSuccess(elements.length);
|
self._reportSuccess(elements.length);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Performs a new request for results
|
// Performs a new request for results
|
||||||
|
|
|
@ -38,9 +38,15 @@
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
[scriptable, uuid(a549a714-2ada-4bb9-8a47-be26e73d49a5)]
|
[scriptable, uuid(f81ed0bc-ee98-4edd-bf2d-751b47bf665d)]
|
||||||
interface nsIAddonSearchResult : nsISupports
|
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
|
* The ID of the add-on
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -69,7 +69,7 @@ var RESULTS = [
|
||||||
thumbnailURL: null,
|
thumbnailURL: null,
|
||||||
homepageURL: "https://addons.mozilla.org/addon/5992",
|
homepageURL: "https://addons.mozilla.org/addon/5992",
|
||||||
eula: null,
|
eula: null,
|
||||||
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
|
type: Ci.nsIAddonSearchResult.TYPE_EXTENSION,
|
||||||
xpiURL: "http://localhost:4444/test.xpi",
|
xpiURL: "http://localhost:4444/test.xpi",
|
||||||
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
|
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
|
||||||
},
|
},
|
||||||
|
@ -84,7 +84,7 @@ var RESULTS = [
|
||||||
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
|
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
|
||||||
homepageURL: null,
|
homepageURL: null,
|
||||||
eula: "EULA should be confirmed",
|
eula: "EULA should be confirmed",
|
||||||
type: Ci.nsIUpdateItem.TYPE_THEME,
|
type: Ci.nsIAddonSearchResult.TYPE_THEME,
|
||||||
xpiURL: "http://localhost:4444/test.xpi",
|
xpiURL: "http://localhost:4444/test.xpi",
|
||||||
xpiHash: null
|
xpiHash: null
|
||||||
}
|
}
|
||||||
|
@ -158,47 +158,48 @@ var FailCallback = {
|
||||||
function run_test()
|
function run_test()
|
||||||
{
|
{
|
||||||
// Setup for test
|
// Setup for test
|
||||||
|
do_test_pending();
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
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
|
// Install an add-on so we can check the same add-on isn't returns in the results
|
||||||
startupEM();
|
startupManager();
|
||||||
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
|
installAllFiles([do_get_addon("test_bug397778")], function() {
|
||||||
restartEM();
|
restartManager();
|
||||||
|
|
||||||
server = new nsHttpServer();
|
server = new nsHttpServer();
|
||||||
server.registerDirectory("/", do_get_file("data"));
|
server.registerDirectory("/", do_get_file("data"));
|
||||||
server.start(4444);
|
server.start(4444);
|
||||||
|
|
||||||
// Point the addons repository to the test server
|
// Point the addons repository to the test server
|
||||||
gPrefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
|
||||||
gPrefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
|
||||||
gPrefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug404024.xml");
|
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:4444/test_bug404024.xml");
|
||||||
gPrefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, SEARCH + "%TERMS%");
|
||||||
gPrefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, "http://localhost:4444/test_%TERMS%.xml");
|
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);
|
|
||||||
|
|
||||||
do_check_neq(addonRepo, null);
|
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
|
||||||
// Check the homepage and recommended urls
|
.getService(Components.interfaces.nsIAddonRepository);
|
||||||
do_check_eq(addonRepo.homepageURL, BROWSE);
|
|
||||||
do_check_eq(addonRepo.getRecommendedURL(), RECOMMENDED);
|
|
||||||
|
|
||||||
// Check that search urls are correct
|
do_check_neq(addonRepo, null);
|
||||||
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
|
// Check the homepage and recommended urls
|
||||||
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
|
do_check_eq(addonRepo.homepageURL, BROWSE);
|
||||||
if (url != BROWSE_SEARCH_URLS[i][1])
|
do_check_eq(addonRepo.getRecommendedURL(), RECOMMENDED);
|
||||||
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
|
|
||||||
}
|
|
||||||
|
|
||||||
do_test_pending();
|
// Check that search urls are correct
|
||||||
// This should fail because we cancel it immediately.
|
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
|
||||||
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
|
||||||
addonRepo.cancelSearch();
|
if (url != BROWSE_SEARCH_URLS[i][1])
|
||||||
// Pull some results.
|
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
|
||||||
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
|
}
|
||||||
// Should be searching now and any attempt to retrieve again should be ignored
|
|
||||||
do_check_true(addonRepo.isSearching);
|
// This should fail because we cancel it immediately.
|
||||||
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
||||||
|
addonRepo.cancelSearch();
|
||||||
|
// Pull some results.
|
||||||
|
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
|
||||||
|
// 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,
|
thumbnailURL: null,
|
||||||
homepageURL: "https://addons.mozilla.org/addon/5992",
|
homepageURL: "https://addons.mozilla.org/addon/5992",
|
||||||
eula: null,
|
eula: null,
|
||||||
type: Ci.nsIUpdateItem.TYPE_EXTENSION,
|
type: Ci.nsIAddonSearchResult.TYPE_EXTENSION,
|
||||||
xpiURL: "http://localhost:4444/test.xpi",
|
xpiURL: "http://localhost:4444/test.xpi",
|
||||||
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
|
xpiHash: "sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3"
|
||||||
},
|
},
|
||||||
|
@ -84,7 +84,7 @@ var RESULTS = [
|
||||||
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
|
thumbnailURL: "http://localhost:4444/test_bug404024/thumbnail.png",
|
||||||
homepageURL: null,
|
homepageURL: null,
|
||||||
eula: "EULA should be confirmed",
|
eula: "EULA should be confirmed",
|
||||||
type: Ci.nsIUpdateItem.TYPE_THEME,
|
type: Ci.nsIAddonSearchResult.TYPE_THEME,
|
||||||
xpiURL: "http://localhost:4444/XPCShell.xpi",
|
xpiURL: "http://localhost:4444/XPCShell.xpi",
|
||||||
xpiHash: null
|
xpiHash: null
|
||||||
}
|
}
|
||||||
|
@ -158,47 +158,48 @@ var FailCallback = {
|
||||||
function run_test()
|
function run_test()
|
||||||
{
|
{
|
||||||
// Setup for test
|
// Setup for test
|
||||||
|
do_test_pending();
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
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
|
// Install an add-on so we can check the same add-on isn't returns in the results
|
||||||
startupEM();
|
startupManager();
|
||||||
gEM.installItemFromFile(do_get_addon("test_bug397778"), NS_INSTALL_LOCATION_APPPROFILE);
|
installAllFiles([do_get_addon("test_bug397778")], function() {
|
||||||
restartEM();
|
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");
|
|
||||||
|
|
||||||
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
|
server = new nsHttpServer();
|
||||||
.getService(Components.interfaces.nsIAddonRepository);
|
server.registerDirectory("/", do_get_file("data"));
|
||||||
|
server.start(4444);
|
||||||
|
|
||||||
do_check_neq(addonRepo, null);
|
// Point the addons repository to the test server
|
||||||
// Check the homepage and recommended urls
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSEADDONS, BROWSE);
|
||||||
do_check_eq(addonRepo.homepageURL, BROWSE);
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, RECOMMENDED);
|
||||||
do_check_eq(addonRepo.getRecommendedURL(), 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");
|
||||||
|
|
||||||
// Check that search urls are correct
|
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
|
||||||
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
|
.getService(Components.interfaces.nsIAddonRepository);
|
||||||
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
|
|
||||||
if (url != BROWSE_SEARCH_URLS[i][1])
|
|
||||||
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
|
|
||||||
}
|
|
||||||
|
|
||||||
do_test_pending();
|
do_check_neq(addonRepo, null);
|
||||||
// This should fail because we cancel it immediately.
|
// Check the homepage and recommended urls
|
||||||
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
do_check_eq(addonRepo.homepageURL, BROWSE);
|
||||||
addonRepo.cancelSearch();
|
do_check_eq(addonRepo.getRecommendedURL(), RECOMMENDED);
|
||||||
// Pull some results.
|
|
||||||
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
|
// Check that search urls are correct
|
||||||
// Should be searching now and any attempt to retrieve again should be ignored
|
for (var i = 0; i < BROWSE_SEARCH_URLS.length; i++) {
|
||||||
do_check_true(addonRepo.isSearching);
|
var url = addonRepo.getSearchURL(BROWSE_SEARCH_URLS[i][0]);
|
||||||
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
if (url != BROWSE_SEARCH_URLS[i][1])
|
||||||
|
do_throw("BROWSE_SEARCH_URL[" + i + "] returned " + url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should fail because we cancel it immediately.
|
||||||
|
addonRepo.retrieveRecommendedAddons(10, FailCallback);
|
||||||
|
addonRepo.cancelSearch();
|
||||||
|
// Pull some results.
|
||||||
|
addonRepo.retrieveRecommendedAddons(10, RecommendedCallback);
|
||||||
|
// 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.
|
// EM needs to be running.
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
||||||
startupEM();
|
startupManager();
|
||||||
|
|
||||||
server = new nsHttpServer();
|
server = new nsHttpServer();
|
||||||
server.registerDirectory("/", do_get_file("data"));
|
server.registerDirectory("/", do_get_file("data"));
|
||||||
server.start(4444);
|
server.start(4444);
|
||||||
|
|
||||||
// Point the addons repository to the test server
|
// 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"]
|
addonRepo = Components.classes["@mozilla.org/extensions/addon-repository;1"]
|
||||||
.getService(Components.interfaces.nsIAddonRepository);
|
.getService(Components.interfaces.nsIAddonRepository);
|
Загрузка…
Ссылка в новой задаче