| <!doctype html> | |
| <title>CSS Container Queries: @container serialization</title> | |
| <link rel="help" href="https://drafts.csswg.org/css-conditional-5/#container-queries"> | |
| <link rel="help" href="https://drafts.csswg.org/cssom/#serialize-a-css-rule"> | |
| <script src="/resources/testharness.js"></script> | |
| <script src="/resources/testharnessreport.js"></script> | |
| <script src="support/cq-testcommon.js"></script> | |
| <style id="testSheet"> | |
| @container (width=100px) { | |
| @container \!-name (inline-size > 200px ) { | |
| #id { color: lime } | |
| } | |
| #id { color: green } | |
| } | |
| </style> | |
| <main id="cq-main"></main> | |
| <script> | |
| setup(() => assert_implements_size_container_queries()); | |
| const rules = testSheet.sheet.cssRules; | |
| test(() => { | |
| assert_equals(rules.length, 1); | |
| assert_equals(rules[0].cssRules.length, 2); | |
| assert_equals(rules[0].conditionText, "(width = 100px)"); | |
| assert_equals(rules[0].cssRules[0].conditionText, "\\!-name (inline-size > 200px)"); | |
| }, "Serialization of conditionText"); | |
| test(() => { | |
| assert_equals(rules[0].cssRules[0].cssText, "@container \\!-name (inline-size > 200px) {\n #id { color: lime; }\n}"); | |
| }, "Serialization of inner @container rule"); | |
| test(() => { | |
| assert_equals(rules[0].cssText, "@container (width = 100px) {\n @container \\!-name (inline-size > 200px) {\n #id { color: lime; }\n}\n #id { color: green; }\n}"); | |
| }, "Serialization of nested @container rule"); | |
| const testCases = [ | |
| ["( wiDTh )", "(width)"], | |
| ["(width:100px)", "(width: 100px)"], | |
| ["(min-width: 100px)", "(min-width: 100px)"], | |
| ["( MAX-WIDTH:100px )", "(max-width: 100px)"], | |
| ["(width > 100px)", "(width > 100px)"], | |
| ["(width < 100px)", "(width < 100px)"], | |
| ["(widTH >= 100px)", "(width >= 100px)"], | |
| ["(width <= 100px)", "(width <= 100px)"], | |
| ["(10px < width < 100px)", "(10px < width < 100px)"], | |
| ["(10px <= width <= 100px)", "(10px <= width <= 100px)"], | |
| ["(100px>WIDTH>10px)", "(100px > width > 10px)"], | |
| ["( 100px >= width >= 10px )", "(100px >= width >= 10px)"], | |
| ["(calc(1em + 1px) >= width >= max(10em, 10px))", "(calc(1em + 1px) >= width >= max(10em, 10px))"], | |
| ["(width),(height) ,--foo ,--bar", "(width), (height), --foo, --bar"], | |
| ]; | |
| for (testCase of testCases) { | |
| test_cq_condition_serialization(testCase[0], testCase[1]); | |
| } | |
| </script> |