michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests compatibility overrides, for when strict compatibility checking is michael@0: // disabled. See bug 693906. michael@0: michael@0: michael@0: const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; 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: michael@0: const PORT = gPort; michael@0: const BASE_URL = "http://localhost:" + PORT; michael@0: const DEFAULT_URL = "about:blank"; michael@0: const REQ_URL = "/data.xml"; michael@0: michael@0: // register static file and mark it for interpolation michael@0: mapUrlToFile(REQ_URL, do_get_file("data/test_compatoverrides.xml"), gServer); michael@0: michael@0: Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); michael@0: Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); michael@0: Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, michael@0: BASE_URL + REQ_URL); michael@0: michael@0: michael@0: // Not hosted, no overrides michael@0: var addon1 = { michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 1", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, no overrides michael@0: var addon2 = { michael@0: id: "addon2@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 2", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, matching override michael@0: var addon3 = { michael@0: id: "addon3@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 3", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, matching override, wouldn't be compatible if strict checking is enabled michael@0: var addon4 = { michael@0: id: "addon4@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 4", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "0.1", michael@0: maxVersion: "0.2" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, app ID doesn't match in override michael@0: var addon5 = { michael@0: id: "addon5@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 5", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, addon version range doesn't match in override michael@0: var addon6 = { michael@0: id: "addon6@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 6", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, app version range doesn't match in override michael@0: var addon7 = { michael@0: id: "addon7@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 7", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Hosted, multiple overrides michael@0: var addon8 = { michael@0: id: "addon8@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 8", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Not hosted, matching override michael@0: var addon9 = { michael@0: id: "addon9@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 9", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: // Not hosted, override is of unsupported type (compatible) michael@0: var addon10 = { michael@0: id: "addon10@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test addon 10", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: michael@0: /* michael@0: * Trigger an AddonManager background update check michael@0: * michael@0: * @param aCallback michael@0: * Callback to call once the background update is complete michael@0: */ michael@0: function trigger_background_update(aCallback) { michael@0: Services.obs.addObserver({ michael@0: observe: function(aSubject, aTopic, aData) { michael@0: Services.obs.removeObserver(this, "addons-background-update-complete"); michael@0: do_execute_soon(aCallback); michael@0: } michael@0: }, "addons-background-update-complete", false); michael@0: michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2"); michael@0: michael@0: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(addon3, profileDir); michael@0: writeInstallRDFForExtension(addon4, profileDir); michael@0: writeInstallRDFForExtension(addon5, profileDir); michael@0: writeInstallRDFForExtension(addon6, profileDir); michael@0: writeInstallRDFForExtension(addon7, profileDir); michael@0: writeInstallRDFForExtension(addon8, profileDir); michael@0: writeInstallRDFForExtension(addon9, profileDir); michael@0: writeInstallRDFForExtension(addon10, profileDir); michael@0: michael@0: startupManager(); michael@0: michael@0: trigger_background_update(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: function check_compat_status(aCallback) { michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org", michael@0: "addon5@tests.mozilla.org", michael@0: "addon6@tests.mozilla.org", michael@0: "addon7@tests.mozilla.org", michael@0: "addon8@tests.mozilla.org", michael@0: "addon9@tests.mozilla.org", michael@0: "addon10@tests.mozilla.org"], michael@0: function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]) { michael@0: michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.compatibilityOverrides, null); michael@0: do_check_true(a1.isCompatible); michael@0: do_check_false(a1.appDisabled); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_eq(a2.compatibilityOverrides, null); michael@0: do_check_true(a2.isCompatible); michael@0: do_check_false(a2.appDisabled); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_neq(a3.compatibilityOverrides, null); michael@0: do_check_eq(a3.compatibilityOverrides.length, 1); michael@0: do_check_false(a3.isCompatible); michael@0: do_check_true(a3.appDisabled); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_neq(a4.compatibilityOverrides, null); michael@0: do_check_eq(a4.compatibilityOverrides.length, 1); michael@0: do_check_false(a4.isCompatible); michael@0: do_check_true(a4.appDisabled); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_eq(a5.compatibilityOverrides, null); michael@0: do_check_true(a5.isCompatible); michael@0: do_check_false(a5.appDisabled); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_neq(a6.compatibilityOverrides, null); michael@0: do_check_eq(a6.compatibilityOverrides.length, 1); michael@0: do_check_true(a6.isCompatible); michael@0: do_check_false(a6.appDisabled); michael@0: michael@0: do_check_neq(a7, null); michael@0: do_check_neq(a7.compatibilityOverrides, null); michael@0: do_check_eq(a7.compatibilityOverrides.length, 1); michael@0: do_check_true(a7.isCompatible); michael@0: do_check_false(a7.appDisabled); michael@0: michael@0: do_check_neq(a8, null); michael@0: do_check_neq(a8.compatibilityOverrides, null); michael@0: do_check_eq(a8.compatibilityOverrides.length, 3); michael@0: do_check_false(a8.isCompatible); michael@0: do_check_true(a8.appDisabled); michael@0: michael@0: do_check_neq(a9, null); michael@0: do_check_neq(a9.compatibilityOverrides, null); michael@0: do_check_eq(a9.compatibilityOverrides.length, 1); michael@0: do_check_false(a9.isCompatible); michael@0: do_check_true(a9.appDisabled); michael@0: michael@0: do_check_neq(a10, null); michael@0: do_check_eq(a10.compatibilityOverrides, null); michael@0: do_check_true(a10.isCompatible); michael@0: do_check_false(a10.appDisabled); michael@0: michael@0: do_execute_soon(aCallback); michael@0: }); michael@0: } michael@0: michael@0: function run_test_1() { michael@0: do_print("Run test 1"); michael@0: check_compat_status(run_test_2); michael@0: } michael@0: michael@0: function run_test_2() { michael@0: do_print("Run test 2"); michael@0: restartManager(); michael@0: check_compat_status(end_test); michael@0: }