michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); michael@0: michael@0: const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url"; michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var server; michael@0: var RESULTS = [ michael@0: null, michael@0: null, michael@0: 0, michael@0: 2, michael@0: 4, michael@0: 5, michael@0: 5, michael@0: 5 michael@0: ]; michael@0: michael@0: var RecommendedCallback = { michael@0: searchSucceeded: function(addons, length, total) { michael@0: dump("loaded"); michael@0: // Search is complete michael@0: do_check_eq(length, RESULTS.length); michael@0: michael@0: for (var i = 0; i < length; i++) { michael@0: if (addons[i].averageRating != RESULTS[i]) michael@0: do_throw("Rating for " + addons[i].id + " was " + addons[i].averageRating + ", should have been " + RESULTS[i]); michael@0: } michael@0: server.stop(do_test_finished); michael@0: }, michael@0: michael@0: searchFailed: function() { michael@0: server.stop(do_test_finished); michael@0: do_throw("Recommended results failed"); michael@0: } michael@0: }; michael@0: michael@0: function run_test() michael@0: { michael@0: // EM needs to be running. michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: startupManager(); michael@0: michael@0: server = new HttpServer(); michael@0: server.start(-1); michael@0: gPort = server.identity.primaryPort; michael@0: mapFile("/data/test_bug424262.xml", server); michael@0: michael@0: // Point the addons repository to the test server michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" + michael@0: gPort + "/data/test_bug424262.xml"); michael@0: michael@0: do_check_neq(AddonRepository, null); michael@0: michael@0: do_test_pending(); michael@0: // Pull some results. michael@0: AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback); michael@0: } michael@0: