| <!DOCTYPE html> |
| <html class="foo"> |
| <title>View transitions: ensure :only-child is supported on view-transition-group</title> |
| <link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/"> |
| <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> |
| function resetState() { |
| if (window.transition) |
| window.transition.skipTransition(); |
| document.documentElement.style.viewTransitionName = ""; |
| target.style.viewTransitionName = ""; |
| target2.style.viewTransitionName = ""; |
| } |
| |
| promise_test((t) => { |
| assert_implements(document.startViewTransition, "Missing document.startViewTransition"); |
| t.add_cleanup(resetState); |
| return new Promise(async (resolve, reject) => { |
| window.transition = document.startViewTransition(); |
| window.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((t) => { |
| assert_implements(document.startViewTransition, "Missing document.startViewTransition"); |
| t.add_cleanup(resetState); |
| return new Promise(async (resolve, reject) => { |
| target.style.viewTransitionName = "target"; |
| window.transition = document.startViewTransition(); |
| window.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((t) => { |
| assert_implements(document.startViewTransition, "Missing document.startViewTransition"); |
| t.add_cleanup(resetState); |
| return new Promise(async (resolve, reject) => { |
| document.documentElement.style.viewTransitionName = "none"; |
| target.style.viewTransitionName = "target"; |
| window.transition = document.startViewTransition(); |
| window.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((t) => { |
| assert_implements(document.startViewTransition, "Missing document.startViewTransition"); |
| t.add_cleanup(resetState); |
| return new Promise(async (resolve, reject) => { |
| document.documentElement.style.viewTransitionName = "none"; |
| target.style.viewTransitionName = "target"; |
| target2.style.viewTransitionName = "target2"; |
| window.transition = document.startViewTransition(); |
| window.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> |