services/sync/tests/unit/test_addons_tracker.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 "use strict";
michael@0 5
michael@0 6 Cu.import("resource://gre/modules/AddonManager.jsm");
michael@0 7 Cu.import("resource://services-sync/engines/addons.js");
michael@0 8 Cu.import("resource://services-sync/constants.js");
michael@0 9 Cu.import("resource://services-sync/service.js");
michael@0 10 Cu.import("resource://services-sync/util.js");
michael@0 11
michael@0 12 loadAddonTestFunctions();
michael@0 13 startupManager();
michael@0 14 Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
michael@0 15 Svc.Prefs.set("engine.addons", true);
michael@0 16
michael@0 17 Service.engineManager.register(AddonsEngine);
michael@0 18 let engine = Service.engineManager.get("addons");
michael@0 19 let reconciler = engine._reconciler;
michael@0 20 let store = engine._store;
michael@0 21 let tracker = engine._tracker;
michael@0 22
michael@0 23 // Don't write out by default.
michael@0 24 tracker.persistChangedIDs = false;
michael@0 25
michael@0 26 const addon1ID = "addon1@tests.mozilla.org";
michael@0 27
michael@0 28 function cleanup_and_advance() {
michael@0 29 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 30 tracker.stopTracking();
michael@0 31
michael@0 32 tracker.resetScore();
michael@0 33 tracker.clearChangedIDs();
michael@0 34
michael@0 35 reconciler._addons = {};
michael@0 36 reconciler._changes = [];
michael@0 37 let cb = Async.makeSpinningCallback();
michael@0 38 reconciler.saveState(null, cb);
michael@0 39 cb.wait();
michael@0 40
michael@0 41 run_next_test();
michael@0 42 }
michael@0 43
michael@0 44 function run_test() {
michael@0 45 initTestLogging("Trace");
michael@0 46 Log.repository.getLogger("Sync.Engine.Addons").level = Log.Level.Trace;
michael@0 47 Log.repository.getLogger("Sync.AddonsReconciler").level =
michael@0 48 Log.Level.Trace;
michael@0 49
michael@0 50 cleanup_and_advance();
michael@0 51 }
michael@0 52
michael@0 53 add_test(function test_empty() {
michael@0 54 _("Verify the tracker is empty to start with.");
michael@0 55
michael@0 56 do_check_eq(0, Object.keys(tracker.changedIDs).length);
michael@0 57 do_check_eq(0, tracker.score);
michael@0 58
michael@0 59 cleanup_and_advance();
michael@0 60 });
michael@0 61
michael@0 62 add_test(function test_not_tracking() {
michael@0 63 _("Ensures the tracker doesn't do anything when it isn't tracking.");
michael@0 64
michael@0 65 let addon = installAddon("test_bootstrap1_1");
michael@0 66 uninstallAddon(addon);
michael@0 67
michael@0 68 do_check_eq(0, Object.keys(tracker.changedIDs).length);
michael@0 69 do_check_eq(0, tracker.score);
michael@0 70
michael@0 71 cleanup_and_advance();
michael@0 72 });
michael@0 73
michael@0 74 add_test(function test_track_install() {
michael@0 75 _("Ensure that installing an add-on notifies tracker.");
michael@0 76
michael@0 77 reconciler.startListening();
michael@0 78
michael@0 79 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 80
michael@0 81 do_check_eq(0, tracker.score);
michael@0 82 let addon = installAddon("test_bootstrap1_1");
michael@0 83 let changed = tracker.changedIDs;
michael@0 84
michael@0 85 do_check_eq(1, Object.keys(changed).length);
michael@0 86 do_check_true(addon.syncGUID in changed);
michael@0 87 do_check_eq(SCORE_INCREMENT_XLARGE, tracker.score);
michael@0 88
michael@0 89 uninstallAddon(addon);
michael@0 90 cleanup_and_advance();
michael@0 91 });
michael@0 92
michael@0 93 add_test(function test_track_uninstall() {
michael@0 94 _("Ensure that uninstalling an add-on notifies tracker.");
michael@0 95
michael@0 96 reconciler.startListening();
michael@0 97
michael@0 98 let addon = installAddon("test_bootstrap1_1");
michael@0 99 let guid = addon.syncGUID;
michael@0 100 do_check_eq(0, tracker.score);
michael@0 101
michael@0 102 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 103
michael@0 104 uninstallAddon(addon);
michael@0 105 let changed = tracker.changedIDs;
michael@0 106 do_check_eq(1, Object.keys(changed).length);
michael@0 107 do_check_true(guid in changed);
michael@0 108 do_check_eq(SCORE_INCREMENT_XLARGE, tracker.score);
michael@0 109
michael@0 110 cleanup_and_advance();
michael@0 111 });
michael@0 112
michael@0 113 add_test(function test_track_user_disable() {
michael@0 114 _("Ensure that tracker sees disabling of add-on");
michael@0 115
michael@0 116 reconciler.startListening();
michael@0 117
michael@0 118 let addon = installAddon("test_bootstrap1_1");
michael@0 119 do_check_false(addon.userDisabled);
michael@0 120 do_check_false(addon.appDisabled);
michael@0 121 do_check_true(addon.isActive);
michael@0 122
michael@0 123 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 124 do_check_eq(0, tracker.score);
michael@0 125
michael@0 126 let cb = Async.makeSyncCallback();
michael@0 127
michael@0 128 let listener = {
michael@0 129 onDisabled: function(disabled) {
michael@0 130 _("onDisabled");
michael@0 131 if (disabled.id == addon.id) {
michael@0 132 AddonManager.removeAddonListener(listener);
michael@0 133 cb();
michael@0 134 }
michael@0 135 },
michael@0 136 onDisabling: function(disabling) {
michael@0 137 _("onDisabling add-on");
michael@0 138 }
michael@0 139 };
michael@0 140 AddonManager.addAddonListener(listener);
michael@0 141
michael@0 142 _("Disabling add-on");
michael@0 143 addon.userDisabled = true;
michael@0 144 _("Disabling started...");
michael@0 145 Async.waitForSyncCallback(cb);
michael@0 146
michael@0 147 let changed = tracker.changedIDs;
michael@0 148 do_check_eq(1, Object.keys(changed).length);
michael@0 149 do_check_true(addon.syncGUID in changed);
michael@0 150 do_check_eq(SCORE_INCREMENT_XLARGE, tracker.score);
michael@0 151
michael@0 152 uninstallAddon(addon);
michael@0 153 cleanup_and_advance();
michael@0 154 });
michael@0 155
michael@0 156 add_test(function test_track_enable() {
michael@0 157 _("Ensure that enabling a disabled add-on notifies tracker.");
michael@0 158
michael@0 159 reconciler.startListening();
michael@0 160
michael@0 161 let addon = installAddon("test_bootstrap1_1");
michael@0 162 addon.userDisabled = true;
michael@0 163 store._sleep(0);
michael@0 164
michael@0 165 do_check_eq(0, tracker.score);
michael@0 166
michael@0 167 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 168 addon.userDisabled = false;
michael@0 169 store._sleep(0);
michael@0 170
michael@0 171 let changed = tracker.changedIDs;
michael@0 172 do_check_eq(1, Object.keys(changed).length);
michael@0 173 do_check_true(addon.syncGUID in changed);
michael@0 174 do_check_eq(SCORE_INCREMENT_XLARGE, tracker.score);
michael@0 175
michael@0 176 uninstallAddon(addon);
michael@0 177 cleanup_and_advance();
michael@0 178 });

mercurial