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