1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<script>
description('Tests to see if the last available event is fired.');
var mockEvent;
function setMockMotion(accelerationX, accelerationY, accelerationZ,
accelerationIncludingGravityX, accelerationIncludingGravityY, accelerationIncludingGravityZ,
rotationRateAlpha, rotationRateBeta, rotationRateGamma,
interval) {
mockEvent = {accelerationX: accelerationX, accelerationY: accelerationY, accelerationZ: accelerationZ,
accelerationIncludingGravityX: accelerationIncludingGravityX, accelerationIncludingGravityY: accelerationIncludingGravityY, accelerationIncludingGravityZ: accelerationIncludingGravityZ,
rotationRateAlpha: rotationRateAlpha, rotationRateBeta: rotationRateBeta, rotationRateGamma: rotationRateGamma,
interval: interval};
if (window.testRunner)
testRunner.setMockDeviceMotion(null != mockEvent.accelerationX, null == mockEvent.accelerationX ? 0 : mockEvent.accelerationX,
null != mockEvent.accelerationY, null == mockEvent.accelerationY ? 0 : mockEvent.accelerationY,
null != mockEvent.accelerationZ, null == mockEvent.accelerationZ ? 0 : mockEvent.accelerationZ,
null != mockEvent.accelerationIncludingGravityX, null == mockEvent.accelerationIncludingGravityX ? 0 : mockEvent.accelerationIncludingGravityX,
null != mockEvent.accelerationIncludingGravityY, null == mockEvent.accelerationIncludingGravityY ? 0 : mockEvent.accelerationIncludingGravityY,
null != mockEvent.accelerationIncludingGravityZ, null == mockEvent.accelerationIncludingGravityZ ? 0 : mockEvent.accelerationIncludingGravityZ,
null != mockEvent.rotationRateAlpha, null == mockEvent.rotationRateAlpha ? 0 : mockEvent.rotationRateAlpha,
null != mockEvent.rotationRateBeta, null == mockEvent.rotationRateBeta ? 0 : mockEvent.rotationRateBeta,
null != mockEvent.rotationRateGamma, null == mockEvent.rotationRateGamma ? 0 : mockEvent.rotationRateGamma,
interval);
else
debug('This test can not be run without the TestRunner');
}
var deviceMotionEvent;
function checkMotion(event) {
deviceMotionEvent = event;
shouldBe('deviceMotionEvent.acceleration.x', 'mockEvent.accelerationX');
shouldBe('deviceMotionEvent.acceleration.y', 'mockEvent.accelerationY');
shouldBe('deviceMotionEvent.acceleration.z', 'mockEvent.accelerationZ');
shouldBe('deviceMotionEvent.accelerationIncludingGravity.x', 'mockEvent.accelerationIncludingGravityX');
shouldBe('deviceMotionEvent.accelerationIncludingGravity.y', 'mockEvent.accelerationIncludingGravityY');
shouldBe('deviceMotionEvent.accelerationIncludingGravity.z', 'mockEvent.accelerationIncludingGravityZ');
shouldBe('deviceMotionEvent.rotationRate.alpha', 'mockEvent.rotationRateAlpha');
shouldBe('deviceMotionEvent.rotationRate.beta', 'mockEvent.rotationRateBeta');
shouldBe('deviceMotionEvent.rotationRate.gamma', 'mockEvent.rotationRateGamma');
shouldBe('deviceMotionEvent.interval', 'mockEvent.interval');
}
function mainFrameListener(event) {
checkMotion(event);
var childFrame = document.createElement('iframe');
document.body.appendChild(childFrame);
window.removeEventListener('devicemotion', mainFrameListener);
testRunner.setMockDeviceMotion(true, 0, true, 0, true, 0,
true, 0, true, 0, true, 0,
true, 0, true, 0, true, 0,
0);
childFrame.contentWindow.addEventListener('devicemotion', childFrameListener);
}
function childFrameListener(event) {
checkMotion(event);
finishJSTest();
}
setMockMotion(1, 2, 3,
4, 5, 6,
7, 8, 9,
10);
window.addEventListener('devicemotion', mainFrameListener);
window.jsTestIsAsync = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
|