<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#view-timeline-shorthand">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7627">
<link rel="help" href="https://github.com/w3c/csswg-drafts/pull/7694">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
<script src="/css/support/parsing-testcommon.js"></script>
<script src="/css/support/shorthand-testcommon.js"></script>
<div id="target"></div>
<script>
test_valid_value('view-timeline', '--abcd');
test_valid_value('view-timeline', 'none block', 'none');
test_valid_value('view-timeline', 'none inline');

// view-timeline-name: inline/block/x/y.
test_valid_value('view-timeline', '--inline block', '--inline');
test_valid_value('view-timeline', '--block block', '--block');
test_valid_value('view-timeline', '--y block', '--y');
test_valid_value('view-timeline', '--x block', '--x');

test_valid_value('view-timeline', '--a, --b, --c');
test_valid_value('view-timeline', '--a inline, --b block, --c y', '--a inline, --b, --c y');
test_valid_value('view-timeline', '--auto');

test_invalid_value('view-timeline', '--abc --abc');
test_invalid_value('view-timeline', 'block none');
test_invalid_value('view-timeline', 'none none');
test_invalid_value('view-timeline', 'default');
test_invalid_value('view-timeline', ',');
test_invalid_value('view-timeline', ',,--block,,');

test_computed_value('view-timeline', '--abcd');
test_computed_value('view-timeline', 'none block', 'none');
test_computed_value('view-timeline', 'none inline');
test_computed_value('view-timeline', '--inline block', '--inline');
test_computed_value('view-timeline', '--block block', '--block');
test_computed_value('view-timeline', '--y block', '--y');
test_computed_value('view-timeline', '--x block', '--x');
test_computed_value('view-timeline', '--a, --b, --c');
test_computed_value('view-timeline', '--a inline, --b block, --c y', '--a inline, --b, --c y');

test_shorthand_value('view-timeline', '--abc y',
{
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'y',
});
test_shorthand_value('view-timeline', '--abc y, --def',
{
  'view-timeline-name': '--abc, --def',
  'view-timeline-axis': 'y, block',
});
test_shorthand_value('view-timeline', '--abc, --def',
{
  'view-timeline-name': '--abc, --def',
  'view-timeline-axis': 'block, block',
});
test_shorthand_value('view-timeline', '--inline x',
{
  'view-timeline-name': '--inline',
  'view-timeline-axis': 'x',
});

function test_shorthand_contraction(shorthand, longhands, expected) {
  let longhands_fmt = Object.entries(longhands).map((e) => `${e[0]}:${e[1]}:${e[2]}`).join(';');
  test((t) => {
    t.add_cleanup(() => {
      for (let shorthand of Object.keys(longhands))
        target.style.removeProperty(shorthand);
    });
    for (let [shorthand, value] of Object.entries(longhands))
      target.style.setProperty(shorthand, value);
    assert_equals(target.style.getPropertyValue(shorthand), expected, 'Declared value');
    assert_equals(getComputedStyle(target).getPropertyValue(shorthand), expected, 'Computed value');
  }, `Shorthand contraction of ${longhands_fmt}`);
}

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--abc',
  'view-timeline-axis': 'inline',
}, '--abc inline');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, block',
}, '--a inline, --b');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': 'none, none',
  'view-timeline-axis': 'block, block',
}, 'none, none');

// Longhands with different lengths:

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b, --c',
  'view-timeline-axis': 'inline, inline',
}, '');

test_shorthand_contraction('view-timeline', {
  'view-timeline-name': '--a, --b',
  'view-timeline-axis': 'inline, inline, inline',
}, '');
</script>
