Index: LayoutTests/fast/js/Promise-init.html |
diff --git a/LayoutTests/fast/js/Promise-init.html b/LayoutTests/fast/js/Promise-init.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..778efb48ad393c96e2453c615570fc2dbd9f27db |
--- /dev/null |
+++ b/LayoutTests/fast/js/Promise-init.html |
@@ -0,0 +1,65 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script src="resources/js-test-pre.js"></script> |
+</head> |
+<body> |
+<div id="description"></div> |
+<div id="console"></div> |
+<script> |
+if (window.testRunner) |
+ testRunner.dumpAsText(); |
+ |
+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'); |
+ |
+try { |
+ new Promise(); |
+ debug('FAIL A TypeError should be thrown for "new Promise()"'); |
+} catch (e) { |
+ window.errorNoInitArgument = e; |
+ shouldBeTrue('errorNoInitArgument instanceof TypeError'); |
+} |
+ |
+try { |
+ new Promise(function() {}, function() {}); |
+ debug('FAIL A TypeError should be thrown for "new Promise(function() {}, function() {})"'); |
+} catch (e) { |
+ window.errorTwoInitArguments = e; |
+ shouldBeTrue('errorTwoInitArguments instanceof TypeError'); |
+} |
+ |
+try { |
+ new Promise(37); |
+ debug('FAIL A TypeError should be thrown for "new Promise(37)'); |
+} catch (e) { |
+ window.errorNumberInitArgument = e; |
+ shouldBeTrue('errorNumberInitArgument instanceof TypeError'); |
+} |
+ |
+try { |
+ new Promise(function() { |
+ throw Error('foo'); |
+ }); |
+ // We can't test if the promise is rejected now. |
+ debug('PASS If an error is thrown from init callback, Promise should return an rejected promise'); |
+} catch (e) { |
+ debug('FAIL If an error is thrown from init callback, Promise should return an rejected promise'); |
+} |
+ |
+</script> |
+<script src="resources/js-test-post.js"></script> |
+</body> |
+</html> |