4 <script src=
"mock_timer.js"></script>
13 mockTimer
= new MockTimer();
19 mockTimer
.uninstall();
22 function testCallbacks() {
38 assertEquals(1, calls1
);
39 assertEquals(1, calls2
);
42 function testCallbacks2() {
59 assertEquals(0, calls1
);
60 assertEquals(1, calls2
);
63 function testCallbacks3() {
77 assertEquals(0, calls1
);
78 assertEquals(0, calls2
);
80 assertEquals(1, calls1
);
81 assertEquals(0, calls2
);
83 assertEquals(1, calls1
);
84 assertEquals(1, calls2
);
87 function testCallbacks4() {
99 var p
= new Promise(V
);
102 assertEquals(1, calls1
);
103 assertEquals(1, calls2
);
106 function testThisInCallback() {
112 assertNotEqual(p
, this);
117 assertEquals(1, calls
);
120 function testPending() {
122 assertEquals(undefined, p
.value
);
126 function testValueCanBeUndefined() {
129 assertEquals(undefined, p
.value
);
133 function testDone() {
140 function testWhen() {
145 Promise
.when(p
, function(v
) {
149 assertEquals(1, calls
);
152 function testWhen2() {
156 Promise
.when(p
, function(v
) {
161 assertEquals(1, calls
);
164 function testWait() {
166 var p
= Promise
.wait(1000, S
);
172 assertEquals(S
, p
.value
);
176 var p1
= new Promise
;
177 var p2
= new Promise
;
178 var p3
= new Promise
;
180 var any
= Promise
.any(p1
, p2
, p3
);
182 assertEquals(2, any
.value
);
184 assertEquals(2, any
.value
);
188 var p1
= new Promise
;
189 var p2
= new Promise
;
190 var p3
= new Promise
;
192 var pAll
= Promise
.all(p1
, p2
, p3
);
196 assertArrayEquals([1, 2, 3], pAll
.value
);
199 function testAllEmpty() {
200 var pAll
= Promise
.all();
201 assertArrayEquals([], pAll
.value
);
204 function testAllAlreadyDone() {
205 var p1
= new Promise(1);
206 var p2
= new Promise(2);
207 var p3
= new Promise(3);
209 var pAll
= Promise
.all(p1
, p2
, p3
);
210 assertArrayEquals([1, 2, 3], pAll
.value
);
213 function testEvent() {
214 var p
= Promise
.event(document
.body
, 'foo');
215 var e
= new Event('foo');
216 document
.body
.dispatchEvent(e
);
217 assertEquals(e
, p
.value
);
220 function testToString() {
221 var p1
= new Promise
;
222 assertEquals('[object Promise]', String(p1
));
224 var p2
= new Promise
;
225 p2
.value
= 'Hello world';
226 assertEquals('Hello world', String(p2
));
229 function testValueOf() {