summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-view-transitions/only-child-new.html
blob: a03e0454f55abbd5bf56beeb3d9f9544c0be50a0 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-new</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
  background-color: black;
}
html:only-child {
  background-color: black;
}
:root:only-child {
  background-color: black;
}
:only-child {
  background-color: black;
}
.foo:only-child {
  background-color: black;
}

::view-transition-new(root) {
  background-color: blue;
}
::view-transition-new(target) {
  background-color: blue;
}
::view-transition-new(*) {
  color: blue;
}

::view-transition-new(root):only-child {
  background-color: red;
}
::view-transition-new(target):only-child {
  background-color: red;
}
::view-transition-new(*):only-child {
  color: red;
}

</style>
<div id="target"></div>

<script>
let matchedColor = "rgb(255, 0, 0)";
let notMatchedColor = "rgb(0, 0, 255)";

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    document.documentElement.style.viewTransitionName = "none";
    target.style.viewTransitionName = "none";
    let transition = document.startViewTransition(() => {
      document.documentElement.style.viewTransitionName = "root";
    });

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(root)");
      if (style.backgroundColor == matchedColor && style.color == matchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should match because ::view-transition-old is not generated (none to root)");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    document.documentElement.style.viewTransitionName = "root";
    target.style.viewTransitionName = "none";
    let transition = document.startViewTransition();

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(root)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-old is generated (root to root)");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    document.documentElement.style.viewTransitionName = "none";
    target.style.viewTransitionName = "root";
    let transition = document.startViewTransition(() => {
       document.documentElement.style.viewTransitionName = "root";
       target.style.viewTransitionName = "none";
    });

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(root)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-old is generated (element to root)");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    target.style.viewTransitionName = "none";
    document.documentElement.style.viewTransitionName = "none";
    let transition = document.startViewTransition(() => {
      target.style.viewTransitionName = "target";
    });

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(target)");
      if (style.backgroundColor == matchedColor && style.color == matchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should match because ::view-transition-old is not generated (none to element)");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    target.style.viewTransitionName = "none";
    document.documentElement.style.viewTransitionName = "root";
    let transition = document.startViewTransition(() => {
      document.documentElement.style.viewTransitionName = "none";
      target.style.viewTransitionName = "element";
    });

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(root)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-old is generated (root to element)");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    target.style.viewTransitionName = "target";
    document.documentElement.style.viewTransitionName = "none";
    let transition = document.startViewTransition();

    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-new(target)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-old is generated (element to element)");
</script>