summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-transforms/2d-transform-inline-js.html
blob: 0c842ddd66fc948de7b4680e01961939d219c02a (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
<!DOCTYPE html>
<html>
  <head>
    <title>JS test: Inline renderer must return the correct computed transform</title>
    <link rel="author" title="Joone Hur" href="https://joone.github.io">
    <link rel="help" href="https://drafts.csswg.org/css-transforms-1/#serialization-of-the-computed-value">
    <link rel="help" href="https://drafts.csswg.org/css-transforms-1/#serialization-of-transform-functions">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <meta name="assert" content="Asserting that you can apply transform to an inline element and it show up in CSS computed values as a matrix">
    <style>
      .container {
      height: 100px;
      width: 200px;
      margin: 30px;
      outline: 1px solid black;
    }
    .box {
      height: 100%;
      width: 100%;
      padding: 5px;
      margin: 5px;
      border: 5px solid gray;
      transform-origin: 20% 50%;
    }
    #test-div {
      background-color: blue;
    }

    #test-span {
      background-color: red;
    }
    </style>

  </head>
  <body>
    <h1>Transform values should be indentical between
      the blue box(block element) and red box(inline element) </h1>
    <div class="container">
      <div id="test-div" class="box"></div>
    </div>
    <span id="test-span" class="box"></span>
    <script>
      const testCases = [
        { 'transform' : 'translate(80px, 90px)',  'result' : 'matrix(1, 0, 0, 1, 80, 90)' },
        { 'transform' : 'scale(1.2, 0.8)',        'result' : 'matrix(1.2, 0, 0, 0.8, 0, 0)' },
        { 'transform' : 'skew(-0.7rad, 20deg)',   'result' : 'matrix(1, 0.36397, -0.842288, 1, 0, 0)' },
        { 'transform' : 'rotate(45deg)',          'result' : 'matrix(0.707107, 0.707107, -0.707107, 0.707107, 0, 0)' },
      ];

      test(function() {
        var testBox = document.getElementById('test-div');
        var testSpan = document.getElementById('test-span');

        testCases.forEach(function(curTest) {
          // set one of our test transforms
          testBox.style.transform = curTest.transform;
          testSpan.style.transform = curTest.transform;

          // read back computed style
          var computedTransform = window.getComputedStyle(testBox).transform;
          var computedSpanTransform = window.getComputedStyle(testSpan).transform;

          assert_equals(computedTransform, curTest.result);
          assert_equals(computedSpanTransform, curTest.result);
        });
      });
    </script>
  </body>
</html>