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.

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

mercurial