1description("Tests the optional properties of DeviceMotionEvent. Each property should be null if not set, or set to null or undefined.");
2
3function ObjectThrowingException() {};
4ObjectThrowingException.prototype.valueOf = function() { throw new Error('valueOf threw exception'); }
5ObjectThrowingException.prototype.__defineGetter__("x", function() { throw new Error('x getter exception'); });
6ObjectThrowingException.prototype.__defineGetter__("alpha", function() { throw new Error('alpha getter exception'); });
7var objectThrowingException = new ObjectThrowingException();
8
9function testException(expression, expectedException)
10{
11    shouldThrow(expression, '(function() { return "' + expectedException + '"; })();');
12}
13
14var event;
15
16evalAndLog("event = document.createEvent('DeviceMotionEvent')");
17shouldBeTrue("event.acceleration == null");
18shouldBeTrue("event.accelerationIncludingGravity == null");
19shouldBeTrue("event.rotationRate == null");
20shouldBeTrue("event.interval == null");
21
22evalAndLog("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)");
23shouldBeTrue("event.acceleration.x == 0");
24shouldBeTrue("event.acceleration.y == 1");
25shouldBeTrue("event.acceleration.z == 2");
26shouldBeTrue("event.accelerationIncludingGravity.x == 3");
27shouldBeTrue("event.accelerationIncludingGravity.y == 4");
28shouldBeTrue("event.accelerationIncludingGravity.z == 5");
29shouldBeTrue("event.rotationRate.alpha == 6");
30shouldBeTrue("event.rotationRate.beta == 7");
31shouldBeTrue("event.rotationRate.gamma == 8");
32shouldBeTrue("event.interval == 9");
33
34testException("event.initDeviceMotionEvent('', false, false, objectThrowingException, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9)", "Error: x getter exception");
35testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, objectThrowingException, {gamma: 8, beta: 7}, 9)", "Error: x getter exception");
36testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, z: 5}, objectThrowingException, 9)", "Error: alpha getter exception");
37
38testException("event.initDeviceMotionEvent('', false, false, {x: objectThrowingException, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)", "Error: valueOf threw exception");
39testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: objectThrowingException, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)", "Error: valueOf threw exception");
40testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: objectThrowingException}, 9)", "Error: valueOf threw exception");
41
42evalAndLog("event.initDeviceMotionEvent('', false, false, {y: 1, x: 0}, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9)");
43shouldBeTrue("event.acceleration.x == 0");
44shouldBeTrue("event.acceleration.y == 1");
45shouldBeTrue("event.acceleration.z == null");
46shouldBeTrue("event.accelerationIncludingGravity.x == 3");
47shouldBeTrue("event.accelerationIncludingGravity.y == null");
48shouldBeTrue("event.accelerationIncludingGravity.z == 5");
49shouldBeTrue("event.rotationRate.alpha == null");
50shouldBeTrue("event.rotationRate.beta == 7");
51shouldBeTrue("event.rotationRate.gamma == 8");
52shouldBeTrue("event.interval == 9");
53
54evalAndLog("event.initDeviceMotionEvent()");
55shouldBeTrue("event.acceleration == null");
56shouldBeTrue("event.accelerationIncludingGravity == null");
57shouldBeTrue("event.rotationRate == null");
58shouldBeTrue("event.interval == null");
59
60evalAndLog("event.initDeviceMotionEvent('', false, false, [], [], [], [])");
61shouldBeTrue("event.acceleration == null");
62shouldBeTrue("event.accelerationIncludingGravity == null");
63shouldBeTrue("event.rotationRate == null");
64shouldBeTrue("event.interval == 0");
65
66evalAndLog("event.initDeviceMotionEvent('', false, false, undefined, undefined, undefined, undefined)");
67shouldBeTrue("event.acceleration == null");
68shouldBeTrue("event.accelerationIncludingGravity == null");
69shouldBeTrue("event.rotationRate == null");
70shouldBeTrue("event.interval == null");
71
72evalAndLog("event.initDeviceMotionEvent('', false, false, '', '', '', '')");
73shouldBeTrue("event.acceleration == null");
74shouldBeTrue("event.accelerationIncludingGravity == null");
75shouldBeTrue("event.rotationRate == null");
76shouldBeTrue("event.interval == 0");
77
78evalAndLog("event.initDeviceMotionEvent('', false, false, null, null, null, null)");
79shouldBeTrue("event.acceleration == null");
80shouldBeTrue("event.accelerationIncludingGravity == null");
81shouldBeTrue("event.rotationRate == null");
82shouldBeTrue("event.interval == null");
83
84evalAndLog("event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: null}, {x: null, y: null, z: null}, {alpha: null, beta: null, gamma: null}, null)");
85shouldBeTrue("event.acceleration == null");
86shouldBeTrue("event.accelerationIncludingGravity == null");
87shouldBeTrue("event.rotationRate == null");
88shouldBeTrue("event.interval == null");
89
90evalAndLog("event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: 1}, {x: null, y: null, z: 2}, {alpha: null, beta: null, gamma: 3}, null)");
91shouldBeTrue("event.acceleration.x == null");
92shouldBeTrue("event.acceleration.y == null");
93shouldBeTrue("event.acceleration.z == 1");
94shouldBeTrue("event.accelerationIncludingGravity.x == null");
95shouldBeTrue("event.accelerationIncludingGravity.y == null");
96shouldBeTrue("event.accelerationIncludingGravity.z == 2");
97shouldBeTrue("event.rotationRate.alpha == null");
98shouldBeTrue("event.rotationRate.beta == null");
99shouldBeTrue("event.rotationRate.gamma == 3");
100shouldBeTrue("event.interval == null");
101
102evalAndLog("event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: undefined}, {x: undefined, y: undefined, z: undefined}, {alpha: undefined, beta: undefined, gamma: undefined}, undefined)");
103shouldBeTrue("event.acceleration == null");
104shouldBeTrue("event.accelerationIncludingGravity == null");
105shouldBeTrue("event.rotationRate == null");
106shouldBeTrue("event.interval == null");
107
108evalAndLog("event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: 1}, {x: undefined, y: undefined, z: 2}, {alpha: undefined, beta: undefined, gamma: 3}, undefined)");
109shouldBeTrue("event.acceleration.x == null");
110shouldBeTrue("event.acceleration.y == null");
111shouldBeTrue("event.acceleration.z == 1");
112shouldBeTrue("event.accelerationIncludingGravity.x == null");
113shouldBeTrue("event.accelerationIncludingGravity.y == null");
114shouldBeTrue("event.accelerationIncludingGravity.z == 2");
115shouldBeTrue("event.rotationRate.alpha == null");
116shouldBeTrue("event.rotationRate.beta == null");
117shouldBeTrue("event.rotationRate.gamma == 3");
118shouldBeTrue("event.interval == null");
119
120window.successfullyParsed = true;
121