Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / resources / Promise-init-in-workers.js
blob0bd1d79d9d5e5eeb945a7ccf4c209169704a0778
1 importScripts('../../../resources/js-test.js');
3 var global = this;
4 global.jsTestIsAsync = true;
6 description('Test Promise.');
8 var thisInInit;
9 var resolve, reject;
10 var promise = new Promise(function(newResolve, newReject) {
11   thisInInit = this;
12   resolve = newResolve;
13   reject = newReject;
14 });
16 shouldBeTrue('promise instanceof Promise');
17 shouldBe('promise.constructor', 'Promise');
18 shouldBeFalse('thisInInit === promise');
19 shouldBeTrue('thisInInit === global');
20 shouldBeTrue('resolve instanceof Function');
21 shouldBeTrue('reject instanceof Function');
23 shouldThrow('new Promise()', '"TypeError: Promise constructor takes a function argument"');
24 shouldThrow('new Promise(37)', '"TypeError: Promise constructor takes a function argument"');
26 shouldNotThrow('promise = new Promise(function() { throw Error("foo"); })');
27 promise.then(undefined, function(result) {
28   global.result = result;
29   shouldBeEqualToString('result.message', 'foo');
30 });
32 new Promise(function(resolve) {
33   resolve("hello");
34   throw Error("foo");
35 }).then(function(result) {
36   global.result = result;
37   testPassed('fulfilled');
38   shouldBeEqualToString('result', 'hello');
39   finishJSTest();
40 }, function(result) {
41   global.result = result;
42   testFailed('rejected');
43   finishJSTest();
44 });