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 background updates & notifications work as expected 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: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: // register static files with server and interpolate port numbers in them michael@0: mapFile("/data/test_backgroundupdate.rdf", testserver); michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); 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: // Verify that with no add-ons installed the background update notifications get michael@0: // called michael@0: function run_test_1() { michael@0: AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) { michael@0: do_check_eq(aAddons.length, 0); michael@0: michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: michael@0: do_execute_soon(run_test_2); michael@0: }, "addons-background-update-complete", false); michael@0: michael@0: AddonManagerPrivate.backgroundUpdateCheck(); michael@0: }); michael@0: } michael@0: michael@0: // Verify that with two add-ons installed both of which claim to have updates michael@0: // available we get the notification after both updates attempted to start michael@0: function run_test_2() { michael@0: writeInstallRDFForExtension({ michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.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 1", michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "addon2@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.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 2", michael@0: }, profileDir); michael@0: michael@0: writeInstallRDFForExtension({ michael@0: id: "addon3@tests.mozilla.org", michael@0: version: "1.0", 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 3", michael@0: }, profileDir); michael@0: michael@0: // Background update uses a different pref, if set michael@0: Services.prefs.setCharPref("extensions.update.background.url", michael@0: "http://localhost:" + gPort +"/data/test_backgroundupdate.rdf"); michael@0: restartManager(); michael@0: michael@0: // Do hotfix checks michael@0: Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org"); michael@0: Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + gPort + "/missing.rdf"); michael@0: michael@0: let installCount = 0; michael@0: let completeCount = 0; michael@0: let sawCompleteNotification = false; michael@0: michael@0: Services.obs.addObserver(function() { michael@0: Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); michael@0: michael@0: do_check_eq(installCount, 3); michael@0: sawCompleteNotification = true; michael@0: }, "addons-background-update-complete", false); michael@0: michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function(aInstall) { michael@0: installCount++; michael@0: }, michael@0: michael@0: onDownloadFailed: function(aInstall) { michael@0: completeCount++; michael@0: if (completeCount == 3) { michael@0: do_check_true(sawCompleteNotification); michael@0: end_test(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: AddonManagerPrivate.backgroundUpdateCheck(); michael@0: }