toolkit/mozapps/extensions/test/xpcshell/test_experiment.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 let scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm");
michael@0 5 const XPIProvider = scope.XPIProvider;
michael@0 6
michael@0 7 function run_test() {
michael@0 8 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 9 startupManager();
michael@0 10
michael@0 11 run_next_test();
michael@0 12 }
michael@0 13
michael@0 14 add_test(function test_experiment() {
michael@0 15 AddonManager.getInstallForFile(do_get_addon("test_experiment1"), (install) => {
michael@0 16 completeAllInstalls([install], () => {
michael@0 17 AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
michael@0 18 Assert.ok(addon, "Addon is found.");
michael@0 19
michael@0 20 Assert.ok(addon.userDisabled, "Experiments are userDisabled by default.");
michael@0 21 Assert.equal(addon.isActive, false, "Add-on is not active.");
michael@0 22 Assert.equal(addon.updateURL, null, "No updateURL for experiments.");
michael@0 23 Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
michael@0 24 "Background updates are disabled.");
michael@0 25 Assert.equal(addon.permissions, AddonManager.PERM_CAN_UNINSTALL,
michael@0 26 "Permissions are minimal.");
michael@0 27
michael@0 28 // Setting applyBackgroundUpdates should not work.
michael@0 29 addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
michael@0 30 Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
michael@0 31 "Setting applyBackgroundUpdates shouldn't do anything.");
michael@0 32
michael@0 33 let noCompatibleCalled = false;
michael@0 34 let noUpdateCalled = false;
michael@0 35 let finishedCalled = false;
michael@0 36
michael@0 37 let listener = {
michael@0 38 onNoCompatibilityUpdateAvailable: () => { noCompatibleCalled = true; },
michael@0 39 onNoUpdateAvailable: () => { noUpdateCalled = true; },
michael@0 40 onUpdateFinished: () => { finishedCalled = true; },
michael@0 41 };
michael@0 42
michael@0 43 addon.findUpdates(listener, "testing", null, null);
michael@0 44 Assert.ok(noCompatibleCalled, "Listener called.");
michael@0 45 Assert.ok(noUpdateCalled, "Listener called.");
michael@0 46 Assert.ok(finishedCalled, "Listener called.");
michael@0 47
michael@0 48 run_next_test();
michael@0 49 });
michael@0 50 });
michael@0 51 });
michael@0 52 });
michael@0 53
michael@0 54 // Changes to userDisabled should not be persisted to the database.
michael@0 55 add_test(function test_userDisabledNotPersisted() {
michael@0 56 AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
michael@0 57 Assert.ok(addon, "Add-on is found.");
michael@0 58 Assert.ok(addon.userDisabled, "Add-on is user disabled.");
michael@0 59
michael@0 60 let listener = {
michael@0 61 onEnabled: (addon2) => {
michael@0 62 AddonManager.removeAddonListener(listener);
michael@0 63
michael@0 64 Assert.equal(addon2.id, addon.id, "Changed add-on matches expected.");
michael@0 65 Assert.equal(addon2.userDisabled, false, "Add-on is no longer user disabled.");
michael@0 66 Assert.ok(addon2.isActive, "Add-on is active.");
michael@0 67
michael@0 68 Assert.ok("experiment1@tests.mozilla.org" in XPIProvider.bootstrappedAddons,
michael@0 69 "Experiment add-on listed in XPIProvider bootstrapped list.");
michael@0 70
michael@0 71 AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
michael@0 72 Assert.ok(addon, "Add-on retrieved.");
michael@0 73 Assert.equal(addon.userDisabled, false, "Add-on is still enabled after API retrieve.");
michael@0 74 Assert.ok(addon.isActive, "Add-on is still active.");
michael@0 75
michael@0 76 // Now when we restart the manager the add-on should revert state.
michael@0 77 restartManager();
michael@0 78 let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
michael@0 79 Assert.ok(!("experiment1@tests.mozilla.org" in persisted),
michael@0 80 "Experiment add-on not persisted to bootstrappedAddons.");
michael@0 81
michael@0 82 AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
michael@0 83 Assert.ok(addon, "Add-on retrieved.");
michael@0 84 Assert.ok(addon.userDisabled, "Add-on is disabled after restart.");
michael@0 85 Assert.equal(addon.isActive, false, "Add-on is not active after restart.");
michael@0 86
michael@0 87 run_next_test();
michael@0 88 });
michael@0 89 });
michael@0 90 },
michael@0 91 };
michael@0 92
michael@0 93 AddonManager.addAddonListener(listener);
michael@0 94 addon.userDisabled = false;
michael@0 95 });
michael@0 96 });

mercurial