Index: LayoutTests/fast/js/Promise-chain.html |
diff --git a/LayoutTests/fast/js/Promise-chain.html b/LayoutTests/fast/js/Promise-chain.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ffac75103028bcc3268233206df5ddb9f88f227 |
--- /dev/null |
+++ b/LayoutTests/fast/js/Promise-chain.html |
@@ -0,0 +1,68 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script src="resources/js-test-pre.js"></script> |
+</head> |
+<body> |
+<div id="description"></div> |
+<div id="console"></div> |
+<script> |
+description("Test Promise."); |
+ |
+window.jsTestIsAsync = true; |
+ |
+var resolver; |
+var promise = new Promise(function (r) {resolver = r;}); |
+var operation; |
+ |
+promise.then(function(value) { // fulfilled - continue |
+ debug('PASS fulfilled'); |
+ window.result = value; |
+ shouldBeEqualToString('result', 'hello'); |
+ return 'hello2'; |
+}, function() { |
+ debug('FAIL rejected'); |
+}).then() // pass through |
+.then(function(value) { // fulfilled - throw an exception |
+ debug('PASS fulfilled'); |
+ window.result = value; |
+ shouldBeEqualToString('result', 'hello2'); |
+ throw 'error'; |
+}, function() { |
+ debug('FAIL rejected'); |
+}).then(function() { // rejected - throw an exception |
+ debug('FAIL fulfilled'); |
+}, function(value) { |
+ debug('PASS rejected'); |
+ window.result = value; |
+ shouldBeEqualToString('result', 'error'); |
+ throw 'error2'; |
+}).then() // pass through |
+.then(function() { // rejected - recover |
+ debug('FAIL fulfilled'); |
+}, function(value) { |
+ debug('PASS rejected'); |
+ window.result = value; |
+ shouldBeEqualToString('result', 'error2'); |
+ return 'recovered'; |
+}).then(function(value) { // fulfilled - the last |
+ debug('PASS fulfilled'); |
+ window.result = value; |
+ shouldBeEqualToString('result', 'recovered'); |
+ finishJSTest(); |
+ shouldBeEqualToString('operation', 'synchronous'); |
+}, function() { |
+ debug('FAIL rejected'); |
+ finishJSTest(); |
+}); |
+ |
+operation = 'synchronous'; |
+resolver.fulfill("hello", true); |
+ |
+// The chain should be executed synchronously. |
+operation = 'asynchronous'; |
+ |
+</script> |
+<script src="resources/js-test-post.js"></script> |
+</body> |
+</html> |