summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/imagebitmap/createImageBitmap-serializable.html
blob: c185cd9cbd9c4964fac8a1f9d0a899d945a206c7 (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
<!DOCTYPE html>
<meta charset=utf-8>
<title>createImageBitmap serialize test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/namespaces.js"></script>
<script src="/common/media.js"></script>
<script src="common.sub.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<div id=log></div>
<script>
let worker, continuations = {};
setup(function() {
    worker = new Worker("transfer-worker.js");
    worker.addEventListener("message", function(event) {
        let { name, bitmap } = event.data;
        if (continuations.hasOwnProperty(name)) {
            continuations[name](bitmap);
        }
    });
});

for (let { name, factory } of imageSourceTypes) {
    promise_test(function(t) {
        return factory().then(createImageBitmap).then(function(bitmap) {
            assert_equals(bitmap.width, 20);
            assert_equals(bitmap.height, 20);

            worker.postMessage({ name: t.name, bitmap: bitmap });

            assert_equals(bitmap.width, 20);
            assert_equals(bitmap.height, 20);

            return new Promise(function(resolve) {
                continuations[t.name] = resolve;
            });
        }).then(function(bitmap) {
            assert_class_string(bitmap, "ImageBitmap");
            assert_equals(bitmap.width, 20);
            assert_equals(bitmap.height, 20);
        });
    }, `Serialize ImageBitmap created from ${name}`);
}

promise_test(async (t) => {
  const url = get_host_info().REMOTE_ORIGIN + '/images/pattern.png';
  const image = await makeMakeHTMLImage(url)();
  const bitmap = await createImageBitmap(image);

  assert_throws_dom('DataCloneError', () => worker.postMessage(bitmap));
}, 'Serializing a non-origin-clean ImageBitmap throws.');
</script>