Bug 1032559 - Fix for mochitest-chrome slow download mar tests fail when the app.update.download.backgroundInterval pref is 0. r=spohl
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 01 Jul 2014 12:53:25 -0700
changeset 191855 dcf6a0d829e64a415589055fab02876a26725d3a
parent 191756 b859e3748f30315056760516b1d382d92e2d9066
child 191856 6703bf831ab18e7d0fd125e9d6182fbbc98563fa
push id45685
push usercbook@mozilla.com
push dateWed, 02 Jul 2014 13:09:48 +0000
treeherdermozilla-inbound@60133a85f8ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1032559
milestone33.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
Bug 1032559 - Fix for mochitest-chrome slow download mar tests fail when the app.update.download.backgroundInterval pref is 0. r=spohl
toolkit/mozapps/update/tests/chrome/test_0083_error_patchApplyFailure_partial_complete.xul
toolkit/mozapps/update/tests/chrome/test_0084_error_patchApplyFailure_verify_failed.xul
toolkit/mozapps/update/tests/chrome/update.sjs
toolkit/mozapps/update/tests/chrome/utils.js
--- a/toolkit/mozapps/update/tests/chrome/test_0083_error_patchApplyFailure_partial_complete.xul
+++ b/toolkit/mozapps/update/tests/chrome/test_0083_error_patchApplyFailure_partial_complete.xul
@@ -18,25 +18,29 @@
 
 <script type="application/javascript">
 <![CDATA[
 
 const TESTS = [ {
   pageid: PAGEID_ERROR_PATCHING,
   buttonClick: "next"
 }, {
-  pageid: PAGEID_DOWNLOADING
+  pageid: PAGEID_DOWNLOADING,
+  extraStartFunction: createContinueFile
 }, {
   pageid: PAGEID_FINISHED,
-  buttonClick: "extra1"
+  buttonClick: "extra1",
+  extraStartFunction: removeContinueFile
 } ];
 
 function runTest() {
   debugDump("entering");
 
+  removeContinueFile();
+
   // Specify the url to update.sjs with a slowDownloadMar param so the ui can
   // load before the download completes.
   let slowDownloadURL = URL_HTTP_UPDATE_XML + "?slowDownloadMar=1";
   let patches = getLocalPatchString("partial", null, null, null, null, null,
                                     STATE_PENDING) +
                 getLocalPatchString("complete", slowDownloadURL, null, null,
                                     null, "false");
   let updates = getLocalUpdateString(patches, null, null, null,
--- a/toolkit/mozapps/update/tests/chrome/test_0084_error_patchApplyFailure_verify_failed.xul
+++ b/toolkit/mozapps/update/tests/chrome/test_0084_error_patchApplyFailure_verify_failed.xul
@@ -11,32 +11,37 @@
 <window title="Update Wizard pages: error patching, download, and errors (partial failed and download complete verification failure)"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="runTestDefault();">
 <script type="application/javascript"
         src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
 <script type="application/javascript"
         src="utils.js"/>
 
+<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
 <script type="application/javascript">
 <![CDATA[
 
 const TESTS = [ {
   pageid: PAGEID_ERROR_PATCHING,
   buttonClick: "next"
 }, {
-  pageid: PAGEID_DOWNLOADING
+  pageid: PAGEID_DOWNLOADING,
+  extraStartFunction: createContinueFile
 }, {
   pageid: PAGEID_ERRORS,
-  buttonClick: "finish"
+  buttonClick: "finish",
+  extraStartFunction: removeContinueFile
 } ];
 
 function runTest() {
   debugDump("entering");
 
+  removeContinueFile();
+
   // Specify the url to update.sjs with a slowDownloadMar param so the ui can
   // load before the download completes.
   let slowDownloadURL = URL_HTTP_UPDATE_XML + "?slowDownloadMar=1";
   let patches = getLocalPatchString("partial", null, null, null, null, null,
                                     STATE_PENDING) +
                 getLocalPatchString("complete", slowDownloadURL, "MD5",
                                     "1234cd43a1c77e30191c53a329a3f99d", null,
                                     "false");
--- a/toolkit/mozapps/update/tests/chrome/update.sjs
+++ b/toolkit/mozapps/update/tests/chrome/update.sjs
@@ -39,33 +39,47 @@ function handleRequest(aRequest, aRespon
   }
 
   // When a mar download is started by the update service it can finish
   // downloading before the ui has loaded. By specifying a serviceURL for the
   // update patch that points to this file and has a slowDownloadMar param the
   // mar will be downloaded asynchronously which will allow the ui to load
   // before the download completes.
   if (params.slowDownloadMar) {
+    var i;
     aResponse.processAsync();
     aResponse.setHeader("Content-Type", "binary/octet-stream");
     aResponse.setHeader("Content-Length", SIZE_SIMPLE_MAR);
+    var continueFile = AUS_Cc["@mozilla.org/file/directory_service;1"].
+                       getService(AUS_Ci.nsIProperties).
+                       get("CurWorkD", AUS_Ci.nsILocalFile);
+    var continuePath = REL_PATH_DATA + "continue";
+    var continuePathParts = continuePath.split("/");
+    for (i = 0; i < continuePathParts.length; ++i) {
+      continueFile.append(continuePathParts[i]);
+    }
+
     var marFile = AUS_Cc["@mozilla.org/file/directory_service;1"].
                   getService(AUS_Ci.nsIProperties).
                   get("CurWorkD", AUS_Ci.nsILocalFile);
     var path = REL_PATH_DATA + FILE_SIMPLE_MAR;
     var pathParts = path.split("/");
-    for(var i = 0; i < pathParts.length; ++i)
+    for (i = 0; i < pathParts.length; ++i) {
       marFile.append(pathParts[i]);
+    }
     var contents = readFileBytes(marFile);
     gTimer = AUS_Cc["@mozilla.org/timer;1"].
              createInstance(AUS_Ci.nsITimer);
     gTimer.initWithCallback(function(aTimer) {
-      aResponse.write(contents);
-      aResponse.finish();
-    }, SLOW_MAR_DOWNLOAD_INTERVAL, AUS_Ci.nsITimer.TYPE_ONE_SHOT);
+      if (continueFile.exists()) {
+        gTimer.cancel();
+        aResponse.write(contents);
+        aResponse.finish();
+      }
+    }, SLOW_MAR_DOWNLOAD_INTERVAL, AUS_Ci.nsITimer.TYPE_REPEATING_SLACK);
     return;
   }
 
   if (params.uiURL) {
     var remoteType = "";
     if (!params.remoteNoTypeAttr &&
         (params.uiURL == "BILLBOARD" || params.uiURL == "LICENSE")) {
       remoteType = " " + params.uiURL.toLowerCase() + "=\"1\"";
--- a/toolkit/mozapps/update/tests/chrome/utils.js
+++ b/toolkit/mozapps/update/tests/chrome/utils.js
@@ -478,29 +478,68 @@ function delayedDefaultCallback() {
     gTest.extraDelayedCheckFunction();
   }
 
   // Used to verify that this test has been performed
   gTest.ranTest = true;
 
   if (gTest.buttonClick) {
     debugDump("clicking " + gTest.buttonClick + " button");
-    if(gTest.extraDelayedFinishFunction) {
+    if (gTest.extraDelayedFinishFunction) {
       throw("Tests cannot have a buttonClick and an extraDelayedFinishFunction property");
     }
     gDocElem.getButton(gTest.buttonClick).click();
   }
   else if (gTest.extraDelayedFinishFunction) {
     debugDump("calling extraDelayedFinishFunction " +
               gTest.extraDelayedFinishFunction.name);
     gTest.extraDelayedFinishFunction();
   }
 }
 
 /**
+ * Gets the continue file used to signal the mock http server to continue
+ * downloading for slow download mar file tests without creating it.
+ *
+ * @return nsILocalFile for the continue file.
+ */
+function getContinueFile() {
+  let continueFile = AUS_Cc["@mozilla.org/file/directory_service;1"].
+                     getService(AUS_Ci.nsIProperties).
+                     get("CurWorkD", AUS_Ci.nsILocalFile);
+  let continuePath = REL_PATH_DATA + "/continue";
+  let continuePathParts = continuePath.split("/");
+  for (let i = 0; i < continuePathParts.length; ++i) {
+    continueFile.append(continuePathParts[i]);
+  }
+  return continueFile;
+}
+
+/**
+ * Creates the continue file used to signal the mock http server to continue
+ * downloading for slow download mar file tests.
+ */
+function createContinueFile() {
+  debugDump("creating 'continue' file for slow mar downloads");
+  writeFile(getContinueFile(), "");
+}
+
+/**
+ * Removes the continue file used to signal the mock http server to continue
+ * downloading for slow download mar file tests.
+ */
+function removeContinueFile() {
+  let continueFile = getContinueFile();
+  if (continueFile.exists()) {
+    debugDump("removing 'continue' file for slow mar downloads");
+    continueFile.remove(false);
+  }
+}
+
+/**
  * Checks the wizard page buttons' disabled and hidden attributes values are
  * correct. If an expected button id is not specified then the expected disabled
  * and hidden attribute value is true.
  */
 function checkButtonStates() {
   debugDump("entering - TESTS[" + gTestCounter + "], pageid: " + gTest.pageid);
 
   const buttonNames = ["extra1", "extra2", "back", "next", "finish", "cancel"];