image-set-computed.sub.html (4743B)
1 <!DOCTYPE html> 2 <title>Image set computed value</title> 3 <link rel="help" href="https://drafts.csswg.org/css-images-4/#serialization"> 4 <link rel="help" href="https://www.w3.org/TR/cssom-1/#serializing-css-values"> 5 <link rel="help" href="https://www.w3.org/TR/css-values-4/#canonical-unit"> 6 <link rel="help" href="https://www.w3.org/TR/css-values-4/#resolution"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/css/support/computed-testcommon.js"></script> 10 <body> 11 <div id="target"></div> 12 <script> 13 function test_computed_value_variants(property, specified, computed) { 14 if (!computed) computed = specified; 15 test_computed_value(property, specified, computed); 16 test_computed_value(property, "-webkit-" + specified, computed); 17 } 18 19 function test_calculated_resolution_units() { 20 test_computed_value_variants( 21 'background-image', 22 "image-set(url('http://{{host}}/example.png') calc(1x * 2))", 23 'image-set(url("http://{{host}}/example.png") 2dppx)' 24 ); 25 26 test_computed_value_variants( 27 'background-image', 28 "image-set(url('http://{{host}}/example.png') calc(6dppx / 3))", 29 'image-set(url("http://{{host}}/example.png") 2dppx)' 30 ); 31 32 test_computed_value_variants( 33 'background-image', 34 "image-set(url('http://{{host}}/example.png') calc(100dpi - 4dpi))", 35 'image-set(url("http://{{host}}/example.png") 1dppx)' 36 ); 37 38 test_computed_value_variants( 39 'background-image', 40 "image-set(url('http://{{host}}/example.png') calc(37dpcm + 0.79532dpcm))", 41 [ 42 'image-set(url("http://{{host}}/example.png") 1dppx)', 43 'image-set(url("http://{{host}}/example.png") 1.000001dppx)' 44 ] 45 ); 46 47 test_computed_value_variants( 48 'background-image', 49 "image-set(url('http://{{host}}/example.png') calc(-1 * 1x))", 50 'image-set(url("http://{{host}}/example.png") 0dppx)' 51 ); 52 } 53 54 // The resolution unit is expected to be converted to the canonical unit 'dppx' 55 // for computed style. 56 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 1x)", 'image-set(url("http://{{host}}/example.png") 1dppx)'); 57 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 1x, 'http://{{host}}/example.png' 2x)", 'image-set(url("http://{{host}}/example.png") 1dppx, url("http://{{host}}/example.png") 2dppx)'); 58 test_computed_value_variants('background-image', 'image-set(url("http://{{host}}/example.png") 1dppx)'); 59 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 48dpi)", 'image-set(url("http://{{host}}/example.png") 0.5dppx)'); 60 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 2400dpcm, 'http://{{host}}/example.png' 2x)", 'image-set(url("http://{{host}}/example.png") 63.5dppx, url("http://{{host}}/example.png") 2dppx)'); 61 test_computed_value_variants('background-image', "image-set('http://{{host}}/example.jpeg' 240dpi, url(http://{{host}}/example.png) 3.5x)", 'image-set(url("http://{{host}}/example.jpeg") 2.5dppx, url("http://{{host}}/example.png") 3.5dppx)'); 62 test_computed_value_variants('background-image', "image-set(linear-gradient(black, white) 1x)", "image-set(linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255)) 1dppx)"); 63 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 1x type('image/png'))", 'image-set(url("http://{{host}}/example.png") 1dppx type("image/png"))'); 64 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) type('image/png'))", 'image-set(url("http://{{host}}/example.png") 1dppx type("image/png"))'); 65 test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) type('image/png') 1x)", 'image-set(url("http://{{host}}/example.png") 1dppx type("image/png"))'); 66 test_computed_value_variants('content', "image-set(url('http://{{host}}/example.png') 192dpi, linear-gradient(black, white) 1x)", 'image-set(url("http://{{host}}/example.png") 2dppx, linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255)) 1dppx)'); 67 68 // Unsupported type should still serialize. 69 test_computed_value_variants('background-image', 'image-set(url("http://{{host}}/example.png") type("image/unsupported"))', 'image-set(url("http://{{host}}/example.png") 1dppx type("image/unsupported"))'); 70 test_computed_value_variants('background-image', 'image-set(url("http://{{host}}/example.png") 2x type("image/unsupported"), url("http://{{host}}/example.png") 1x type("image/unsupported"))', 'image-set(url("http://{{host}}/example.png") 2dppx type("image/unsupported"), url("http://{{host}}/example.png") 1dppx type("image/unsupported"))'); 71 72 test_calculated_resolution_units(); 73 </script>