зеркало из https://github.com/mozilla/gecko-dev.git
Factored out fake-timer code into a separate class and moved it to head.js.
This commit is contained in:
Родитель
832e0d67de
Коммит
30722d0b82
|
@ -41,6 +41,33 @@ function loadInSandbox(aUri) {
|
|||
return sandbox;
|
||||
}
|
||||
|
||||
function FakeTimerService() {
|
||||
Cu.import("resource://weave/util.js");
|
||||
|
||||
this.callbackQueue = [];
|
||||
|
||||
var self = this;
|
||||
|
||||
this.__proto__ = {
|
||||
makeTimerForCall: function FTS_makeTimerForCall(cb) {
|
||||
// Just add the callback to our queue and we'll call it later, so
|
||||
// as to simulate a real nsITimer.
|
||||
self.callbackQueue.push(cb);
|
||||
return "fake nsITimer";
|
||||
},
|
||||
processCallback: function FTS_processCallbacks() {
|
||||
var cb = self.callbackQueue.pop();
|
||||
if (cb) {
|
||||
cb();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Utils.makeTimerForCall = self.makeTimerForCall;
|
||||
};
|
||||
|
||||
function initTestLogging() {
|
||||
Cu.import("resource://weave/log4moz.js");
|
||||
|
||||
|
|
|
@ -2,17 +2,10 @@ Cu.import("resource://weave/util.js");
|
|||
Cu.import("resource://weave/async.js");
|
||||
|
||||
function run_test() {
|
||||
var callbackQueue = [];
|
||||
var fts = new FakeTimerService();
|
||||
|
||||
Function.prototype.async = Async.sugar;
|
||||
|
||||
Utils.makeTimerForCall = function fake_makeTimerForCall(cb) {
|
||||
// Just add the callback to our queue and we'll call it later, so
|
||||
// as to simulate a real nsITimer.
|
||||
callbackQueue.push(cb);
|
||||
return "fake nsITimer";
|
||||
};
|
||||
|
||||
var onCompleteCalled = false;
|
||||
|
||||
function onComplete() {
|
||||
|
@ -31,9 +24,7 @@ function run_test() {
|
|||
// Ensure that 'this' is set properly.
|
||||
do_check_eq(this.sampleProperty, true);
|
||||
|
||||
// Simulate the calling of an asynchronous function that will call
|
||||
// our callback.
|
||||
callbackQueue.push(self.cb);
|
||||
fts.makeTimerForCall(self.cb);
|
||||
yield;
|
||||
|
||||
timesYielded++;
|
||||
|
@ -45,15 +36,11 @@ function run_test() {
|
|||
|
||||
do_check_eq(timesYielded, 1);
|
||||
|
||||
let func = callbackQueue.pop();
|
||||
do_check_eq(typeof func, "function");
|
||||
func();
|
||||
do_check_true(fts.processCallback());
|
||||
|
||||
do_check_eq(timesYielded, 2);
|
||||
|
||||
func = callbackQueue.pop();
|
||||
do_check_eq(typeof func, "function");
|
||||
func();
|
||||
do_check_true(fts.processCallback());
|
||||
|
||||
do_check_eq(callbackQueue.length, 0);
|
||||
do_check_false(fts.processCallback());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче