summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/tools/yaml-new/drawing-images-to-the-canvas.yaml
blob: 93c556288d7125988f3190c0ecd8e3ce2e71f3fe (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
- name: 2d.drawImage.canvas
  canvasType: ['HTMLCanvas']
  code: |
    var canvas2 = document.createElement('canvas');
    canvas2.width = 100;
    canvas2.height = 50;
    var ctx2 = canvas2.getContext('2d');
    ctx2.fillStyle = '#0f0';
    ctx2.fillRect(0, 0, 100, 50);

    ctx.fillStyle = '#f00';
    ctx.drawImage(canvas2, 0, 0);

    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

    ctx.drawImage(document.createElement('canvas'), 0, 0);

    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.self.1
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 50, 50);
    ctx.fillStyle = '#f00';
    ctx.fillRect(50, 0, 50, 50);
    ctx.drawImage(canvas, 50, 0);

    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.self.2
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 1, 100, 49);
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 1);
    ctx.drawImage(canvas, 0, 1);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 2);

    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.null
  code: |
    @assert throws TypeError ctx.drawImage(null, 0, 0);

- name: 2d.drawImage.wrongtype
  desc: Incorrect image types in drawImage do not match any defined overloads, so
    WebIDL throws a TypeError
  code: |
    @assert throws TypeError ctx.drawImage(undefined, 0, 0);
    @assert throws TypeError ctx.drawImage(0, 0, 0);
    @assert throws TypeError ctx.drawImage("", 0, 0);

- name: 2d.drawImage.wrongtype.paragraph
  desc: Incorrect image types in drawImage do not match any defined overloads, so
    WebIDL throws a TypeError
  notes: &bindings Defined in "Web IDL" (draft)
  canvasType: ['HTMLCanvas']
  code: |
    @assert throws TypeError ctx.drawImage(document.createElement('p'), 0, 0);

