summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fullscreen/api/document-exit-fullscreen-nested-shadow-dom.html
blob: 695ae0032235fc4af020b8d5d2bf35c08979cbaa (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
<!doctype html>
<title>Exiting fullscreen from a nested shadow root should work correctly.</title>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1652155">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div id="host">
  <button>
    <!--
        This is gross, but testdriver doesn't let us click stuff in shadow
        DOM, so here we are instead, using nested slots.
    -->
    fullscreen
  </button>
</div>
<script>
promise_test(async function() {
  let host = document.getElementById("host");
  host.attachShadow({ mode: "open" }).innerHTML = `
    <style>
      #outer { width: 200px; height: 200px; background: blue }
    </style>
    <div id="outer">
      <slot></slot>
    </div>
  `;

  let outer = host.shadowRoot.getElementById("outer");
  outer.attachShadow({ mode: "open" }).innerHTML = `
    <style>
      #inner { width: 100px; height: 100px; background: purple }
    </style>
    <div id="inner"></div>
    <slot></slot>
  `;

  let button = document.querySelector("button");

  let inner = outer.shadowRoot.getElementById("inner");
  let finished = new Promise(resolve => {
    button.addEventListener("click", async function() {
      await outer.requestFullscreen();
      assert_equals(outer.getRootNode().fullscreenElement, outer);
      assert_equals(document.fullscreenElement, host);

      button.addEventListener("click", async function() {
        await inner.requestFullscreen();
        assert_equals(inner.getRootNode().fullscreenElement, inner);
        assert_equals(document.fullscreenElement, host);
        await document.exitFullscreen();
        assert_equals(inner.getRootNode().fullscreenElement, null);
        assert_equals(outer.getRootNode().fullscreenElement, outer);
        assert_equals(document.fullscreenElement, host);
        resolve();
      }, { once: true });

      requestAnimationFrame(() => requestAnimationFrame(() => {
        test_driver.click(button);
      }));
    }, { once: true });
  });

  test_driver.click(button);
  await finished;
}, "Exiting fullscreen from a nested shadow root works correctly.");
</script>