summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-view-transitions/input-targets-root-while-render-blocked.html
blob: dbeb39da5468b56130413c2e29a134e5e67887fe (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
<!DOCTYPE html>
<html>
<title>View transitions: ensure input targets document root while rendering is suppressed</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7797">
<link rel="author" href="mailto:bokan@chromium.org">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<style>
:root {
  /* Ensure clicks during the transition fall through the pseudo tree root to
   * real DOM */
  view-transition-name: none;
}

::view-transition {
  /* Ensure clicks during the transition fall through the pseudo tree root to
   * real DOM */
  pointer-events: none;
  width: 0;
  height: 0;
}

::view-transition-group(*) {
  animation-duration: 30s;
}

#clicktarget {
  width: 100px;
  height: 100px;
  background: red;
}

#transition {
  width: 100px;
  height: 100px;
  background: blue;
  contain: paint;
  view-transition-name: transitionElement;
}
</style>

<div id="clicktarget"></div>
<div id="transition"></div>

<script>
const target = document.getElementById("clicktarget");

async function sendAndWaitForClick() {
  return new Promise(async (resolve) => {

    function eventHandler(ev) {
      resolve(ev);
    }

    document.documentElement.addEventListener("click", eventHandler);

    await new test_driver.Actions()
             .setContext(window)
             .addPointer("mousePointer1", "mouse")
             .pointerMove(10, 10, {origin: 'viewport', sourceName: "mousePointer1"})
             .pointerDown({sourceName: "mousePointer1"})
             .pointerUp({sourceName: "mousePointer1"})
             .send();

    document.documentElement.removeEventListener("click", eventHandler);
  });
}

promise_test(async t => {
  assert_implements(document.startViewTransition, "Missing document.startViewTransition");
  assert_not_equals(target, null, "PRECONDITION: target element is valid");

  // Ensure input is initialized before blocking rendering.
  await new test_driver.Actions()
               .setContext(window)
               .addPointer("mousePointer1", "mouse")
               .pointerMove(0, 0, {origin: "viewport", sourceName: "mousePointer1"})
               .send();

  let clickEvent = null;

  let transition = document.startViewTransition(async () => {
    clickEvent = await sendAndWaitForClick();
  });

  await transition.ready;

  assert_equals(clickEvent.target, document.documentElement,
      "Events must target the transition root while render blocked");
  clickEvent = null;

  clickEvent = await sendAndWaitForClick();

  // This just ensures we're not passing the above check by accident.
  assert_equals(clickEvent.target, target,
      "During transition, event should hit real DOM");

}, "Input when rendering suppressed targets root");
</script>