summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-view-transitions/only-child-old.html
blob: 7a55af7397ddad2cf1e54aea1df49a5a998ec173 (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
166
167
168
169
170
171
<!DOCTYPE html>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-old</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-old(root) {
  background-color: blue;
}
::view-transition-old(target) {
  background-color: blue;
}
::view-transition-old(*) {
  color: blue;
}

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

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

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

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

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

promise_test(() => {
  assert_implements(document.startViewTransition, "Missing document.startViewTransition");
  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-old(root)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-new is generated (root to root)");

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

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

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

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

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

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

promise_test(() => {
  assert_implements(document.startViewTransition, "Missing document.startViewTransition");
  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-old(target)");
      if (style.backgroundColor == notMatchedColor && style.color == notMatchedColor)
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-new is generated (element to element)");
</script>