summaryrefslogtreecommitdiffstats
path: root/dom/animation/test/style/test_composite.html
blob: 1383b1b1e6dd543dc835d4ab2416292fb69725d5 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../testcommon.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
div {
  /* Element needs geometry to be eligible for layerization */
  width: 20px;
  height: 20px;
  background-color: white;
}
</style>
<body>
<div id="log"></div>
<script>
'use strict';

if (!SpecialPowers.DOMWindowUtils.layerManagerRemote ||
    !SpecialPowers.getBoolPref(
      'layers.offmainthreadcomposition.async-animations')) {
  // If OMTA is disabled, nothing to run.
  done();
}

function waitForPaintsFlushed() {
  return new Promise(function(resolve, reject) {
    waitForAllPaintsFlushed(resolve);
  });
}

promise_test(t => {
  // Without this, the first test case fails on Android.
  return waitForDocumentLoad();
}, 'Ensure document has been loaded');

promise_test(t => {
  var div;
  return useTestRefreshMode(t).then(() => {
    div = addDiv(t, { style: 'transform: translateX(100px)' });
    div.animate({ transform: ['translateX(0px)', 'translateX(200px)'],
                  composite: 'accumulate' },
                100 * MS_PER_SEC);

    return waitForPaintsFlushed();
  }).then(() => {
    SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(50 * MS_PER_SEC);
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(1, 0, 0, 1, 200, 0)',
      'Transform value at 50%');
  });
}, 'Accumulate onto the base value');

promise_test(t => {
  var div;
  return useTestRefreshMode(t).then(() => {
    div = addDiv(t);
    div.animate({ transform: ['translateX(100px)', 'translateX(200px)'],
                  composite: 'replace' },
                100 * MS_PER_SEC);
    div.animate({ transform: ['translateX(0px)', 'translateX(100px)'],
                  composite: 'accumulate' },
                100 * MS_PER_SEC);

    return waitForPaintsFlushed();
  }).then(() => {
    SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(50 * MS_PER_SEC);
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(1, 0, 0, 1, 200, 0)',
      'Transform value at 50%');
  });
}, 'Accumulate onto an underlying animation value');

promise_test(t => {
  var div;
  return useTestRefreshMode(t).then(() => {
    div = addDiv(t, { style: 'transform: translateX(100px)' });
    div.animate([{ transform: 'translateX(100px)', composite: 'accumulate' },
                 { transform: 'translateX(300px)', composite: 'replace' }],
                100 * MS_PER_SEC);

    return waitForPaintsFlushed();
  }).then(() => {
    SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(50 * MS_PER_SEC);
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(1, 0, 0, 1, 250, 0)',
      'Transform value at 50s');
  });
}, 'Composite when mixing accumulate and replace');

promise_test(t => {
  var div;
  return useTestRefreshMode(t).then(() => {
    div = addDiv(t, { style: 'transform: translateX(100px)' });
    div.animate([{ transform: 'translateX(100px)', composite: 'replace' },
                 { transform: 'translateX(300px)' }],
                { duration: 100 * MS_PER_SEC, composite: 'accumulate' });
    return waitForPaintsFlushed();
  }).then(() => {
    SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(50 * MS_PER_SEC);
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(1, 0, 0, 1, 250, 0)',
      'Transform value at 50%');
  });
}, 'Composite specified on a keyframe overrides the composite mode of the ' +
   'effect');

promise_test(t => {
  var div;
  var anim;
  return useTestRefreshMode(t).then(() => {
    div = addDiv(t);
    div.animate({ transform: [ 'scale(2)', 'scale(2)' ] }, 100 * MS_PER_SEC);
    anim = div.animate({ transform: [ 'scale(4)', 'scale(4)' ] },
                       { duration: 100 * MS_PER_SEC, composite: 'add' });

    return waitForPaintsFlushed();
  }).then(() => {
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(8, 0, 0, 8, 0, 0)',
      'The additive scale value should be scale(8)'); // scale(2) scale(4)

    anim.effect.composite = 'accumulate';
    return waitForPaintsFlushed();
  }).then(() => {
    SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(1);
    var transform =
      SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
    assert_matrix_equals(transform, 'matrix(5, 0, 0, 5, 0, 0)',
      // (scale(2 - 1) + scale(4 - 1) + scale(1))
      'The accumulate scale value should be scale(5)');
  });
}, 'Composite operation change');

</script>
</body>