dom/tests/mochitest/gamepad/test_gamepad_connect_events.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    11   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    12 </head>
    13 <body>
    14 <script type="text/javascript" src="mock_gamepad.js"></script>
    15 <script class="testbody" type="text/javascript">
    16 SimpleTest.waitForExplicitFinish();
    17 var index = GamepadService.addGamepad("test gamepad", // id
    18                                       SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
    19                                       4, // buttons
    20                                       2);// axes
    22 function pressButton() {
    23   GamepadService.newButtonEvent(index, 0, true);
    24   GamepadService.newButtonEvent(index, 0, false);
    25 }
    27 var f1, f2;
    28 function frame_loaded() {
    29   f1 = document.getElementById('f1');
    30   pressButton();
    31 }
    33 window.addEventListener("gamepadbuttondown", function() {
    34   // Wait to ensure that all frames received the button press as well.
    35   SpecialPowers.executeSoon(tests[testNum++]);
    36 });
    38 var testNum = 0;
    39 var tests = [
    40   test1,
    41   test2,
    42 ];
    44 function test1() {
    45   is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
    47   // Now add another frame.
    48   f2 = document.createElement("iframe");
    49   f2.addEventListener("load", function() {
    50     // When the frame is loaded, press a button again.
    51     pressButton();
    52   });
    53   f2.src = "gamepad_frame.html";
    54   document.body.appendChild(f2);
    55 }
    57 function test2() {
    58   is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1");
    59   is(f2.contentWindow.connectedEvents, 1, "right number of connection events in frame 2");
    60   GamepadService.removeGamepad(index);
    61   SimpleTest.finish();
    62 }
    64 </script>
    65 <iframe id="f1" src="gamepad_frame.html" onload="frame_loaded()"></iframe>
    66 </body>
    67 </html>

mercurial