gecko/services/sync/tests/unit/test_async.js
Atul Varma 4e39258260 Made the tracking of async generators/coroutines more robust for debugging purposes.
Refactored code	in syncCores.js	to use Utils.makeTimerForCall().

Improved test_passwords to perform an additional sync after the initial one.
2008-06-20 13:58:56 -07:00

51 lines
1015 B
JavaScript

Cu.import("resource://weave/util.js");
Cu.import("resource://weave/async.js");
function run_test() {
var fts = new FakeTimerService();
Function.prototype.async = Async.sugar;
var onCompleteCalled = false;
function onComplete() {
onCompleteCalled = true;
}
let timesYielded = 0;
function testAsyncFunc(x) {
let self = yield;
timesYielded++;
// Ensure that argument was passed in properly.
do_check_eq(x, 5);
// Ensure that 'this' is set properly.
do_check_eq(this.sampleProperty, true);
fts.makeTimerForCall(self.cb);
yield;
timesYielded++;
self.done();
}
var thisArg = {sampleProperty: true};
testAsyncFunc.async(thisArg, onComplete, 5);
do_check_eq(timesYielded, 1);
do_check_true(fts.processCallback());
do_check_eq(timesYielded, 2);
do_check_eq(Async.outstandingGenerators.length, 1);
do_check_true(fts.processCallback());
do_check_false(fts.processCallback());
do_check_eq(Async.outstandingGenerators.length, 0);
}