blob: 9a25791b3ae15b41c57c297d5501999c2c9ccc93 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
window.jsTestIsAsync = true;
description('Test Promise.');
var thisInInit;
var resolver;
var promise = new Promise(function(r) {
thisInInit = this;
resolver = r;
});
shouldBeTrue('promise instanceof Promise');
shouldBe('promise.constructor', 'Promise');
shouldBe('thisInInit', 'promise');
shouldBeTrue('resolver instanceof PromiseResolver');
shouldBe('resolver.constructor', 'PromiseResolver');
shouldThrow('new Promise()', '"TypeError: Expected at least one argument"');
shouldThrow('new Promise(37)', '"TypeError: Expected function as as first argument"');
shouldNotThrow('promise = new Promise(function() { throw Error("foo"); })');
promise.then(undefined, function(result) {
window.result = result;
shouldBeEqualToString('result.message', 'foo');
});
new Promise(function(resolver) {
resolver.fulfill("hello");
throw Error("foo");
}).then(function(result) {
window.result = result;
testPassed('fulfilled');
shouldBeEqualToString('result', 'hello');
finishJSTest();
}, function(result) {
window.result = result;
testFailed('rejected');
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>