tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

file_pointerlock_xorigin_iframe_not_focused.html (3297B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--https://bugzilla.mozilla.org/show_bug.cgi?id=1662587-->
      4 <head>
      5 <title>Bug 1662587</title>
      6 <script src="/tests/SimpleTest/EventUtils.js"></script>
      7 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8 <script src="pointerlock_utils.js"></script>
      9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 <style>
     11 #target {
     12  width: 50px;
     13  height: 50px;
     14  background-color: green;
     15 }
     16 iframe {
     17  width: 400px;
     18  height: 300px;
     19  border: 1px solid blue;
     20 }
     21 </style>
     22 </head>
     23 <body>
     24 <a target="_blank"href="https://bugzilla.mozilla.org/show_bug.cgi?id=1698611">Mozilla Bug 1698611</a>
     25 <div id="target"></div>
     26 <iframe src="https://example.com/tests/dom/tests/mochitest/pointerlock/iframe_differentDOM.html"></iframe>
     27 
     28 <pre id="test">
     29 <script type="text/javascript">
     30 /**
     31 * Test for Bug 1698611
     32 */
     33 SimpleTest.waitForExplicitFinish();
     34 
     35 async function requestPointerLock(aWin) {
     36  await SpecialPowers.spawn(aWin, [], async () => {
     37    info("request pointer lock in xorigin iframe");
     38    SpecialPowers.wrap(content.document).notifyUserGestureActivation();
     39    content.document.body.requestPointerLock();
     40    await new Promise((aResolve) => {
     41      let handler = function(aEvent) {
     42        is(aEvent.type, 'pointerlockchange', `got ${aEvent.type}`);
     43        content.document.onpointerlockchange = null;
     44        content.document.onpointerlockerror = null;
     45        aResolve();
     46      };
     47      content.document.onpointerlockchange = handler;
     48      content.document.onpointerlockerror = handler;
     49    });
     50  });
     51 }
     52 
     53 async function exitPointerLock(aWin) {
     54  await SpecialPowers.spawn(aWin, [], async () => {
     55    info("exit pointer lock in xorigin iframe");
     56    if (content.document.pointerLockElement) {
     57      content.document.exitPointerLock();
     58      await new Promise((aResolve) => {
     59        content.document.addEventListener("pointerlockchange", (aEvent) => {
     60          ok(true, `got ${aEvent.type}`);
     61          aResolve();
     62        }, { once: true });
     63      });
     64    }
     65    is(content.document.pointerLockElement, null, "pointer unlocked");
     66  });
     67 }
     68 
     69 function addEventListenerOnRemote(aWin, aEvent) {
     70  return SpecialPowers.spawn(aWin, [aEvent], async (aEvent) => {
     71    info(`wait for ${aEvent} event on remote`);
     72    content.document.addEventListener(aEvent, function(e) {
     73      info(`get ${aEvent} event on remote`);
     74      content.parent.postMessage(aEvent, "*");
     75    });
     76  });
     77 }
     78 
     79 function waitForMessage(aWin, aMessage) {
     80  return new Promise((aResolve) => {
     81    info(`wait for ${aMessage} message`);
     82    window.addEventListener("message", function handler(e) {
     83      info(`get ${e.data} message`);
     84      if (e.data === aMessage) {
     85        window.removeEventListener("message", handler);
     86        aResolve();
     87      }
     88    });
     89  });
     90 }
     91 
     92 async function start() {
     93  info("Put the focus on top-level document");
     94  await SimpleTest.promiseFocus(window);
     95 
     96  let iframe = document.querySelector("iframe");
     97  let win = iframe.contentWindow;
     98  await requestPointerLock(win);
     99  await addEventListenerOnRemote(win, "mousemove");
    100 
    101  let promise = waitForMessage(win, "mousemove");
    102  let div = document.querySelector("div");
    103  synthesizeMouseAtCenter(div, { type: "mousemove" });
    104  await promise;
    105 
    106  await exitPointerLock(win);
    107  SimpleTest.finish();
    108 }
    109 </script>
    110 </pre>
    111 </body>
    112 </html>