summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-view-transitions/pseudo-rendering-invalidation.html
blob: 55a9d5d373ea7042b5af5b64ab8aca380cb93197 (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
<!DOCTYPE html>
<html class=reftest-wait>
<title>View transitions: invalidating VT pseudo elements renders correctly</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:bokan@chromium.org">
<link rel="match" href="pseudo-rendering-invalidation-ref.html">
<meta name="fuzzy" content="pseudo-rendering-invalidation-ref.html:0-20;0-300">

<script src="/common/reftest-wait.js"></script>
<style>
:root {
  view-transition-name: none;
  background-color: red;
}

div {
  position: absolute;
  left: 0px;
  top: 600px;
  width: 100px;
  height: 100px;

  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;

  background: darkseagreen;
}

::view-transition-group(*) {
  animation-duration: 50s;
}

::view-transition {
  background-color: limegreen;
}

::view-transition-new(new) {
  animation: none;
  opacity: 1;
}
::view-transition-old(new) {
  animation: none;
  opacity: 0;
}

::view-transition-new(old) {
  animation: none;
  opacity: 0;
}
::view-transition-old(old) {
  animation: none;
  opacity: 1;
}

.invalidateRoot::view-transition {
  /* Making view-transition `display: none` will abort the transition. Changing
     it to position: static (at least in Chrome) will cause it to rebuild its
     layout tree. */
  position: static;
}

.invalidateGroup::view-transition-group(group) {
  display: none;
}

.invalidateImagePair::view-transition-image-pair(imagepair) {
  display: none;
}

.invalidateNew::view-transition-new(new) {
  display: none;
}

.invalidateOld::view-transition-old(old) {
  display: none;
}

</style>

<div style="left: 0px; top: 100px; view-transition-name:group;">Group</div>
<div style="left: 150px; top: 100px; view-transition-name:imagepair;">Image-Pair</div>
<div style="left: 0px; top: 250px; view-transition-name:old;">Old</div>
<div style="left: 150px; top: 250px; view-transition-name:new;">New</div>

<script>
failIfNot(document.startViewTransition, "Missing document.startViewTransition");

async function rAF() {
  return new Promise(resolve => requestAnimationFrame(resolve));
}

async function performInvalidations() {
  await rAF();
  await rAF();

  const docClassList = document.documentElement.classList;
  const classNames = [
      'invalidateRoot',       // Invalidates ::view-transition
      'invalidateGroup',      // Invalidates ::view-transition-group
      'invalidateImagePair',  // Invalidates ::view-transition-image-pair
      'invalidateOld',        // Invalidates ::view-transition-old
      'invalidateNew'         // Invalidates ::view-transition-new
  ];

  for (let className of classNames) {
    document.documentElement.classList.add(className);
    await rAF();
    document.documentElement.classList.remove(className);
    await rAF();
  }
}

// This test ensures each of the view-transition pseudos is able to be
// individually recreated after becoming display: none.
async function runTest() {
  let transition = document.startViewTransition();
  await transition.ready;
  await performInvalidations();
  takeScreenshot();
}

onload = () => requestAnimationFrame(() => requestAnimationFrame(runTest));
</script>