-
Notifications
You must be signed in to change notification settings - Fork 0
/
listing-2.6.html
79 lines (73 loc) · 2.13 KB
/
listing-2.6.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<title>Test Suite</title>
<script>
(function() {
var queue = [],
paused = false,
results;
this.test = function(name, fn) {
queue.push(function() {
results = document.getElementById("results");
results = assert(true, name).appendChild(
document.createElement("ul"));
fn();
});
runTest();
};
this.pause = function() {
paused = true;
};
this.resume = function() {
paused = false;
setTimeout(runTest, 1);
};
function runTest() {
if (!paused && queue.length) {
queue.shift()();
if (!paused) {
resume();
}
}
}
this.assert = function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
results.appendChild(li);
if (!value) {
li.parentNode.parentNode.className = "fail";
}
return li;
};
})();
window.onload = function() {
test("Async Test #1", function() {
pause();
setTimeout(function() {
assert(true, "First test completed");
resume();
}, 1000);
});
test("Async Test #2", function() {
pause();
setTimeout(function() {
assert(true, "Second test completed");
resume();
}, 1000);
});
};
</script>
<style>
#results li.pass {
color: green;
}
#results li.fail {
color: red;
}
</style>
</head>
<body>
<ul id="results"></ul>
</body>
</html>