summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/portals-host-exposure.sub.html
blob: fd3ac18f69d444f679d4b45a26ebd3d21521dc70 (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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/stash-utils.sub.js"></script>
<script src="/common/utils.js"></script>
<body>
<script>
  function openPortal(portalSrc) {
    assert_implements("HTMLPortalElement" in self);
    const portal = document.createElement('portal');
    portal.src = portalSrc;
    return portal;
  }

  async function openPortalAndReceiveMessage(portalSrc) {
    const key = token();
    const portal = openPortal(`${portalSrc}?key=${key}`);
    document.body.appendChild(portal);
    return StashUtils.takeValue(key);
  }

  promise_test(async () => {
    const result = await openPortalAndReceiveMessage("resources/portal-host.html");
    assert_equals(result, "passed");
  }, "window.portalHost should be exposed in same-origin portal");

  promise_test(async () => {
    const result = await openPortalAndReceiveMessage(
        "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html");
    assert_equals(result, "passed");
  }, "window.portalHost should be exposed in cross-origin portal");

  promise_test(async () => {
    const result = await openPortalAndReceiveMessage(
        'resources/portal-host-cross-origin-navigate.sub.html');
    assert_equals(result, "passed");
  }, "window.portalHost should be exposed in portal after cross-origin navigation");

</script>
</body>