Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | */ |
michael@0 | 5 | Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url"; |
michael@0 | 8 | |
michael@0 | 9 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 10 | var server; |
michael@0 | 11 | var RESULTS = [ |
michael@0 | 12 | null, |
michael@0 | 13 | null, |
michael@0 | 14 | 0, |
michael@0 | 15 | 2, |
michael@0 | 16 | 4, |
michael@0 | 17 | 5, |
michael@0 | 18 | 5, |
michael@0 | 19 | 5 |
michael@0 | 20 | ]; |
michael@0 | 21 | |
michael@0 | 22 | var RecommendedCallback = { |
michael@0 | 23 | searchSucceeded: function(addons, length, total) { |
michael@0 | 24 | dump("loaded"); |
michael@0 | 25 | // Search is complete |
michael@0 | 26 | do_check_eq(length, RESULTS.length); |
michael@0 | 27 | |
michael@0 | 28 | for (var i = 0; i < length; i++) { |
michael@0 | 29 | if (addons[i].averageRating != RESULTS[i]) |
michael@0 | 30 | do_throw("Rating for " + addons[i].id + " was " + addons[i].averageRating + ", should have been " + RESULTS[i]); |
michael@0 | 31 | } |
michael@0 | 32 | server.stop(do_test_finished); |
michael@0 | 33 | }, |
michael@0 | 34 | |
michael@0 | 35 | searchFailed: function() { |
michael@0 | 36 | server.stop(do_test_finished); |
michael@0 | 37 | do_throw("Recommended results failed"); |
michael@0 | 38 | } |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | function run_test() |
michael@0 | 42 | { |
michael@0 | 43 | // EM needs to be running. |
michael@0 | 44 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 45 | startupManager(); |
michael@0 | 46 | |
michael@0 | 47 | server = new HttpServer(); |
michael@0 | 48 | server.start(-1); |
michael@0 | 49 | gPort = server.identity.primaryPort; |
michael@0 | 50 | mapFile("/data/test_bug424262.xml", server); |
michael@0 | 51 | |
michael@0 | 52 | // Point the addons repository to the test server |
michael@0 | 53 | Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" + |
michael@0 | 54 | gPort + "/data/test_bug424262.xml"); |
michael@0 | 55 | |
michael@0 | 56 | do_check_neq(AddonRepository, null); |
michael@0 | 57 | |
michael@0 | 58 | do_test_pending(); |
michael@0 | 59 | // Pull some results. |
michael@0 | 60 | AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback); |
michael@0 | 61 | } |
michael@0 | 62 |