summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/tools/yaml-new/drawing-rectangles-to-the-canvas.yaml
blob: 408e932abe86b31ce3e8d88672e04abed12b74b2 (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
- name: 2d.clearRect.basic
  desc: clearRect clears to transparent black
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.clearRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.clearRect.path
  desc: clearRect does not affect the current path
  code: |
    ctx.fillStyle = '#0f0';
    ctx.beginPath();
    ctx.rect(0, 0, 100, 50);
    ctx.clearRect(0, 0, 16, 16);
    ctx.fill();
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.clearRect.zero
  desc: clearRect of zero pixels has no effect
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.clearRect(0, 0, 100, 0);
    ctx.clearRect(0, 0, 0, 50);
    ctx.clearRect(0, 0, 0, 0);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.clearRect.negative
  desc: clearRect of negative sizes works
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.clearRect(0, 0, 50, 25);
    ctx.clearRect(100, 0, -50, 25);
    ctx.clearRect(0, 50, 50, -25);
    ctx.clearRect(100, 50, -50, -25);
    @assert pixel 25,12 == 0,0,0,0;
    @assert pixel 75,12 == 0,0,0,0;
    @assert pixel 25,37 == 0,0,0,0;
    @assert pixel 75,37 == 0,0,0,0;
  expected: clear

- name: 2d.clearRect.transform
  desc: clearRect is affected by transforms
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.scale(10, 10);
    ctx.translate(0, 5);
    ctx.clearRect(0, -5, 10, 5);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.clearRect.globalalpha
  desc: clearRect is not affected by globalAlpha
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.globalAlpha = 0.1;
    ctx.clearRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.clearRect.globalcomposite
  desc: clearRect is not affected by globalCompositeOperation
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.globalCompositeOperation = 'destination-atop';
    ctx.clearRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.clearRect.clip
  desc: clearRect is affected by clipping regions
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.beginPath();
    ctx.rect(0, 0, 16, 16);
    ctx.clip();
    ctx.clearRect(0, 0, 100, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 16, 16);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.clearRect.shadow
  desc: clearRect does not draw shadows
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.shadowColor = '#f00';
    ctx.shadowBlur = 0;
    ctx.shadowOffsetX = 0;
    ctx.shadowOffsetY = 50;
    ctx.clearRect(0, -50, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.clearRect.nonfinite
  desc: clearRect() with Infinity/NaN is ignored
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    @nonfinite ctx.clearRect(<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


- name: 2d.fillRect.basic
  desc: fillRect works
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.path
  desc: fillRect does not affect the current path
  code: |
    ctx.beginPath();
    ctx.rect(0, 0, 100, 50);
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 16, 16);
    ctx.fillStyle = '#0f0';
    ctx.fill();
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.zero
  desc: fillRect of zero pixels has no effect
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 0);
    ctx.fillRect(0, 0, 0, 50);
    ctx.fillRect(0, 0, 0, 0);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.negative
  desc: fillRect of negative sizes works
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 50, 25);
    ctx.fillRect(100, 0, -50, 25);
    ctx.fillRect(0, 50, 50, -25);
    ctx.fillRect(100, 50, -50, -25);
    @assert pixel 25,12 == 0,255,0,255;
    @assert pixel 75,12 == 0,255,0,255;
    @assert pixel 25,37 == 0,255,0,255;
    @assert pixel 75,37 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.transform
  desc: fillRect is affected by transforms
  code: |
    ctx.scale(10, 10);
    ctx.translate(0, 5);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, -5, 10, 5);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

# don't bother testing globalalpha, globalcomposite because they're already heavily used by other test cases

