summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/chrome/test_sanitySpawnTask.xul
blob: d3f0ccc1f518576d8ec8c7d2a4a181ae0d71d089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>
<window title="Test spawnTawk function"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"/>
  <script type="application/javascript">
  <![CDATA[
    SimpleTest.waitForExplicitFinish();

    var externalGeneratorFunction = function* () {
      return 8;
    };

    var nestedFunction = function* () {
      return yield function* () {
        return yield function* () {
          return yield function* () {
            return yield Promise.resolve(9);
          }();
        }();
      }();
    }

    var variousTests = function* () {
      var val1 = yield [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)];
      is(val1.join(""), "123", "Array of promises -> Promise.all");
      var val2 = yield Promise.resolve(2);
      is(val2, 2, "Resolved promise yields value.");
      var val3 = yield function* () { return 3; };
      is(val3, 3, "Generator functions are spawned.");
      //var val4 = yield function () { return 4; };
      //is(val4, 4, "Plain functions run and return.");
      var val5 = yield (function* () { return 5; }());
      is(val5, 5, "Generators are spawned.");
      try {
        var val6 = yield Promise.reject(Error("error6"));
        ok(false, "Shouldn't reach this line.");
      } catch (error) {
        is(error.message, "error6", "Rejected promise throws error.");
      }
      try {
        var val7 = yield function* () { throw Error("error7"); };
        ok(false, "Shouldn't reach this line.");
      } catch (error) {
        is(error.message, "error7", "Thrown error propagates.");
      }
      var val8 = yield externalGeneratorFunction();
      is(val8, 8, "External generator also spawned.");
      var val9 = yield nestedFunction();
      is(val9, 9, "Nested generator functions work.");
      return 10;
    };

    spawn_task(variousTests).then(function(result) {
      is(result, 10, "spawn_task(...) returns promise");
      SimpleTest.finish();
    });
    ]]>
  </script>

  <body xmlns="http://www.w3.org/1999/xhtml" >
  </body>
</window>