summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-color/parsing/color-computed-color-contrast-function.html
blob: 74be5ced3748dcaa9b86d99938390cd7de122de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 6: Computation of colors using color-contrast() function syntax</title>
<link rel="author" title="Sam Weinig" href="mailto:weinig@apple.com">
<link rel="help" href="https://drafts.csswg.org/css-color-6/#colorcontrast">
<link rel="help" href="https://drafts.csswg.org/css-color-6/#resolving-contrast">
<link rel="help" href="https://drafts.csswg.org/css-color-6/#serial-color-contrast">
<meta name="assert" content="computed value of color-contrast() matches expected values">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
</head>
<body>
<div id="target"></div>
<script>
    // Test with no specified target contrast
    test_computed_value(`color`, `color-contrast(white vs red, blue)`, `rgb(0, 0, 255)`);
    test_computed_value(`color`, `color-contrast(white vs blue, red)`, `rgb(0, 0, 255)`);
    test_computed_value(`color`, `color-contrast(white vs red, blue, green)`, `rgb(0, 0, 255)`);
    test_computed_value(`color`, `color-contrast(white vs white, white)`, `rgb(255, 255, 255)`);
    test_computed_value(`color`, `color-contrast(blue vs red, white)`, `rgb(255, 255, 255)`);
    test_computed_value(`color`, `color-contrast(red vs blue, white, red)`, `rgb(255, 255, 255)`);
    test_computed_value(`color`, `color-contrast(black vs red, blue)`, `rgb(255, 0, 0)`);
    test_computed_value(`color`, `color-contrast(black vs blue, red)`, `rgb(255, 0, 0)`);
    test_computed_value(`color`, `color-contrast(black vs white, white)`, `rgb(255, 255, 255)`);
    test_computed_value(`color`, `color-contrast(red vs blue, rgb(255, 255, 255, .5))`, `rgba(255, 255, 255, 0.5)`);

    // Test with specified target contrast.
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)`, `rgb(0, 100, 0)`); // darkgreen
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA-large)`, `rgb(128, 128, 0)`); // olive
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA)`, `rgb(128, 0, 0)`); // maroon
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA-large)`, `rgb(0, 100, 0)`); // darkgreen
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)`, `rgb(128, 0, 0)`); // maroon

    // Test with specified target contrast that none meet.
    test_computed_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive to 100)`, `rgb(0, 0, 0)`); // black
    test_computed_value(`color`, `color-contrast(green vs bisque, darkgoldenrod, olive to 100)`, `rgb(255, 255, 255)`); // white

    // Test non-sRGB colors.
    test_computed_value(`color`, `color-contrast(green vs color(display-p3 0 1 0), color(display-p3 0 0 1))`, `color(display-p3 0 1 0)`);
    test_computed_value(`color`, `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)`);
    test_computed_value(`color`, `color-contrast(green vs lab(50% -160 160), lch(0.2 50 20deg))`, `lch(0.2 50 20)`);
    test_computed_value(`color`, `color-contrast(lab(50% -160 160) vs green, lch(0.2 50 20deg))`, `lch(0.2 50 20)`);

    // Test with extra whitespace
    test_computed_value(`color`, `color-contrast( white vs red, blue )`, `rgb(0, 0, 255)`);
</script>
</body>
</html>