summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/test/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/normandy/test/browser
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/normandy/test/browser')
-rw-r--r--toolkit/components/normandy/test/browser/browser_ActionsManager.js2
-rw-r--r--toolkit/components/normandy/test/browser/browser_BaseAction.js4
-rw-r--r--toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js138
-rw-r--r--toolkit/components/normandy/test/browser/browser_PreferenceExperiments.js21
-rw-r--r--toolkit/components/normandy/test/browser/browser_RecipeRunner.js12
-rw-r--r--toolkit/components/normandy/test/browser/browser_actions_BranchedAddonStudyAction.js2
-rw-r--r--toolkit/components/normandy/test/browser/browser_actions_PreferenceExperimentAction.js1
7 files changed, 149 insertions, 31 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_ActionsManager.js b/toolkit/components/normandy/test/browser/browser_ActionsManager.js
index 8b5772fa26..2667a085cf 100644
--- a/toolkit/components/normandy/test/browser/browser_ActionsManager.js
+++ b/toolkit/components/normandy/test/browser/browser_ActionsManager.js
@@ -14,7 +14,7 @@ const { ActionSchemas } = ChromeUtils.importESModule(
);
// Test life cycle methods for actions
-decorate_task(async function (reportActionStub, Stub) {
+decorate_task(async function () {
let manager = new ActionsManager();
const recipe = { id: 1, action: "test-local-action-used" };
diff --git a/toolkit/components/normandy/test/browser/browser_BaseAction.js b/toolkit/components/normandy/test/browser/browser_BaseAction.js
index 240a235346..3a5ebd9d39 100644
--- a/toolkit/components/normandy/test/browser/browser_BaseAction.js
+++ b/toolkit/components/normandy/test/browser/browser_BaseAction.js
@@ -19,7 +19,7 @@ class NoopAction extends BaseAction {
this._testPreExecutionFlag = true;
}
- _run(recipe) {
+ _run() {
this._testRunFlag = true;
}
@@ -37,7 +37,7 @@ class FailPreExecutionAction extends NoopAction {
}
class FailRunAction extends NoopAction {
- _run(recipe) {
+ _run() {
throw NoopAction._errorToThrow;
}
}
diff --git a/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js
index 465e5c1040..8d48298da8 100644
--- a/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js
+++ b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js
@@ -9,6 +9,9 @@ const { BaseAction } = ChromeUtils.importESModule(
const { ClientEnvironment } = ChromeUtils.importESModule(
"resource://normandy/lib/ClientEnvironment.sys.mjs"
);
+const { EventEmitter } = ChromeUtils.importESModule(
+ "resource://normandy/lib/EventEmitter.sys.mjs"
+);
const { Heartbeat } = ChromeUtils.importESModule(
"resource://normandy/lib/Heartbeat.sys.mjs"
);
@@ -27,6 +30,9 @@ const { RecipeRunner } = ChromeUtils.importESModule(
const { RemoteSettings } = ChromeUtils.importESModule(
"resource://services-settings/remote-settings.sys.mjs"
);
+const { JsonSchema } = ChromeUtils.importESModule(
+ "resource://gre/modules/JsonSchema.sys.mjs"
+);
const SURVEY = {
surveyId: "a survey",
@@ -39,9 +45,80 @@ const SURVEY = {
repeatOption: "once",
};
+// See properties.payload in
+// https://github.com/mozilla-services/mozilla-pipeline-schemas/blob/main/schemas/telemetry/heartbeat/heartbeat.4.schema.json
+
+const PAYLOAD_SCHEMA = {
+ additionalProperties: false,
+ anyOf: [
+ {
+ required: ["closedTS"],
+ },
+ {
+ required: ["windowClosedTS"],
+ },
+ ],
+ properties: {
+ closedTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ engagedTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ expiredTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ flowId: {
+ pattern:
+ "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
+ type: "string",
+ },
+ learnMoreTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ offeredTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ score: {
+ minimum: 1,
+ type: "integer",
+ },
+ surveyId: {
+ type: "string",
+ },
+ surveyVersion: {
+ pattern: "^([0-9]+|[a-fA-F0-9]{64})$",
+ type: "string",
+ },
+ testing: {
+ type: "boolean",
+ },
+ version: {
+ maximum: 1,
+ minimum: 1,
+ type: "number",
+ },
+ votedTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ windowClosedTS: {
+ minimum: 0,
+ type: "integer",
+ },
+ },
+ required: ["version", "flowId", "offeredTS", "surveyId", "surveyVersion"],
+ type: "object",
+};
+
function assertSurvey(actual, expected) {
for (const key of Object.keys(actual)) {
- if (["postAnswerUrl", "flowId"].includes(key)) {
+ if (["flowId", "postAnswerUrl", "surveyVersion"].includes(key)) {
continue;
}
@@ -52,6 +129,7 @@ function assertSurvey(actual, expected) {
);
}
+ Assert.equal(actual.surveyVersion, "1");
Assert.ok(actual.postAnswerUrl.startsWith(expected.postAnswerUrl));
}
@@ -86,3 +164,61 @@ decorate_task(
}
}
);
+
+decorate_task(
+ withClearStorage(),
+ async function testLegacyHeartbeatPingPayload() {
+ const sandbox = sinon.createSandbox();
+
+ const cleanupEnrollment = await ExperimentFakes.enrollWithFeatureConfig({
+ featureId: "legacyHeartbeat",
+ value: {
+ survey: SURVEY,
+ },
+ });
+
+ const client = RemoteSettings("normandy-recipes-capabilities");
+ sandbox.stub(client, "get").resolves([]);
+
+ // Override Heartbeat so we can get the instance and manipulate it directly.
+ const heartbeatDeferred = Promise.withResolvers();
+ class TestHeartbeat extends Heartbeat {
+ constructor(...args) {
+ super(...args);
+ heartbeatDeferred.resolve(this);
+ }
+ }
+ ShowHeartbeatAction.overrideHeartbeatForTests(TestHeartbeat);
+
+ try {
+ await RecipeRunner.run();
+ const heartbeat = await heartbeatDeferred.promise;
+ // We are going to simulate the timer timing out, so we do not want it to
+ // *actually* time out.
+ heartbeat.endTimerIfPresent("surveyEndTimer");
+ const notice = await heartbeat.noticePromise;
+ await notice.updateComplete;
+
+ const telemetrySentPromise = new Promise(resolve => {
+ heartbeat.eventEmitter.once("TelemetrySent", payload =>
+ resolve(payload)
+ );
+ });
+
+ // This method would be triggered when the timer timed out. This will
+ // trigger telemetry to be submitted.
+ heartbeat.close();
+
+ const payload = await telemetrySentPromise;
+
+ const result = JsonSchema.validate(payload, PAYLOAD_SCHEMA);
+ Assert.ok(result.valid);
+ Assert.equal(payload.surveyVersion, "1");
+
+ await cleanupEnrollment();
+ } finally {
+ ShowHeartbeatAction.overrideHeartbeatForTests();
+ sandbox.restore();
+ }
+ }
+);
diff --git a/toolkit/components/normandy/test/browser/browser_PreferenceExperiments.js b/toolkit/components/normandy/test/browser/browser_PreferenceExperiments.js
index 4269020975..e50e9bee0e 100644
--- a/toolkit/components/normandy/test/browser/browser_PreferenceExperiments.js
+++ b/toolkit/components/normandy/test/browser/browser_PreferenceExperiments.js
@@ -312,7 +312,7 @@ decorate_task(
// clearAllExperimentStorage
decorate_task(
withMockExperiments([preferenceStudyFactory({ slug: "test" })]),
- async function ({ prefExperiments }) {
+ async function () {
ok(await PreferenceExperiments.has("test"), "Mock experiment is detected.");
await PreferenceExperiments.clearAllExperimentStorage();
ok(
@@ -434,12 +434,7 @@ decorate_task(
withMockPreferences(),
withStub(PreferenceExperiments, "startObserver"),
withSendEventSpy(),
- async function testStart({
- prefExperiments,
- mockPreferences,
- startObserverStub,
- sendEventSpy,
- }) {
+ async function testStart({ mockPreferences, startObserverStub }) {
mockPreferences.set("fake.preference", "oldvalue", "default");
mockPreferences.set("fake.preference", "uservalue", "user");
mockPreferences.set("fake.preferenceinteger", 1, "default");
@@ -1193,7 +1188,7 @@ decorate_task(withMockExperiments(), async function () {
// get
decorate_task(
withMockExperiments([preferenceStudyFactory({ slug: "test" })]),
- async function ({ prefExperiments }) {
+ async function () {
const experiment = await PreferenceExperiments.get("test");
is(experiment.slug, "test", "get fetches the correct experiment");
@@ -1253,9 +1248,7 @@ decorate_task(
}),
]),
withMockPreferences(),
- async function testGetAllActive({
- prefExperiments: [activeExperiment, inactiveExperiment],
- }) {
+ async function testGetAllActive({ prefExperiments: [activeExperiment] }) {
let allActiveExperiments = await PreferenceExperiments.getAllActive();
Assert.deepEqual(
allActiveExperiments,
@@ -1306,11 +1299,7 @@ decorate_task(
withMockPreferences(),
withStub(TelemetryEnvironment, "setExperimentActive"),
withStub(PreferenceExperiments, "startObserver"),
- async function testInit({
- prefExperiments,
- mockPreferences,
- setExperimentActiveStub,
- }) {
+ async function testInit({ mockPreferences, setExperimentActiveStub }) {
mockPreferences.set("fake.pref", "experiment value");
await PreferenceExperiments.init();
ok(
diff --git a/toolkit/components/normandy/test/browser/browser_RecipeRunner.js b/toolkit/components/normandy/test/browser/browser_RecipeRunner.js
index 00f0f81c51..864c237ff9 100644
--- a/toolkit/components/normandy/test/browser/browser_RecipeRunner.js
+++ b/toolkit/components/normandy/test/browser/browser_RecipeRunner.js
@@ -216,7 +216,6 @@ decorate_task(
withMockNormandyApi(),
withStub(ClientEnvironment, "getClientClassification"),
async function testClientClassificationCache({
- mockNormandyApi,
getClientClassificationStub,
}) {
getClientClassificationStub.returns(Promise.resolve(false));
@@ -294,7 +293,6 @@ decorate_task(
async function testReadFromRemoteSettings({
verifyObjectSignatureStub,
processRecipeStub,
- finalizeStub,
reportRecipeStub,
}) {
const matchRecipe = {
@@ -334,7 +332,7 @@ decorate_task(
let recipesFromRS = (
await RecipeRunner._remoteSettingsClientForTesting.get()
- ).map(({ recipe, signature }) => recipe);
+ ).map(({ recipe }) => recipe);
// Sort the records by id so that they match the order in the assertion
recipesFromRS.sort((a, b) => a.id - b.id);
Assert.deepEqual(
@@ -518,11 +516,7 @@ decorate_task(
withStub(RecipeRunner, "run"),
withStub(RecipeRunner, "registerTimer"),
withStub(RecipeRunner, "watchPrefs"),
- async function testInitFirstRun({
- runStub,
- registerTimerStub,
- watchPrefsStub,
- }) {
+ async function testInitFirstRun({ runStub, registerTimerStub }) {
await RecipeRunner.init();
Assert.deepEqual(
runStub.args,
@@ -818,7 +812,7 @@ decorate_task(
withStub(Uptake, "reportRunner"),
withStub(ActionsManager.prototype, "finalize"),
NormandyTestUtils.withMockRecipeCollection([]),
- async function testRunEvents({ reportRunnerStub, finalizeStub }) {
+ async function testRunEvents() {
const observer = sinon.spy();
Services.obs.addObserver(observer, "recipe-runner:start");
diff --git a/toolkit/components/normandy/test/browser/browser_actions_BranchedAddonStudyAction.js b/toolkit/components/normandy/test/browser/browser_actions_BranchedAddonStudyAction.js
index cce82ae89e..b7d4b34754 100644
--- a/toolkit/components/normandy/test/browser/browser_actions_BranchedAddonStudyAction.js
+++ b/toolkit/components/normandy/test/browser/browser_actions_BranchedAddonStudyAction.js
@@ -719,7 +719,7 @@ decorate_task(
ensureAddonCleanup(),
AddonStudies.withStudies([branchedAddonStudyFactory({ active: false })]),
withSendEventSpy(),
- async ({ addonStudies: [study], sendEventSpy }) => {
+ async ({ addonStudies: [study] }) => {
const action = new BranchedAddonStudyAction();
await Assert.rejects(
action.unenroll(study.recipeId),
diff --git a/toolkit/components/normandy/test/browser/browser_actions_PreferenceExperimentAction.js b/toolkit/components/normandy/test/browser/browser_actions_PreferenceExperimentAction.js
index 5359174169..f275487e14 100644
--- a/toolkit/components/normandy/test/browser/browser_actions_PreferenceExperimentAction.js
+++ b/toolkit/components/normandy/test/browser/browser_actions_PreferenceExperimentAction.js
@@ -831,7 +831,6 @@ decorate_task(
withSpy(PreferenceExperiments, "stop"),
withStub(PreferenceExperimentAction.prototype, "_considerTemporaryError"),
async function testNoRecipes({
- stopSpy,
_considerTemporaryErrorStub,
prefExperiments: [experiment],
}) {