summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/chrome/test_will_change.html
blob: fb8122b0bbca3ab3aeb5d2435f2d1956d6d92e88 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Tests for MozAfterPaint</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script>
  <style>
    #checkOpacityRepaint {
      will-change: opacity;
    }
    #checkTransformRepaint {
      will-change: transform;
    }
    div {
      width: 100px;
      height: 100px;
      background: radial-gradient(ellipse at center, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
    }
  </style>
</head>
<body>
  <div id="checkRepaint">
    Check repaint without will-change
  </div>
  <div id="checkOpacityRepaint">
    Check repaint with will-change
  </div>
  <div id="checkTransformRepaint">
    Check repaint with will-change
  </div>
</body>
<script>

var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
              getInterface(Components.interfaces.nsIDOMWindowUtils);

var initialPaintCount = 0;

function test_checkRepaint(next) {
  var element = document.getElementById("checkRepaint");
  waitForAllPaintsFlushed(function () {
    utils.checkAndClearPaintedState(element);
    element.style.opacity = "0.5";
    waitForAllPaintsFlushed(function () {
      var painted = utils.checkAndClearPaintedState(element);
      // *** We check that this repaints because the test is relying
      //     on this property. If this is broken then this test wont
      //     be reliable check for will-change.
      is(painted, true, "element should have been painted");
      next();
    });
  });
}

function test_checkOpacityRepaint(next) {
  var element = document.getElementById("checkOpacityRepaint");
  waitForAllPaintsFlushed(function () {
    utils.checkAndClearPaintedState(element);
    element.style.opacity = "0.5";
    waitForAllPaintsFlushed(function () {
      var painted = utils.checkAndClearPaintedState(element);
      // BasicLayers' heuristics are so that even with will-change:opacity,
      // we can still have repaints.
      if (utils.layerManagerType != "Basic") {
        is(painted, false, "will-change checkOpacityRepaint element should not have been painted");
      }
      next();
    });
  });
}

function test_checkTransformRepaint(next) {
  var element = document.getElementById("checkTransformRepaint");
  waitForAllPaintsFlushed(function () {
    utils.checkAndClearPaintedState(element);
    element.style.transform = "translateY(-5px)";
    waitForAllPaintsFlushed(function () {
      var painted = utils.checkAndClearPaintedState(element);
      // BasicLayers' heuristics are so that even with will-change:transform,
      // we can still have repaints.
      if (utils.layerManagerType != "Basic") {
        is(painted, false, "will-change checkTransformRepaint element should not have been painted");
      }
      next();
    });
  });
}

SimpleTest.waitForExplicitFinish();
test_checkRepaint(function(){
  test_checkOpacityRepaint(function(){
    test_checkTransformRepaint(function(){
      SimpleTest.finish();
    });
  });
});

</script>
</html>