summaryrefslogtreecommitdiffstats
path: root/browser/components/asrouter/tests/xpcshell/test_remoteExperiments.js
blob: 40c0993b4f80b9e391c1696753e087bd72f54755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const { CFRMessageProvider } = ChromeUtils.importESModule(
  "resource:///modules/asrouter/CFRMessageProvider.sys.mjs"
);

add_task(async function test_multiMessageTreatment() {
  const { experimentValidator } = await makeValidators();
  // Use the entire list of messages as if it was a single treatment branch's
  // feature value.
  let messages = await CFRMessageProvider.getMessages();
  let featureValue = { template: "multi", messages };
  assertValidates(
    experimentValidator,
    featureValue,
    `Multi-message treatment validates as MessagingExperiment`
  );
  for (const message of messages) {
    assertValidates(
      experimentValidator,
      message,
      `Message ${message.id} validates as MessagingExperiment`
    );
  }

  // Add an invalid message to the list and make sure it fails validation.
  messages.push({
    id: "INVALID_MESSAGE",
    template: "cfr_doorhanger",
  });
  const result = experimentValidator.validate(featureValue);
  Assert.ok(
    !(result.valid && result.errors.length === 0),
    "Multi-message treatment with invalid message fails validation"
  );
});