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

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

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

<script>
promise_test(() => {
  return new Promise(async (resolve, reject) => {
    let transition = document.startViewTransition();
    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-group(root)");
      if (style.backgroundColor == "rgb(255, 0, 0)" && style.color == "rgb(255, 0, 0)")
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should match because ::view-transition-group is generated for root element only");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    target.style.viewTransitionName = "target";
    let transition = document.startViewTransition();
    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-group(root)");
      if (style.backgroundColor == "rgb(0, 0, 255)" && style.color == "rgb(0, 0, 255)")
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-group is generated for multiple elements");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    document.documentElement.style.viewTransitionName = "none";
    target.style.viewTransitionName = "target";
    let transition = document.startViewTransition();
    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-group(target)");
      if (style.backgroundColor == "rgb(255, 0, 0)" && style.color == "rgb(255, 0, 0)")
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should match because ::view-transition-group is generated for sub element only");

promise_test(() => {
  return new Promise(async (resolve, reject) => {
    document.documentElement.style.viewTransitionName = "none";
    target.style.viewTransitionName = "target";
    target2.style.viewTransitionName = "target2";
    let transition = document.startViewTransition();
    transition.ready.then(() => {
      let style = getComputedStyle(
        document.documentElement, ":view-transition-group(target)");
      if (style.backgroundColor == "rgb(0, 0, 255)" && style.color == "rgb(0, 0, 255)")
        resolve();
      else
        reject(style.backgroundColor + " and " + style.color);
    });
  });
}, ":only-child should not match because ::view-transition-group is generated for multiple sub elements");
</script>