blob: 62f9ccb693c4532b64a40bed090e8f31f507d52c [file] [log] [blame]
- name: 2d.composite.globalAlpha.range
testing:
- 2d.composite.globalAlpha.range
code: |
ctx.globalAlpha = 0.5;
var a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons
ctx.globalAlpha = 1.1;
@assert ctx.globalAlpha === a;
ctx.globalAlpha = -0.1;
@assert ctx.globalAlpha === a;
ctx.globalAlpha = 0;
@assert ctx.globalAlpha === 0;
ctx.globalAlpha = 1;
@assert ctx.globalAlpha === 1;
t.done();
- name: 2d.composite.globalAlpha.invalid
testing:
- 2d.composite.globalAlpha.range
code: |
ctx.globalAlpha = 0.5;
var a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons
ctx.globalAlpha = Infinity;
@assert ctx.globalAlpha === a;
ctx.globalAlpha = -Infinity;
@assert ctx.globalAlpha === a;
ctx.globalAlpha = NaN;
@assert ctx.globalAlpha === a;
t.done();
- name: 2d.composite.globalAlpha.default
testing:
- 2d.composite.globalAlpha.default
code: |
@assert ctx.globalAlpha === 1.0;
t.done();
- name: 2d.composite.globalAlpha.fill
testing:
- 2d.composite.globalAlpha.shape
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50);
@assert pixel 50,25 ==~ 2,253,0,255;
t.done();
- name: 2d.composite.globalAlpha.image
testing:
- 2d.composite.globalAlpha.image
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
var promise = new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", '/images/red.png');
xhr.responseType = 'blob';
xhr.send();
xhr.onload = function() {
resolve(xhr.response);
};
});
promise.then(function(response) {
createImageBitmap(response).then(bitmap => {
ctx.drawImage(bitmap, 0, 0);
@assert pixel 50,25 ==~ 2,253,0,255;
}, t_fail);
}).then(t_pass, t_fail);
- name: 2d.composite.globalAlpha.canvas
testing:
- 2d.composite.globalAlpha.image
code: |
var offscreenCanvas2 = new OffscreenCanvas(100, 50);
var ctx2 = offscreenCanvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.drawImage(offscreenCanvas2, 0, 0);
@assert pixel 50,25 ==~ 2,253,0,255;
t.done();
- name: 2d.composite.globalAlpha.imagepattern
testing:
- 2d.composite.globalAlpha.image
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
var promise = new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", '/images/red.png');
xhr.responseType = 'blob';
xhr.send();
xhr.onload = function() {
resolve(xhr.response);
};
});
promise.then(function(response) {
createImageBitmap(response).then(bitmap => {
ctx.fillStyle = ctx.createPattern(bitmap, 'no-repeat');
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillRect(0, 0, 100, 50);
@assert pixel 50,25 ==~ 2,253,0,255;
}, t_fail);
}).then(t_pass, t_fail);
- name: 2d.composite.globalAlpha.canvaspattern
testing:
- 2d.composite.globalAlpha.image
code: |
var offscreenCanvas2 = new OffscreenCanvas(100, 50);
var ctx2 = offscreenCanvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = ctx.createPattern(offscreenCanvas2, 'no-repeat');
ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations
ctx.fillRect(0, 0, 100, 50);
@assert pixel 50,25 ==~ 2,253,0,255;
t.done();
- name: 2d.composite.globalAlpha.canvascopy
testing:
- 2d.composite.globalAlpha.image
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.fillRect(0, 0, 100, 50);
ctx.globalCompositeOperation = 'copy'
ctx.globalAlpha = 0.51;
ctx.drawImage(offscreenCanvas2, 0, 0);
@assert pixel 50,25 ==~ 0,255,0,130;
t.done();
- name: 2d.composite.operation.get
testing:
- 2d.composite.operation
code: |
var modes = ['source-atop', 'source-in', 'source-out', 'source-over',
'destination-atop', 'destination-in', 'destination-out', 'destination-over',
'lighter', 'copy', 'xor'];
for (var i = 0; i < modes.length; ++i)
{
ctx.globalCompositeOperation = modes[i];
@assert ctx.globalCompositeOperation === modes[i];
}
t.done();
- name: 2d.composite.operation.unrecognised
testing:
- 2d.composite.operation.unrecognised
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'nonexistent';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.darker
testing:
- 2d.composite.operation.unrecognised
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'darker';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.over
testing:
- 2d.composite.operation.unrecognised
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'over';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.clear
testing:
- 2d.composite.operation.clear
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'clear';
@assert ctx.globalCompositeOperation === 'clear';
t.done();
- name: 2d.composite.operation.highlight
testing:
- 2d.composite.operation.unrecognised
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'highlight';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.nullsuffix
testing:
- 2d.composite.operation.exact
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'source-over\0';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.casesensitive
testing:
- 2d.composite.operation.casesensitive
code: |
ctx.globalCompositeOperation = 'xor';
ctx.globalCompositeOperation = 'Source-over';
@assert ctx.globalCompositeOperation === 'xor';
t.done();
- name: 2d.composite.operation.default
testing:
- 2d.composite.operation.default
code: |
@assert ctx.globalCompositeOperation === 'source-over';
t.done();