Skip to content

Commit

Permalink
CanvasRenderingContext2DSettings: follow the spec types
Browse files Browse the repository at this point in the history
The type for willReadFrequently is boolean, not an enum with values of
"true", "false", and "undefined".

Add WPT tests for this. And for the rest of the attributes.

The WPT tests failed for the desynchronized property because, when
it was discovered that this feature was never implemented on macOS,
it was disabled at compile time, when parsing the input from V8,
losing the information required to correctly implement
getContextAttributes. Add a temporary workaround for this situation
by separately storing the specified desynchronized value.

Bug: 388290815
Change-Id: I00e6b6c82a23cdb627a3eba1314ebf3b0f9abf9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6157723
Reviewed-by: Yi Xu <yiyix@chromium.org>
Commit-Queue: ccameron chromium <ccameron@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1404356}
  • Loading branch information
ccameron-chromium authored and chromium-wpt-export-bot committed Jan 9, 2025
1 parent 0c50f7d commit d431fd4
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,67 @@
<script>

var testScenarios = [
// defaults
{testDescription: "Test default context creation attributes",
canvasContextAttributes: {},
expectedContextAttributes: {alpha: true, desynchronized: false, willReadFrequently: false}},
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(testScenario) {
function runTestScenario(canvas, testScenario) {
var t = test(function() {
var canvas = document. createElement('canvas');
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(testScenarios[i]);
for (var i = 0; i < testScenarios.length; i++) {
runTestScenario(document.createElement('canvas'), testScenarios[i]);
}
}

runAllTests();
Expand Down

0 comments on commit d431fd4

Please sign in to comment.