Bug 622227: Make it easier for Test Pilot to switch index files. r+a=dtownsend
authorJono S Xia <jdicarlo@mozilla.com>
Mon, 03 Jan 2011 12:27:29 -0800
changeset 59807 6e25fd92573186d0462d0f434b7e255f30c43b6a
parent 59806 3a3d81c1c6365b06e80cf8f4ecc47aaccfe9a902
child 59808 486c465a73fc4ee406390ffc5d62d166219416e7
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs622227
milestone2.0b9pre
Bug 622227: Make it easier for Test Pilot to switch index files. r+a=dtownsend
browser/app/profile/extensions/testpilot@labs.mozilla.com/content/debug.html
browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/debug.html
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/debug.html
@@ -166,26 +166,54 @@
     var task = TestPilotSetup.getTaskById(getEid());
 
     var selector = document.getElementById("status-selector");
     var i = selector.selectedIndex;
     var newStatus = parseInt( selector.options[i].value );
     task.changeStatus(newStatus, false);
   }
 
+  function showIndexFileDropdown() {
+    var prefService  = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+    var prefName = "extensions.testpilot.indexFileName";
+    var selector = document.getElementById("index-file-selector");
+    if (prefService.getCharPref(prefName) == "index.json") {
+      selector.selectedIndex = 0;
+    } else {
+      selector.selectedIndex = 1;
+    }
+  }
+
+  function setSelectedIndexFile() {
+    var prefService  = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+    var prefName = "extensions.testpilot.indexFileName";
+    var selector = document.getElementById("index-file-selector");
+    var i = selector.selectedIndex;
+    prefService.setCharPref( prefName, selector.options[i].value );
+
+    // DELETE CACHED INDEX FILE
+    var file = Components.classes["@mozilla.org/file/directory_service;1"].
+                     getService(Components.interfaces.nsIProperties).
+                     get("ProfD", Components.interfaces.nsIFile);
+    file.append("TestPilotExperimentFiles");
+    file.append("index.json");
+    if (file.exists()) {
+      file.remove(false);
+    }
+  }
 
 </script>
 
 <style type="text/css">
       canvas { border: 1px solid black; }
     </style>
 
 </head>
 
-<body onload="populateFileDropdown();showSelectedTaskStatus();">
+<body onload="populateFileDropdown();showSelectedTaskStatus();showIndexFileDropdown();">
 
 <fieldset>
 <p><select id="task-selector" onchange="showSelectedTaskStatus();"></select> Current Status = <span id="show-status-span"></span>.
 <button onclick="resetSelectedTask();showSelectedTaskStatus();">Reset Task</button>
 or set it to
 <select id="status-selector" onchange="setSelectedTaskStatus(); showSelectedTaskStatus();">
   <option value="0">0 (New)</option>
   <option value="1">1 (Pending)</option>
@@ -203,16 +231,21 @@ or set it to
 <button onclick="showMetaData();">Show Metadata</button>
 <button onclick="runUnitTests();">Run Tests</button>
 </fieldset>
 <fieldset>
 <p><button onclick="makeThereBeAPopup();">Show Dummy Popup</button>
 <button onclick="reloadAllExperiments();">Reload All Experiments</button>
 <button onclick="remindMe();">Notify Me</button>
 <button onclick="testJarStore();">Test Jar Store</button>
+Index file: 
+<select id="index-file-selector" onchange="setSelectedIndexFile();">
+  <option value="index.json">index.json</option>
+  <option value="index-dev.json">index-dev.json</option>
+</select>
 </p>
 </fieldset>
 <p><span id="debug"></span></p>
 
 
 <textarea id="experiment-code-area" rows="40" cols="80">
 </textarea>
 <select id="file-selector"></select>
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/remote-experiment-loader.js
@@ -180,17 +180,17 @@ exports.RemoteExperimentLoader.prototype
     this._legacyStudies = [];
     let prefs = require("preferences-service");
     this._baseUrl = prefs.get(BASE_URL_PREF, "");
     if (fileGetterFunction != undefined) {
       this._fileGetter = fileGetterFunction;
     } else {
       this._fileGetter = downloadFile;
     }
-    this._logger.trace("About to instantiate preferences store.");
+    this._logger.trace("About to instantiate jar store.");
     this._jarStore = new JarStore();
     this._experimentFileNames = [];
     let self = this;
     this._logger.trace("About to instantiate cuddlefish loader.");
     this._refreshLoader();
     // set up the unloading
     require("unload").when( function() {
                               self._loader.unload();
@@ -319,21 +319,27 @@ exports.RemoteExperimentLoader.prototype
         this._experimentFileNames.push(j.studyfile);
       }
     }
     return true;
   },
 
   // TODO a bad thing that can go wrong: If we have a net connection but the index file
   // has not changed, we currently don't try to download anything...
+  // The logic is bad because executeCachedIndexFile is called in two different
+  // cases: the one with no network, and the one with network but unchanged file.
 
   // Another bad thing: If there's a jar download that's corrupt or unreadable or has
-    // the wrong permissions or something, we need to kill it and download a new one.
+  // the wrong permissions or something, we need to kill it and download a new one.
+  // Should also try to download a new jar if any required modules are missing
+  // (Which is currently the case!)
 
-  // WTF every jar file I'm downloading appears as 0 bytes with __x__x___ permissions!
+  // (module "about_firefox.js" is not found; there is no about_firefox.jar on disk,
+  // indicating it didn't download, and we're not trying again because index-dev is
+  // unmodified.  Hmmm.)
 
   _cachedIndexNsiFile: null,
   get cachedIndexNsiFile() {
     if (!this._cachedIndexNsiFile) {
       try {
         let file = Cc["@mozilla.org/file/directory_service;1"].
                          getService(Ci.nsIProperties).
                          get("ProfD", Ci.nsIFile);