dom/tests/mochitest/gamepad/test_gamepad_hidden_frame.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_hidden_frame.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     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 pressButton() {
    1.23 +  GamepadService.newButtonEvent(index, 0, true);
    1.24 +  GamepadService.newButtonEvent(index, 0, false);
    1.25 +}
    1.26 +
    1.27 +function setFrameVisible(f, visible) {
    1.28 +  var Ci = SpecialPowers.Ci;
    1.29 +  var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
    1.30 +  docshell.isActive = visible;
    1.31 +}
    1.32 +
    1.33 +var frames_loaded = 0;
    1.34 +var f1, f2;
    1.35 +function frame_loaded() {
    1.36 +  frames_loaded++;
    1.37 + if (frames_loaded == 2) {
    1.38 +    f1 = document.getElementById('f1');
    1.39 +    f2 = document.getElementById('f2');
    1.40 +    pressButton();
    1.41 +  }
    1.42 +}
    1.43 +
    1.44 +window.addEventListener("gamepadbuttondown", function() {
    1.45 +  // Wait to ensure that all frames received the button press as well.
    1.46 + SpecialPowers.executeSoon(tests[testNum++]);
    1.47 +});
    1.48 +
    1.49 +var testNum = 0;
    1.50 +var tests = [
    1.51 +  test1,
    1.52 +  test2,
    1.53 +];
    1.54 +
    1.55 +function test1() {
    1.56 +  is(f1.contentWindow.buttonPresses, 1, "right number of button presses in frame 1");
    1.57 +  is(f2.contentWindow.buttonPresses, 1, "right number of button presses in frame 2");
    1.58 +
    1.59 +  // Now hide the second frame and send another button press.
    1.60 +  setFrameVisible(f2, false);
    1.61 +  SpecialPowers.executeSoon(function() { pressButton(); });
    1.62 +}
    1.63 +
    1.64 +function test2() {
    1.65 +  is(f1.contentWindow.buttonPresses, 2, "right number of button presses in frame 1");
    1.66 +  is(f2.contentWindow.buttonPresses, 1, "right number of button presses in frame 2");
    1.67 +  GamepadService.removeGamepad(index);
    1.68 +  SimpleTest.finish();
    1.69 +}
    1.70 +
    1.71 +</script>
    1.72 +<iframe id="f1" src="gamepad_frame.html" onload="frame_loaded()"></iframe>
    1.73 +<iframe id="f2" src="gamepad_frame.html" onload="frame_loaded()"></iframe>
    1.74 +</body>
    1.75 +</html>

mercurial