summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-values/getComputedStyle-calc-mixed-units-001.html
blob: a44b70ab472e52c464a8a624c811841480c73fe3 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>

  <meta charset="UTF-8">

  <title>CSS Values Test: computed value of 3 calc() values</title>


  <!--
  "
  Where percentages are not resolved at computed-value time,
  they are not resolved in math functions, e.g.
  'calc(100% - 100% + 1px)' resolves to 'calc(0% + 1px)', not to
  '1px'. If there are special rules for computing percentages
  in a value (e.g. the 'height' property), they apply whenever
  a math function contains percentages.
  "
  § 10.11 Computed Value
  https://www.w3.org/TR/css-values-4/#calc-computed-value
  -->

  <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
  <link rel="help" href="https://www.w3.org/TR/css-values-4/#calc-computed-value">

  <meta name="flags" content="">
  <meta content="This test verifies that terms with a percentage unit that can not be resolved at computed-value time will require a calc() wrapper. A term with an em value, on the other hand, must be resolved at computed-value time and therefore must be absolutized to 'px'." name="assert">

  <script src="/resources/testharness.js"></script>

  <script src="/resources/testharnessreport.js"></script>

  <style>
  html, body
    {
      font-size: 16px;
      height: 570px;
    }

  div#target
    {
      background-color: yellow;
      background-image: url("support/cat.png");
      background-position: top center;
      background-repeat: no-repeat;
      background-size: 14% 50%; /* entirely arbitrary and random background-size values */
      height: 200px;
    }
  </style>

  <div id="target"></div>

  <script>
  function startTesting()
  {

  var targetElement = document.getElementById("target");

    function verifyComputedStyle(property_name, specified_value, expected_value)
    {

    test(function()
      {

      targetElement.style.setProperty(property_name, specified_value);

      assert_equals(getComputedStyle(targetElement)[property_name], expected_value);

      }, `testing ${property_name}: ${specified_value}`);
    }

    verifyComputedStyle("background-size", "calc(67% - 54% + 4em) 50%", "calc(13% + 64px) 50%");

    /*
    "Where percentages are not resolved at computed-value time,
    they are not resolved in math functions (...)"
    https://www.w3.org/TR/css-values-4/#calc-serialize

    Therefore here, the percentage is preserved and
    a calc() wrapper must be used. The 4em term
    must be resolved though.
    */

    verifyComputedStyle("background-position", "calc(100% - 100% + 20em)", "calc(0% + 320px) 50%");

    /*
    Here too, the percentage is preserved and
    a calc() wrapper must be used. The 20em term
    must be resolved though.
    */


    verifyComputedStyle("height", "calc(60% - 50% + 3em)", "105px");

    /*

    The height of the containing block of div#target is not auto.
    So, such percentage can and must be resolved at
    computed-value time.

     570px mult 10% == 57px

                 +     48px
                 ============
                      105px

    */
  }

  startTesting();

  </script>