- name: 2d.fillRect.clip
  desc: fillRect is affected by clipping regions
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.beginPath();
    ctx.rect(0, 0, 16, 16);
    ctx.clip();
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 16, 16);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.shadow
  desc: fillRect draws shadows
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.shadowColor = '#0f0';
    ctx.shadowBlur = 0;
    ctx.shadowOffsetX = 0;
    ctx.shadowOffsetY = 50;
    ctx.fillRect(0, -50, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillRect.nonfinite
  desc: fillRect() with Infinity/NaN is ignored
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#f00';
    @nonfinite ctx.fillRect(<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


- name: 2d.strokeRect.basic
  desc: strokeRect works
  code: |
    ctx.strokeStyle = '#0f0';
    ctx.lineWidth = 50;
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.path
  desc: strokeRect does not affect the current path
  code: |
    ctx.beginPath();
    ctx.rect(0, 0, 100, 50);
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 5;
    ctx.strokeRect(0, 0, 16, 16);
    ctx.fillStyle = '#0f0';
    ctx.fill();
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.zero.1
  desc: strokeRect of 0x0 pixels draws nothing
  code: |
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 250;
    ctx.strokeRect(50, 25, 0, 0);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.strokeRect.zero.2
  desc: strokeRect of 0x0 pixels draws nothing, including caps and joins
  code: |
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 250;
    ctx.lineCap = 'round';
    ctx.lineJoin = 'round';
    ctx.strokeRect(50, 25, 0, 0);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.strokeRect.zero.3
  desc: strokeRect of Nx0 pixels draws a straight line
  code: |
    ctx.strokeStyle = '#0f0';
    ctx.lineWidth = 50;
    ctx.strokeRect(0, 25, 100, 0);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.zero.4
  desc: strokeRect of Nx0 pixels draws a closed line with no caps
  code: |
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 250;
    ctx.lineCap = 'round';
    ctx.strokeRect(100, 25, 100, 0);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.strokeRect.zero.5
  desc: strokeRect of Nx0 pixels draws a closed line with joins
  code: |
    ctx.strokeStyle = '#0f0';
    ctx.lineWidth = 250;
    ctx.lineJoin = 'round';
    ctx.strokeRect(100, 25, 100, 0);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.negative
  desc: strokeRect of negative sizes works
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.strokeStyle = '#0f0';
    ctx.lineWidth = 25;
    ctx.strokeRect(12, 12, 26, 1);
    ctx.strokeRect(88, 12, -26, 1);
    ctx.strokeRect(12, 38, 26, -1);
    ctx.strokeRect(88, 38, -26, -1);
    @assert pixel 25,12 == 0,255,0,255;
    @assert pixel 75,12 == 0,255,0,255;
    @assert pixel 25,37 == 0,255,0,255;
    @assert pixel 75,37 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.transform
  desc: fillRect is affected by transforms
  code: |
    ctx.scale(10, 10);
    ctx.translate(0, 5);
    ctx.strokeStyle = '#0f0';
    ctx.lineWidth = 5;
    ctx.strokeRect(2.5, -2.6, 5, 0.2);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.globalalpha
  desc: strokeRect is affected by globalAlpha
  code: |
    ctx.globalAlpha = 0;
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 50;
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.strokeRect.globalcomposite
  desc: strokeRect is not affected by globalCompositeOperation
  code: |
    ctx.globalCompositeOperation = 'source-in';
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 50;
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,0,0;
  expected: clear

- name: 2d.strokeRect.clip
  desc: strokeRect is affected by clipping regions
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.beginPath();
    ctx.rect(0, 0, 16, 16);
    ctx.clip();
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 50;
    ctx.strokeRect(0, 0, 100, 50);
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 16, 16);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.shadow
  desc: strokeRect draws shadows
  code: |
    ctx.fillStyle = '#f00';
    ctx.fillRect(0, 0, 100, 50);
    ctx.fillStyle = '#f00';
    ctx.shadowColor = '#0f0';
    ctx.shadowBlur = 0;
    ctx.shadowOffsetX = 0;
    ctx.shadowOffsetY = 50;
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 50;
    ctx.strokeRect(0, -75, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeRect.nonfinite
  desc: strokeRect() with Infinity/NaN is ignored
  code: |
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 100, 50);
    ctx.strokeStyle = '#f00';
    ctx.lineWidth = 150;
    @nonfinite ctx.strokeRect(<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

- name: 2d.fillStyle.colorObject
  desc: ctx.fillStyle works with color objects
  canvasType:
    ['HTMLCanvas']
  code: |
    ctx.fillStyle = {r: 1, g: 0, b: 0};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 255,0,0,255;
    ctx.fillStyle = {r: 0, g: 0, b: 1};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,255,255;
    ctx.fillStyle = {r: 0.2, g: 0.4, b: 0.6};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 51,102,153,255;
    ctx.fillStyle = {r: 0, g: 1, b: 0};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
    ctx.fillStyle = {r: -1, g: 0, b: 0};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,255;
    ctx.fillStyle = {r: 0, g: 2, b: 0};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.fillStyle.colorObject.transparency
  desc: ctx.fillStyle with color objects has transparency
  canvasType:
    ['HTMLCanvas']
  code: |
    ctx.fillStyle = {r: 0, g: 1, b: 0, a: 0};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,0;
    ctx.clearRect(0, 0, 100, 50);
    ctx.fillStyle = {r: 0, g: 1, b: 0, a: -1};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,0,0,0;
    ctx.clearRect(0, 0, 100, 50);
    ctx.fillStyle = {r: 0, g: 1, b: 0, a: 0.5};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,255,0,128;
    ctx.clearRect(0, 0, 100, 50);
    ctx.fillStyle = {r: 0, g: 1, b: 0, a: 1};
    ctx.fillRect(0, 0, 100, 50);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeStyle.colorObject
  desc: ctx.strokeStyle works with color objects
  canvasType:
    ['HTMLCanvas']
  code: |
    ctx.lineWidth = 50;
    ctx.strokeStyle = {r: 1, g: 0, b: 0};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 255,0,0,255;
    ctx.strokeStyle = {r: 0, g: 0, b: 1};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,255,255;
    ctx.strokeStyle = {r: 0.2, g: 0.4, b: 0.6};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 51,102,153,255;
    ctx.strokeStyle = {r: 0, g: 1, b: 0};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,255,0,255;
    ctx.strokeStyle = {r: -1, g: 0, b: 0};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,0,255;
    ctx.strokeStyle = {r: 0, g: 2, b: 0};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green

- name: 2d.strokeStyle.colorObject.transparency
  desc: ctx.strokeStyle with color objects has transparency
  canvasType:
    ['HTMLCanvas']
  code: |
    ctx.lineWidth = 50;
    ctx.strokeStyle = {r: 0, g: 1, b: 0, a: 0};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,0,0;
    ctx.strokeStyle = {r: 0, g: 1, b: 0, a: -1};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,0,0,0;
    ctx.clearRect(0, 0, 100, 50);
    ctx.strokeStyle = {r: 0, g: 1, b: 0, a: 0.5};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,255,0,128;
    ctx.clearRect(0, 0, 100, 50);
    ctx.strokeStyle = {r: 0, g: 1, b: 0, a: 1};
    ctx.strokeRect(25, 24, 50, 2);
    @assert pixel 50,25 == 0,255,0,255;
  expected: green