File: canvas-ImageBitmap-close.html

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (89 lines) | stat: -rw-r--r-- 3,586 bytes parent folder | download | duplicates (22)
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
87
88
89
<!DOCTYPE html>
<body>
    <p>Tests that the close method of ImageBitmap does dispose the image data.</p>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

promise_test(function(t) {
    var worker = new Worker('worker-onmessage-noop.js');

    var imgHeight = 10;
    var imgWidth = 10;
    var imageData = new ImageData(10, 10);
    var bitmap;
    var ctx;
    return createImageBitmap(imageData).then(imageBitmap => {
        bitmap = imageBitmap;
        assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
        assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");

        // Apply structured clone to the bitmap, nothing should be changed
        worker.postMessage({data: bitmap});
        assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
        assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");

        // After calling close, the image data associated with the bitmap should no longer exist
        bitmap.close();
        assert_equals(bitmap.width, 0, "bitmap.width = 0");
        assert_equals(bitmap.height, 0, "bitmap.height = 0");

        var canvas = document.createElement("canvas");
        canvas.width = imgWidth;
        canvas.height = imgHeight;
        ctx = canvas.getContext("2d");
        assert_throws_dom("InvalidStateError", function() { ctx.drawImage(bitmap, 0, 0); });

        // Try to apply structured clone to an already closed bitmap
        try {
            worker.postMessage({data: bitmap});
            throw new Error("Apply clone to an closed bitmap should be rejected");
        }
        catch(ex) {
             // Apply structured clone to an already closed bitmap is rejected as expected.
        }

        // Try to apply transferring to an already closed bitmap
        try {
            worker.postMessage({data: bitmap}, [bitmap]);
            throw new Error("Apply transferring to an closed bitmap should be rejected");
        } catch(ex) {
             // Apply structured clone to an already closed bitmap is rejected as expected.
        }

        // Calling createImageBitmap from a closed bitmap should be rejected
        return createImageBitmap(bitmap).then(function() {
           throw new Error("createImageBitmap from a closed bitmap should be rejected");
        }, ex => {
            // Calling createImageBitmap from a closed ImageBitmap is rejected as expected.
        });
    }).then(() => {
        // Call close to a already closed bitmap should be noop.
        bitmap.close();
        assert_equals(bitmap.width, 0, "bitmap.height = 0");
        assert_equals(bitmap.height, 0, "bitmap.height = 0");

        return createImageBitmap(imageData).then(imageBitmap => {
            bitmap = imageBitmap;
            assert_equals(bitmap.width, imgWidth, "bitmap.width = 10");
            assert_equals(bitmap.height, imgWidth, "bitmap.height = 10");

            // Transfer the bitmap to a worker
            worker.postMessage({data: bitmap}, [bitmap]);

            // After transferring, the bitmap is neutered.
            assert_equals(bitmap.width, 0, "bitmap.height = 0");
            assert_equals(bitmap.height, 0, "bitmap.height = 0");

            // Calling close to a neutered bitmap should be noop.
            bitmap.close();
            assert_equals(bitmap.width, 0, "bitmap.height = 0");
            assert_equals(bitmap.height, 0, "bitmap.height = 0");

        });
    }).catch(function(ex) {
        throw new Error("No exception should be thrown.");
    })
});
</script>