|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 // This test is designed to fail. |
|
7 // It ensures that throwing an asynchronous error from add_task will |
|
8 // fail the test. |
|
9 |
|
10 let passedTests = 0; |
|
11 |
|
12 function rejectWithTimeout(error = undefined) { |
|
13 let deferred = Promise.defer(); |
|
14 executeSoon(function() { |
|
15 ok(true, "we get here after a timeout"); |
|
16 deferred.reject(error); |
|
17 }); |
|
18 return deferred.promise; |
|
19 } |
|
20 |
|
21 add_task(function failWithoutError() { |
|
22 try { |
|
23 yield rejectWithTimeout(); |
|
24 } finally { |
|
25 ++passedTests; |
|
26 } |
|
27 }); |
|
28 |
|
29 add_task(function failWithString() { |
|
30 try { |
|
31 yield rejectWithTimeout("Meaningless error"); |
|
32 } finally { |
|
33 ++passedTests; |
|
34 } |
|
35 }); |
|
36 |
|
37 add_task(function failWithoutInt() { |
|
38 try { |
|
39 yield rejectWithTimeout(42); |
|
40 } finally { |
|
41 ++passedTests; |
|
42 } |
|
43 }); |
|
44 |
|
45 |
|
46 // This one should display a stack trace |
|
47 add_task(function failWithError() { |
|
48 try { |
|
49 yield rejectWithTimeout(new Error("This is an error")); |
|
50 } finally { |
|
51 ++passedTests; |
|
52 } |
|
53 }); |
|
54 |
|
55 add_task(function done() { |
|
56 is(passedTests, 4, "Passed all tests"); |
|
57 }); |