Skip to content

Commit

Permalink
Merge 70be013 into c3c7a97
Browse files Browse the repository at this point in the history
  • Loading branch information
chromium-wpt-export-bot authored Nov 4, 2022
2 parents c3c7a97 + 70be013 commit 1254926
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion css/support/computed-testcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function test_computed_value(property, specified, computed, titleExtra) {
if (Array.isArray(computed)) {
assert_in_array(readValue, computed);
} else {
assert_equals(readValue, computed);
if (property == "color")
colorValuesAlmostEqual(readValue, computed, 0.0001);
else
assert_equals(readValue, computed);
}
if (readValue !== specified) {
target.style[property] = '';
Expand All @@ -36,6 +39,31 @@ function test_computed_value(property, specified, computed, titleExtra) {
}, `Property ${property} value '${specified}'${titleExtra ? ' ' + titleExtra : ''}`);
}

function colorValuesAlmostEqual(color1, color2, epsilon) {
// Colors can be split by spaces, commas or the '(' character.
const colorElementDividers = /( |\(|,)/;
// Return the string stripped of numbers.
function getNonNumbers(color) {
return color.replace(/[0-9]/g, '');
}
// Return an array of all numbers in the color.
function getNumbers(color) {
const result = [];
// const entries = color.split(colorElementDividers);
color.split(colorElementDividers).forEach(element => {
const numberElement = parseFloat(element);
if (!isNaN(numberElement)) {
result.push(numberElement);
}
});
return result;
}

assert_array_approx_equals(getNumbers(color1), getNumbers(color2), epsilon, "Numeric parameters are approximately equal.");
// Assert that the text of the two colors are equal. i.e. colorSpace, colorFunction and format.
assert_equals(getNonNumbers(color1), getNonNumbers(color2), "Color format is correct.");
}

function testComputedValueGreaterOrLowerThan(property, specified, expected, titleExtra) {
test(() => {
const target = document.getElementById('target');
Expand Down

0 comments on commit 1254926

Please sign in to comment.