Commit cd2693c5 authored by Andrei Oprea's avatar Andrei Oprea
Browse files

Bug 1749955 - Studies get installed even though Normandy is disabled r=mythmon

parent 71bbf38c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,8 @@ class _ExperimentManager {
    for (const rollout of restoredRollouts) {
      this.setExperimentActive(rollout);
    }

    this.observe();
  }

  /**
+35 −0
Original line number Diff line number Diff line
@@ -63,6 +63,41 @@ add_task(async function test_onStartup_setRolloutActive_called() {
  );
});

add_task(async function test_startup_unenroll() {
  Services.prefs.setBoolPref("app.shield.optoutstudies.enabled", false);
  const store = ExperimentFakes.store();
  const sandbox = sinon.createSandbox();
  let recipe = ExperimentFakes.experiment("startup_unenroll", {
    experimentType: "unittest",
    source: "test",
  });
  // Test initializing ExperimentManager with an active
  // recipe in the store. If the user has opted out it should
  // unenroll.
  await store.init();
  let enrollmentPromise = new Promise(resolve =>
    store.on(`update:${recipe.slug}`, resolve)
  );
  store.addEnrollment(recipe);
  await enrollmentPromise;

  const manager = ExperimentFakes.manager(store);
  const unenrollStub = sandbox.stub(manager, "unenroll");

  await manager.onStartup();

  Assert.ok(
    unenrollStub.calledOnce,
    "Unenrolled from active experiment if user opt out is true"
  );
  Assert.ok(
    unenrollStub.calledWith("startup_unenroll", "studies-opt-out"),
    "Called unenroll for expected recipe"
  );

  Services.prefs.clearUserPref("app.shield.optoutstudies.enabled");
});

/**
 * onRecipe()
 * - should add recipe slug to .session[source]