tor-browser

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

test_eventctors_sensors.html (3120B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=675884
      5 -->
      6 <head>
      7  <title>Test for Bug 675884</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 
     20 SimpleTest.waitForExplicitFinish();
     21 
     22 SpecialPowers.pushPrefEnv({"set": [
     23  ["device.sensors.enabled", true],
     24  ["device.sensors.orientation.enabled", true],
     25  ["device.sensors.motion.enabled", true],
     26  ["device.sensors.proximity.enabled", true],
     27  ["device.sensors.ambientLight.enabled", true]
     28 ]}, () => {
     29  let receivedEvent;
     30  document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
     31 
     32  // UserProximityEvent
     33  e = new UserProximityEvent("hello", {near: true});
     34  is(e.type, "hello", "Wrong event type!");
     35  ok(!e.isTrusted, "Event should not be trusted");
     36  is(e.near, true, "near should be true");
     37  document.dispatchEvent(e);
     38  is(receivedEvent, e, "Wrong event!");
     39 
     40  // DeviceLightEvent
     41  e = new DeviceLightEvent("hello", {value: 1} );
     42  is(e.type, "hello", "Wrong event type!");
     43  ok(!e.isTrusted, "Event should not be trusted");
     44  is(e.value, 1, "value should be 1");
     45  document.dispatchEvent(e);
     46  is(receivedEvent, e, "Wrong event!");
     47  e = new DeviceLightEvent("hello", {value: Infinity} );
     48  is(e.value, Infinity, "value should be positive infinity");
     49  e = new DeviceLightEvent("hello", {value: -Infinity} );
     50  is(e.value, -Infinity, "value should be negative infinity");
     51  e = new DeviceLightEvent("hello");
     52  is(e.value, Infinity, "Uninitialized value should be positive infinity");
     53 
     54  // DeviceOrientationEvent
     55  e = new DeviceOrientationEvent("hello");
     56  is(e.type, "hello", "Wrong event type!");
     57  ok(!e.isTrusted, "Event should not be trusted");
     58  is(e.alpha, null);
     59  is(e.beta, null);
     60  is(e.gamma, null);
     61  is(e.absolute, false);
     62 
     63  e = new DeviceOrientationEvent("hello", { alpha: 1, beta: 2, gamma: 3, absolute: true } );
     64  is(e.type, "hello", "Wrong event type!");
     65  ok(!e.isTrusted, "Event should not be trusted");
     66  is(e.alpha, 1);
     67  is(e.beta, 2);
     68  is(e.gamma, 3);
     69  is(e.absolute, true);
     70  document.dispatchEvent(e);
     71  is(receivedEvent, e, "Wrong event!");
     72 
     73  // DeviceMotionEvent
     74  e = new DeviceMotionEvent("hello");
     75  is(e.type, "hello", "Wrong event type!");
     76  ok(!e.isTrusted, "Event should not be trusted");
     77  is(typeof e.acceleration, "object");
     78  is(e.acceleration.x, null);
     79  is(e.acceleration.y, null);
     80  is(e.acceleration.z, null);
     81  is(typeof e.accelerationIncludingGravity, "object");
     82  is(e.accelerationIncludingGravity.x, null);
     83  is(e.accelerationIncludingGravity.y, null);
     84  is(e.accelerationIncludingGravity.z, null);
     85  is(typeof e.rotationRate, "object");
     86  is(e.rotationRate.alpha, null);
     87  is(e.rotationRate.beta, null);
     88  is(e.rotationRate.gamma, null);
     89  is(e.interval, null);
     90 
     91  SimpleTest.finish();
     92 });
     93 
     94 </script>
     95 </pre>
     96 </body>
     97 </html>