|
1 Tests.prototype.AccelerometerTests = function() { |
|
2 module('Accelerometer (navigator.accelerometer)'); |
|
3 test("should exist", function() { |
|
4 expect(1); |
|
5 ok(navigator.accelerometer != null, "navigator.accelerometer should not be null."); |
|
6 }); |
|
7 test("should contain a getCurrentAcceleration function", function() { |
|
8 expect(2); |
|
9 ok(typeof navigator.accelerometer.getCurrentAcceleration != 'undefined' && navigator.accelerometer.getCurrentAcceleration != null, "navigator.accelerometer.getCurrentAcceleration should not be null."); |
|
10 ok(typeof navigator.accelerometer.getCurrentAcceleration == 'function', "navigator.accelerometer.getCurrentAcceleration should be a function."); |
|
11 }); |
|
12 test("getCurrentAcceleration success callback should be called with an Acceleration object", function() { |
|
13 expect(7); |
|
14 stop(tests.TEST_TIMEOUT); |
|
15 var win = function(a) { |
|
16 ok(typeof a == 'object', "Acceleration object returned in getCurrentAcceleration success callback should be of type 'object'."); |
|
17 ok(a.x != null, "Acceleration object returned in getCurrentAcceleration success callback should have an 'x' property."); |
|
18 ok(typeof a.x == 'number', "Acceleration object's 'x' property returned in getCurrentAcceleration success callback should be of type 'number'."); |
|
19 ok(a.y != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'y' property."); |
|
20 ok(typeof a.y == 'number', "Acceleration object's 'y' property returned in getCurrentAcceleration success callback should be of type 'number'."); |
|
21 ok(a.z != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'z' property."); |
|
22 ok(typeof a.z == 'number', "Acceleration object's 'z' property returned in getCurrentAcceleration success callback should be of type 'number'."); |
|
23 start(); |
|
24 }; |
|
25 var fail = function() { start(); }; |
|
26 navigator.accelerometer.getCurrentAcceleration(win, fail); |
|
27 }); |
|
28 test("should contain a watchAcceleration function", function() { |
|
29 expect(2); |
|
30 ok(typeof navigator.accelerometer.watchAcceleration != 'undefined' && navigator.accelerometer.watchAcceleration != null, "navigator.accelerometer.watchAcceleration should not be null."); |
|
31 ok(typeof navigator.accelerometer.watchAcceleration == 'function', "navigator.accelerometer.watchAcceleration should be a function."); |
|
32 }); |
|
33 test("should contain a clearWatch function", function() { |
|
34 expect(2); |
|
35 ok(typeof navigator.accelerometer.clearWatch != 'undefined' && navigator.accelerometer.clearWatch != null, "navigator.accelerometer.clearWatch should not be null."); |
|
36 ok(typeof navigator.accelerometer.clearWatch == 'function', "navigator.accelerometer.clearWatch should be a function!"); |
|
37 }); |
|
38 module('Acceleration model'); |
|
39 test("should be able to define a new Acceleration object with x, y, z and timestamp properties.", function () { |
|
40 expect(9); |
|
41 var x = 1; |
|
42 var y = 2; |
|
43 var z = 3; |
|
44 var a = new Acceleration(x, y, z); |
|
45 ok(a != null, "new Acceleration object should not be null."); |
|
46 ok(typeof a == 'object', "new Acceleration object should be of type 'object'."); |
|
47 ok(a.x != null, "new Acceleration object should have an 'x' property."); |
|
48 equals(a.x, x, "new Acceleration object should have 'x' property equal to first parameter passed in Acceleration constructor."); |
|
49 ok(a.y != null, "new Acceleration object should have a 'y' property."); |
|
50 equals(a.y, y, "new Acceleration object should have 'y' property equal to second parameter passed in Acceleration constructor."); |
|
51 ok(a.z != null, "new Acceleration object should have a 'z' property."); |
|
52 equals(a.z, z, "new Acceleration object should have 'z' property equal to third parameter passed in Acceleration constructor."); |
|
53 ok(a.timestamp != null, "new Acceleration object should have a 'timestamp' property."); |
|
54 }); |
|
55 }; |