Bug 1032559 - Fix for mochitest-chrome slow download mar tests fail when the app.update.download.backgroundInterval pref is 0. r=spohl

This commit is contained in:
Robert Strong 2014-07-01 12:53:25 -07:00
parent 4c1c6bcbf5
commit d92b0d2579
4 changed files with 71 additions and 9 deletions

View File

@ -23,15 +23,19 @@ 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";

View File

@ -16,6 +16,7 @@
<script type="application/javascript"
src="utils.js"/>
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript">
<![CDATA[
@ -23,15 +24,19 @@ 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";

View File

@ -44,23 +44,37 @@ function handleRequest(aRequest, aResponse) {
// 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;
}

View File

@ -483,7 +483,7 @@ function delayedDefaultCallback() {
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();
@ -495,6 +495,45 @@ function delayedDefaultCallback() {
}
}
/**
* 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