1/* spec tests gl-matrix when embedded into a Web Worker */
2
3// only test with workers if workers are available
4if (typeof(Worker) !== 'undefined') {
5  describe("Embedded within Web Workers", function() {
6    it("should initialize successfully", function() {
7      var xhr = new XMLHttpRequest();
8      var source = null;
9      xhr.onreadystatechange = function() {
10        if (this.readyState == this.DONE) {
11          if (this.status == 200) {
12            source = this.responseText;
13          }
14        }
15      };
16      xhr.open("GET", "/dist/gl-matrix-min.js");
17      xhr.send();
18
19      var result = null;
20
21      waitsFor(function() {
22        if (!source) return false;
23        var blob = new Blob([
24            source,
25            "self.postMessage(vec3.create());"
26          ],
27          {type: "application/javascript"}
28        );
29
30        var worker = new Worker(URL.createObjectURL(blob));
31        worker.onmessage = function(e) {
32          result = e.data;
33        };
34        return true;
35      });
36
37      waitsFor(function() {
38        if (!result) return false;
39        expect(result).toBeEqualish([0, 0, 0]);
40        return true;
41      });
42    });
43  });
44}
45