summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/drawing-images-to-the-canvas/drawimage_svg_image_with_foreign_object_does_not_taint.html
blob: f29b2bf5a8a7eb45c22306faaf5028428e28cf9b (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Draw an SVG image with a foreignObject to a canvas</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function loadImage(url) {
  return new Promise(resolve => {
    const image = new window.Image();
    image.onload = () => {
      resolve(image);
    };
    image.src = url;
  });
}

promise_test(async (t) => {
  // Load a data URL for an SVG image with a foreign object.
  const url = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><foreignObject></foreignObject></svg>';
  const image = await loadImage(url);

  // Draw the image to a canvas.
  const canvas = document.createElement('canvas');
  const context = canvas.getContext('2d');
  canvas.width = image.width;
  canvas.height = image.height;
  context.drawImage(image, 0, 0);

  // The canvas should not be tainted, so the following shouldn't throw.
  assert_true(canvas.toDataURL().length > 0);
}, 'Canvas should not be tainted after drawing SVG including <foreignObject>');
</script>