tor-browser

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

test_gamepad_frame_state_sync_iframe.html (3151B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2   - http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!DOCTYPE HTML>
      4 <html>
      5 <head>
      6  <title>Test hidden frames</title>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <script type="text/javascript" src="mock_gamepad.js"></script>
     11 <script class="testbody" type="text/javascript">
     12 let ok = window.parent.ok;
     13 let is = window.parent.is;
     14 let SimpleTest = window.parent.SimpleTest;
     15 let SpecialPowers = window.parent.SpecialPowers;
     16 
     17 // Add a gamepad
     18 var index;
     19 
     20 var frames_loaded = 0;
     21 async function startTest() {
     22  frames_loaded++;
     23  if (frames_loaded != 2) return;
     24  index = await GamepadService.addGamepad("test gamepad", // id
     25                              GamepadService.standardMapping,
     26                              GamepadService.noHand,
     27                              4, // buttons
     28                              2,
     29                              0,
     30                              0,
     31                              0);
     32  await gamepad_loaded();
     33 }
     34 var f1, f2;
     35 async function gamepad_loaded() {
     36  f1 = document.getElementById('f1');
     37  f2 = document.getElementById('f2');
     38  let w1 = f1.contentWindow;
     39  let w2 = f2.contentWindow;
     40  w1.addEventListener("gamepadbuttonup", () => {
     41                       ok(!f1.contentWindow.gamepad.buttons[0].pressed,
     42                          "frame 1 no button pressed");
     43                       ok(!f1.contentWindow.gamepad.buttons[0].touched,
     44                          "frame 1 no button touched");
     45                      });
     46  w2.addEventListener("gamepadbuttonup", () => {
     47                      ok(!f2.contentWindow.gamepad.buttons[0].pressed,
     48                         "frame 2 no button pressed");
     49                      ok(!f2.contentWindow.gamepad.buttons[0].touched,
     50                         "frame 2 no button touched");
     51                      })
     52  // Now press the button, but don't release it.
     53  await GamepadService.newButtonEvent(index, 0, true, true);
     54 }
     55 
     56 window.addEventListener("gamepadbuttondown", function() {
     57  // Wait to ensure that all frames received the button press as well.
     58 SpecialPowers.executeSoon(tests[testNum++]);
     59 });
     60 
     61 var testNum = 0;
     62 var tests = [
     63  check_button_pressed,
     64 ];
     65 
     66 async function check_button_pressed() {
     67  // At this point the both frames should see the button as pressed.
     68  ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
     69  ok(f1.contentWindow.gamepad.buttons[0].touched, "frame 1 sees button touched");
     70  ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
     71  ok(f2.contentWindow.gamepad.buttons[0].touched, "frame 2 sees button touched");
     72 
     73  // Now release the button, then hide the second frame.
     74  await GamepadService.newButtonEvent(index, 0, false, false);
     75 
     76  SpecialPowers.executeSoon(async function() {
     77    // cleanup
     78    await GamepadService.removeGamepad(index);
     79    SimpleTest.finish();
     80  });
     81 }
     82 
     83 </script>
     84 <iframe id="f1" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe>
     85 <iframe id="f2" src="gamepad_frame_state.html" onload="runGamepadTest(startTest)"></iframe>
     86 </body>
     87 </html>