mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1336501 - Sync shield-recipe-client from GitHub (ad0f45e) r=Gijs
MozReview-Commit-ID: KiDjjs2qpk5 --HG-- extra : rebase_source : 50b1743435eab1eabc67cb4bae726e881190a698
This commit is contained in:
parent
d06d0c7897
commit
e16ca50773
@ -7,6 +7,14 @@ const {utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
Cu.import("resource://gre/modules/Log.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LogManager",
|
||||
"resource://shield-recipe-client/lib/LogManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "RecipeRunner",
|
||||
"resource://shield-recipe-client/lib/RecipeRunner.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "CleanupManager",
|
||||
"resource://shield-recipe-client/lib/CleanupManager.jsm");
|
||||
|
||||
const REASONS = {
|
||||
APP_STARTUP: 1, // The application is starting up.
|
||||
@ -16,7 +24,7 @@ const REASONS = {
|
||||
ADDON_INSTALL: 5, // The add-on is being installed.
|
||||
ADDON_UNINSTALL: 6, // The add-on is being uninstalled.
|
||||
ADDON_UPGRADE: 7, // The add-on is being upgraded.
|
||||
ADDON_DOWNGRADE: 8, //The add-on is being downgraded.
|
||||
ADDON_DOWNGRADE: 8, // The add-on is being downgraded.
|
||||
};
|
||||
|
||||
const PREF_BRANCH = "extensions.shield-recipe-client.";
|
||||
@ -53,19 +61,15 @@ this.startup = function() {
|
||||
}
|
||||
|
||||
// Setup logging and listen for changes to logging prefs
|
||||
Cu.import("resource://shield-recipe-client/lib/LogManager.jsm");
|
||||
LogManager.configure(Services.prefs.getIntPref(PREF_LOGGING_LEVEL));
|
||||
Preferences.observe(PREF_LOGGING_LEVEL, LogManager.configure);
|
||||
CleanupManager.addCleanupHandler(
|
||||
() => Preferences.ignore(PREF_LOGGING_LEVEL, LogManager.configure));
|
||||
|
||||
Cu.import("resource://shield-recipe-client/lib/RecipeRunner.jsm");
|
||||
RecipeRunner.init();
|
||||
};
|
||||
|
||||
this.shutdown = function(data, reason) {
|
||||
Preferences.ignore(PREF_LOGGING_LEVEL, LogManager.configure);
|
||||
|
||||
Cu.import("resource://shield-recipe-client/lib/CleanupManager.jsm");
|
||||
|
||||
CleanupManager.cleanup();
|
||||
|
||||
if (reason === REASONS.ADDON_DISABLE || reason === REASONS.ADDON_UNINSTALL) {
|
||||
|
@ -5,7 +5,6 @@
|
||||
"use strict";
|
||||
|
||||
const {utils: Cu} = Components;
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["CleanupManager"];
|
||||
|
||||
const cleanupHandlers = new Set();
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetryArchive.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
@ -74,14 +75,16 @@ this.EnvExpressions = {
|
||||
|
||||
eval(expr, extraContext = {}) {
|
||||
// First clone the extra context
|
||||
const context = Object.assign({}, extraContext);
|
||||
const context = Object.assign({normandy: {}}, extraContext);
|
||||
// jexl handles promises, so it is fine to include them in this data.
|
||||
context.telemetry = EnvExpressions.getLatestTelemetry();
|
||||
context.normandy = context.normandy || {};
|
||||
context.normandy.userId = EnvExpressions.getUserId();
|
||||
|
||||
context.normandy = Object.assign(context.normandy, {
|
||||
userId: EnvExpressions.getUserId(),
|
||||
distribution: Preferences.get("distribution.id", "default"),
|
||||
});
|
||||
|
||||
const onelineExpr = expr.replace(/[\t\n\r]/g, " ");
|
||||
|
||||
return jexl.eval(onelineExpr, context);
|
||||
},
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ Cu.import("resource://gre/modules/Log.jsm");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["LogManager"];
|
||||
|
||||
const ROOT_LOGGER_NAME = "extensions.shield-recipe-client"
|
||||
const ROOT_LOGGER_NAME = "extensions.shield-recipe-client";
|
||||
let rootLogger = null;
|
||||
|
||||
this.LogManager = {
|
||||
|
@ -75,8 +75,12 @@ this.NormandyDriver = function(sandboxManager, extraContext = {}) {
|
||||
isDefaultBrowser: ShellService.isDefaultBrowser() || null,
|
||||
searchEngine: null,
|
||||
syncSetup: Preferences.isSet("services.sync.username"),
|
||||
syncDesktopDevices: Preferences.get("services.sync.clients.devices.desktop", 0),
|
||||
syncMobileDevices: Preferences.get("services.sync.clients.devices.mobile", 0),
|
||||
syncTotalDevices: Preferences.get("services.sync.numClients", 0),
|
||||
plugins: {},
|
||||
doNotTrack: Preferences.get("privacy.donottrackheader.enabled", false),
|
||||
distribution: Preferences.get("distribution.id", "default"),
|
||||
};
|
||||
|
||||
const searchEnginePromise = new Promise(resolve => {
|
||||
|
@ -82,4 +82,13 @@ add_task(function* () {
|
||||
"[normandy.userId, normandy.injectedValue]",
|
||||
{normandy: {injectedValue: "injected"}});
|
||||
Assert.deepEqual(val, ["fake id", "injected"], "context is correctly merged");
|
||||
|
||||
// distribution id defaults to "default"
|
||||
val = yield EnvExpressions.eval("normandy.distribution");
|
||||
Assert.equal(val, "default", "distribution has a default value");
|
||||
|
||||
// distribution id is in the context
|
||||
yield SpecialPowers.pushPrefEnv({set: [["distribution.id", "funnelcake"]]});
|
||||
val = yield EnvExpressions.eval("normandy.distribution");
|
||||
Assert.equal(val, "funnelcake", "distribution is read from preferences");
|
||||
});
|
||||
|
@ -18,3 +18,32 @@ add_task(Utils.withDriver(Assert, function* userId(driver) {
|
||||
// Test that userId is a UUID
|
||||
ok(Utils.UUID_REGEX.test(driver.userId), "userId is a uuid");
|
||||
}));
|
||||
|
||||
add_task(Utils.withDriver(Assert, function* syncDeviceCounts(driver) {
|
||||
let client = yield driver.client();
|
||||
is(client.syncMobileDevices, 0, "syncMobileDevices defaults to zero");
|
||||
is(client.syncDesktopDevices, 0, "syncDesktopDevices defaults to zero");
|
||||
is(client.syncTotalDevices, 0, "syncTotalDevices defaults to zero");
|
||||
|
||||
yield SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["services.sync.numClients", 9],
|
||||
["services.sync.clients.devices.mobile", 5],
|
||||
["services.sync.clients.devices.desktop", 4],
|
||||
],
|
||||
});
|
||||
|
||||
client = yield driver.client();
|
||||
is(client.syncMobileDevices, 5, "syncMobileDevices is read when set");
|
||||
is(client.syncDesktopDevices, 4, "syncDesktopDevices is read when set");
|
||||
is(client.syncTotalDevices, 9, "syncTotalDevices is read when set");
|
||||
}));
|
||||
|
||||
add_task(Utils.withDriver(Assert, function* distribution(driver) {
|
||||
let client = yield driver.client();
|
||||
is(client.distribution, "default", "distribution has a default value");
|
||||
|
||||
yield SpecialPowers.pushPrefEnv({set: [["distribution.id", "funnelcake"]]});
|
||||
client = yield driver.client();
|
||||
is(client.distribution, "funnelcake", "distribution is read from preferences");
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user