dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +<!-- Any copyright is dedicated to the Public Domain.
     1.5 +   - http://creativecommons.org/publicdomain/zero/1.0/ -->
     1.6 +<!DOCTYPE HTML>
     1.7 +<html>
     1.8 +<head>
     1.9 +  <title>Test hidden frames</title>
    1.10 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body>
    1.14 +<script type="text/javascript" src="mock_gamepad.js"></script>
    1.15 +<script class="testbody" type="text/javascript">
    1.16 +SimpleTest.waitForExplicitFinish();
    1.17 +var index = GamepadService.addGamepad("test gamepad", // id
    1.18 +                                      SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
    1.19 +                                      4, // buttons
    1.20 +                                      2);// axes
    1.21 +
    1.22 +function setFrameVisible(f, visible) {
    1.23 +  var Ci = SpecialPowers.Ci;
    1.24 +  var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
    1.25 +  docshell.isActive = visible;
    1.26 +}
    1.27 +
    1.28 +var frames_loaded = 0;
    1.29 +var f1, f2;
    1.30 +function frame_loaded() {
    1.31 +  frames_loaded++;
    1.32 +  if (frames_loaded == 2) {
    1.33 +    f1 = document.getElementById('f1');
    1.34 +    f2 = document.getElementById('f2');
    1.35 +    // Now press the button, but don't release it.
    1.36 +    GamepadService.newButtonEvent(index, 0, true);
    1.37 + }
    1.38 +}
    1.39 +
    1.40 +window.addEventListener("gamepadbuttondown", function() {
    1.41 +  // Wait to ensure that all frames received the button press as well.
    1.42 + SpecialPowers.executeSoon(tests[testNum++]);
    1.43 +});
    1.44 +
    1.45 +var testNum = 0;
    1.46 +var tests = [
    1.47 +  check_button_pressed,
    1.48 +  check_second_frame_no_button_press,
    1.49 +];
    1.50 +
    1.51 +function check_button_pressed() {
    1.52 +  // At this point the both frames should see the button as pressed.
    1.53 +  ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
    1.54 +  ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
    1.55 +
    1.56 +  // Now release the button, then hide the second frame.
    1.57 +  GamepadService.newButtonEvent(index, 0, false);
    1.58 +  setFrameVisible(f2, false);
    1.59 +  SpecialPowers.executeSoon(function() {
    1.60 +    // Now press the button, but don't release it.
    1.61 +    GamepadService.newButtonEvent(index, 0, true);
    1.62 +  });
    1.63 +}
    1.64 +
    1.65 +function check_second_frame_no_button_press () {
    1.66 +  /*
    1.67 +   * At this point the first frame should see the button as pressed,
    1.68 +   * but the second frame should not, since it's hidden.
    1.69 +   */
    1.70 +  ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
    1.71 +  ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 should not see button pressed");
    1.72 +
    1.73 +  // Now unhide the second frame.
    1.74 +  setFrameVisible(f2, true);
    1.75 +  SpecialPowers.executeSoon(function() {
    1.76 +    // Now that the frame is visible again, it should see the button
    1.77 +    // that was pressed.
    1.78 +    ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
    1.79 +    // cleanup
    1.80 +    GamepadService.removeGamepad(index);
    1.81 +    SimpleTest.finish();
    1.82 +  });
    1.83 +}
    1.84 +
    1.85 +</script>
    1.86 +<iframe id="f1" src="gamepad_frame_state.html" onload="frame_loaded()"></iframe>
    1.87 +<iframe id="f2" src="gamepad_frame_state.html" onload="frame_loaded()"></iframe>
    1.88 +</body>
    1.89 +</html>

mercurial