DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
<!DOCTYPE html>
<meta name="timeout" content="long">
<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>
<script src="resources/open-blank-host.js"></script>
<body>
<script>
  async function createPortal(doc, url) {
    assert_implements("HTMLPortalElement" in self);
    let portal = doc.createElement("portal");
    portal.src = url;
    doc.body.appendChild(portal);
    await new Promise(r => portal.onload = r);
    return portal;
  }

  promise_test(async t => {
    let portal = await createPortal(document, new URL("resources/focus-page-with-button.html", location.href));
    try {
      portal.onmessage = t.step_func(e => {
        assert_unreached("button inside portal should not be focused");
      });
      portal.postMessage("focus", "*");
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      document.body.removeChild(portal);
    }
  }, "test that an element inside a portal cannot steal focus");

  promise_test(async t => {
    let portal = await createPortal(document, new URL("resources/focus-page-with-x-origin-iframe.sub.html", location.href));
    try {
      portal.onmessage = t.step_func(e => {
        assert_unreached("button inside portal should not be focused");
      });
      portal.postMessage("focus", "*");
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      document.body.removeChild(portal);
    }
  }, "test that an element inside a portal's x-origin subframe cannot steal focus");

  promise_test(async t => {
    let win = await openBlankPortalHost();
    let doc = win.document;
    try {
      let portal = await createPortal(doc, new URL("resources/simple-portal-adopts-predecessor.html", location.href));
      let button = doc.createElement("button");
      doc.body.appendChild(button);

      await portal.activate();
      doc.body.removeChild(portal);

      button.onfocus = t.step_func(() => {
        assert_unreached("button inside adopted portal should not be focused");
      });
      button.focus();
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      win.close();
    }
  }, "test that an element inside an adopted portal cannot steal focus");

  promise_test(async t => {
    let win = await openBlankPortalHost();
    let doc = win.document;
    try {
      let portal = await createPortal(doc, new URL("resources/simple-portal-adopts-predecessor.html", location.href));
      let iframe = doc.createElement("iframe");
      iframe.src = new URL("resources/focus-page-with-button.html",
                           "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/");
      doc.body.appendChild(iframe);
      await new Promise(r => iframe.onload = r);

      await portal.activate();
      doc.body.removeChild(portal);

      iframe.contentWindow.postMessage("focus", "*");
      window.onmessage = t.step_func(() => {
        assert_unreached("button inside x-origin iframe inside a portal should not be focused");
      });
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      win.close();
    }
  }, "test that a x-origin iframe inside an adopted portal cannot steal focus");

  const TAB = "\ue004"; // https://w3c.github.io/webdriver/#keyboard-actions
  const SPACE = " "
  const RETURN = "\r";

  promise_test(async t => {
    let portal = await createPortal(document, "resources/focus-page-with-button.html");
    try {
      await test_driver.send_keys(document.body, TAB);
      portal.onmessage = t.unreached_func("button inside portal should not be focused");
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      document.body.removeChild(portal);
    }
  }, "test that a portal is keyboard focusable");

  promise_test(async t => {
    let portal = await createPortal(document, "resources/focus-page-with-button.html");
    try {
      let portalFocusPromise = new Promise(r => portal.onfocus = r);
      portal.onmessage = t.unreached_func("button inside portal should not be focused");
      await test_driver.send_keys(document.body, TAB);
      await portalFocusPromise;
      await test_driver.send_keys(document.body, TAB);
      await new Promise(r => t.step_timeout(r, 500));
    } finally {
      document.body.removeChild(portal);
    }
  }, "test that we cannot tab into a portal's contents");

  promise_test(async t => {
    let portal = await createPortal(document, "resources/simple-portal.html");
    try {
      portal.focus();
      for (let key of [SPACE, RETURN]) {
        let clickPromise = new Promise(r => portal.onclick = r);
        await test_driver.send_keys(document.body, key);
        await clickPromise;
      }
    } finally {
      document.body.removeChild(portal);
    }
  }, "test that a portal is keyboard activatable");

</script>
</body>