dom/events/test/test_bug662678.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug662678.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,153 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=662678
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 662678</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=662678">Mozilla Bug 662678</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 662678 **/
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +
    1.26 +var checkMotion = function(event) {
    1.27 +  window.removeEventListener("devicemotion", checkMotion, true);
    1.28 +
    1.29 +  is(event.acceleration.x, 1.5, "acceleration.x");
    1.30 +  is(event.acceleration.y, 2.5, "acceleration.y");
    1.31 +  is(event.acceleration.z, 3.5, "acceleration.z");
    1.32 +  is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x");
    1.33 +  is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y");
    1.34 +  is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z");
    1.35 +  is(event.rotationRate.alpha, 7.5, "rotationRate.alpha");
    1.36 +  is(event.rotationRate.beta, 8.5, "rotationRate.beta");
    1.37 +  is(event.rotationRate.gamma, 9.5, "rotationRate.gamma");
    1.38 +  is(event.interval, 0.5, "interval");
    1.39 +
    1.40 +  var e = document.createEvent("DeviceMotionEvent");
    1.41 +  e.initDeviceMotionEvent('devicemotion', true, true,
    1.42 +                          null, null, null, null);
    1.43 +  is(e.acceleration.x, null, "acceleration.x");
    1.44 +  is(e.acceleration.y, null, "acceleration.y");
    1.45 +  is(e.acceleration.z, null, "acceleration.z");
    1.46 +  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
    1.47 +  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
    1.48 +  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
    1.49 +  is(e.rotationRate.alpha, null, "rotationRate.alpha");
    1.50 +  is(e.rotationRate.beta, null, "rotationRate.beta");
    1.51 +  is(e.rotationRate.gamma, null, "rotationRate.gamma");
    1.52 +  is(e.interval, null, "interval");
    1.53 +
    1.54 +  e.initDeviceMotionEvent('devicemotion', true, true,
    1.55 +                          {}, {}, {}, 0);
    1.56 +  is(e.acceleration.x, null, "acceleration.x");
    1.57 +  is(e.acceleration.y, null, "acceleration.y");
    1.58 +  is(e.acceleration.z, null, "acceleration.z");
    1.59 +  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
    1.60 +  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
    1.61 +  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
    1.62 +  is(e.rotationRate.alpha, null, "rotationRate.alpha");
    1.63 +  is(e.rotationRate.beta, null, "rotationRate.beta");
    1.64 +  is(e.rotationRate.gamma, null, "rotationRate.gamma");
    1.65 +  is(e.interval, 0, "interval");
    1.66 +
    1.67 +  window.addEventListener("devicemotion", checkMotionCtor, true);
    1.68 +
    1.69 +  event = new DeviceMotionEvent('devicemotion', {
    1.70 +    bubbles: true, cancelable: true,
    1.71 +    acceleration: {x:1.5,y:2.5,z:3.5},
    1.72 +    accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5},
    1.73 +    rotationRate: {alpha:7.5,beta:8.5,gamma:9.5},
    1.74 +    interval: 0.5
    1.75 +  });
    1.76 +  window.dispatchEvent(event);
    1.77 +};
    1.78 +
    1.79 +var checkMotionCtor = function(event) {
    1.80 +  window.removeEventListener("devicemotion", checkMotionCtor, true);
    1.81 +
    1.82 +  is(event.acceleration.x, 1.5, "acceleration.x");
    1.83 +  is(event.acceleration.y, 2.5, "acceleration.y");
    1.84 +  is(event.acceleration.z, 3.5, "acceleration.z");
    1.85 +  is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x");
    1.86 +  is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y");
    1.87 +  is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z");
    1.88 +  is(event.rotationRate.alpha, 7.5, "rotationRate.alpha");
    1.89 +  is(event.rotationRate.beta, 8.5, "rotationRate.beta");
    1.90 +  is(event.rotationRate.gamma, 9.5, "rotationRate.gamma");
    1.91 +  is(event.interval, 0.5, "interval");
    1.92 +
    1.93 +  var e = new DeviceMotionEvent('devicemotion');
    1.94 +  is(e.acceleration.x, null, "acceleration.x");
    1.95 +  is(e.acceleration.y, null, "acceleration.y");
    1.96 +  is(e.acceleration.z, null, "acceleration.z");
    1.97 +  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
    1.98 +  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
    1.99 +  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
   1.100 +  is(e.rotationRate.alpha, null, "rotationRate.alpha");
   1.101 +  is(e.rotationRate.beta, null, "rotationRate.beta");
   1.102 +  is(e.rotationRate.gamma, null, "rotationRate.gamma");
   1.103 +  is(e.interval, null, "interval");
   1.104 +
   1.105 +  e = new DeviceMotionEvent('devicemotion', {
   1.106 +    bubbles: true, cancelable: true,
   1.107 +    acceleration: null, accelerationIncludingGravity: null,
   1.108 +    rotationRate: null, interval: null
   1.109 +  });
   1.110 +  is(e.acceleration.x, null, "acceleration.x");
   1.111 +  is(e.acceleration.y, null, "acceleration.y");
   1.112 +  is(e.acceleration.z, null, "acceleration.z");
   1.113 +  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
   1.114 +  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
   1.115 +  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
   1.116 +  is(e.rotationRate.alpha, null, "rotationRate.alpha");
   1.117 +  is(e.rotationRate.beta, null, "rotationRate.beta");
   1.118 +  is(e.rotationRate.gamma, null, "rotationRate.gamma");
   1.119 +  is(e.interval, null, "interval");
   1.120 +
   1.121 +  e = new DeviceMotionEvent('devicemotion', {
   1.122 +    bubbles: true, cancelable: true,
   1.123 +    acceleration: {}, accelerationIncludingGravity: {},
   1.124 +    rotationRate: {}, interval: 0
   1.125 +  });
   1.126 +  is(e.acceleration.x, null, "acceleration.x");
   1.127 +  is(e.acceleration.y, null, "acceleration.y");
   1.128 +  is(e.acceleration.z, null, "acceleration.z");
   1.129 +  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
   1.130 +  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
   1.131 +  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
   1.132 +  is(e.rotationRate.alpha, null, "rotationRate.alpha");
   1.133 +  is(e.rotationRate.beta, null, "rotationRate.beta");
   1.134 +  is(e.rotationRate.gamma, null, "rotationRate.gamma");
   1.135 +  is(e.interval, 0, "interval");
   1.136 +
   1.137 +  SimpleTest.finish();
   1.138 +};
   1.139 +
   1.140 +window.addEventListener("devicemotion", checkMotion, true);
   1.141 +
   1.142 +var event = DeviceMotionEvent;
   1.143 +ok(!!event, "Should have seen DeviceMotionEvent!");
   1.144 +
   1.145 +event = document.createEvent("DeviceMotionEvent");
   1.146 +event.initDeviceMotionEvent('devicemotion', true, true, 
   1.147 +                            {x:1.5,y:2.5,z:3.5},
   1.148 +                            {x:4.5,y:5.5,z:6.5},
   1.149 +                            {alpha:7.5,beta:8.5,gamma:9.5},
   1.150 +                            0.5);
   1.151 +window.dispatchEvent(event);
   1.152 +
   1.153 +</script>
   1.154 +</pre>
   1.155 +</body>
   1.156 +</html>

mercurial