chromium/third_party/blink/web_tests/fast/canvas/canvas-createImageBitmap-svg-no-intrinsic-size.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>

description("Test createImageBitmap from a SVG image without intrinsic size and with zero size.");
window.jsTestIsAsync = true;

var image1Loaded = false;
var image2Loaded = false;
var image1 = new Image();
var image2 = new Image();
image1.onload = function() {
    image1Loaded = true;
    testCreateImageBitmap();
}
image1.src = '../../svg/hixie/intrinsic/resources/003.svg';
image2.onload = function() {
    image2Loaded = true;
    testCreateImageBitmap();
}
image2.src = 'resources/zeroSize.svg';

function testCreateImageBitmap()
{
    if (image1Loaded && image2Loaded) {
        createImageBitmap(image1).then(function(bitmap1) {
            testFailed("createImageBitmap from a SVG without intrinsic size succeed, expected to be rejected");
            finishJSTest();
        }, function (e) {
            testPassed("createImageBitmap from a SVG without intrinsic size rejected: " + e);
            createImageBitmap(image2).then(function(bitmap2) {
                testFailed("createImageBitmap from a SVG with zero size succeed, expected to be rejected");
                finishJSTest();
            }, function(e) {
                testPassed("createImageBitmap from a SVG with zero size rejected: " + e);
                createImageBitmap(image2, 0, 0, 100, 100).then(function(bitmap3) {
                    testPassed("createImageBitmap from a zero size SVG with cropRect succeed");
                    checkImageBitmap(bitmap3);
                    createImageBitmap(image2, {resizeWidth: 50, resizeHeight: 50, resizeQuality: "high"}).then(function(bitmap4) {
                        testPassed("createImageBitmap from a zero size SVG with resize and cropRect succeed");
                        finishJSTest();
                    }, function(e) {
                        testFailed("createImageBitmap from a zero size SVG with resize and cropRect rejected: " + e);
                        finishJSTest();
                    });
                }, function(e) {
                    testFailed("createImageBitmap from a zero size SVG with cropRect rejected: " + e);
                    finishJSTest();
                });
            });
        });
    }
}

function shouldBeClear(ctx, x, y) {
    // should be transparent black pixels
    d = ctx.getImageData(x, y, 1, 1).data;
    shouldBe("d[0]", "0");
    shouldBe("d[1]", "0");
    shouldBe("d[2]", "0");
    shouldBe("d[3]", "0");
}

function checkImageBitmap(bitmap)
{
    var canvas = document.createElement("canvas");
    canvas.width = 100;
    canvas.height = 100;
    var ctx = canvas.getContext('2d', {willReadFrequently: true});
    ctx.clearRect(0, 0, 100, 100);
    ctx.drawImage(bitmap, 0, 0);
    shouldBeClear(ctx, 0, 0);
    shouldBeClear(ctx, 0, 99);
    shouldBeClear(ctx, 99, 0);
    shouldBeClear(ctx, 99, 99);
}

</script>
</body>
</html>