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 add-on update check correctly fills in the michael@0: // %COMPATIBILITY_MODE% token in the update URL. michael@0: michael@0: michael@0: // The test extension uses an insecure update url. michael@0: Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: mapFile("/data/test_updatecompatmode_ignore.rdf", testserver); michael@0: mapFile("/data/test_updatecompatmode_normal.rdf", testserver); michael@0: mapFile("/data/test_updatecompatmode_strict.rdf", testserver); michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); 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: writeInstallRDFForExtension({ michael@0: id: "compatmode-normal@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon - normal" michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "compatmode-strict@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon - strict" michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "compatmode-strict-optin@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon - strict opt-in", michael@0: strictCompatibility: true michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "compatmode-ignore@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon - ignore", michael@0: }, profileDir); michael@0: michael@0: startupManager(); michael@0: run_test_1(); michael@0: } michael@0: michael@0: function end_test() { michael@0: testserver.stop(do_test_finished); michael@0: } 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: AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: addon.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function() { michael@0: do_throw("Should have not have seen compatibility information"); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function() { michael@0: do_throw("Should have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_check_eq(install.version, "2.0") michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: run_test_2(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); 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: AddonManager.getAddonByID("compatmode-strict@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: addon.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function() { michael@0: do_throw("Should have not have seen compatibility information"); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function() { michael@0: do_throw("Should have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_check_eq(install.version, "2.0") michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: run_test_3(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: } michael@0: michael@0: // Strict compatibility checking opt-in. michael@0: function run_test_3() { michael@0: do_print("Testing with strict compatibility disabled, but addon opt-in"); michael@0: Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); michael@0: AddonManager.getAddonByID("compatmode-strict-optin@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: addon.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function() { michael@0: do_throw("Should have not have seen compatibility information"); michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_throw("Should not have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: run_test_4(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: } michael@0: michael@0: // Compatibility checking disabled. michael@0: function run_test_4() { michael@0: do_print("Testing with all compatibility checking disabled"); michael@0: AddonManager.checkCompatibility = false; michael@0: AddonManager.getAddonByID("compatmode-ignore@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: addon.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function() { michael@0: do_throw("Should have not have seen compatibility information"); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function() { michael@0: do_throw("Should have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateAvailable: function(addon, install) { michael@0: do_check_eq(install.version, "2.0") michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: end_test(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: }