OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="resources/js-test-pre.js"></script> |
| 5 </head> |
| 6 <body> |
| 7 <div id="description"></div> |
| 8 <div id="console"></div> |
| 9 <script> |
| 10 if (window.testRunner) |
| 11 testRunner.dumpAsText(); |
| 12 |
| 13 description('Test Promise.'); |
| 14 |
| 15 var thisInInit; |
| 16 var resolver; |
| 17 var promise = new Promise(function(r) { |
| 18 thisInInit = this; |
| 19 resolver = r; |
| 20 }); |
| 21 |
| 22 shouldBeTrue('promise instanceof Promise'); |
| 23 shouldBe('promise.constructor', 'Promise'); |
| 24 shouldBe('thisInInit', 'promise'); |
| 25 shouldBeTrue('resolver instanceof PromiseResolver'); |
| 26 shouldBe('resolver.constructor', 'PromiseResolver'); |
| 27 |
| 28 try { |
| 29 new Promise(); |
| 30 debug('FAIL A TypeError should be thrown for "new Promise()"'); |
| 31 } catch (e) { |
| 32 window.errorNoInitArgument = e; |
| 33 shouldBeTrue('errorNoInitArgument instanceof TypeError'); |
| 34 } |
| 35 |
| 36 try { |
| 37 new Promise(function() {}, function() {}); |
| 38 debug('FAIL A TypeError should be thrown for "new Promise(function() {}, funct
ion() {})"'); |
| 39 } catch (e) { |
| 40 window.errorTwoInitArguments = e; |
| 41 shouldBeTrue('errorTwoInitArguments instanceof TypeError'); |
| 42 } |
| 43 |
| 44 try { |
| 45 new Promise(37); |
| 46 debug('FAIL A TypeError should be thrown for "new Promise(37)'); |
| 47 } catch (e) { |
| 48 window.errorNumberInitArgument = e; |
| 49 shouldBeTrue('errorNumberInitArgument instanceof TypeError'); |
| 50 } |
| 51 |
| 52 try { |
| 53 new Promise(function() { |
| 54 throw Error('foo'); |
| 55 }); |
| 56 // We can't test if the promise is rejected now. |
| 57 debug('PASS If an error is thrown from init callback, Promise should return an
rejected promise'); |
| 58 } catch (e) { |
| 59 debug('FAIL If an error is thrown from init callback, Promise should return an
rejected promise'); |
| 60 } |
| 61 |
| 62 </script> |
| 63 <script src="resources/js-test-post.js"></script> |
| 64 </body> |
| 65 </html> |
OLD | NEW |