Bug 625507: Allow studies and surveys to use arbitrary logic to decide whether to run or not. r+a=dtownsend
authorJono S Xia <jdicarlo@mozilla.com>
Thu, 20 Jan 2011 19:56:21 -0800
changeset 61079 4d89f48b2abdd9b001728b05f257a5972918da80
parent 61078 3d49b553bc4ba88e083bd13fd4a8ea25a5081fd1
child 61080 4f296157ad3eca6a6662ead36fa7659de76373bb
push idunknown
push userunknown
push dateunknown
bugs625507
milestone2.0b10pre
Bug 625507: Allow studies and surveys to use arbitrary logic to decide whether to run or not. r+a=dtownsend
browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/setup.js
@@ -682,32 +682,38 @@ let TestPilotSetup = {
     if (result < 0) {
       return true; // versionString is newer than Firefox
     } else {
       return false; // versionString is the same as or older than Firefox
     }
   },
 
   _experimentRequirementsAreMet: function TPS__requirementsMet(experiment) {
-    // Returns true if we we meet the requirements to run this experiment
-    // (e.g. meet the minimum Test Pilot version and Firefox version)
-    // false if not.
-    // If the experiment doesn't specify minimum versions, attempt to run it.
+    /* Returns true if we we meet the requirements to run this experiment
+     * (e.g. meet the minimum Test Pilot version and Firefox version)
+     * false if not.
+     * Default is always to run the study - return true UNLESS the study
+     * specifies a requirement that we don't meet. */
     let logger = this._logger;
     try {
-      let minTpVer, minFxVer, expName;
-      if (experiment.experimentInfo) {
-        minTpVer = experiment.experimentInfo.minTPVersion;
-        minFxVer = experiment.experimentInfo.minFXVersion;
-        expName =  experiment.experimentInfo.testName;
-      } else if (experiment.surveyInfo) {
-        minTpVer = experiment.surveyInfo.minTPVersion;
-        minFxVer = experiment.surveyInfo.minFXVersion;
-        expName = experiment.surveyInfo.surveyName;
+      let minTpVer, minFxVer, expName, runOrNotFunc;
+      /* Could be an experiment, which specifies experimentInfo, or survey,
+       * which specifies surveyInfo. */
+      let info = experiment.experimentInfo ?
+                   experiment.experimentInfo :
+                   experiment.surveyInfo;
+      if (!info) {
+        // If neither one is supplied, study lacks metadata required to run
+        logger.warn("Study lacks minimum metadata to run.");
+        return false;
       }
+      minTpVer = info.minTPVersion;
+      minFxVer = info.minFXVersion;
+      expName =  info.testName;
+      runOrNotFunc = info.runOrNotFunc;
 
       // Minimum test pilot version:
       if (minTpVer && this._isNewerThanMe(minTpVer)) {
         logger.warn("Not loading " + expName);
         logger.warn("Because it requires Test Pilot version " + minTpVer);
 
         // Let user know there is a newer version of Test Pilot available:
         if (!this._isShowingUpdateNotification()) {
@@ -723,16 +729,22 @@ let TestPilotSetup = {
       }
 
       // Minimum firefox version:
       if (minFxVer && this._isNewerThanFirefox(minFxVer)) {
         logger.warn("Not loading " + expName);
         logger.warn("Because it requires Firefox version " + minFxVer);
         return false;
       }
+
+      /* The all-purpose, arbitrary code "Should this study run?" function - if
+       * provided, use its return value. */
+      if (runOrNotFunc) {
+        return runOrNotFunc();
+      }
     } catch (e) {
       logger.warn("Error in requirements check " +  e);
     }
     return true;
   },
 
   checkForTasks: function TPS_checkForTasks(callback) {
     let logger = this._logger;