diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-11 07:03:16 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-11 07:03:16 -0500 |
commit | 203eb0f61a09372310a2a8fb57e169cb3f47800b (patch) | |
tree | 8490329d3dae4de3c7ffd127bce1f65fdc009abd /toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js | |
parent | e45706ca3acbb6530419433212becc61d5953a2d (diff) | |
parent | 8f6d3dab81c7f8f97ef197e26ab9439b09735b8f (diff) | |
download | UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.gz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.lz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.xz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.zip |
Merge branch 'ext-work'FF_Checkpoint_1
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js b/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js new file mode 100644 index 000000000..d69c33e33 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_backgroundupdate.js @@ -0,0 +1,122 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// This verifies that background updates & notifications work as expected + +// The test extension uses an insecure update url. +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); + +Components.utils.import("resource://testing-common/httpd.js"); +var testserver = new HttpServer(); +testserver.start(-1); +gPort = testserver.identity.primaryPort; +const profileDir = gProfD.clone(); +profileDir.append("extensions"); + +// register static files with server and interpolate port numbers in them +mapFile("/data/test_backgroundupdate.rdf", testserver); + +function run_test() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + + testserver.registerDirectory("/addons/", do_get_file("addons")); + + startupManager(); + + do_test_pending(); + run_test_1(); +} + +function end_test() { + testserver.stop(do_test_finished); +} + +// Verify that with no add-ons installed the background update notifications get +// called +function run_test_1() { + AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) { + do_check_eq(aAddons.length, 0); + + Services.obs.addObserver(function() { + Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); + + do_execute_soon(run_test_2); + }, "addons-background-update-complete", false); + + // Trigger the background update timer handler + gInternalManager.notify(null); + }); +} + +// Verify that with two add-ons installed both of which claim to have updates +// available we get the notification after both updates attempted to start +function run_test_2() { + writeInstallRDFForExtension({ + id: "addon1@tests.mozilla.org", + version: "1.0", + updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.rdf", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 1", + }, profileDir); + + writeInstallRDFForExtension({ + id: "addon2@tests.mozilla.org", + version: "1.0", + updateURL: "http://localhost:" + gPort + "/data/test_backgroundupdate.rdf", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 2", + }, profileDir); + + writeInstallRDFForExtension({ + id: "addon3@tests.mozilla.org", + version: "1.0", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 3", + }, profileDir); + + // Background update uses a different pref, if set + Services.prefs.setCharPref("extensions.update.background.url", + "http://localhost:" + gPort +"/data/test_backgroundupdate.rdf"); + restartManager(); + + let installCount = 0; + let completeCount = 0; + let sawCompleteNotification = false; + + Services.obs.addObserver(function() { + Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); + + do_check_eq(installCount, 3); + sawCompleteNotification = true; + }, "addons-background-update-complete", false); + + AddonManager.addInstallListener({ + onNewInstall: function(aInstall) { + installCount++; + }, + + onDownloadFailed: function(aInstall) { + completeCount++; + if (completeCount == 3) { + do_check_true(sawCompleteNotification); + end_test(); + } + } + }); + + // Trigger the background update timer handler + gInternalManager.notify(null); +} |