|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>CSS Conditional Test: @container stuck query parsing</title> |
| 3 | +<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#container-rule"> |
| 4 | +<script src="/resources/testharness.js"></script> |
| 5 | +<script src="/resources/testharnessreport.js"></script> |
| 6 | +<script src="/css/css-conditional/container-queries/support/cq-testcommon.js"></script> |
| 7 | +<div style="container-name:name;container-type:scroll-state"> |
| 8 | + <main id="main"></main> |
| 9 | +</div> |
| 10 | +<script> |
| 11 | + setup(() => assert_implements_container_queries()); |
| 12 | + |
| 13 | + function cleanup_main() { |
| 14 | + while (main.firstChild) |
| 15 | + main.firstChild.remove(); |
| 16 | + } |
| 17 | + |
| 18 | + function set_style(text) { |
| 19 | + let style = document.createElement('style'); |
| 20 | + style.innerText = text; |
| 21 | + main.append(style); |
| 22 | + return style; |
| 23 | + } |
| 24 | + |
| 25 | + function test_rule_valid(query) { |
| 26 | + test(t => { |
| 27 | + t.add_cleanup(cleanup_main); |
| 28 | + let style = set_style(`@container ${query} {}`); |
| 29 | + assert_equals(style.sheet.rules.length, 1); |
| 30 | + }, query); |
| 31 | + } |
| 32 | + |
| 33 | + function test_condition_invalid(condition) { |
| 34 | + test(t => { |
| 35 | + t.add_cleanup(cleanup_main); |
| 36 | + let style = set_style(`@container name ${condition} {}`); |
| 37 | + assert_equals(style.sheet.rules.length, 0); |
| 38 | + }, condition); |
| 39 | + } |
| 40 | + |
| 41 | + // Tests that 1) the condition parses, and 2) is either "unknown" or not, as |
| 42 | + // specified. |
| 43 | + function test_condition_valid(condition, unknown) { |
| 44 | + test(t => { |
| 45 | + t.add_cleanup(cleanup_main); |
| 46 | + let style = set_style(` |
| 47 | + @container name ${condition} {} |
| 48 | + @container name (${condition}) or (not (${condition})) { main { --match:true; } } |
| 49 | + `); |
| 50 | + assert_equals(style.sheet.rules.length, 2); |
| 51 | + const expected = unknown ? '' : 'true'; |
| 52 | + assert_equals(getComputedStyle(main).getPropertyValue('--match'), expected); |
| 53 | + }, condition); |
| 54 | + } |
| 55 | + |
| 56 | + function test_condition_known(condition) { |
| 57 | + test_condition_valid(condition, false /* unknown */); |
| 58 | + } |
| 59 | + |
| 60 | + function test_condition_unknown(condition) { |
| 61 | + test_condition_valid(condition, true /* unknown */); |
| 62 | + } |
| 63 | + |
| 64 | + test_condition_known('scroll-state(stuck)'); |
| 65 | + test_condition_known('scroll-state(stuck: none)'); |
| 66 | + test_condition_known('scroll-state(stuck: top)'); |
| 67 | + test_condition_known('scroll-state(stuck: left)'); |
| 68 | + test_condition_known('scroll-state(stuck: bottom)'); |
| 69 | + test_condition_known('scroll-state(stuck: right)'); |
| 70 | + test_condition_known('scroll-state(stuck: block-start)'); |
| 71 | + test_condition_known('scroll-state(stuck: block-end)'); |
| 72 | + test_condition_known('scroll-state(stuck: inline-start)'); |
| 73 | + test_condition_known('scroll-state(stuck: inline-end)'); |
| 74 | + test_condition_known('(scroll-state(stuck: top))'); |
| 75 | + test_condition_known('scroll-state((stuck: top))'); |
| 76 | + test_condition_known('scroll-state(not ((stuck: top) and (stuck: bottom)))'); |
| 77 | + test_condition_known('scroll-state((stuck: right) or (stuck: left))'); |
| 78 | + |
| 79 | + test_condition_unknown('scroll-state(stuck: auto)'); |
| 80 | + test_condition_unknown('scroll-state(stuck: true)'); |
| 81 | + test_condition_unknown('scroll-state(style(stuck: top))'); |
| 82 | + test_condition_unknown('style(scroll-state(stuck: top))'); |
| 83 | + test_condition_unknown('scroll-state(stuck:)'); |
| 84 | + test_condition_unknown('scroll-state(--foo)'); |
| 85 | +</script> |
0 commit comments