michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm"); michael@0: const XPIProvider = scope.XPIProvider; michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: startupManager(); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_experiment() { michael@0: AddonManager.getInstallForFile(do_get_addon("test_experiment1"), (install) => { michael@0: completeAllInstalls([install], () => { michael@0: AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => { michael@0: Assert.ok(addon, "Addon is found."); michael@0: michael@0: Assert.ok(addon.userDisabled, "Experiments are userDisabled by default."); michael@0: Assert.equal(addon.isActive, false, "Add-on is not active."); michael@0: Assert.equal(addon.updateURL, null, "No updateURL for experiments."); michael@0: Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE, michael@0: "Background updates are disabled."); michael@0: Assert.equal(addon.permissions, AddonManager.PERM_CAN_UNINSTALL, michael@0: "Permissions are minimal."); michael@0: michael@0: // Setting applyBackgroundUpdates should not work. michael@0: addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE; michael@0: Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE, michael@0: "Setting applyBackgroundUpdates shouldn't do anything."); michael@0: michael@0: let noCompatibleCalled = false; michael@0: let noUpdateCalled = false; michael@0: let finishedCalled = false; michael@0: michael@0: let listener = { michael@0: onNoCompatibilityUpdateAvailable: () => { noCompatibleCalled = true; }, michael@0: onNoUpdateAvailable: () => { noUpdateCalled = true; }, michael@0: onUpdateFinished: () => { finishedCalled = true; }, michael@0: }; michael@0: michael@0: addon.findUpdates(listener, "testing", null, null); michael@0: Assert.ok(noCompatibleCalled, "Listener called."); michael@0: Assert.ok(noUpdateCalled, "Listener called."); michael@0: Assert.ok(finishedCalled, "Listener called."); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Changes to userDisabled should not be persisted to the database. michael@0: add_test(function test_userDisabledNotPersisted() { michael@0: AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => { michael@0: Assert.ok(addon, "Add-on is found."); michael@0: Assert.ok(addon.userDisabled, "Add-on is user disabled."); michael@0: michael@0: let listener = { michael@0: onEnabled: (addon2) => { michael@0: AddonManager.removeAddonListener(listener); michael@0: michael@0: Assert.equal(addon2.id, addon.id, "Changed add-on matches expected."); michael@0: Assert.equal(addon2.userDisabled, false, "Add-on is no longer user disabled."); michael@0: Assert.ok(addon2.isActive, "Add-on is active."); michael@0: michael@0: Assert.ok("experiment1@tests.mozilla.org" in XPIProvider.bootstrappedAddons, michael@0: "Experiment add-on listed in XPIProvider bootstrapped list."); michael@0: michael@0: AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => { michael@0: Assert.ok(addon, "Add-on retrieved."); michael@0: Assert.equal(addon.userDisabled, false, "Add-on is still enabled after API retrieve."); michael@0: Assert.ok(addon.isActive, "Add-on is still active."); michael@0: michael@0: // Now when we restart the manager the add-on should revert state. michael@0: restartManager(); michael@0: let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons")); michael@0: Assert.ok(!("experiment1@tests.mozilla.org" in persisted), michael@0: "Experiment add-on not persisted to bootstrappedAddons."); michael@0: michael@0: AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => { michael@0: Assert.ok(addon, "Add-on retrieved."); michael@0: Assert.ok(addon.userDisabled, "Add-on is disabled after restart."); michael@0: Assert.equal(addon.isActive, false, "Add-on is not active after restart."); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }, michael@0: }; michael@0: michael@0: AddonManager.addAddonListener(listener); michael@0: addon.userDisabled = false; michael@0: }); michael@0: });