summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/imagebitmap_on_worker.js
blob: be7046710917d39af0a26a858c1fc1decb54ead1 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
importScripts("imagebitmap_bug1239300.js");

function ok(expect, msg) {
  postMessage({type: "status", status: !!expect, msg: msg});
}

function doneTask() {
  postMessage({type: "doneTask"});
}

function promiseThrows(p, name) {
  var didThrow;
  return p.then(function() { didThrow = false; },
                function() { didThrow = true; })
          .then(function() { ok(didThrow, "[TestException] " + name); });
}

onmessage = function(event) {
  if (event.data.type == "testImageData") {
    var width = event.data.width;
    var height = event.data.height;
    var imageData = event.data.source;
    ok(imageData, "[CreateFromImageData] An ImageData is passed into worker.")
    ok(imageData.width == width, "[CreateFromImageData] Passed ImageData has right width = " + width);
    ok(imageData.height == height, "[CreateFromImageData] Passed ImageData has right height = " + height);

    var promise = createImageBitmap(imageData);
    promise.then(function(bitmap) {
      ok(bitmap, "[CreateFromImageData] ImageBitmap is created successfully.");
      ok(bitmap.width == width, "[CreateFromImageData] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width);
      ok(bitmap.height == height, "[CreateFromImageData] ImageBitmap.height = " + bitmap.height + ", expected height = " + height);

      doneTask();
    });
  } else if (event.data.type == "testBlob") {
    var width = event.data.width;
    var height = event.data.height;
    var blob = event.data.source;
    ok(blob, "[CreateFromBlob] A Blob object is passed into worker.");

    var promise = createImageBitmap(blob);
    promise.then(function(bitmap) {
      ok(bitmap, "[CreateFromBlob] ImageBitmap is created successfully.");
      ok(bitmap.width == width, "[CreateFromBlob] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width);
      ok(bitmap.height == height, "[CreateFromBlob] ImageBitmap.height = " + bitmap.height + ", expected height = " + height);

      doneTask();
    });
  } else if (event.data.type == "testImageBitmap") {
    var width  = event.data.width;
    var height = event.data.height;
    var source = event.data.source;
    ok(source, "[CreateFromImageBitmap] A soruce object is passed into worker.");

    var promise = createImageBitmap(source);
    promise.then(function(bitmap) {
      ok(bitmap, "[CreateFromImageBitmap] ImageBitmap is created successfully.");
      ok(bitmap.width == width, "[CreateFromImageBitmap] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width);
      ok(bitmap.height == height, "[CreateFromImageBitmap] ImageBitmap.height = " + bitmap.height + ", expected height = " + height);

      var promise2 = createImageBitmap(bitmap);
      promise2.then(function(bitmap2) {
        ok(bitmap2, "[CreateFromImageBitmap] 2nd ImageBitmap is created successfully.");
        ok(bitmap.width == width, "[CreateFromImageBitmap] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width);
        ok(bitmap.height == height, "[CreateFromImageBitmap] ImageBitmap.height = " + bitmap.height + ", expected height = " + height);

        doneTask();
      });
    });
  } else if (event.data.type == "testException") {
    var source = event.data.source;
    if (event.data.sx) {
      var sx = event.data.sx;
      var sy = event.data.sy;
      var sw = event.data.sw;
      var sh = event.data.sh;
      promiseThrows(createImageBitmap(source, sx, sy, sw, sh), event.data.msg);
    } else {
      promiseThrows(createImageBitmap(source), event.data.msg);
    }
    doneTask();
  } else if (event.data.type == "testBug1239300") {
    var promise = testBug1239300();
    promise.then(doneTask, doneTask);
  }
};