Bug 525819 - Make do_timeout take a callback function, not a string to eval. r=jwalden

--HG--
extra : rebase_source : 6fbaac51eabe95fcfaf4706feb9fd8a28ba4dfbf
This commit is contained in:
John Daniels 2009-11-24 11:58:42 -08:00
parent 4e4672de10
commit b260d02c5f
38 changed files with 71 additions and 70 deletions

View File

@ -76,7 +76,7 @@ function run_test() {
// Restore could take some time, usually less than 1s.
// We will poll later in continue_test to be sure restore has finished.
do_test_pending();
do_timeout(1000, "continue_test();");
do_timeout(1000, continue_test);
}
function continue_test() {
@ -85,7 +85,7 @@ function continue_test() {
if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
// Not enough time to complete restore, poll again later.
do_timeout(1000, "continue_test();");
do_timeout(1000, continue_test);
return;
}

View File

@ -56,7 +56,7 @@ let observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == TOPIC_CUSTOMIZATION_COMPLETE) {
os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
do_timeout(0, "continue_test();");
do_timeout(0, continue_test);
}
}
}

View File

@ -90,7 +90,7 @@ function run_test() {
// Import could take some time, usually less than 1s, but to be sure we will
// check after 3s.
do_test_pending();
do_timeout(3000, "continue_test();");
do_timeout(3000, continue_test);
}
function continue_test() {

View File

@ -71,7 +71,7 @@ function run_test() {
// Restore could take some time, usually less than 1s.
// We will poll later in continue_test() to be sure restore has finished.
do_test_pending();
do_timeout(1000, "continue_test();");
do_timeout(1000, continue_test);
}
function continue_test() {
@ -80,7 +80,7 @@ function continue_test() {
if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
// Not enough time to complete restore, poll again later.
do_timeout(1000, "continue_test();");
do_timeout(1000, continue_test);
return;
}

View File

@ -143,7 +143,7 @@ function run_test() {
// Kick-off tests.
do_test_pending();
do_timeout(0, "run_next_test();");
do_timeout(0, run_next_test);
}
function run_next_test() {
@ -160,7 +160,7 @@ function run_next_test() {
do_check_true(compareJSON(gReferenceJSON, leftPaneJSON));
do_check_eq(PlacesUtils.bookmarks.getItemTitle(gFolderId), "test");
// Go to next test.
do_timeout(0, "run_next_test();");
do_timeout(0, run_next_test);
}
else {
// All tests finished.

View File

@ -58,7 +58,7 @@ var asyncXHR = {
function run_test() {
do_test_pending();
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
// network offline

View File

@ -32,15 +32,15 @@ function run_test() {
// ... and the first one has
do_test_pending();
do_timeout(10, "verifyFirstExpiration();");
do_timeout(10, verifyFirstExpiration);
// ... and that the short-term one will
do_test_pending();
do_timeout(200, "verifyExpiration();");
do_timeout(200, verifyExpiration);
// clean up
do_test_pending();
do_timeout(300, "end_test();");
do_timeout(300, end_test);
}
function verifyFirstExpiration() {

View File

@ -114,7 +114,7 @@ function run_test() {
do_test_pending(); // for 'cleared' notification
pm.removeAll();
do_timeout(100, "cleanup();");
do_timeout(100, cleanup);
}
function cleanup() {

View File

@ -121,7 +121,7 @@ function checkValueAndTrigger(request, data, ctx) {
if (index < tests.length - 1) {
var delay = tests[index++].delay;
if (delay) {
do_timeout(delay, "triggerNextTest()");
do_timeout(delay, triggerNextTest);
} else {
triggerNextTest();
}

View File

@ -21,7 +21,7 @@ TestListener.prototype.onStartRequest = function(request, context) {
TestListener.prototype.onStopRequest = function(request, context, status) {
change_content_type();
do_timeout(0, "after_channel_closed()");
do_timeout(0, after_channel_closed);
}
function after_channel_closed() {

View File

@ -59,7 +59,7 @@ var copyObserver =
do_check_true(test_source_closed);
}
do_timeout(0, "do_test();");
do_timeout(0, do_test);
},
QueryInterface: function(aIID)
@ -119,8 +119,9 @@ function do_test() {
pipe1.outputStream.write(test_content, test_content.length);
pipe1.outputStream.flush();
do_timeout(20,
"copier.cancel(test_result);" +
"pipe1.outputStream.write(\"a\", 1);");
function(){
copier.cancel(test_result);
pipe1.outputStream.write("a", 1);});
break;
case 5:
case 6: // close sink
@ -156,10 +157,12 @@ function do_test() {
// we will close the sink
test_sink_closed = true;
do_timeout(20,
"pipe2.outputStream" +
" .QueryInterface(Ci.nsIAsyncOutputStream)" +
" .closeWithStatus(test_result);" +
"pipe1.outputStream.write(\"a\", 1);");
function()
{
pipe2.outputStream
.QueryInterface(Ci.nsIAsyncOutputStream)
.closeWithStatus(test_result);
pipe1.outputStream.write("a", 1);});
break;
case 13:
do_test_finished();
@ -169,6 +172,6 @@ function do_test() {
function run_test() {
test_nr = 0;
do_timeout(0, "do_test();");
do_timeout(0, do_test);
do_test_pending();
}

View File

@ -35,7 +35,7 @@ var listener = {
do_check_eq(buffer, "0123456789");
do_check_eq(observers_called, results[test_nr]);
test_nr++;
do_timeout(0, "do_test();");
do_timeout(0, do_test);
}
};
@ -53,7 +53,7 @@ function run_test() {
obs.addObserver(observer, "http-on-examine-merged-response", false);
obs.addObserver(observer, "http-on-examine-cached-response", false);
do_timeout(0, "do_test();");
do_timeout(0, do_test);
do_test_pending();
}

View File

@ -72,7 +72,7 @@ function checkValueAndTrigger(request, data, ctx) {
index++;
// this call happens in onStopRequest from the channel, and opening a
// new channel to the same url here is no good idea... post it instead
do_timeout(1, "triggerNextTest();");
do_timeout(1, triggerNextTest);
} else {
httpserver.stop(do_test_finished);
}

View File

@ -57,7 +57,7 @@ Test.prototype = {
do_check_eq(this._isFromCache, this.readFromCache);
do_check_eq(gHitServer, this.hitServer);
do_timeout(0, "run_next_test();");
do_timeout(0, run_next_test);
},
run: function() {

View File

@ -77,7 +77,7 @@ var listener = {
// Once onStopRequest is reached, the channel is marked as having been
// opened
check_async_open_throws(NS_ERROR_ALREADY_OPENED);
do_timeout(0, "after_channel_closed()");
do_timeout(0, after_channel_closed);
}
};

View File

@ -49,5 +49,5 @@ function run_test() {
do_check_true(true);
do_test_pending();
do_timeout(100, "do_test_finished();");
do_timeout(100, do_test_finished);
}

View File

@ -75,13 +75,11 @@ if ("@mozilla.org/toolkit/crash-reporter;1" in Components.classes) {
function _TimerCallback(expr, timer) {
this._expr = expr;
this._func = expr;
// Keep timer alive until it fires
_pendingCallbacks.push(timer);
}
_TimerCallback.prototype = {
_expr: "",
QueryInterface: function(iid) {
if (iid.Equals(Components.interfaces.nsITimerCallback) ||
iid.Equals(Components.interfaces.nsISupports))
@ -92,7 +90,7 @@ _TimerCallback.prototype = {
notify: function(timer) {
_pendingCallbacks.splice(_pendingCallbacks.indexOf(timer), 1);
eval(this._expr);
this._func.call(null);
}
};

View File

@ -58,7 +58,7 @@ function checkResult() {
// Need to poll RecentDocs value because the SHAddToRecentDocs call
// doesn't update the registry immediately.
do_timeout(POLL_REGISTRY_TIMEOUT, "pollRecentDocs();");
do_timeout(POLL_REGISTRY_TIMEOUT, pollRecentDocs);
}
var gPollsCount = 0;
@ -74,7 +74,7 @@ function pollRecentDocs() {
do_test_finished();
}
else
do_timeout(POLL_REGISTRY_TIMEOUT, "pollRecentDocs();");
do_timeout(POLL_REGISTRY_TIMEOUT, pollRecentDocs);
}
function checkRecentDocsFor(aFileName) {

View File

@ -63,7 +63,7 @@ function run_test() {
do_test_pending();
gItemId1 = bmsvc.insertBookmark(gTestRoot, gURI, bmsvc.DEFAULT_INDEX, "");
do_timeout(100, "phase2();");
do_timeout(100, phase2);
}
function phase2() {
@ -71,7 +71,7 @@ function phase2() {
var b = bmsvc.getBookmarkIdsForURI(gURI);
do_check_eq(b[0], gItemId2);
do_check_eq(b[1], gItemId1);
do_timeout(100, "phase3();");
do_timeout(100, phase3);
}
function phase3() {

View File

@ -97,7 +97,7 @@ var observer = {
// The database connection will be closed after this sync, but we can't
// know how much time it will take, so we use a polling strategy.
do_timeout(POLLING_TIMEOUT_MS, "check_results();");
do_timeout(POLLING_TIMEOUT_MS, check_results);
}
}
}
@ -111,7 +111,7 @@ function check_results() {
}
if (hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection.connectionReady) {
do_timeout(POLLING_TIMEOUT_MS, "check_results();");
do_timeout(POLLING_TIMEOUT_MS, check_results);
return;
}

View File

@ -85,7 +85,7 @@ function run_test() {
ghist.addURI(testURI, false, true, null);
ghist.addURI(testURI, false, true, testURI);
// lazy message timer is 3000, see LAZY_MESSAGE_TIMEOUT
do_timeout(3500, "confirm_results();");
do_timeout(3500, confirm_results);
}
function confirm_results() {

View File

@ -124,7 +124,7 @@ function run_test() {
do_test_pending();
// lazy timeout is 3s and favicons are lazy added
do_timeout(3500, "end_test();");
do_timeout(3500, end_test);
}
function end_test() {

View File

@ -77,5 +77,5 @@ function run_test() {
bs.DEFAULT_INDEX, "bookmark");
do_test_pending();
do_timeout(1000, "verify();");
do_timeout(1000, verify);
}

View File

@ -527,7 +527,7 @@ function startExpireNeither() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireNeither();");
do_timeout(600, checkExpireNeither);
}
function checkExpireNeither() {
@ -588,7 +588,7 @@ function startExpireDaysOnly() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireDaysOnly();");
do_timeout(600, checkExpireDaysOnly);
}
function checkExpireDaysOnly() {
@ -658,7 +658,7 @@ function startExpireBoth() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireBoth();"); // incremental expiration timer is 3500
do_timeout(600, checkExpireBoth); // incremental expiration timer is 3500
}
function checkExpireBoth() {
@ -716,7 +716,7 @@ function startExpireNeitherOver() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireNeitherOver();");
do_timeout(600, checkExpireNeitherOver);
}
function checkExpireNeitherOver() {
@ -765,7 +765,7 @@ function startExpireHistoryDisabled() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireHistoryDisabled();");
do_timeout(600, checkExpireHistoryDisabled);
}
function checkExpireHistoryDisabled() {
@ -817,7 +817,7 @@ function startExpireBadPrefs() {
// Changing expiration preferences triggers partial expiration.
// Check results.
do_timeout(600, "checkExpireBadPrefs();");
do_timeout(600, checkExpireBadPrefs);
}
function checkExpireBadPrefs() {

View File

@ -77,5 +77,5 @@ function run_test() {
hs.TRANSITION_TYPED, false, 0);
do_test_pending();
do_timeout(1000, "verify();");
do_timeout(1000, verify);
}

View File

@ -133,7 +133,7 @@ function run_test()
// test too soon the timestamp will be the same! So, we'll wait a short
// period of time to make sure the timestamp will differ.
do_test_pending();
do_timeout(50, "delayed_test()");
do_timeout(50, delayed_test);
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;

View File

@ -362,7 +362,7 @@ function run_test() {
do_test_pending();
// Give time for phone home to complete.
do_timeout(DELAY, "run_test_pt2()");
do_timeout(DELAY, run_test_pt2);
}
/**

View File

@ -437,7 +437,7 @@ var WindowWatcher = {
gNewBlocks.push(list[i].name + " " + list[i].version);
// Call the callback after the blocklist has finished up
do_timeout(0, "gCallback()");
do_timeout(0, gCallback);
},
QueryInterface: function(iid) {

View File

@ -174,7 +174,7 @@ var WindowWatcher = {
}
// Call the next test after the blocklist has finished up
do_timeout(0, "gTestCheck()");
do_timeout(0, gTestCheck);
},
QueryInterface: function(iid) {

View File

@ -107,7 +107,7 @@ var WindowWatcher = {
do_check_neq(item.name, "test_bug514327_outdated");
// Call the next test after the blocklist has finished up
do_timeout(0, "gNextTestPart()");
do_timeout(0, gNextTestPart);
},
QueryInterface: function(iid) {

View File

@ -603,7 +603,7 @@ xhr.prototype = {
responseXML: null,
responseText: null,
send: function(body) {
do_timeout(0, "gXHRCallback()"); // Use a timeout so the XHR completes
do_timeout(0, gXHRCallback); // Use a timeout so the XHR completes
},
_onprogress: null,
set onprogress(val) { gXHR._onprogress = val; },
@ -656,7 +656,7 @@ const updateCheckListener = {
"update.statusText = " + request.statusText + ", " +
"updateCount = " + updateCount + "\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
do_timeout(0, gCheckFunc);
},
onError: function(request, update) {
@ -667,7 +667,7 @@ const updateCheckListener = {
"request.status = " + gStatusCode + ", " +
"update.statusText = " + gStatusText + "\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
do_timeout(0, gCheckFunc);
},
QueryInterface: function(aIID) {

View File

@ -52,7 +52,7 @@ function run_test() {
overrideXHR(callHandleEvent);
startAUS();
startUpdateChecker();
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
function end_test() {

View File

@ -52,7 +52,7 @@ function run_test() {
startUpdateChecker();
// The HTTP server is only used for the mar file downloads which is slow
start_httpserver(DIR_DATA);
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
function end_test() {
@ -218,7 +218,7 @@ const downloadListener = {
onStopRequest: function(request, context, status) {
gStatusResult = status;
// Use a timeout to allow the request to complete
do_timeout(0, "gCheckFunc()");
do_timeout(0, gCheckFunc);
},
QueryInterface: function(iid) {

View File

@ -57,7 +57,7 @@ function run_test() {
gAppInfo = AUS_Cc["@mozilla.org/xre/app-info;1"].
getService(AUS_Ci.nsIXULAppInfo).
QueryInterface(AUS_Ci.nsIXULRuntime);
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
function end_test() {

View File

@ -56,7 +56,7 @@ function run_test() {
getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE,
URL_HOST + "update.xml");
overrideXHR(callHandleEvent);
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
function end_test() {

View File

@ -72,7 +72,7 @@ function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0");
setDefaultPrefs();
do_timeout(0, "run_test_pt1()");
do_timeout(0, run_test_pt1);
}
function end_test() {
@ -111,7 +111,7 @@ function run_test_pt1() {
do_check_true(privBrowsing.autoStarted);
// Use a timeout to give private browsing time to reset necko.
do_timeout(0, "run_test_pt2()");
do_timeout(0, run_test_pt2);
}
function run_test_pt2() {
dump("Testing: update count should equal 1\n");

View File

@ -161,7 +161,7 @@ function end_test() {
}
function run_test1thru6() {
gNextFunc = "check_test1thru6()";
gNextFunc = check_test1thru6;
// bogus default interval
gCompReg.registerFactory(TESTS[0].classID, TESTS[0].desc,
TESTS[0].contractID, gTest1Factory);
@ -271,11 +271,11 @@ function check_test1thru6() {
"registered\n");
do_check_eq(count, 0);
do_timeout(0, "run_test7()");
do_timeout(0, run_test7());
}
function run_test7() {
gNextFunc = "check_test7()";
gNextFunc = check_test7;
gPref.setIntPref(PREF_BRANCH_LAST_UPDATE_TIME + TESTS[6].timerID, 1);
gCompReg.registerFactory(TESTS[6].classID, TESTS[6].desc,
TESTS[6].contractID, gTest7Factory);
@ -386,7 +386,7 @@ var gTest6Factory = {
var gTest7TimerCallback = {
notify: function T7CB_notify(aTimer) {
TESTS[6].notified = true;
do_timeout(0, "check_test7()");
do_timeout(0, check_test7);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback])
};

View File

@ -58,7 +58,7 @@ function checkFile() {
}
else {
// Wait a bit longer then try again
do_timeout(1000, "checkFile()");
do_timeout(1000, checkFile);
}
}
@ -155,5 +155,5 @@ function run_test() {
localHandler.launchWithURI(uri);
do_test_pending();
do_timeout(1000, "checkFile()");
do_timeout(1000, checkFile);
}