view-transition: Enable concurrent transitions for same-document.

Currently we only allow 1 transition within a LocalFrame tree. If
multiple LocalFrames rendering to the same compositor attempt to run a
ViewTransition, the ancestor transition suppresses the child transition.

This change removes this restriction now that the compositing stack
supports this pattern.

Bug: 330917526
Change-Id: Ib7973799b46a3d9dd223d8fdc6e3b5bb99e22f01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5499058
Auto-Submit: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1296341}
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe-ref.html
new file mode 100644
index 0000000..86bc2a4
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe-ref.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+body {
+  background: lightgreen;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: lightblue;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe.html b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe.html
new file mode 100644
index 0000000..89360c0
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-new-iframe.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-new-main-new-iframe-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+/* Keep showing the live state for the main frame so we can assert the state of
+   screenshots in the iframe */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 0;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 1;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+  /* The iframe is showing new live DOM */
+  ::view-transition-group(root) {
+    animation-duration: 300s;
+  }
+  ::view-transition-new(root) {
+    animation: unset;
+    opacity: 1;
+  }
+  ::view-transition-old(root) {
+    animation: unset;
+    opacity: 0;
+  }
+</style>
+<body></body>
+"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor) {
+    document.documentElement.style.background = oldColor;
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+    }).ready;
+  }
+
+  async function runTest() {
+    await startTransition(document, "green", "lightgreen");
+
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue");
+
+    takeScreenshot();
+  }
+</script>
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe-ref.html
new file mode 100644
index 0000000..baafea3
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe-ref.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+body {
+  background: lightgreen;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: blue;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe.html b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe.html
new file mode 100644
index 0000000..7a9c53f
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-new-main-old-iframe.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-new-main-old-iframe-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+/* Keep showing the live state for the main frame so we can assert the state of
+   screenshots in the iframe */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 0;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 1;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+  /* The iframe is showing old screenshots */
+  ::view-transition-group(root) {
+    animation-duration: 300s;
+  }
+  ::view-transition-old(root) {
+    animation: unset;
+    opacity: 1;
+  }
+  ::view-transition-new(root) {
+    animation: unset;
+    opacity: 0;
+  }
+</style>
+<body></body>
+"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor) {
+    document.documentElement.style.background = oldColor;
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+    }).ready;
+  }
+
+  async function runTest() {
+    await startTransition(document, "green", "lightgreen");
+
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue");
+
+    takeScreenshot();
+  }
+</script>
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe-ref.html
new file mode 100644
index 0000000..7033cd9
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe-ref.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+body {
+  background: green;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: lightblue;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe.html
new file mode 100644
index 0000000..d3681aa
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-new-iframe.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-old-main-new-iframe-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+/* Keep showing the screenshot for the main frame */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 1;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 0;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+  /* The iframe is showing live DOM */
+  ::view-transition-group(root) {
+    animation-duration: 300s;
+  }
+  ::view-transition-new(root) {
+    animation: unset;
+    opacity: 1;
+  }
+  ::view-transition-old(root) {
+    animation: unset;
+    opacity: 0;
+  }
+</style>
+<body></body>
+"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor) {
+    document.documentElement.style.background = oldColor;
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+    }).ready;
+  }
+
+  async function runTest() {
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue");
+
+    await startTransition(document, "green", "lightgreen");
+
+    takeScreenshot();
+  }
+</script>
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe-ref.html
new file mode 100644
index 0000000..2824884
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe-ref.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+body {
+  background: green;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: blue;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe.html
new file mode 100644
index 0000000..bcdc566
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-old-iframe.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-old-main-old-iframe-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+/* Keep showing the screenshot for the main frame */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 1;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 0;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+  /* The iframe is showing an old screenshot */
+  ::view-transition-group(root) {
+    animation-duration: 300s;
+  }
+  ::view-transition-old(root) {
+    animation: unset;
+    opacity: 1;
+  }
+  ::view-transition-new(root) {
+    animation: unset;
+    opacity: 0;
+  }
+</style>
+<body></body>
+"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor) {
+    document.documentElement.style.background = oldColor;
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+    }).ready;
+  }
+
+  async function runTest() {
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue");
+
+    await startTransition(document, "green", "lightgreen");
+
+    takeScreenshot();
+  }
+</script>
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-ref.html
new file mode 100644
index 0000000..9253bb5
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main-ref.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+body {
+  background: green;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: orange;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-old-main.html b/css/css-view-transitions/iframe-and-main-frame-transition-old-main.html
new file mode 100644
index 0000000..bd58368
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-old-main.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-old-main-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+}
+
+/* The main frame is showing the old screenshot */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 0;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 1;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+  body {
+    background: orange;
+  }
+</style>
+<body></body>"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor) {
+    document.documentElement.style.background = oldColor;
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+    }).ready;
+  }
+
+  async function runTest() {
+    await startTransition(document, "green", "lightgreen");
+
+    // Start an iframe transition while the main frame transition is showing the
+    // old screenshot. This change shouldn't show up visually because the old
+    // screenshot on the main frame still has the iframe's old content.
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue");
+
+    takeScreenshot();
+  }
+</script>
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe-ref.html b/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe-ref.html
new file mode 100644
index 0000000..94bd3bd
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe-ref.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<title>View transitions: iframe and main frame transition at the same time with name on iframe (ref)</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+  border: 1px solid orange;
+}
+
+body {
+  background: green;
+}
+</style>
+
+<iframe srcdoc="
+<style>
+body {
+  background: blue;
+}
+</style>
+"></iframe>
+
+
diff --git a/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe.html b/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe.html
new file mode 100644
index 0000000..f948e89
--- /dev/null
+++ b/css/css-view-transitions/iframe-and-main-frame-transition-with-name-on-iframe.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<html class=reftest-wait>
+<title>View transitions: iframe and main frame transition at the same time with name on iframe</title>
+<link rel="help" href="https://drafts.csswg.org/css-view-transitions-1/">
+<link rel="author" href="mailto:khushalsagar@chromium.org">
+<link rel="match" href="iframe-and-main-frame-transition-with-name-on-iframe-ref.html">
+<script src="/common/reftest-wait.js"></script>
+<style>
+iframe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 50vw;
+  height: 50vh;
+  view-transition-name: inner;
+}
+
+.old {
+  border: 1px solid black;
+}
+
+.new {
+  border: 1px solid orange;
+}
+
+/* The main frame is showing the old screenshot for the root */
+::view-transition-group(root) {
+  animation-duration: 300s;
+}
+::view-transition-new(root) {
+  animation: unset;
+  opacity: 0;
+}
+::view-transition-old(root) {
+  animation: unset;
+  opacity: 1;
+}
+
+/* The iframe is showing the live screenshot */
+::view-transition-new(inner) {
+  animation: unset;
+  opacity: 1;
+}
+::view-transition-old(inner) {
+  animation: unset;
+  opacity: 0;
+}
+
+</style>
+
+<iframe id="inner" srcdoc="
+<style>
+  /* The iframe document itself is showing an old screenshot */
+  ::view-transition-group(root) {
+    animation-duration: 300s;
+  }
+  ::view-transition-new(root) {
+    animation: unset;
+    opacity: 0;
+  }
+  ::view-transition-old(root) {
+    animation: unset;
+    opacity: 1;
+  }
+</style>
+<body></body>"></iframe>
+<script>
+  onload = runTest;
+
+  async function startTransition(document, oldColor, newColor, nestedFrame) {
+    document.documentElement.style.background = oldColor;
+    if (nestedFrame != null)
+      nestedFrame.classList.add("old");
+
+    await document.startViewTransition(() => {
+      document.documentElement.style.background = newColor;
+      if (nestedFrame != null) {
+        nestedFrame.classList.remove("old");
+        nestedFrame.classList.add("new");
+      }
+    }).ready;
+  }
+
+  async function runTest() {
+    await startTransition(document, "green", "lightgreen", document.getElementById("inner"));
+
+    const iframeDocument = document.querySelector("iframe").contentDocument;
+    await startTransition(iframeDocument, "blue", "lightblue", null);
+
+    takeScreenshot();
+  }
+</script>
+