Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var testScenarios = [
// defaults
{testDescription: "Test default context creation attributes",
canvasContextAttributes: {},
expectedContextAttributes: {alpha: true, desynchronized: false, willReadFrequently: false, colorSpace: "srgb"}},
// alpha
{testDescription: "Test context creation attributes alpha: true",
canvasContextAttributes: {alpha: true},
expectedContextAttributes: {alpha: true}},
{testDescription: "Test context creation attributes alpha: false",
canvasContextAttributes: {alpha: false},
expectedContextAttributes: {alpha: false}},
// colorSpace
{testDescription: "Test context creation attributes colorSpace: 'srgb'",
canvasContextAttributes: {colorSpace: "srgb"},
expectedContextAttributes: {colorSpace: "srgb"}},
{testDescription: "Test context creation attributes colorSpace: 'display-p3'",
canvasContextAttributes: {colorSpace: "display-p3"},
expectedContextAttributes: {colorSpace: "display-p3"}},
// desynchronized
{testDescription: "Test context creation attributes desynchronized: true",
canvasContextAttributes: {desynchronized: true},
expectedContextAttributes: {desynchronized: true}},
{testDescription: "Test context creation attributes desynchronized: false",
canvasContextAttributes: {desynchronized: false},
expectedContextAttributes: {desynchronized: false}},
// willReadFrequently
{testDescription: "Test context creation attributes willReadFrequently: true",
canvasContextAttributes: {willReadFrequently: true},
expectedContextAttributes: {willReadFrequently: true}},
{testDescription: "Test context creation attributes willReadFrequently: false",
canvasContextAttributes: {willReadFrequently: false},
expectedContextAttributes: {willReadFrequently: false}},
];
function runTestScenario(canvas, testScenario) {
var t = test(function() {
var ctx = canvas.getContext('2d', testScenario.canvasContextAttributes);
var contextAttributes = ctx.getContextAttributes();
if (testScenario.expectedContextAttributes.alpha !== undefined) {
assert_equals(contextAttributes.alpha,
testScenario.expectedContextAttributes.alpha);
}
if (testScenario.expectedContextAttributes.colorSpace !== undefined) {
assert_equals(contextAttributes.colorSpace,
testScenario.expectedContextAttributes.colorSpace);
}
if (testScenario.expectedContextAttributes.desynchronized !== undefined) {
assert_equals(contextAttributes.desynchronized,
testScenario.expectedContextAttributes.desynchronized);
}
if (testScenario.expectedContextAttributes.willReadFrequently !== undefined) {
assert_equals(contextAttributes.willReadFrequently,
testScenario.expectedContextAttributes.willReadFrequently);
}
}, testScenario.testDescription);
}
function runAllTests() {
for (var i = 0; i < testScenarios.length; i++) {
runTestScenario(document.createElement('canvas'), testScenarios[i]);
}
}
runAllTests();
</script>