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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // This verifies that AddonRepository correctly fills in the
     6 // %COMPATIBILITY_MODE% token in the Search API URL.
     8 const PREF_GETADDONS_GETSEARCHRESULTS    = "extensions.getAddons.search.url";
    10 Components.utils.import("resource://testing-common/httpd.js");
    11 var gServer = new HttpServer();
    12 gServer.start(-1);
    13 gPort = gServer.identity.primaryPort;
    14 var COMPATIBILITY_PREF;
    16 // register static files with server and interpolate port numbers in them
    17 mapFile("/data/test_AddonRepository_compatmode_ignore.xml", gServer);
    18 mapFile("/data/test_AddonRepository_compatmode_normal.xml", gServer);
    19 mapFile("/data/test_AddonRepository_compatmode_strict.xml", gServer);
    21 function run_test() {
    22   do_test_pending();
    23   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    25   Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS,
    26                              "http://localhost:" + gPort + "/data/test_AddonRepository_compatmode_%COMPATIBILITY_MODE%.xml");
    27   startupManager();
    28   run_test_1();
    29 }
    31 function end_test() {
    32   gServer.stop(do_test_finished);
    33 }
    35 // Strict compatibility checking disabled.
    36 function run_test_1() {
    37   do_print("Testing with strict compatibility checking disabled");
    38   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
    40   AddonRepository.searchAddons("test", 6, {
    41     searchSucceeded: function(aAddons) {
    42       do_check_neq(aAddons, null);
    43       do_check_eq(aAddons.length, 1);
    44       do_check_eq(aAddons[0].id, "compatmode-normal@tests.mozilla.org");
    46       run_test_2();
    47     },
    48     searchFailed: function() {
    49       do_throw("Search should not have failed");
    50     }
    51   });
    52 }
    54 // Strict compatibility checking enabled.
    55 function run_test_2() {
    56   do_print("Testing with strict compatibility checking enabled");
    57   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
    59   AddonRepository.searchAddons("test", 6, {
    60     searchSucceeded: function(aAddons) {
    61       do_check_neq(aAddons, null);
    62       do_check_eq(aAddons.length, 1);
    63       do_check_eq(aAddons[0].id, "compatmode-strict@tests.mozilla.org");
    65       run_test_3();
    66     },
    67     searchFailed: function() {
    68       do_throw("Search should not have failed");
    69     }
    70   });
    71 }
    73 // Compatibility checking disabled.
    74 function run_test_3() {
    75   do_print("Testing with all compatibility checking disabled");
    76   AddonManager.checkCompatibility = false;
    78   AddonRepository.searchAddons("test", 6, {
    79     searchSucceeded: function(aAddons) {
    80       do_check_neq(aAddons, null);
    81       do_check_eq(aAddons.length, 1);
    82       do_check_eq(aAddons[0].id, "compatmode-ignore@tests.mozilla.org");
    84       end_test();
    85     },
    86     searchFailed: function() {
    87       do_throw("Search should not have failed");
    88     }
    89   });
    90 }

mercurial