summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-values/getComputedStyle-calc-mixed-units-003.html
blob: fae9682b2c0088fa2de10254bf352450a5fe0b68 (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
<!DOCTYPE html>

  <meta charset="UTF-8">

  <title>CSS Values Test: computed value of calc() values using multiplication/division with mixed units</title>

  <link rel="help" href="https://www.w3.org/TR/css-values-4/#calc-computed-value">

  <meta name="flags" content="">
  <meta content="This meta-test checks for the resolution and absolutization of computed values with mixed units to 'px' when multiplication/division is used." name="assert">

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

  <style>
  html {
      font-size: 30px;
  }

  body {
      font-size: 16px;
      line-height: 1.25; /* computed value: 20px */
      width: 520px;
      height: 500px;
      margin: 20px;
  }

  div#target {
      height: 100px;
      width: 100px;
  }
  </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, "initial");
        targetElement.style.setProperty(property_name, specified_value);
        assert_equals(getComputedStyle(targetElement)[property_name], expected_value);
      }, `testing ${property_name}: ${specified_value}`);
    }

    verifyComputedStyle("width", "calc(5px * 10lh / 1px)", "1000px");
    /*
      10lh = 200px
      5px * 200px / 1px = 1000px^2 / 1px = 1000px
      Total = 1000px
    */

    verifyComputedStyle("width", "calc(20% * 0.5em / 1px)", "832px");
    /*
      20% of 520px = 104px
      0.5em = 8px
      104px * 8px / 1px = 832px^2 / 1px = 832px
      Total = 832px
    */

    verifyComputedStyle("width", "calc(4px * 4em / 1px)", "256px");
    /*
      4em = 64px
      4px * 64px / 1px = 256px^2 / 1px = 256px
      Total = 256px
    */

    verifyComputedStyle("width", "calc(400px / 4lh * 1px)", "5px");
    /*
      4lh = 80px
      400px / 80px * 1px = 5 * 1px = 5px
      Total = 5px
    */

    verifyComputedStyle("width", "calc(20% / 0.5em * 1px)", "13px");
    /*
      20% of 520px = 104px
      0.5em = 8px
      104px / 8px * 1px = 13 * 1px = 13px
      Total = 13px
    */
  }

  startTesting();

  </script>