- name: 2d.drawImage.incomplete.nosrc
  canvasType: ['HTMLCanvas']
  mozilla: {throws: !!null ''}
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    var img = new Image();
    ctx.drawImage(img, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.incomplete.immediate
  canvasType: ['HTMLCanvas']
  images:
  - red.png
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    var img = new Image();
    img.src = '../images/red.png';
    // This triggers the "update the image data" algorithm.
    // The image will not go to the "completely available" state
    // until a fetch task in the networking task source is processed,
    // so the image must not be fully decodable yet:
    ctx.drawImage(img, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255; @moz-todo
  expected: green

- name: 2d.drawImage.incomplete.reload
  canvasType: ['HTMLCanvas']
  images:
  - yellow.png
  - red.png
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    var img = document.getElementById('yellow.png');
    img.src = '../images/red.png';
    // This triggers the "update the image data" algorithm,
    // and resets the image to the "unavailable" state.
    // The image will not go to the "completely available" state
    // until a fetch task in the networking task source is processed,
    // so the image must not be fully decodable yet:
    ctx.drawImage(img, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255; @moz-todo
  expected: green

- name: 2d.drawImage.incomplete.emptysrc
  canvasType: ['HTMLCanvas']
  images:
  - red.png
  mozilla: {throws: !!null ''}
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    var img = document.getElementById('red.png');
    img.src = "";
    ctx.drawImage(img, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.incomplete.removedsrc
  canvasType: ['HTMLCanvas']
  images:
  - red.png
  mozilla: {throws: !!null ''}
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    var img = document.getElementById('red.png');
    img.removeAttribute('src');
    ctx.drawImage(img, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.nonexistent
  canvasType: ['HTMLCanvas']
  images:
  - not-found-at-all.png
  code: |
    var img = document.getElementById('not-found-at-all.png');
    @assert throws INVALID_STATE_ERR ctx.drawImage(img, 0, 0);

- name: 2d.drawImage.zerocanvas
  desc: drawImage with zero-sized canvas as the source shoud throw exception
  canvasType: ['HTMLCanvas']
  code: |
    var canvas2 = document.createElement('canvas');
    canvas2.width = 0;
    canvas2.height = 50;
    @assert throws INVALID_STATE_ERR ctx.drawImage(canvas2, 0, 0);

    canvas2.width = 50;
    canvas2.height = 0;
    @assert throws INVALID_STATE_ERR ctx.drawImage(canvas2, 0, 0);

    canvas2.width = 0;
    canvas2.height = 0;
    @assert throws INVALID_STATE_ERR ctx.drawImage(canvas2, 0, 0);

- name: 2d.drawImage.animated.gif
  desc: drawImage() of an animated GIF draws the first frame
  canvasType: ['HTMLCanvas']
  images:
  - anim-gr.gif
  code: |
    deferTest();
    step_timeout(t.step_func_done(function () {
        ctx.drawImage(document.getElementById('anim-gr.gif'), 0, 0);
        @assert pixel 50,25 ==~ 0,255,0,255;
    }), 500);
  expected: green

# TODO: drawImage shadows

- name: 2d.drawImage.3arg
  test_type: promise
  code: |
    const response_red = await fetch('/images/red.png');
    const blob_red = await response_red.blob();
    const bitmap_red = await createImageBitmap(blob_red);

    const response_green = await fetch('/images/green.png');
    const blob_green = await response_green.blob();
    const bitmap_green = await createImageBitmap(blob_green);

    ctx.drawImage(bitmap_green, 0, 0);
    ctx.drawImage(bitmap_red, -100, 0);
    ctx.drawImage(bitmap_red, 100, 0);
    ctx.drawImage(bitmap_red, 0, -50);
    ctx.drawImage(bitmap_red, 0, 50);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

- name: 2d.drawImage.5arg
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response_red = await fetch('/images/red.png');
    const blob_red = await response_red.blob();
    const bitmap_red = await createImageBitmap(blob_red);

    const response_green = await fetch('/images/green.png');
    const blob_green = await response_green.blob();
    const bitmap_green = await createImageBitmap(blob_green);

    ctx.drawImage(bitmap_green, 50, 0, 50, 50);
    ctx.drawImage(bitmap_red, 0, 0, 50, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 50, 50);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

- name: 2d.drawImage.9arg.basic
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/green.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, 0, 0, 100, 50, 0, 0, 100, 50);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.9arg.sourcepos
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/rgrg-256x256.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 140, 20, 100, 50, 0, 0, 100, 50);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.9arg.sourcesize
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/rgrg-256x256.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 0, 0, 256, 256, 0, 0, 100, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 51, 26);
    ctx.fillRect(49, 24, 51, 26);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;
    @assert pixel 20,20 ==~ 0,255,0,255;
    @assert pixel 80,20 ==~ 0,255,0,255;
    @assert pixel 20,30 ==~ 0,255,0,255;
    @assert pixel 80,30 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.9arg.destpos
  test_type: promise
  code: |
    const response_red = await fetch('/images/red.png');
    const blob_red = await response_red.blob();
    const bitmap_red = await createImageBitmap(blob_red);

    const response_green = await fetch('/images/green.png');
    const blob_green = await response_green.blob();
    const bitmap_green = await createImageBitmap(blob_green);

    ctx.drawImage(bitmap_green, 0, 0, 100, 50, 0, 0, 100, 50);
    ctx.drawImage(bitmap_green, 0, 0, 100, 50, -100, 0, 100, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 100, 0, 100, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 0, -50, 100, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 0, 50, 100, 50);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

- name: 2d.drawImage.9arg.destsize
  test_type: promise
  code: |
    const response_red = await fetch('/images/red.png');
    const blob_red = await response_red.blob();
    const bitmap_red = await createImageBitmap(blob_red);

    const response_green = await fetch('/images/green.png');
    const blob_green = await response_green.blob();
    const bitmap_green = await createImageBitmap(blob_green);

    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.drawImage(bitmap_green, 1, 1, 1, 1, 0, 0, 100, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, -50, 0, 50, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 100, 0, 50, 50);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 0, -25, 100, 25);
    ctx.drawImage(bitmap_red, 0, 0, 100, 50, 0, 50, 100, 25);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

- name: 2d.drawImage.canvas
  canvasType: ['OffscreenCanvas', 'Worker']
  code: |
    var offscreenCanvas2 = new OffscreenCanvas(100, 50);
    var ctx2 = offscreenCanvas2.getContext('2d');
    ctx2.fillStyle = '#0f0';
    ctx2.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#f00';
    ctx.drawImage(offscreenCanvas2, 0, 0);
    @assert pixel 0,0 ==~ 0,255,0,255;
    @assert pixel 99,0 ==~ 0,255,0,255;
    @assert pixel 0,49 ==~ 0,255,0,255;
    @assert pixel 99,49 ==~ 0,255,0,255;

- name: 2d.drawImage.zerocanvas
  canvasType: ['OffscreenCanvas', 'Worker']
  code: |
    var offscreenCanvas2 = new OffscreenCanvas(0, 10);
    @assert throws INVALID_STATE_ERR ctx.drawImage(offscreenCanvas2, 0, 0);

    offscreenCanvas2.width = 10;
    offscreenCanvas2.height = 0;
    @assert throws INVALID_STATE_ERR ctx.drawImage(offscreenCanvas2, 0, 0);

    offscreenCanvas2.width = 0;
    offscreenCanvas2.height = 0;
    @assert throws INVALID_STATE_ERR ctx.drawImage(offscreenCanvas2, 0, 0);

- name: 2d.drawImage.floatsource
  test_type: promise
  code: |
    const response = await fetch('/images/green.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 10.1, 10.1, 0.1, 0.1, 0, 0, 100, 50);
    @assert pixel 50,25 ==~ 0,255,0,255;
  Expected: green

- name: 2d.drawImage.zerosource
  desc: drawImage with zero-sized source rectangle draws nothing without exception
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 10, 10, 0, 1, 0, 0, 100, 50);
    ctx.drawImage(bitmap, 10, 10, 1, 0, 0, 0, 100, 50);
    ctx.drawImage(bitmap, 10, 10, 0, 0, 0, 0, 100, 50);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.zerosource.image
  desc: drawImage with zero-sized source rectangle from image draws nothing without exception
  test_type: promise
  canvasType: ['HTMLCanvas', 'OffscreenCanvas']
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);

    function loadImage(src) {
      return new Promise((resolve, reject) => {
        const img = new Image();
        img.onload = () => resolve(img);
        img.onerror = (err) => reject(err);
        img.src = src;
      });
    }
    const img1 = await loadImage('/images/red-zerowidth.svg');
    const img2 = await loadImage('/images/red-zeroheight.svg');
    const img3 = await loadImage('/images/red-zerosize.svg');

    ctx.drawImage(img1, 0, 0, 100, 50);
    ctx.drawImage(img2, 0, 0, 100, 50);
    ctx.drawImage(img3, 0, 0, 100, 50);
    _assertPixel(canvas, 50, 25, 0, 255, 0, 255);
  expected: green


