Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=662678 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 662678</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=662678">Mozilla Bug 662678</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script type="application/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 662678 **/ |
michael@0 | 21 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | var checkMotion = function(event) { |
michael@0 | 24 | window.removeEventListener("devicemotion", checkMotion, true); |
michael@0 | 25 | |
michael@0 | 26 | is(event.acceleration.x, 1.5, "acceleration.x"); |
michael@0 | 27 | is(event.acceleration.y, 2.5, "acceleration.y"); |
michael@0 | 28 | is(event.acceleration.z, 3.5, "acceleration.z"); |
michael@0 | 29 | is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x"); |
michael@0 | 30 | is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y"); |
michael@0 | 31 | is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z"); |
michael@0 | 32 | is(event.rotationRate.alpha, 7.5, "rotationRate.alpha"); |
michael@0 | 33 | is(event.rotationRate.beta, 8.5, "rotationRate.beta"); |
michael@0 | 34 | is(event.rotationRate.gamma, 9.5, "rotationRate.gamma"); |
michael@0 | 35 | is(event.interval, 0.5, "interval"); |
michael@0 | 36 | |
michael@0 | 37 | var e = document.createEvent("DeviceMotionEvent"); |
michael@0 | 38 | e.initDeviceMotionEvent('devicemotion', true, true, |
michael@0 | 39 | null, null, null, null); |
michael@0 | 40 | is(e.acceleration.x, null, "acceleration.x"); |
michael@0 | 41 | is(e.acceleration.y, null, "acceleration.y"); |
michael@0 | 42 | is(e.acceleration.z, null, "acceleration.z"); |
michael@0 | 43 | is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
michael@0 | 44 | is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
michael@0 | 45 | is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
michael@0 | 46 | is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
michael@0 | 47 | is(e.rotationRate.beta, null, "rotationRate.beta"); |
michael@0 | 48 | is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
michael@0 | 49 | is(e.interval, null, "interval"); |
michael@0 | 50 | |
michael@0 | 51 | e.initDeviceMotionEvent('devicemotion', true, true, |
michael@0 | 52 | {}, {}, {}, 0); |
michael@0 | 53 | is(e.acceleration.x, null, "acceleration.x"); |
michael@0 | 54 | is(e.acceleration.y, null, "acceleration.y"); |
michael@0 | 55 | is(e.acceleration.z, null, "acceleration.z"); |
michael@0 | 56 | is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
michael@0 | 57 | is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
michael@0 | 58 | is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
michael@0 | 59 | is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
michael@0 | 60 | is(e.rotationRate.beta, null, "rotationRate.beta"); |
michael@0 | 61 | is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
michael@0 | 62 | is(e.interval, 0, "interval"); |
michael@0 | 63 | |
michael@0 | 64 | window.addEventListener("devicemotion", checkMotionCtor, true); |
michael@0 | 65 | |
michael@0 | 66 | event = new DeviceMotionEvent('devicemotion', { |
michael@0 | 67 | bubbles: true, cancelable: true, |
michael@0 | 68 | acceleration: {x:1.5,y:2.5,z:3.5}, |
michael@0 | 69 | accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5}, |
michael@0 | 70 | rotationRate: {alpha:7.5,beta:8.5,gamma:9.5}, |
michael@0 | 71 | interval: 0.5 |
michael@0 | 72 | }); |
michael@0 | 73 | window.dispatchEvent(event); |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | var checkMotionCtor = function(event) { |
michael@0 | 77 | window.removeEventListener("devicemotion", checkMotionCtor, true); |
michael@0 | 78 | |
michael@0 | 79 | is(event.acceleration.x, 1.5, "acceleration.x"); |
michael@0 | 80 | is(event.acceleration.y, 2.5, "acceleration.y"); |
michael@0 | 81 | is(event.acceleration.z, 3.5, "acceleration.z"); |
michael@0 | 82 | is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x"); |
michael@0 | 83 | is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y"); |
michael@0 | 84 | is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z"); |
michael@0 | 85 | is(event.rotationRate.alpha, 7.5, "rotationRate.alpha"); |
michael@0 | 86 | is(event.rotationRate.beta, 8.5, "rotationRate.beta"); |
michael@0 | 87 | is(event.rotationRate.gamma, 9.5, "rotationRate.gamma"); |
michael@0 | 88 | is(event.interval, 0.5, "interval"); |
michael@0 | 89 | |
michael@0 | 90 | var e = new DeviceMotionEvent('devicemotion'); |
michael@0 | 91 | is(e.acceleration.x, null, "acceleration.x"); |
michael@0 | 92 | is(e.acceleration.y, null, "acceleration.y"); |
michael@0 | 93 | is(e.acceleration.z, null, "acceleration.z"); |
michael@0 | 94 | is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
michael@0 | 95 | is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
michael@0 | 96 | is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
michael@0 | 97 | is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
michael@0 | 98 | is(e.rotationRate.beta, null, "rotationRate.beta"); |
michael@0 | 99 | is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
michael@0 | 100 | is(e.interval, null, "interval"); |
michael@0 | 101 | |
michael@0 | 102 | e = new DeviceMotionEvent('devicemotion', { |
michael@0 | 103 | bubbles: true, cancelable: true, |
michael@0 | 104 | acceleration: null, accelerationIncludingGravity: null, |
michael@0 | 105 | rotationRate: null, interval: null |
michael@0 | 106 | }); |
michael@0 | 107 | is(e.acceleration.x, null, "acceleration.x"); |
michael@0 | 108 | is(e.acceleration.y, null, "acceleration.y"); |
michael@0 | 109 | is(e.acceleration.z, null, "acceleration.z"); |
michael@0 | 110 | is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
michael@0 | 111 | is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
michael@0 | 112 | is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
michael@0 | 113 | is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
michael@0 | 114 | is(e.rotationRate.beta, null, "rotationRate.beta"); |
michael@0 | 115 | is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
michael@0 | 116 | is(e.interval, null, "interval"); |
michael@0 | 117 | |
michael@0 | 118 | e = new DeviceMotionEvent('devicemotion', { |
michael@0 | 119 | bubbles: true, cancelable: true, |
michael@0 | 120 | acceleration: {}, accelerationIncludingGravity: {}, |
michael@0 | 121 | rotationRate: {}, interval: 0 |
michael@0 | 122 | }); |
michael@0 | 123 | is(e.acceleration.x, null, "acceleration.x"); |
michael@0 | 124 | is(e.acceleration.y, null, "acceleration.y"); |
michael@0 | 125 | is(e.acceleration.z, null, "acceleration.z"); |
michael@0 | 126 | is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x"); |
michael@0 | 127 | is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y"); |
michael@0 | 128 | is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z"); |
michael@0 | 129 | is(e.rotationRate.alpha, null, "rotationRate.alpha"); |
michael@0 | 130 | is(e.rotationRate.beta, null, "rotationRate.beta"); |
michael@0 | 131 | is(e.rotationRate.gamma, null, "rotationRate.gamma"); |
michael@0 | 132 | is(e.interval, 0, "interval"); |
michael@0 | 133 | |
michael@0 | 134 | SimpleTest.finish(); |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | window.addEventListener("devicemotion", checkMotion, true); |
michael@0 | 138 | |
michael@0 | 139 | var event = DeviceMotionEvent; |
michael@0 | 140 | ok(!!event, "Should have seen DeviceMotionEvent!"); |
michael@0 | 141 | |
michael@0 | 142 | event = document.createEvent("DeviceMotionEvent"); |
michael@0 | 143 | event.initDeviceMotionEvent('devicemotion', true, true, |
michael@0 | 144 | {x:1.5,y:2.5,z:3.5}, |
michael@0 | 145 | {x:4.5,y:5.5,z:6.5}, |
michael@0 | 146 | {alpha:7.5,beta:8.5,gamma:9.5}, |
michael@0 | 147 | 0.5); |
michael@0 | 148 | window.dispatchEvent(event); |
michael@0 | 149 | |
michael@0 | 150 | </script> |
michael@0 | 151 | </pre> |
michael@0 | 152 | </body> |
michael@0 | 153 | </html> |