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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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");
     7 const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
     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 ];
    22 var RecommendedCallback = {
    23   searchSucceeded: function(addons, length, total) {
    24     dump("loaded");
    25     // Search is complete
    26     do_check_eq(length, RESULTS.length);
    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   },
    35   searchFailed: function() {
    36     server.stop(do_test_finished);
    37     do_throw("Recommended results failed");
    38   }
    39 };
    41 function run_test()
    42 {
    43   // EM needs to be running.
    44   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    45   startupManager();
    47   server = new HttpServer();
    48   server.start(-1);
    49   gPort = server.identity.primaryPort;
    50   mapFile("/data/test_bug424262.xml", server);
    52   // Point the addons repository to the test server
    53   Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" +
    54                              gPort + "/data/test_bug424262.xml");
    56   do_check_neq(AddonRepository, null);
    58   do_test_pending();
    59   // Pull some results.
    60   AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback);
    61 }

mercurial