- name: 2d.drawImage.negativesource
  desc: Negative source width/height represents the correct rectangle
  mozilla: {throws: !!null ''}
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/ggrr-256x256.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 100, 78, -100, 50, 0, 0, 50, 50);
    ctx.drawImage(bitmap, 100, 128, -100, -50, 50, 0, 50, 50);
    @assert pixel 1,1 ==~ 0,255,0,255;
    @assert pixel 1,48 ==~ 0,255,0,255;
    @assert pixel 98,1 ==~ 0,255,0,255;
    @assert pixel 98,48 ==~ 0,255,0,255;
    @assert pixel 48,1 ==~ 0,255,0,255;
    @assert pixel 48,48 ==~ 0,255,0,255;
    @assert pixel 51,1 ==~ 0,255,0,255;
    @assert pixel 51,48 ==~ 0,255,0,255;
    @assert pixel 25,25 ==~ 0,255,0,255;
    @assert pixel 75,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.negativedest
  desc: Negative destination width/height represents the correct rectangle
  mozilla: {throws: !!null ''}
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/ggrr-256x256.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 100, 78, 50, 50, 0, 50, 50, -50);
    ctx.drawImage(bitmap, 100, 128, 50, -50, 100, 50, -50, -50);
    @assert pixel 1,1 ==~ 0,255,0,255;
    @assert pixel 1,48 ==~ 0,255,0,255;
    @assert pixel 98,1 ==~ 0,255,0,255;
    @assert pixel 98,48 ==~ 0,255,0,255;
    @assert pixel 48,1 ==~ 0,255,0,255;
    @assert pixel 48,48 ==~ 0,255,0,255;
    @assert pixel 51,1 ==~ 0,255,0,255;
    @assert pixel 51,48 ==~ 0,255,0,255;
    @assert pixel 25,25 ==~ 0,255,0,255;
    @assert pixel 75,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.negativedir
  desc: Negative dimensions do not affect the direction of the image
  mozilla: {throws: !!null ''}
  test_type: promise
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/ggrr-256x256.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);
    ctx.drawImage(bitmap, 0, 178, 50, -100, 0, 0, 50, 100);
    ctx.drawImage(bitmap, 0, 78, 50, 100, 50, 100, 50, -100);
    @assert pixel 1,1 ==~ 0,255,0,255;
    @assert pixel 1,48 ==~ 0,255,0,255;
    @assert pixel 98,1 ==~ 0,255,0,255;
    @assert pixel 98,48 ==~ 0,255,0,255;
    @assert pixel 48,1 ==~ 0,255,0,255;
    @assert pixel 48,48 ==~ 0,255,0,255;
    @assert pixel 51,1 ==~ 0,255,0,255;
    @assert pixel 51,48 ==~ 0,255,0,255;
    @assert pixel 25,25 ==~ 0,255,0,255;
    @assert pixel 75,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.outsidesource
  DISABLED: fix this to match the current spec (transparent black outside source)
  canvasType: ['OffscreenCanvas', 'Worker']
  code: |
    const response_red = await fetch('/images/red.png');
    const blob_red = await response_red.blob();
    const bitmap_red = await createImageBitmap(blob_red);

    const response_green = await fetch('/images/green.png');
    const blob_green = await response_green.blob();
    const bitmap_green = await createImageBitmap(blob_green);
    ctx.drawImage(bitmap_green, 10.5, 10.5, 89.5, 39.5, 0, 0, 100, 50);
    ctx.drawImage(bitmap_green, 5.5, 5.5, -5.5, -5.5, 0, 0, 100, 50);
    ctx.drawImage(bitmap_green, 100, 50, -5, -5, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, -0.001, 0, 100, 50, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 0, -0.001, 100, 50, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 0, 0, 100.001, 50, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 0, 0, 100, 50.001, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 50, 0, 50.001, 50, 0, 0, 100, 50); @moz-todo
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 0, 0, -5, 5, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 0, 0, 5, -5, 0, 0, 100, 50);
    @assert throws INDEX_SIZE_ERR ctx.drawImage(bitmap1, 110, 60, -20, -20, 0, 0, 100, 50);
    @assert pixel 50,25 ==~ 0,255,0,255; @moz-todo
  expected: green

