tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

font-shorthand-serialization-prevention.html (5290B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>CSS Test: font shorthand serialization prevention for font subproperty values the shorthand cannot express</title>
      4 <link rel="help" href="https://drafts.csswg.org/css-fonts-4/#propdef-font">
      5 <link rel="help" href="https://drafts.csswg.org/cssom-1/#serializing-css-values">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <div id="test"></div>
      9 <script>
     10 
     11 function is_property_supported(property) {
     12  const element = document.getElementById('test')
     13  element.style = ''
     14  element.style = property + ': initial'
     15  return element.style[property] == 'initial'
     16 }
     17 
     18 function overwrite_font_shorthand(property, value) {
     19  const element = document.getElementById('test')
     20  element.style = ''
     21  element.style.font = '16px serif'
     22  element.style[property] = value
     23 }
     24 
     25 function test_font_shorthand_specified_serializable_after_setting_subproperty(property, value) {
     26  test(() => {
     27    overwrite_font_shorthand(property, value)
     28    assert_not_equals(document.getElementById('test').style.font, '')
     29  }, 'Setting ' + property + ' to ' + value + ' should not prevent the font shorthand from serializing in specified style')
     30 }
     31 
     32 function test_font_shorthand_computed_serializable_after_setting_subproperty(property, value) {
     33  test(() => {
     34    overwrite_font_shorthand(property, value)
     35    assert_not_equals(getComputedStyle(document.getElementById('test')).font, '')
     36  }, 'Setting ' + property + ' to ' + value + ' should not prevent the font shorthand from serializing in computed style')
     37 }
     38 
     39 function test_font_shorthand_specified_unserializable_after_setting_subproperty(property, value) {
     40  test(() => {
     41    overwrite_font_shorthand(property, value)
     42    assert_equals(document.getElementById('test').style.font, '')
     43  }, 'Setting ' + property + ' to ' + value + ' should prevent the font shorthand from serializing in specified style')
     44 }
     45 
     46 function test_font_shorthand_computed_unserializable_after_setting_subproperty(property, value) {
     47  test(() => {
     48    overwrite_font_shorthand(property, value)
     49    assert_equals(getComputedStyle(document.getElementById('test')).font, '')
     50  }, 'Setting ' + property + ' to ' + value + ' should prevent the font shorthand from serializing in computed style')
     51 }
     52 
     53 function test_font_shorthand_serializable_after_setting_subproperty(property, value) {
     54  test_font_shorthand_specified_serializable_after_setting_subproperty(property, value)
     55  test_font_shorthand_computed_serializable_after_setting_subproperty(property, value)
     56 }
     57 
     58 function test_font_shorthand_unserializable_after_setting_subproperty(property, value) {
     59  test_font_shorthand_specified_unserializable_after_setting_subproperty(property, value)
     60  test_font_shorthand_computed_unserializable_after_setting_subproperty(property, value)
     61 }
     62 
     63 function test_font_shorthand_serialization_after_setting_subproperty(property, defaultValue, otherValue) {
     64  if (!is_property_supported(property))
     65    return
     66  const keywords = [ 'initial', 'inherit', 'unset', 'revert', 'revert-layer' ]
     67  keywords.forEach(keyword => {
     68      test_font_shorthand_specified_unserializable_after_setting_subproperty(property, keyword)
     69      test_font_shorthand_computed_serializable_after_setting_subproperty(property, keyword)
     70    });
     71  test_font_shorthand_serializable_after_setting_subproperty(property, defaultValue)
     72  test_font_shorthand_unserializable_after_setting_subproperty(property, otherValue)
     73 }
     74 
     75 test_font_shorthand_serializable_after_setting_subproperty('font-family', 'sans-serif')
     76 
     77 test_font_shorthand_serialization_after_setting_subproperty('font-variant', 'normal', 'none')
     78 test_font_shorthand_serializable_after_setting_subproperty('font-variant', 'small-caps')
     79 test_font_shorthand_unserializable_after_setting_subproperty('font-variant', 'all-small-caps')
     80 
     81 test_font_shorthand_serialization_after_setting_subproperty('font-variant-caps', 'small-caps', 'all-small-caps')
     82 test_font_shorthand_serialization_after_setting_subproperty('font-stretch', 'normal', '95%')
     83 test_font_shorthand_serialization_after_setting_subproperty('font-size-adjust', 'none', '0')
     84 test_font_shorthand_serialization_after_setting_subproperty('font-kerning', 'auto', 'normal')
     85 test_font_shorthand_serialization_after_setting_subproperty('font-variant-ligatures', 'normal', 'none')
     86 test_font_shorthand_serialization_after_setting_subproperty('font-variant-position', 'normal', 'sub')
     87 test_font_shorthand_serialization_after_setting_subproperty('font-variant-numeric', 'normal', 'ordinal')
     88 test_font_shorthand_serialization_after_setting_subproperty('font-variant-alternates', 'normal', 'historical-forms')
     89 test_font_shorthand_serialization_after_setting_subproperty('font-variant-east-asian', 'normal', 'full-width')
     90 test_font_shorthand_serialization_after_setting_subproperty('font-variant-emoji', 'normal', 'text')
     91 test_font_shorthand_serialization_after_setting_subproperty('font-feature-settings', 'normal', '"sinf"')
     92 test_font_shorthand_serialization_after_setting_subproperty('font-language-override', 'normal', '"SRB"')
     93 test_font_shorthand_serialization_after_setting_subproperty('font-optical-sizing', 'auto', 'none')
     94 test_font_shorthand_serialization_after_setting_subproperty('font-variation-settings', 'normal', '"aaaa" 1')
     95 
     96 </script>