michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This verifies that AddonRepository correctly fills in the michael@0: // %COMPATIBILITY_MODE% token in the Search API URL. michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var gServer = new HttpServer(); michael@0: gServer.start(-1); michael@0: gPort = gServer.identity.primaryPort; michael@0: var COMPATIBILITY_PREF; michael@0: michael@0: // register static files with server and interpolate port numbers in them michael@0: mapFile("/data/test_AddonRepository_compatmode_ignore.xml", gServer); michael@0: mapFile("/data/test_AddonRepository_compatmode_normal.xml", gServer); michael@0: mapFile("/data/test_AddonRepository_compatmode_strict.xml", gServer); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, michael@0: "http://localhost:" + gPort + "/data/test_AddonRepository_compatmode_%COMPATIBILITY_MODE%.xml"); michael@0: startupManager(); michael@0: run_test_1(); michael@0: } michael@0: michael@0: function end_test() { michael@0: gServer.stop(do_test_finished); michael@0: } michael@0: michael@0: // Strict compatibility checking disabled. michael@0: function run_test_1() { michael@0: do_print("Testing with strict compatibility checking disabled"); michael@0: Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); michael@0: michael@0: AddonRepository.searchAddons("test", 6, { michael@0: searchSucceeded: function(aAddons) { michael@0: do_check_neq(aAddons, null); michael@0: do_check_eq(aAddons.length, 1); michael@0: do_check_eq(aAddons[0].id, "compatmode-normal@tests.mozilla.org"); michael@0: michael@0: run_test_2(); michael@0: }, michael@0: searchFailed: function() { michael@0: do_throw("Search should not have failed"); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: // Strict compatibility checking enabled. michael@0: function run_test_2() { michael@0: do_print("Testing with strict compatibility checking enabled"); michael@0: Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); michael@0: michael@0: AddonRepository.searchAddons("test", 6, { michael@0: searchSucceeded: function(aAddons) { michael@0: do_check_neq(aAddons, null); michael@0: do_check_eq(aAddons.length, 1); michael@0: do_check_eq(aAddons[0].id, "compatmode-strict@tests.mozilla.org"); michael@0: michael@0: run_test_3(); michael@0: }, michael@0: searchFailed: function() { michael@0: do_throw("Search should not have failed"); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: // Compatibility checking disabled. michael@0: function run_test_3() { michael@0: do_print("Testing with all compatibility checking disabled"); michael@0: AddonManager.checkCompatibility = false; michael@0: michael@0: AddonRepository.searchAddons("test", 6, { michael@0: searchSucceeded: function(aAddons) { michael@0: do_check_neq(aAddons, null); michael@0: do_check_eq(aAddons.length, 1); michael@0: do_check_eq(aAddons[0].id, "compatmode-ignore@tests.mozilla.org"); michael@0: michael@0: end_test(); michael@0: }, michael@0: searchFailed: function() { michael@0: do_throw("Search should not have failed"); michael@0: } michael@0: }); michael@0: }