const PREF_FEATURES = {
[USER]: new ExperimentFeature("test-set-pref-user-1", {
description: "Test feature that sets prefs on the user branch via setPref",
owner: "test@test.test",
hasExposure: false,
variables: {
foo: {
type: "string",
description: "test variable",
setPref: {
branch: USER,
pref: "nimbus.test-only.foo",
},
},
},
}),
[DEFAULT]: new ExperimentFeature("test-set-pref-default-1", {
description: "Test feature that sets prefs on the default branch via setPref",
owner: "test@test.test",
hasExposure: false,
variables: {
foo: {
type: "string",
description: "test variable",
setPref: {
branch: DEFAULT,
pref: "nimbus.test-only.foo",
},
},
},
}),
};
function assertNoObservers(manager) { Assert.equal(
manager._prefs.size,
0, "There should be no active pref observers on ExperimentManager"
); Assert.equal(
manager._prefsBySlug.size,
0, "There should be no active pref observers on ExperimentManager"
); Assert.equal(
manager._prefFlips._prefs.size,
0, "There should be no prefFlips feature observers"
);
}
function setPrefs(prefs) { for (const [name, { userBranchValue, defaultBranchValue }] of Object.entries(
prefs
)) { // If the different prefs have the same value, we must set the user branch // value first. Otherwise when we try to set the user branch value after // the default value, it will see the value already set for the user // branch (because it falls back to the default branch value) and will not // set it, leaving only a default branch pref. if (typeof userBranchValue !== "undefined") {
PrefUtils.setPref(name, userBranchValue);
}
function cleanupPrefs(prefs) { for (const name of Object.keys(prefs)) {
Services.prefs.deleteBranch(name);
}
}
function checkExpectedPrefs(prefs) { for (const [name, value] of Object.entries(prefs)) { Assert.equal(PrefUtils.getPref(name), value);
}
}
function checkExpectedPrefBranches(prefs) { for (const [
name,
{ defaultBranchValue = null, userBranchValue = null },
] of Object.entries(prefs)) { if (userBranchValue === null) { Assert.ok(
!Services.prefs.prefHasUserValue(name),
`Pref ${name} has no value on user branch`
);
} else { Assert.equal(
PrefUtils.getPref(name, { branch: USER }),
userBranchValue,
`Pref ${name} has correct value on user branch`
);
}
if (defaultBranchValue === null) { Assert.ok(
!Services.prefs.prefHasDefaultValue(name),
`Pref ${name} has no value on default branch`
);
} else { Assert.equal(
PrefUtils.getPref(name, { branch: DEFAULT }),
defaultBranchValue,
`Pref ${name} has correct value on default branch`
);
}
}
}
const TEST_CASES = [
{
name: "Set prefs on the user branch",
featureValue: setUserPrefs,
},
{
name: "Set prefs on the user branch with pre-existing values on the user branch",
featureValue: setUserPrefs,
setPrefsBefore: PRE_SET_PREFS[USER],
},
{
name: "Set prefs on the user branch with pre-existing values on the default branch",
featureValue: setUserPrefs,
setPrefsBefore: PRE_SET_PREFS[DEFAULT],
},
{
name: "Set prefs on the user branch with pre-existing values on both branches",
featureValue: setUserPrefs,
setPrefsBefore: PRE_SET_PREFS.BOTH_BRANCHES,
},
{
name: "Set prefs on the default branch",
featureValue: setDefaultPrefs,
},
{
name: "Set prefs on the default branch with pre-existing values on the default branch",
featureValue: setDefaultPrefs,
setPrefsBefore: PRE_SET_PREFS[DEFAULT],
},
{
name: "Set prefs on the default branch with pre-existing values on the user branch",
featureValue: setDefaultPrefs,
setPrefsBefore: PRE_SET_PREFS[USER],
expectedPrefs: {
[STRING_PREF]: PRE_SET_PREFS[USER][STRING_PREF].userBranchValue,
[INT_PREF]: PRE_SET_PREFS[USER][INT_PREF].userBranchValue,
[BOOL_PREF]: PRE_SET_PREFS[USER][BOOL_PREF].userBranchValue,
},
},
{
name: "Set prefs on the default branch with pre-existing values on both branches",
featureValue: setDefaultPrefs,
setPrefsBefore: PRE_SET_PREFS.BOTH_BRANCHES,
expectedPrefs: {
[STRING_PREF]: PRE_SET_PREFS.BOTH_BRANCHES[STRING_PREF].userBranchValue,
[INT_PREF]: PRE_SET_PREFS.BOTH_BRANCHES[INT_PREF].userBranchValue,
[BOOL_PREF]: PRE_SET_PREFS.BOTH_BRANCHES[BOOL_PREF].userBranchValue,
},
},
{
name: "Clearing prefs on the user branch (with value null) without pre-existing values",
featureValue: clearUserPrefs,
},
{
name: "Clearing prefs on the user branch (with value null) with pre-existing values on the user branch",
featureValue: clearUserPrefs,
setPrefsBefore: PRE_SET_PREFS[USER],
},
{
name: "Clearing prefs on the user branch (with value null) with pre-existing values on the default branch",
featureValue: clearUserPrefs,
setPrefsBefore: PRE_SET_PREFS[DEFAULT], // This will not affect the default branch prefs.
expectedPrefs: {
[STRING_PREF]: PRE_SET_PREFS[DEFAULT][STRING_PREF].defaultBranchValue,
[INT_PREF]: PRE_SET_PREFS[DEFAULT][INT_PREF].defaultBranchValue,
[BOOL_PREF]: PRE_SET_PREFS[DEFAULT][BOOL_PREF].defaultBranchValue,
},
},
{
name: "Clearing prefs on the user branch (with value null) with pre-existing values on both branches",
featureValue: clearUserPrefs,
setPrefsBefore: PRE_SET_PREFS.BOTH_BRANCHES,
expectedPrefs: {
[STRING_PREF]:
PRE_SET_PREFS.BOTH_BRANCHES[STRING_PREF].defaultBranchValue,
[INT_PREF]: PRE_SET_PREFS.BOTH_BRANCHES[INT_PREF].defaultBranchValue,
[BOOL_PREF]: PRE_SET_PREFS.BOTH_BRANCHES[BOOL_PREF].defaultBranchValue,
},
},
];
for (const [i, { name, ...testCase }] of TEST_CASES.entries()) {
info(`Running test case ${i}: ${name}`);
const sandbox = sinon.createSandbox();
const { // The feature config to enroll.
featureValue,
// Prefs that should be set before enrollment. These will be undone after // each test case.
setPrefsBefore = {},
// Additional prefs to check after enrollment. They will be checked on the // user branch.
expectedPrefs = {},
} = testCase;
info("Setting initial values of prefs...");
setPrefs(setPrefsBefore);
// Collect the values of any prefs that will be set by the enrollment so we // can compare their values after unenrollment. const prefValuesBeforeEnrollment = Object.fromEntries(
Object.keys(featureValue.prefs).map(prefName => [
prefName,
PrefUtils.getPref(prefName),
])
);
info("Checking prefs were set by enrollment..."); for (const [prefName, { branch, value }] of Object.entries(
featureValue.prefs
)) { if (typeof value === "undefined" || value === null) { if (branch === USER) { Assert.ok(
!Services.prefs.prefHasUserValue(prefName),
`${prefName} was cleared on the user branch`
);
} elseif (prefValuesBeforeEnrollment[prefName] !== null) { // Can't clear the user branch. Assert.equal(
PrefUtils.getPref(prefName, { branch }),
prefValuesBeforeEnrollment
);
} else { Assert.equal(PrefUtils.getPref(prefName, { branch }), value);
}
} else { Assert.equal(PrefUtils.getPref(prefName, { branch }), value);
}
}
if (expectedPrefs) {
info("Checking expected prefs...");
checkExpectedPrefs(expectedPrefs);
}
info("Unenrolling...");
await cleanup();
info("Checking prefs were restored after unenrollment..."); // After unenrollment, the prefs should have been restored to their values // before enrollment. for (const [prefName, originalValue] of Object.entries(
prefValuesBeforeEnrollment
)) { // If the pref was set on the default branch, it won't be cleared. It will // persist until the next restart. const expectedValue =
featureValue.prefs[prefName].branch === "default" &&
originalValue === null
? featureValue.prefs[prefName].value
: originalValue; Assert.equal(PrefUtils.getPref(prefName), expectedValue);
}
info("Cleaning up..."); // Clear all the prefs we specified in `setPrefsBefore`.
cleanupPrefs(setPrefsBefore);
// Clear all prefs specified by the enrollment. for (const prefName of Object.keys(featureValue.prefs)) {
Services.prefs.deleteBranch(prefName);
}
// NB: We don't need to test setPref experiments/rollouts on both branches // for the same pref because that configuration is prohibited by // gen_feature_manifests.py
// NB: prefFlip experiments/rollouts will stay enrolled over setPref // experiment/rollouts, no matter the enrollment order.
// NB: If there is a prefFlips experiment/rollout controlling a pref and the // client would enroll in a setPref experiment for that same pref, the // setPref experiment will not be enrolled.
// * prefFlip experiment -> setPref experiment
// TODO: These need to be rewritten
{
name: "enroll in a prefFlips experiment on the user branch and then a setPref experiment on the user branch",
enrollmentOrder: [{ slug: PREF_FLIPS_USER_1 }, { slug: SET_PREF_USER_1 }],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedUnenrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the user branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
// * prefFlip experiment -> prefFlip rollout -> setPref experiment
{
name: "enroll in a prefFlips experiment on the user branch and rollout on the user branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_USER_2, isRollout: true },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_USER_2, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the user branch and rollout on the user branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_USER_2, isRollout: true },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_USER_2, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips experiment on the user branch and rollout on the default branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the user branch and rollout on the default branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1 },
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and rollout on the user branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_USER_1, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and rollout on the user branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_USER_1, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and rollout on the default branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_DEFAULT_2, isRollout: true },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_DEFAULT_2, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips experiment on the default branch and rollout on the default branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_DEFAULT_2, isRollout: true },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: PREF_FLIPS_DEFAULT_2, isRollout: true },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
// * prefFlip rollout -> prefFlip experiment -> setPref experiment
{
name: "enroll in a prefFlips rollout on the user branch and experiment on the user branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips rollout on the user branch and experiment on the user branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips rollout on the user branch and experiment on the default branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_USER_2 },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips rollout on the user branch and experiment on the default branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_USER_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips rollout on the default branch and experiment on the user branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
{ slug: SET_PREF_USER_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips rollout on the default branch and experiment on the user branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
},
{
name: "enroll in a prefFlips rollout on the default branch and experiment on the default branch and then a setPref experiment on the user branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_2 },
{ slug: SET_PREF_USER_1 },
],
expectedUnnrollments: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_2 },
],
expectedEnrollments: [{ slug: SET_PREF_USER_1 }],
expectedPrefs: { [PREF]: SET_PREF_USER_1 },
},
{
name: "enroll in a prefFlips rollout on the default branch and experiment on the default branch and then a setPref experiment on the default branch",
enrollmentOrder: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_2 },
{ slug: SET_PREF_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: PREF_FLIPS_DEFAULT_1, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_2 },
],
expectedEnrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedPrefs: { [PREF]: SET_PREF_DEFAULT_1 },
}, // Multiple enrollment cases (setPref -> prefFlips) // * setPref experiment -> prefFLip experiment:
{
name: "enroll in a setPref experiment on the user branch and then a prefFlip experiment on the user branch",
enrollmentOrder: [{ slug: SET_PREF_USER_1 }, { slug: PREF_FLIPS_USER_1 }],
expectedUnenrollments: [{ slug: SET_PREF_USER_1 }],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref experiment on the user branch and then a prefFlip experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_USER_1 },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [{ slug: SET_PREF_USER_1 }],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
},
{
name: "enroll in a setPref experiment on the default branch and then a prefFlip experiment on the user branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: PREF_FLIPS_USER_1 },
],
expectedUnenrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref experiment on the default branch and then a prefFlip experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [{ slug: SET_PREF_DEFAULT_1 }],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
}, // * setPref experiment -> setPref rollout -> prefFlip experiment
{
name: "enroll in a setPref experiment and rollout on the user branch and then a prefFlips experiment on the user branch",
enrollmentOrder: [
{ slug: SET_PREF_USER_1 },
{ slug: SET_PREF_USER_2, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_USER_1 },
{ slug: SET_PREF_USER_2, isRollout: true },
],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref experiment and rollout on the user branch and then a prefFlips experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_USER_1 },
{ slug: SET_PREF_USER_2, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_USER_1 },
{ slug: SET_PREF_USER_2, isRollout: true },
],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
},
{
name: "enroll in a setPref experiment and rollout on the default branch and then a prefFlips experiment on the user branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_2, isRollout: true },
{ slug: PREF_FLIPS_USER_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_2, isRollout: true },
],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref experiment and rollout on the default branch and then a prefFlips experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_2, isRollout: true },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_DEFAULT_1 },
{ slug: SET_PREF_DEFAULT_2, isRollout: true },
],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
}, // * setPref rollout -> setPref experiment -> prefFlip experiment
{
name: "enroll in a setPref rollout on the user branch and experiment on the user branch and then a prefFlip experiment on the user branch",
enrollmentOrder: [
{ slug: SET_PREF_USER_1, isRollout: true },
{ slug: SET_PREF_USER_2 },
{ slug: PREF_FLIPS_USER_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_USER_1, isRollout: true },
{ slug: SET_PREF_USER_2 },
],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref rollout on the user branch and experiment on the user branch and then a prefFlip experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_USER_1, isRollout: true },
{ slug: SET_PREF_USER_2 },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_USER_1, isRollout: true },
{ slug: SET_PREF_USER_2 },
],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
},
{
name: "enroll in a setPref rollout on the default branch and experiment on the user branch and then a prefFlip experiment on the user branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_2 },
{ slug: PREF_FLIPS_USER_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_2 },
],
expectedEnrollments: [{ slug: PREF_FLIPS_USER_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_USER_1 },
},
{
name: "enroll in a setPref rollout on the default branch and experiment on the user branch and then a prefFlip experiment on the default branch",
enrollmentOrder: [
{ slug: SET_PREF_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_2 },
{ slug: PREF_FLIPS_DEFAULT_1 },
],
expectedUnenrollments: [
{ slug: SET_PREF_DEFAULT_1, isRollout: true },
{ slug: SET_PREF_DEFAULT_2 },
],
expectedEnrollments: [{ slug: PREF_FLIPS_DEFAULT_1 }],
expectedPrefs: { [PREF]: PREF_FLIPS_DEFAULT_1 },
},
];
for (const [i, { name, ...testCase }] of TEST_CASES.entries()) {
info(`Running test case ${i}: ${name}`);
const sandbox = sinon.createSandbox();
const { // Prefs that should be set after enrollment. These will be undone after // each test case.
setPrefsBefore = {}, // The slugs to enroll in the order they should be enrolled in, and // whether or not they should enroll as rollouts.
enrollmentOrder, // Prefs that should be set after enrollment. These will be undone // after each test case.
setPrefsAfter = {}, // The expected active enrollments after all enrollments have finished.
expectedEnrollments = [], // The expected inactive enrollments after all enrollments have finished.
expectedUnenrollments = [], // Prefs to check after enrollment. They will be checked on the user // branch.
expectedPrefs,
} = testCase;
info("Setting prefs before enrollment...");
setPrefs(setPrefsBefore);
Assert.ok(
enrollment !== null && typeof enrollment !== "undefined",
`An enrollment for ${computedSlug} should exist`
); Assert.ok(enrollment.active, `It should still be active`);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.