summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-images/image-set/image-set-computed.sub.html
blob: 6d54fd0d09b4ade26a254a0a9c8cb5a76097e88a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<title>Image set computed value</title>
<link rel="help" href="https://drafts.csswg.org/css-images-4/#serialization">
<link rel="help" href="https://www.w3.org/TR/cssom-1/#serializing-css-values">
<link rel="help" href="https://www.w3.org/TR/css-values-4/#canonical-unit">
<link rel="help" href="https://www.w3.org/TR/css-values-4/#resolution">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/computed-testcommon.js"></script>
<body>
<div id="target"></div>
<script>
function test_computed_value_variants(property, specified, computed) {
  if (!computed) computed = specified;
  test_computed_value(property, specified, computed);
  test_computed_value(property, "-webkit-" + specified, computed);
}

function test_calculated_resolution_units() {
  test_computed_value_variants(
    'background-image',
    "image-set(url('http://{{host}}/example.png') calc(1x * 2))",
    'image-set(url("http://{{host}}/example.png") 2dppx)'
  );

  test_computed_value_variants(
    'background-image',
    "image-set(url('http://{{host}}/example.png') calc(6dppx / 3))",
    'image-set(url("http://{{host}}/example.png") 2dppx)'
  );

  test_computed_value_variants(
    'background-image',
    "image-set(url('http://{{host}}/example.png') calc(100dpi - 4dpi))",
    'image-set(url("http://{{host}}/example.png") 1dppx)'
  );

  test_computed_value_variants(
    'background-image',
    "image-set(url('http://{{host}}/example.png') calc(37dpcm + 0.79532dpcm))",
    'image-set(url("http://{{host}}/example.png") 1dppx)'
  );
}

// The resolution unit is expected to be converted to the canonical unit 'dppx'
// for computed style.
test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 1x)", 'image-set(url("http://{{host}}/example.png") 1dppx)');
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)');
test_computed_value_variants('background-image', 'image-set(url("http://{{host}}/example.png") 1dppx)');
test_computed_value_variants('background-image', "image-set(url(http://{{host}}/example.png) 48dpi)", 'image-set(url("http://{{host}}/example.png") 0.5dppx)');
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)');
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)');
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)");
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"))');
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"))');
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"))');
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)');

// Unsupported type should still serialize.
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"))');
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"))');

test_calculated_resolution_units();
</script>