<!DOCTYPE html>
<html>
<title>View transitions: duplicate tags in the new DOM skip the transition</title>
<link rel="help" href="https://www.w3.org/TR/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>
div {
  width: 100px;
  height: 100px;
  background: blue;
  contain: paint;
}
</style>

<div id=first></div>
<div id=second></div>

<script>
promise_test(async t => {
  assert_implements(document.startViewTransition, "Missing document.startViewTransition");
  return new Promise((resolve, reject) => {
    first.style = "view-transition-name: target";
    let transition = document.startViewTransition(() => {
      first.style = "view-transition-name: target";
      second.style = "view-transition-name: target";
    });

    // First updateCallbackDone resolves since the callback runs successfully.
    let updateCallbackDoneResolved = false;
    transition.updateCallbackDone.then(() => { updateCallbackDoneResolved = true; }, reject);

    // Then finished resolves since updateCallbackDone was already resolved.
    let finishResolved = false;
    transition.updateCallbackDone.then(() => {
      assert_true(updateCallbackDoneResolved, "updateCallbackDone not resolved before finish");
      finishResolved = true;
    }, reject);

    // Finally ready rejects.
    transition.ready.then(reject, () => {
      assert_true(finishResolved, "finish not resolved before ready");
      resolve();
    });
  });
}, "Two different elements with the same name in the new DOM should skip the transition");
</script>
