tor-browser

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

test_gamepad_hidden_frame.html (2197B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2   - http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!DOCTYPE HTML>
      4 <title>Test hidden frames</title>
      5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
      7 <script>
      8 const GamepadService = navigator.requestGamepadServiceTest();
      9 
     10 let index;
     11 async function pressButton(win) {
     12  let p = new Promise(r => {
     13    win.addEventListener("gamepadbuttondown", r, { once: true });
     14  });
     15 
     16  await GamepadService.newButtonEvent(index, 0, true, true);
     17  await GamepadService.newButtonEvent(index, 0, false, false);
     18 
     19  await p;
     20  // Wait to ensure that all tabs received (or didn't) the button press as
     21  // well.
     22  await new Promise(r => SpecialPowers.executeSoon(r));
     23 }
     24 
     25 async function openGamepadTab() {
     26  let win = SpecialPowers.wrap(window).open("gamepad_frame.html");
     27  await new Promise(r => {
     28    win.addEventListener("load", r, { once: true });
     29  });
     30  return win.wrappedJSObject;
     31 }
     32 
     33 function waitForTabVisible(win, visible) {
     34  if (!win.document.hidden == visible) {
     35    return Promise.resolve();
     36  }
     37  return new Promise(r => {
     38    win.document.addEventListener("visibilitychange", r, { once: true });
     39  });
     40 }
     41 
     42 add_task(async function test_gamepad_hidden_frame() {
     43  let t1 = await openGamepadTab();
     44  let t2 = await openGamepadTab();
     45 
     46  index = await GamepadService.addGamepad(
     47    "test gamepad", // id
     48    GamepadService.standardMapping,
     49    GamepadService.noHand,
     50    4, // buttons
     51    2,
     52    0,
     53    0,
     54    0
     55  );
     56 
     57  await Promise.all([
     58    waitForTabVisible(t1, false),
     59    waitForTabVisible(t2, true),
     60  ]);
     61 
     62  await pressButton(t2);
     63 
     64  is(t1.buttonPresses, 0, "right number of button presses in tab 1");
     65  is(t2.buttonPresses, 1, "right number of button presses in tab 2");
     66 
     67  t1.focus(); // Switches t1 to the foreground.
     68 
     69  await Promise.all([
     70    waitForTabVisible(t1, true),
     71    waitForTabVisible(t2, false),
     72  ]);
     73 
     74  await pressButton(t1);
     75 
     76  is(t1.buttonPresses, 1, "right number of button presses in tab 1");
     77  is(t2.buttonPresses, 1, "right number of button presses in tab 2");
     78  await GamepadService.removeGamepad(index);
     79  t1.close();
     80  t2.close();
     81 });
     82 </script>