summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-transitions/animations/color-transition-premultiplied.html
blob: 745e6c0c735da728a948120fc9417ff67c639df0 (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>transition from transparent background</title>
  <link rel="help" href="https://www.w3.org/TR/css-color-4/#interpolation-alpha">
  <style>
    .box {
      width: 100px;
      height: 100px;
      margin: 10px;
      border: 1px solid black;
      transition: background-color 1s linear;
    }

    #one {
      background-color: transparent;
    }

    #one.changed {
      background-color: green;
    }

    #two {
      background-color: rgba(0, 255, 0, 0);
    }

    #two.changed {
      background-color: rgba(0, 0, 255, 1);
    }
  </style>
</head>
<body>
  <div class="box" id="one"></div>
  <div class="box" id="two"></div>
</body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/css-transitions/support/helper.js"></script>
<script type="text/javascript">

promise_test(async t => {
  // Make sure we have rendered the page before making the style change
  // to ensure we get transitions.
  await waitForAnimationFrames(2);
  promises = [];

  const elem1 = document.getElementById('one');
  const elem2 = document.getElementById('two');
  elem1.classList.add('changed');
  elem2.classList.add('changed');

  document.getAnimations().forEach(anim => {
    anim.pause();
    anim.currentTime = 500;
    promises.push(anim.ready);
  });

  Promise.all(promises).then(() => {
    assert_equals(promises.length, 2, 'Unexpected animation count');
    assert_equals(getComputedStyle(elem1).backgroundColor,
                  'rgba(0, 128, 0, 0.5)');
    assert_equals(getComputedStyle(elem2).backgroundColor,
                  'rgba(0, 0, 255, 0.5)');
  });
}, 'Transition from transparent background');

</script>
</html>