dom/tests/mochitest/gamepad/test_gamepad_connect_events.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_connect_events.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +<!-- Any copyright is dedicated to the Public Domain.
     1.5 +   - http://creativecommons.org/publicdomain/zero/1.0/ -->
     1.6 +<!-- bug 893785 - Test that sending a gamepadconnected event to a new window
     1.7 +     doesn't result in a gamepadconnected event being sent to existing
     1.8 +     windows that have already received it. -->
     1.9 +<!DOCTYPE HTML>
    1.10 +<html>
    1.11 +<head>
    1.12 +  <title>Test hidden frames</title>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.15 +</head>
    1.16 +<body>
    1.17 +<script type="text/javascript" src="mock_gamepad.js"></script>
    1.18 +<script class="testbody" type="text/javascript">
    1.19 +SimpleTest.waitForExplicitFinish();
    1.20 +var index = GamepadService.addGamepad("test gamepad", // id
    1.21 +                                      SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
    1.22 +                                      4, // buttons
    1.23 +                                      2);// axes
    1.24 +
    1.25 +function pressButton() {
    1.26 +  GamepadService.newButtonEvent(index, 0, true);
    1.27 +  GamepadService.newButtonEvent(index, 0, false);
    1.28 +}
    1.29 +
    1.30 +var f1, f2;
    1.31 +function frame_loaded() {
    1.32 +  f1 = document.getElementById('f1');
    1.33 +  pressButton();
    1.34 +}
    1.35 +
    1.36 +window.addEventListener("gamepadbuttondown", function() {
    1.37 +  // Wait to ensure that all frames received the button press as well.
    1.38 +  SpecialPowers.executeSoon(tests[testNum++]);
    1.39 +});
    1.40 +
    1.41 +var testNum = 0;
    1.42 +var tests = [
    1.43 +  test1,
    1.44 +  test2,
    1.45 +];
    1.46 +
    1.47 +function test1() {
    1.48 +  is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
    1.49 +
    1.50 +  // Now add another frame.
    1.51 +  f2 = document.createElement("iframe");
    1.52 +  f2.addEventListener("load", function() {
    1.53 +    // When the frame is loaded, press a button again.
    1.54 +    pressButton();
    1.55 +  });
    1.56 +  f2.src = "gamepad_frame.html";
    1.57 +  document.body.appendChild(f2);
    1.58 +}
    1.59 +
    1.60 +function test2() {
    1.61 +  is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
    1.62 +  is(f2.contentWindow.connectedEvents, 1, "right number of connection events in frame 2");
    1.63 +  GamepadService.removeGamepad(index);
    1.64 +  SimpleTest.finish();
    1.65 +}
    1.66 +
    1.67 +</script>
    1.68 +<iframe id="f1" src="gamepad_frame.html" onload="frame_loaded()"></iframe>
    1.69 +</body>
    1.70 +</html>

mercurial