1 - name: 2d.canvas.reference
2 desc: canvas refers back to its canvas
6 @assert ctx.canvas === canvas;
9 - name: 2d.canvas.readonly
10 desc: canvas is readonly
14 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
16 @assert offscreenCanvas2 !== d;
17 ctx.canvas = offscreenCanvas2;
18 @assert ctx.canvas === d;
21 - name: 2d.getcontext.exists
22 desc: The 2D context is implemented
26 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
27 @assert offscreenCanvas2.getContext('2d') !== null;
30 - name: 2d.getcontext.extraargs.create
31 desc: The 2D context doesn't throw with extra getContext arguments (new context)
33 - context.2d.extraargs
35 @assert (new OffscreenCanvas(100, 50)).getContext('2d', false, {}, [], 1, "2") !== null;
36 @assert (new OffscreenCanvas(100, 50)).getContext('2d', 123) !== null;
37 @assert (new OffscreenCanvas(100, 50)).getContext('2d', "test") !== null;
38 @assert (new OffscreenCanvas(100, 50)).getContext('2d', undefined) !== null;
39 @assert (new OffscreenCanvas(100, 50)).getContext('2d', null) !== null;
40 @assert (new OffscreenCanvas(100, 50)).getContext('2d', Symbol.hasInstance) !== null;
43 - name: 2d.getcontext.extraargs.cache
44 desc: The 2D context doesn't throw with extra getContext arguments (cached)
46 - context.2d.extraargs
48 @assert canvas.getContext('2d', false, {}, [], 1, "2") !== null;
49 @assert canvas.getContext('2d', 123) !== null;
50 @assert canvas.getContext('2d', "test") !== null;
51 @assert canvas.getContext('2d', undefined) !== null;
52 @assert canvas.getContext('2d', null) !== null;
53 @assert canvas.getContext('2d', Symbol.hasInstance) !== null;
56 - name: 2d.getcontext.unique
57 desc: getContext('2d') returns the same object
61 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
62 @assert offscreenCanvas2.getContext('2d') === offscreenCanvas2.getContext('2d');
65 - name: 2d.getcontext.shared
66 desc: getContext('2d') returns objects which share canvas state
70 var ctx2 = canvas.getContext('2d');
71 ctx.fillStyle = '#f00';
72 ctx2.fillStyle = '#0f0';
73 ctx.fillRect(0, 0, 100, 50);
74 @assert pixel 50,25 == 0,255,0,255;
77 - name: context.emptystring
78 desc: getContext with empty string returns null
80 - context.unrecognised
82 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
83 @assert throws TypeError offscreenCanvas2.getContext("");
86 - name: context.unrecognised.badname
87 desc: getContext with unrecognised context name returns null
89 - context.unrecognised
91 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
92 @assert throws TypeError offscreenCanvas2.getContext('This is not an implemented context in any real browser');
95 - name: context.unrecognised.badsuffix
96 desc: Context name "2d" plus a suffix is unrecognised
98 - context.unrecognised
100 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
101 @assert throws TypeError offscreenCanvas2.getContext("2d#");
104 - name: context.unrecognised.nullsuffix
105 desc: Context name "2d" plus a "\0" suffix is unrecognised
107 - context.unrecognised
109 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
110 @assert throws TypeError offscreenCanvas2.getContext("2d\0");
113 - name: context.unrecognised.unicode
114 desc: Context name which kind of looks like "2d" is unrecognised
116 - context.unrecognised
118 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
119 @assert throws TypeError offscreenCanvas2.getContext("2\uFF44");
122 - name: context.casesensitive
123 desc: Context name "2D" is unrecognised; matching is case sensitive
125 - context.unrecognised
127 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
128 @assert throws TypeError offscreenCanvas2.getContext('2D');
131 - name: context.arguments.missing
135 var offscreenCanvas2 = new OffscreenCanvas(100, 50);
136 @assert throws TypeError offscreenCanvas2.getContext(); @moz-todo
140 - name: initial.color
141 desc: Initial state is transparent black
145 @assert pixel 20,20 == 0,0,0,0;
148 - name: initial.reset.different
149 desc: Changing size resets canvas to transparent black
153 ctx.fillStyle = '#f00';
154 ctx.fillRect(0, 0, 50, 50);
155 @assert pixel 20,20 == 255,0,0,255;
157 @assert pixel 20,20 == 0,0,0,0;
160 - name: initial.reset.same
161 desc: Setting size (not changing the value) resets canvas to transparent black
166 ctx.fillStyle = '#f00';
167 ctx.fillRect(0, 0, 50, 50);
168 @assert pixel 20,20 == 255,0,0,255;
170 @assert pixel 20,20 == 0,0,0,0;
173 - name: initial.reset.path
174 desc: Resetting the canvas state resets the current path
179 ctx.rect(0, 0, 100, 50);
181 ctx.fillStyle = '#f00';
183 @assert pixel 20,20 == 0,0,0,0;
186 - name: initial.reset.clip
187 desc: Resetting the canvas state resets the current clip region
192 ctx.rect(0, 0, 1, 1);
195 ctx.fillStyle = '#0f0';
196 ctx.fillRect(0, 0, 100, 50);
197 @assert pixel 20,20 == 0,255,0,255;
200 - name: initial.reset.transform
201 desc: Resetting the canvas state resets the current transformation matrix
208 ctx.fillStyle = '#0f0';
209 ctx.fillRect(0, 0, 100, 50);
210 @assert pixel 20,20 == 0,255,0,255;
213 - name: initial.reset.gradient
214 desc: Resetting the canvas state does not invalidate any existing gradients
219 var g = ctx.createLinearGradient(0, 0, 100, 0);
220 g.addColorStop(0, '#0f0');
221 g.addColorStop(1, '#0f0');
223 ctx.fillStyle = '#f00';
224 ctx.fillRect(0, 0, 100, 50);
226 ctx.fillRect(0, 0, 100, 50);
227 @assert pixel 50,25 == 0,255,0,255;
230 - name: initial.reset.pattern
231 desc: Resetting the canvas state does not invalidate any existing patterns
236 ctx.fillStyle = '#0f0';
237 ctx.fillRect(0, 0, 30, 50);
238 var p = ctx.createPattern(canvas, 'repeat-x');
240 ctx.fillStyle = '#f00';
241 ctx.fillRect(0, 0, 100, 50);
243 ctx.fillRect(0, 0, 100, 50);
244 @assert pixel 50,25 == 0,255,0,255;
247 - name: size.attributes.idl.set.zero
248 desc: Setting width/height IDL attributes to 0
255 @assert canvas.width === 0;
256 @assert canvas.height === 0;
259 - name: size.attributes.idl
260 desc: Getting/setting width/height IDL attributes
267 canvas.width = "100";
268 canvas.height = "100";
269 @assert canvas.width === 100;
270 @assert canvas.height === 100;
271 canvas.width = "+1.5e2";
272 canvas.height = "0x96";
273 @assert canvas.width === 150;
274 @assert canvas.height === 150;
275 canvas.width = 301.999;
276 canvas.height = 301.001;
277 @assert canvas.width === 301;
278 @assert canvas.height === 301;
279 @assert throws TypeError canvas.width = "400x";
280 @assert throws TypeError canvas.height = "foo";
281 @assert canvas.width === 301;
282 @assert canvas.height === 301;
285 - name: size.attributes.default
286 desc: Default width/height when attributes are missing
291 @assert canvas.width === 100;
292 @assert canvas.height === 50;
295 - name: size.attributes.reflect.setidl
296 desc: Setting IDL attributes updates IDL and content attributes
302 @assert canvas.width === 120;
303 @assert canvas.height === 60;
306 - name: size.attributes.reflect.setidlzero
307 desc: Setting IDL attributes to 0 updates IDL and content attributes
313 @assert canvas.width === 0;
314 @assert canvas.height === 0;
321 notes: Not sure how reasonable this is, but the spec doesn't say there's an upper
324 var n = 2147483647; // 2^31 - 1, which should be supported by any sensible definition of "long"
327 @assert canvas.width === n;
328 @assert canvas.height === n;
331 - name: 2d.text.setFont.mathFont
332 desc: crbug.com/1212190, make sure offscreencanvas doesn't crash with Math Font
334 - 2d.text.setFont.mathFont
336 ctx.font = "math serif";