toolkit/mozapps/extensions/test/xpcshell/test_bug424262.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug424262.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm");
     1.9 +
    1.10 +const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
    1.11 +
    1.12 +Components.utils.import("resource://testing-common/httpd.js");
    1.13 +var server;
    1.14 +var RESULTS = [
    1.15 +  null,
    1.16 +  null,
    1.17 +  0,
    1.18 +  2,
    1.19 +  4,
    1.20 +  5,
    1.21 +  5,
    1.22 +  5
    1.23 +];
    1.24 +
    1.25 +var RecommendedCallback = {
    1.26 +  searchSucceeded: function(addons, length, total) {
    1.27 +    dump("loaded");
    1.28 +    // Search is complete
    1.29 +    do_check_eq(length, RESULTS.length);
    1.30 +
    1.31 +    for (var i = 0; i < length; i++) {
    1.32 +      if (addons[i].averageRating != RESULTS[i])
    1.33 +        do_throw("Rating for " + addons[i].id + " was " + addons[i].averageRating + ", should have been " + RESULTS[i]);
    1.34 +    }
    1.35 +    server.stop(do_test_finished);
    1.36 +  },
    1.37 +
    1.38 +  searchFailed: function() {
    1.39 +    server.stop(do_test_finished);
    1.40 +    do_throw("Recommended results failed");
    1.41 +  }
    1.42 +};
    1.43 +
    1.44 +function run_test()
    1.45 +{
    1.46 +  // EM needs to be running.
    1.47 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    1.48 +  startupManager();
    1.49 +
    1.50 +  server = new HttpServer();
    1.51 +  server.start(-1);
    1.52 +  gPort = server.identity.primaryPort;
    1.53 +  mapFile("/data/test_bug424262.xml", server);
    1.54 +
    1.55 +  // Point the addons repository to the test server
    1.56 +  Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" +
    1.57 +                             gPort + "/data/test_bug424262.xml");
    1.58 +
    1.59 +  do_check_neq(AddonRepository, null);
    1.60 +
    1.61 +  do_test_pending();
    1.62 +  // Pull some results.
    1.63 +  AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback);
    1.64 +}
    1.65 +

mercurial