Revert "Bug 1907633 - Add ExperimentAPI.optInToExperiment API r=nalexander,nimbus-reviewers,relud,omc-reviewers,aminomancer" for causing bc failures on browser_about_studies.js.

This reverts commit d50af79d99.
This commit is contained in:
iulian moraru
2025-05-19 21:38:11 +03:00
committed by imoraru@mozilla.com
parent 658d19a425
commit 83b2199691
7 changed files with 22 additions and 45 deletions

View File

@@ -283,7 +283,7 @@ add_task(async function test_forceEnrollUpdatesMessages() {
await assertMessageInState("xman_test_message", false, false);
await ExperimentAPI.optInToExperiment({
await RemoteSettingsExperimentLoader.optInToExperiment({
slug: experiment.slug,
branch: experiment.branches[0].slug,
});

View File

@@ -37,6 +37,9 @@ ChromeUtils.defineESModuleGetters(lazy, {
"resource:///modules/asrouter/ASRouterDefaultConfig.sys.mjs",
ExperimentAPI: "resource://nimbus/ExperimentAPI.sys.mjs",
RemoteSettingsExperimentLoader:
"resource://nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs",
});
class CannotLockProfileError extends Error {
@@ -323,7 +326,7 @@ export var BackgroundTasksUtils = {
branch: params.get("optin_branch"),
collection: params.get("optin_collection"),
};
await lazy.ExperimentAPI.optInToExperiment(data);
await lazy.RemoteSettingsExperimentLoader.optInToExperiment(data);
lazy.log.info(`Opted in to experiment: ${JSON.stringify(data)}`);
} else if (uri.schemeIs("file")) {
let branchSlug = params.get("optin_branch");

View File

@@ -393,34 +393,6 @@ export const ExperimentAPI = {
branch => new Proxy(branch, experimentBranchAccessor)
);
},
/**
* Opt-in to the given experiment on the given branch.
*
* @param {object} options
*
* @param {string} options.slug
* The slug of the experiment to enroll in.
*
* @param {string} options.branch
* The slug of the specific branch to enroll in.
*
* @param {string | undefined} options.collection
* The collection to fetch the recipe from. If not provided it will be fetched
* from the default experiment collection.
*
* @param {boolean | undefined} options.applyTargeting
* Whether or not to apply targeting. Defaults to false.
*
* @returns {Promise<void>}
* A promise that resolves when the enrollment is successful or rejects when
* it is unsuccessful.
*
* @throws {Error} If enrollment fails.
*/
async optInToExperiment(options) {
return this._rsLoader._optInToExperiment(options);
},
};
/**

View File

@@ -503,7 +503,7 @@ export class _RemoteSettingsExperimentLoader {
});
}
async _optInToExperiment({
async optInToExperiment({
slug,
branch: branchSlug,
collection,

View File

@@ -50,7 +50,7 @@ add_task(async function test_fetch_recipe_and_branch_no_debug() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
}),
@@ -65,7 +65,7 @@ add_task(async function test_fetch_recipe_and_branch_no_debug() {
Services.prefs.setBoolPref("nimbus.debug", true);
await ExperimentAPI.optInToExperiment({
await RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
});
@@ -79,7 +79,7 @@ add_task(async function test_fetch_recipe_and_branch_badslug() {
const cleanup = await setup([]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug: "other_slug",
branch: "control",
}),
@@ -101,7 +101,7 @@ add_task(async function test_fetch_recipe_and_branch_badbranch() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "other_branch",
}),
@@ -122,7 +122,7 @@ add_task(async function test_fetch_recipe_and_branch() {
const recipe = NimbusTestUtils.factories.recipe(slug, { targeting: "false" });
const cleanup = await setup([recipe]);
await ExperimentAPI.optInToExperiment({
await RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
});
@@ -148,7 +148,7 @@ add_task(async function test_invalid_recipe() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
}),
@@ -188,7 +188,7 @@ add_task(async function test_invalid_branch_variablesOnly() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
}),
@@ -225,7 +225,7 @@ add_task(async function test_invalid_branch_schema() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
}),
@@ -261,7 +261,7 @@ add_task(async function test_invalid_branch_featureId() {
const cleanup = await setup([recipe]);
await Assert.rejects(
ExperimentAPI.optInToExperiment({
RemoteSettingsExperimentLoader.optInToExperiment({
slug,
branch: "control",
}),

View File

@@ -228,7 +228,7 @@ add_task(async function test_optIn_debug_disabled() {
Services.prefs.setBoolPref(STUDIES_OPT_OUT_PREF, true);
await Assert.rejects(
loader._optInToExperiment({
loader.optInToExperiment({
slug: recipe.slug,
branchSlug: recipe.branches[0].slug,
}),
@@ -264,7 +264,7 @@ add_task(async function test_optIn_studies_disabled() {
Services.prefs.setBoolPref(pref, false);
await Assert.rejects(
loader._optInToExperiment({
loader.optInToExperiment({
slug: recipe.slug,
branchSlug: recipe.branches[0].slug,
}),
@@ -312,7 +312,7 @@ add_task(async function test_experiment_optin_targeting() {
sandbox.stub(RemoteSettings("nimbus-preview"), "get").resolves([recipe]);
await Assert.rejects(
loader._optInToExperiment({
loader.optInToExperiment({
slug: recipe.slug,
branch: recipe.branches[0].slug,
collection: "nimbus-preview",
@@ -327,7 +327,7 @@ add_task(async function test_experiment_optin_targeting() {
"Should not enroll in experiment"
);
await loader._optInToExperiment({
await loader.optInToExperiment({
slug: recipe.slug,
branch: recipe.branches[0].slug,
collection: "nimbus-preview",

View File

@@ -15,6 +15,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
PreferenceExperiments:
"resource://normandy/lib/PreferenceExperiments.sys.mjs",
RecipeRunner: "resource://normandy/lib/RecipeRunner.sys.mjs",
RemoteSettingsExperimentLoader:
"resource://nimbus/lib/RemoteSettingsExperimentLoader.sys.mjs",
UnenrollmentCause: "resource://nimbus/lib/ExperimentManager.sys.mjs",
});
@@ -106,7 +108,7 @@ ChromeUtils.defineLazyGetter(AboutPages, "aboutStudies", () => {
async optInToExperiment(data) {
try {
await lazy.ExperimentAPI.optInToExperiment(data);
await lazy.RemoteSettingsExperimentLoader.optInToExperiment(data);
return {
error: false,
message: "Opt-in was successful.",