forked from mozilla/zamboni
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS Widgets for Add-on validator logic (bug 609355)
The widget sends a request for validation then builds some panels to display results and classifies them appropriately.
- Loading branch information
Showing
4 changed files
with
536 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
/* | ||
Functions that tests can use. | ||
*/ | ||
tests = {}; | ||
|
||
tests.waitFor = function(checkCondition, config) { | ||
/* | ||
Wait for a condition before doing anything else. | ||
Good for making async tests fast on fast machines. | ||
Use it like this: | ||
tests.waitFor(function() { | ||
return (thing == 'done); | ||
}).thenDo(function() { | ||
equals(1,1); | ||
ok(stuff()); | ||
}); | ||
You can pass in a config object as the second argument | ||
with these possible attributed: | ||
config.interval = milliseconds to wait between polling condition | ||
config.timeout = milliseconds to wait before giving up on condition | ||
*/ | ||
if (typeof(config) === 'undefined') { | ||
config = {}; | ||
} | ||
var interval = config.interval || 5, | ||
timeout = config.timeout || 300, | ||
run, | ||
runWhenReady, | ||
timeSpent = 0; | ||
|
||
run = function() { | ||
if (timeSpent > timeout) { | ||
throw new Error("Spent too long waiting for condition"); | ||
} | ||
timeSpent += interval; | ||
var ready = checkCondition(); | ||
if (!ready) { | ||
setTimeout(run, interval); | ||
} else { | ||
if (typeof runWhenReady === 'function') { | ||
runWhenReady(); | ||
} | ||
} | ||
}; | ||
setTimeout(run, interval); | ||
return { | ||
thenDo: function(fn) { | ||
runWhenReady = fn; | ||
} | ||
} | ||
}; |
Oops, something went wrong.