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 hotfix installation works michael@0: michael@0: // The test extension uses an insecure update url. michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: // Ignore any certificate requirements the app has set michael@0: Services.prefs.setBoolPref("extensions.hotfix.cert.checkAttributes", 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: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: mapFile("/data/test_hotfix_1.rdf", testserver); michael@0: mapFile("/data/test_hotfix_2.rdf", testserver); michael@0: mapFile("/data/test_hotfix_3.rdf", testserver); michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: startupManager(); michael@0: michael@0: do_test_pending(); 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: // Test that background updates find and install any available hotfix michael@0: function run_test_1() { michael@0: Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org"); michael@0: Services.prefs.setCharPref("extensions.update.background.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_1.rdf"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], callback_soon(check_test_1)); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function check_test_1() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { michael@0: do_check_neq(aAddon, null); michael@0: do_check_eq(aAddon.version, "1.0"); michael@0: michael@0: aAddon.uninstall(); michael@0: do_execute_soon(run_test_2); michael@0: }); michael@0: } michael@0: michael@0: // Don't install an already used hotfix michael@0: function run_test_2() { michael@0: restartManager(); michael@0: michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function() { michael@0: do_throw("Should not have seen a new install created"); michael@0: } michael@0: }); michael@0: michael@0: function observer() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: do_execute_soon(run_test_3); michael@0: } michael@0: michael@0: Services.obs.addObserver(observer, "addons-background-update-complete", false); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: // Install a newer hotfix michael@0: function run_test_3() { michael@0: restartManager(); michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_2.rdf"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], callback_soon(check_test_3)); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function check_test_3() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { michael@0: do_check_neq(aAddon, null); michael@0: do_check_eq(aAddon.version, "2.0"); michael@0: michael@0: aAddon.uninstall(); michael@0: do_execute_soon(run_test_4); michael@0: }); michael@0: } michael@0: michael@0: // Don't install an incompatible hotfix michael@0: function run_test_4() { michael@0: restartManager(); michael@0: michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_3.rdf"); michael@0: michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function() { michael@0: do_throw("Should not have seen a new install created"); michael@0: } michael@0: }); michael@0: michael@0: function observer() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: do_execute_soon(run_test_5); michael@0: } michael@0: michael@0: Services.obs.addObserver(observer, "addons-background-update-complete", false); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: // Don't install an older hotfix michael@0: function run_test_5() { michael@0: restartManager(); michael@0: michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_1.rdf"); michael@0: michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function() { michael@0: do_throw("Should not have seen a new install created"); michael@0: } michael@0: }); michael@0: michael@0: function observer() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: do_execute_soon(run_test_6); michael@0: } michael@0: michael@0: Services.obs.addObserver(observer, "addons-background-update-complete", false); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: // Don't re-download an already pending install michael@0: function run_test_6() { michael@0: restartManager(); michael@0: michael@0: Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_1.rdf"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], callback_soon(check_test_6)); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function check_test_6() { michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function() { michael@0: do_throw("Should not have seen a new install created"); michael@0: } michael@0: }); michael@0: michael@0: function observer() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { michael@0: aAddon.uninstall(); michael@0: do_execute_soon(run_test_7); michael@0: }); michael@0: } michael@0: michael@0: Services.obs.addObserver(observer, "addons-background-update-complete", false); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: // Start downloading again if something cancels the install michael@0: function run_test_7() { michael@0: restartManager(); michael@0: michael@0: Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], check_test_7); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function check_test_7(aInstall) { michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onOperationCancelled" michael@0: ] michael@0: }, [ michael@0: "onInstallCancelled", michael@0: ]); michael@0: michael@0: aInstall.cancel(); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], callback_soon(finish_test_7)); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function finish_test_7() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { michael@0: do_check_neq(aAddon, null); michael@0: do_check_eq(aAddon.version, "1.0"); michael@0: michael@0: aAddon.uninstall(); michael@0: do_execute_soon(run_test_8); michael@0: }); michael@0: } michael@0: michael@0: // Cancel a pending install when a newer version is already available michael@0: function run_test_8() { michael@0: restartManager(); michael@0: michael@0: Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_1.rdf"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], check_test_8); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function check_test_8() { michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + michael@0: gPort + "/data/test_hotfix_2.rdf"); michael@0: michael@0: prepare_test({ michael@0: "hotfix@tests.mozilla.org": [ michael@0: "onOperationCancelled", michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onDownloadStarted", michael@0: "onDownloadEnded", michael@0: "onInstallStarted", michael@0: "onInstallCancelled", michael@0: "onInstallEnded", michael@0: ], finish_test_8); michael@0: michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: function finish_test_8() { michael@0: AddonManager.getAllInstalls(callback_soon(function(aInstalls) { michael@0: do_check_eq(aInstalls.length, 1); michael@0: do_check_eq(aInstalls[0].version, "2.0"); michael@0: michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("hotfix@tests.mozilla.org", callback_soon(function(aAddon) { michael@0: do_check_neq(aAddon, null); michael@0: do_check_eq(aAddon.version, "2.0"); michael@0: michael@0: aAddon.uninstall(); michael@0: restartManager(); michael@0: michael@0: end_test(); michael@0: })); michael@0: })); michael@0: }