<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Color Level 6: Parsing and serialization of colors using valid 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="color-contrast() parses and serializes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
    // Test with no specified target contrast
    test_valid_value(`color`, `color-contrast(white vs red, blue)`, `rgb(0, 0, 255)`);
    test_valid_value(`color`, `color-contrast(white vs blue, red)`, `rgb(0, 0, 255)`);
    test_valid_value(`color`, `color-contrast(white vs red, blue, green)`, `rgb(0, 0, 255)`);
    test_valid_value(`color`, `color-contrast(white vs white, white)`, `rgb(255, 255, 255)`);
    test_valid_value(`color`, `color-contrast(blue vs red, white)`, `rgb(255, 255, 255)`);
    test_valid_value(`color`, `color-contrast(red vs blue, white, red)`, `rgb(255, 255, 255)`);
    test_valid_value(`color`, `color-contrast(black vs red, blue)`, `rgb(255, 0, 0)`);
    test_valid_value(`color`, `color-contrast(black vs blue, red)`, `rgb(255, 0, 0)`);
    test_valid_value(`color`, `color-contrast(black vs white, white)`, `rgb(255, 255, 255)`);
    test_valid_value(`color`, `color-contrast(red vs blue, rgb(255, 255, 255, .5))`, `rgba(255, 255, 255, 0.5)`);

    // Test with specified target contrast.
    test_valid_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)`, `rgb(0, 100, 0)`); // darkgreen
    test_valid_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA-large)`, `rgb(128, 128, 0)`); // olive
    test_valid_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA)`, `rgb(128, 0, 0)`); // maroon
    test_valid_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA-large)`, `rgb(0, 100, 0)`); // darkgreen
    test_valid_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_valid_value(`color`, `color-contrast(wheat vs bisque, darkgoldenrod, olive to 100)`, `rgb(0, 0, 0)`); // black
    test_valid_value(`color`, `color-contrast(green vs bisque, darkgoldenrod, olive to 100)`, `rgb(255, 255, 255)`); // white

    // Test non-sRGB colors.
    test_valid_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_valid_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_valid_value(`color`, `color-contrast(green vs lab(50% -160 160), lch(0.2 50 20deg))`, `lch(0.2 50 20)`);
    test_valid_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_valid_value(`color`, `color-contrast( white vs red, blue )`, `rgb(0, 0, 255)`);
</script>
</body>
</html>
