Sync Bug 1399245: Fix mozilla/normandy#1058: Bind PreferenceExperiment driver functions. r=Gijs
authorMichael Kelly <mkelly@mozilla.com>
Tue, 12 Sep 2017 13:30:38 -0700
changeset 380404 9771577eeeaefd398137f1dba84da326e7974691
parent 380403 f2bd9e8d0975b435bd437b001d94200d43cab5ff
child 380405 c9589184e49f72ea5634a331453e11498e107b9f
push id51057
push usermkelly@mozilla.com
push dateWed, 13 Sep 2017 01:40:23 +0000
treeherderautoland@9771577eeeae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1399245
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Sync Bug 1399245: Fix mozilla/normandy#1058: Bind PreferenceExperiment driver functions. r=Gijs MozReview-Commit-ID: 7e6f6QdHdVf
browser/extensions/shield-recipe-client/lib/NormandyDriver.jsm
browser/extensions/shield-recipe-client/test/browser/browser_NormandyDriver.js
--- a/browser/extensions/shield-recipe-client/lib/NormandyDriver.jsm
+++ b/browser/extensions/shield-recipe-client/lib/NormandyDriver.jsm
@@ -167,22 +167,33 @@ this.NormandyDriver = function(sandboxMa
       uninstall: sandboxManager.wrapAsync(Addons.uninstall.bind(Addons)),
     },
 
     // Sampling
     ratioSample: sandboxManager.wrapAsync(Sampling.ratioSample),
 
     // Preference Experiment API
     preferenceExperiments: {
-      start: sandboxManager.wrapAsync(PreferenceExperiments.start, {cloneArguments: true}),
-      markLastSeen: sandboxManager.wrapAsync(PreferenceExperiments.markLastSeen),
-      stop: sandboxManager.wrapAsync(PreferenceExperiments.stop),
-      get: sandboxManager.wrapAsync(PreferenceExperiments.get, {cloneInto: true}),
-      getAllActive: sandboxManager.wrapAsync(PreferenceExperiments.getAllActive, {cloneInto: true}),
-      has: sandboxManager.wrapAsync(PreferenceExperiments.has),
+      start: sandboxManager.wrapAsync(
+        PreferenceExperiments.start.bind(PreferenceExperiments),
+        {cloneArguments: true}
+      ),
+      markLastSeen: sandboxManager.wrapAsync(
+        PreferenceExperiments.markLastSeen.bind(PreferenceExperiments)
+      ),
+      stop: sandboxManager.wrapAsync(PreferenceExperiments.stop.bind(PreferenceExperiments)),
+      get: sandboxManager.wrapAsync(
+        PreferenceExperiments.get.bind(PreferenceExperiments),
+        {cloneInto: true}
+      ),
+      getAllActive: sandboxManager.wrapAsync(
+        PreferenceExperiments.getAllActive.bind(PreferenceExperiments),
+        {cloneInto: true}
+      ),
+      has: sandboxManager.wrapAsync(PreferenceExperiments.has.bind(PreferenceExperiments)),
     },
 
     // Study storage API
     studies: {
       start: sandboxManager.wrapAsync(
         AddonStudies.start.bind(AddonStudies),
         {cloneArguments: true, cloneInto: true}
       ),
--- a/browser/extensions/shield-recipe-client/test/browser/browser_NormandyDriver.js
+++ b/browser/extensions/shield-recipe-client/test/browser/browser_NormandyDriver.js
@@ -310,8 +310,52 @@ decorate_task(
         ok(
           !driver.preferences.has("test.does.not.exist"),
           "preferences.has returns false if the given preference does not exist."
         );
       })();
     `);
   })
 );
+
+decorate_task(
+  withSandboxManager(Assert),
+  withMockPreferences,
+  async function testAddonStudies(sandboxManager) {
+    const driver = new NormandyDriver(sandboxManager);
+    sandboxManager.cloneIntoGlobal("driver", driver, {cloneFunctions: true});
+
+    // Assertion helpers
+    sandboxManager.addGlobal("is", is);
+    sandboxManager.addGlobal("ok", ok);
+
+    await sandboxManager.evalInSandbox(`
+      (async function sandboxTest() {
+        const studyName = "preftest";
+        let hasStudy = await driver.preferenceExperiments.has(studyName);
+        ok(!hasStudy, "preferenceExperiments.has returns false if the study hasn't been started yet.");
+
+        await driver.preferenceExperiments.start({
+          name: studyName,
+          branch: "control",
+          preferenceName: "test.pref",
+          preferenceValue: true,
+          preferenceBranchType: "user",
+          preferenceType: "boolean",
+        });
+        hasStudy = await driver.preferenceExperiments.has(studyName);
+        ok(hasStudy, "preferenceExperiments.has returns true after the study has been started.");
+
+        let study = await driver.preferenceExperiments.get(studyName);
+        is(
+          study.branch,
+          "control",
+          "preferenceExperiments.get fetches studies from within a sandbox."
+        );
+        ok(!study.expired, "Studies are marked as active after being started by the driver.");
+
+        await driver.preferenceExperiments.stop(studyName);
+        study = await driver.preferenceExperiments.get(studyName);
+        ok(study.expired, "Studies are marked as inactive after being stopped by the driver.");
+      })();
+    `);
+  }
+);