summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/layers/2d.layer.malformed-operations.html
blob: cf6e7a80db0a68f1ce8d6f7599fd47bd18977a29 (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
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
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.layer.malformed-operations</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">

<script>

test(t => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  // Shouldn't throw on its own.
  ctx.createPattern(canvas, 'repeat');
  // Make sure the exception isn't caused by calling the function twice.
  ctx.createPattern(canvas, 'repeat');
  // Calling again inside a layer should throw.
  ctx.beginLayer();
  assert_throws_dom("InvalidStateError",
                    () => ctx.createPattern(canvas, 'repeat'));
}, "Throws if createPattern is called while layers are open.");

test(t => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  const canvas2 = new OffscreenCanvas(200, 200);
  const ctx2 = canvas2.getContext('2d');
  // Shouldn't throw on its own.
  ctx2.drawImage(canvas, 0, 0);
  // Make sure the exception isn't caused by calling the function twice.
  ctx2.drawImage(canvas, 0, 0);
  // Calling again inside a layer should throw.
  ctx.beginLayer();
  assert_throws_dom("InvalidStateError",
                    () => ctx2.drawImage(canvas, 0, 0));
}, "Throws if drawImage is called while layers are open.");

test(t => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  // Shouldn't throw on its own.
  ctx.getImageData(0, 0, 200, 200);
  // Make sure the exception isn't caused by calling the function twice.
  ctx.getImageData(0, 0, 200, 200);
  // Calling again inside a layer should throw.
  ctx.beginLayer();
  assert_throws_dom("InvalidStateError",
                    () => ctx.getImageData(0, 0, 200, 200));
}, "Throws if getImageData is called while layers are open.");

test(t => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  const canvas2 = new OffscreenCanvas(200, 200);
  const ctx2 = canvas2.getContext('2d')
  const data = ctx2.getImageData(0, 0, 1, 1);
  // Shouldn't throw on its own.
  ctx.putImageData(data, 0, 0);
  // Make sure the exception isn't caused by calling the function twice.
  ctx.putImageData(data, 0, 0);
  // Calling again inside a layer should throw.
  ctx.beginLayer();
  assert_throws_dom("InvalidStateError",
                    () => ctx.putImageData(data, 0, 0));
}, "Throws if putImageData is called while layers are open.");

test(t => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  // Shouldn't throw on its own.
  canvas.toDataURL();
  // Make sure the exception isn't caused by calling the function twice.
  canvas.toDataURL();
  // Calling again inside a layer should throw.
  ctx.beginLayer();
  assert_throws_dom("InvalidStateError",
                    () => canvas.toDataURL());
}, "Throws if toDataURL is called while layers are open.");

</script>
</div>