1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_compatmode.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This verifies that AddonRepository correctly fills in the 1.9 +// %COMPATIBILITY_MODE% token in the Search API URL. 1.10 + 1.11 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.12 + 1.13 +Components.utils.import("resource://testing-common/httpd.js"); 1.14 +var gServer = new HttpServer(); 1.15 +gServer.start(-1); 1.16 +gPort = gServer.identity.primaryPort; 1.17 +var COMPATIBILITY_PREF; 1.18 + 1.19 +// register static files with server and interpolate port numbers in them 1.20 +mapFile("/data/test_AddonRepository_compatmode_ignore.xml", gServer); 1.21 +mapFile("/data/test_AddonRepository_compatmode_normal.xml", gServer); 1.22 +mapFile("/data/test_AddonRepository_compatmode_strict.xml", gServer); 1.23 + 1.24 +function run_test() { 1.25 + do_test_pending(); 1.26 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.27 + 1.28 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, 1.29 + "http://localhost:" + gPort + "/data/test_AddonRepository_compatmode_%COMPATIBILITY_MODE%.xml"); 1.30 + startupManager(); 1.31 + run_test_1(); 1.32 +} 1.33 + 1.34 +function end_test() { 1.35 + gServer.stop(do_test_finished); 1.36 +} 1.37 + 1.38 +// Strict compatibility checking disabled. 1.39 +function run_test_1() { 1.40 + do_print("Testing with strict compatibility checking disabled"); 1.41 + Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); 1.42 + 1.43 + AddonRepository.searchAddons("test", 6, { 1.44 + searchSucceeded: function(aAddons) { 1.45 + do_check_neq(aAddons, null); 1.46 + do_check_eq(aAddons.length, 1); 1.47 + do_check_eq(aAddons[0].id, "compatmode-normal@tests.mozilla.org"); 1.48 + 1.49 + run_test_2(); 1.50 + }, 1.51 + searchFailed: function() { 1.52 + do_throw("Search should not have failed"); 1.53 + } 1.54 + }); 1.55 +} 1.56 + 1.57 +// Strict compatibility checking enabled. 1.58 +function run_test_2() { 1.59 + do_print("Testing with strict compatibility checking enabled"); 1.60 + Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); 1.61 + 1.62 + AddonRepository.searchAddons("test", 6, { 1.63 + searchSucceeded: function(aAddons) { 1.64 + do_check_neq(aAddons, null); 1.65 + do_check_eq(aAddons.length, 1); 1.66 + do_check_eq(aAddons[0].id, "compatmode-strict@tests.mozilla.org"); 1.67 + 1.68 + run_test_3(); 1.69 + }, 1.70 + searchFailed: function() { 1.71 + do_throw("Search should not have failed"); 1.72 + } 1.73 + }); 1.74 +} 1.75 + 1.76 +// Compatibility checking disabled. 1.77 +function run_test_3() { 1.78 + do_print("Testing with all compatibility checking disabled"); 1.79 + AddonManager.checkCompatibility = false; 1.80 + 1.81 + AddonRepository.searchAddons("test", 6, { 1.82 + searchSucceeded: function(aAddons) { 1.83 + do_check_neq(aAddons, null); 1.84 + do_check_eq(aAddons.length, 1); 1.85 + do_check_eq(aAddons[0].id, "compatmode-ignore@tests.mozilla.org"); 1.86 + 1.87 + end_test(); 1.88 + }, 1.89 + searchFailed: function() { 1.90 + do_throw("Search should not have failed"); 1.91 + } 1.92 + }); 1.93 +}