chromium/third_party/blink/web_tests/http/tests/security/cross-origin-createImageBitmap-structured-clone.html

<!DOCTYPE html>
<html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script id="myWorker" type="text/worker">
self.onmessage = function(e) {
    postMessage(e.data);
};
</script>
<script>
async_test(function(t) {
    function makeWorker(script) {
        var blob = new Blob([script]);
        return new Worker(URL.createObjectURL(blob));
    }
    var worker = makeWorker(document.getElementById('myWorker').textContent);
    var returnedBitmap;

    var image = new Image();
    image.onload = t.step_func(() => {
        shouldBeTainted(image);
        createImageBitmap(image).then(t.step_func((imageBitmap) => {
            assert_throws_dom('DataCloneError',
                              () => worker.postMessage({data:imageBitmap}, [imageBitmap]));
            t.done();
        }));
    });
    image.src = 'http://localhost:8080/security/resources/abe.png';

    function shouldBeTainted(imageBitmap) {
        var canvas = document.createElement("canvas");
        canvas.width = 10;
        canvas.height = 10;
        var context = canvas.getContext("2d");
        context.drawImage(imageBitmap, 0, 0, 10, 10);
        assert_throws_dom('SecurityError', function () { context.getImageData(0, 0, 10, 10); }, 'ImageBitmap should be tainted');
    }
}, 'Transfer and structured-clone an ImageBitmap should preserve the originClean flag.');
</script>
</body>
</html>