Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / resources / Promise-then-in-workers.js
blob5acdcd1e5c70419bf18427c8848e552272826e4b
1 importScripts('../../../resources/js-test.js');
3 description('Test Promise.');
5 var global = this;
7 global.jsTestIsAsync = true;
9 var resolve;
11 var firstPromise = new Promise(function(newResolve) {
12   global.thisInInit = this;
13   resolve = newResolve;
14 });
16 var secondPromise = firstPromise.then(function(result) {
17   global.thisInFulfillCallback = this;
18   shouldBeFalse('thisInFulfillCallback === firstPromise');
19   shouldBeFalse('thisInFulfillCallback === secondPromise');
20   shouldBeTrue('thisInFulfillCallback === global');
21   global.result = result;
22   shouldBeEqualToString('result', 'hello');
23   return 'world';
24 });
26 shouldBeFalse('thisInInit === firstPromise');
27 shouldBeTrue('thisInInit === global');
28 shouldBeTrue('firstPromise instanceof Promise');
29 shouldBeTrue('secondPromise instanceof Promise');
31 secondPromise.then(null, 37).then(function(result) {
32   global.result = result;
33   shouldBeEqualToString('result', 'world');
34   throw 'exception'
35 }).then(1, 2).then(function() {
36   testFailed('resolved');
37 }, function(result) {
38   testPassed('rejected');
39   global.result = result;
40   shouldBeEqualToString('result', 'exception');
41 }).then(function() {
42   testPassed('resolved');
43   finishJSTest();
44 }, function() {
45   testFailed('rejected');
46   finishJSTest();
47 });
49 resolve('hello');