tor-browser

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

test_gamepad_connect_events_iframe.html (2668B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2   - http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!-- bug 893785 - Test that sending a gamepadconnected event to a new window
      4     doesn't result in a gamepadconnected event being sent to existing
      5     windows that have already received it. -->
      6 <!DOCTYPE HTML>
      7 <html>
      8 <head>
      9  <title>Test hidden frames</title>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <script type="text/javascript" src="mock_gamepad.js"></script>
     14 <script class="testbody" type="text/javascript">
     15 let ok = window.parent.ok;
     16 let is = window.parent.is;
     17 let SimpleTest = window.parent.SimpleTest;
     18 let SpecialPowers = window.parent.SpecialPowers;
     19 
     20 var gamepad_index;
     21 
     22 async function pressButton() {
     23  await GamepadService.newButtonEvent(gamepad_index, 0, true, true);
     24  await GamepadService.newButtonEvent(gamepad_index, 0, false, false);
     25 }
     26 
     27 // Add a gamepad
     28 async function startTests() {
     29  window.addEventListener("gamepadbuttondown", function() {
     30    // Wait to ensure that all frames received the button press as well.
     31    SpecialPowers.executeSoon(tests[testNum++]);
     32  });
     33 
     34  gamepad_index = await GamepadService.addGamepad("test gamepad", // id
     35                            GamepadService.standardMapping,
     36                            GamepadService.noHand,
     37                            4, // buttons
     38                            2,
     39                            0,
     40                            0,
     41                            0)
     42 
     43  await gamepad_connected();
     44 }
     45 
     46 var f1, f2;
     47 async function gamepad_connected() {
     48  f1 = document.getElementById('f1');
     49  await pressButton();
     50 }
     51 
     52 var testNum = 0;
     53 var tests = [
     54  test1,
     55  test2,
     56 ];
     57 
     58 function test1() {
     59  is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
     60 
     61  // Now add another frame.
     62  f2 = document.createElement("iframe");
     63  f2.addEventListener("load", async () => {
     64    // When the frame is loaded, press a button again.
     65    await pressButton();
     66  });
     67  f2.src = "gamepad_frame.html";
     68  document.body.appendChild(f2);
     69 }
     70 
     71 async function test2() {
     72  is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
     73  is(f2.contentWindow.connectedEvents, 1, "right number of connection events in frame 2");
     74  is(f1.contentWindow.idlConnected, 1, "right number of IDL connection events in frame 1");
     75  is(f2.contentWindow.idlConnected, 1, "right number of IDL connection events in frame 2");
     76  await GamepadService.removeGamepad(gamepad_index);
     77  SimpleTest.finish();
     78 }
     79 
     80 </script>
     81 <iframe id="f1" src="gamepad_frame.html" onload="runGamepadTest(startTests)"></iframe>
     82 </body>
     83 </html>