85 lines
4.0 KiB
HTML
85 lines
4.0 KiB
HTML
<!DOCTYPE html><!-- webkit-test-runner [ CSSColorContrastEnabled=true ] -->
|
|
<html>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
description("Test the parsing of CSS Color 5 color-contrast().");
|
|
|
|
function computedStyle(property, value)
|
|
{
|
|
var div = document.createElement("div");
|
|
document.body.appendChild(div);
|
|
div.style.setProperty(property, value);
|
|
var computedValue = getComputedStyle(div).getPropertyValue(property);
|
|
document.body.removeChild(div);
|
|
return computedValue;
|
|
}
|
|
|
|
function testComputedProperty(property, value, expected)
|
|
{
|
|
shouldBeEqualToString('computedStyle("' + property + '", "' + value + '")', expected);
|
|
}
|
|
|
|
function testComputed(value, expected)
|
|
{
|
|
testComputedProperty("background-color", value, expected);
|
|
}
|
|
|
|
debug('color-contrast(... vs ..., ... [to ...])');
|
|
|
|
debug('');
|
|
debug('Test with no specified target contrast')
|
|
|
|
testComputed(`color-contrast(white vs red, blue)`, `rgb(0, 0, 255)`);
|
|
testComputed(`color-contrast(white vs blue, red)`, `rgb(0, 0, 255)`);
|
|
testComputed(`color-contrast(white vs red, blue, green)`, `rgb(0, 0, 255)`);
|
|
testComputed(`color-contrast(white vs white, white)`, `rgb(255, 255, 255)`);
|
|
testComputed(`color-contrast(blue vs red, white)`, `rgb(255, 255, 255)`);
|
|
testComputed(`color-contrast(red vs blue, white, red)`, `rgb(255, 255, 255)`);
|
|
testComputed(`color-contrast(black vs red, blue)`, `rgb(255, 0, 0)`);
|
|
testComputed(`color-contrast(black vs blue, red)`, `rgb(255, 0, 0)`);
|
|
testComputed(`color-contrast(black vs white, white)`, `rgb(255, 255, 255)`);
|
|
testComputed(`color-contrast(red vs blue, rgb(255, 255, 255, .5))`, `rgba(255, 255, 255, 0.5)`);
|
|
|
|
debug('');
|
|
debug('Test with specified target contrast')
|
|
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)`, `rgb(0, 100, 0)`); // darkgreen
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA-large)`, `rgb(128, 128, 0)`); // olive
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA)`, `rgb(128, 0, 0)`); // maroon
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA-large)`, `rgb(0, 100, 0)`); // darkgreen
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)`, `rgb(128, 0, 0)`); // maroon
|
|
|
|
debug('');
|
|
debug('Test with specified target contrast that none meet')
|
|
testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive to 100)`, `rgb(0, 0, 0)`); // black
|
|
testComputed(`color-contrast(green vs bisque, darkgoldenrod, olive to 100)`, `rgb(255, 255, 255)`); // white
|
|
|
|
|
|
debug('');
|
|
debug('Test non-sRGB colors');
|
|
|
|
testComputed(`color-contrast(green vs color(display-p3 0 1 0), color(display-p3 0 0 1))`, `color(display-p3 0 1 0)`);
|
|
testComputed(`color-contrast(color(display-p3 1 1 0) vs color(display-p3 0 1 0), color(display-p3 0 0 1))`, `color(display-p3 0 0 1)`);
|
|
testComputed(`color-contrast(green vs lab(50% -160 160), lch(20% 50 20deg))`, `lch(20% 50 20)`);
|
|
testComputed(`color-contrast(lab(50% -160 160) vs green, lch(20% 50 20deg))`, `lch(20% 50 20)`);
|
|
|
|
debug('');
|
|
debug('Test invalid values');
|
|
|
|
testComputed(`color-contrast(white vs red)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs red,)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs )`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs red green)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs red, green to)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs red, green to invalid)`, `rgba(0, 0, 0, 0)`);
|
|
testComputed(`color-contrast(white vs red to AA)`, `rgba(0, 0, 0, 0)`);
|
|
|
|
</script>
|
|
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
</body>
|
|
</html>
|