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