- name: 2d.drawImage.broken
  test_type: promise
  code: |
    const response = await fetch('/images/broken.png');
    const blob = await response.blob();

    await promise_rejects_dom(t, 'InvalidStateError', createImageBitmap(blob), 'The source image could not be decoded.');
  expected: green

- name: 2d.drawImage.svg
  desc: drawImage() of an SVG image
  test_type: promise
  canvasType: ['HTMLCanvas', 'OffscreenCanvas']
  code: |
    const img = new Image();
    const imageLoadPromise = new Promise((resolve, reject) => {
      img.onload = () => resolve();
      img.onerror = (err) => reject(err);
    });
    img.src = '/images/green.svg';
    await imageLoadPromise;

    ctx.drawImage(img, 0, 0);
    _assertPixelApprox(canvas, 50, 25, 0, 255, 0, 255, 2);
  expected: green

- name: 2d.drawImage.path
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.rect(0, 0, 100, 50);
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, 0, 0);
    ctx.fill();
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.transform
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.translate(100, 0);
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.alpha
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.globalAlpha = 0;
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.clip
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.rect(-10, -10, 1, 1);
    ctx.clip();
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.rect(-10, -10, 1, 1);
    ctx.clip();
    ctx.drawImage(bitmap, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.composite
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.globalCompositeOperation = 'destination-over';
    const response = await fetch('/images/red.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, 0, 0);
    @assert pixel 50,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.nowrap
  desc: Stretched images do not get pixels wrapping around the edges
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/redtransparent.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    ctx.drawImage(bitmap, -1950, 0, 2000, 50);
    @assert pixel 45,25 ==~ 0,255,0,255;
    @assert pixel 50,25 ==~ 0,255,0,255;
    @assert pixel 55,25 ==~ 0,255,0,255;
  expected: green

- name: 2d.drawImage.nonfinite
  desc: drawImage() with Infinity/NaN is ignored
  test_type: promise
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    const response = await fetch('/images/redtransparent.png');
    const blob = await response.blob();
    const bitmap = await createImageBitmap(blob);

    @nonfinite ctx.drawImage(<bitmap>, <0 Infinity -Infinity NaN>, <0 Infinity -Infinity NaN>);
    @nonfinite ctx.drawImage(<bitmap>, <0 Infinity -Infinity NaN>, <0 Infinity -Infinity NaN>, <100 Infinity -Infinity NaN>, <50 Infinity -Infinity NaN>);
    @nonfinite ctx.drawImage(<bitmap>, <0 Infinity -Infinity NaN>, <0 Infinity -Infinity NaN>, <100 Infinity -Infinity NaN>, <50 Infinity -Infinity NaN>, <0 Infinity -Infinity NaN>, <0 Infinity -Infinity NaN>, <100 Infinity -Infinity NaN>, <50 Infinity -Infinity NaN>);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green