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.GeoLocationTests = function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
2 |
module('Geolocation (navigator.geolocation)'); |
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.geolocation != null, "navigator.geolocation 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 have an initially null lastPosition property", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
8 |
expect(1); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
9 |
ok(typeof navigator.geolocation.lastPosition != 'undefined' && navigator.geolocation.lastPosition == null, "navigator.geolocation.lastPosition should be initially null."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
10 |
}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
11 |
test("should contain a getCurrentPosition function", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
12 |
expect(2); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
13 |
ok(typeof navigator.geolocation.getCurrentPosition != 'undefined' && navigator.geolocation.getCurrentPosition != null, "navigator.geolocation.getCurrentPosition should not be null."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
14 |
ok(typeof navigator.geolocation.getCurrentPosition == 'function', "navigator.geolocation.getCurrentPosition should be a function."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
15 |
}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
16 |
test("should contain a watchPosition function", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
17 |
expect(2); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
18 |
ok(typeof navigator.geolocation.watchPosition != 'undefined' && navigator.geolocation.watchPosition != null, "navigator.geolocation.watchPosition should not be null."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
19 |
ok(typeof navigator.geolocation.watchPosition == 'function', "navigator.geolocation.watchPosition should be a function."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
20 |
}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
21 |
test("getCurrentPosition success callback should be called with a Position object", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
22 |
expect(3); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
23 |
stop(tests.TEST_TIMEOUT); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
24 |
var win = function(p) { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
25 |
ok(p.coords != null, "Position object returned in getCurrentPosition success callback has a 'coords' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
26 |
ok(p.timestamp != null, "Position object returned in getCurrentPosition success callback has a 'timestamp' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
27 |
equals(p, navigator.geolocation.lastPosition, "Position object returned in getCurrentPosition success callback equals navigator.geolocation.lastPosition."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
28 |
start(); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
29 |
}; |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
30 |
var fail = function() { start(); }; |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
31 |
navigator.geolocation.getCurrentPosition(win, fail); |
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 |
// TODO: Need to test error callback... how? |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
34 |
// TODO: Need to test watchPosition success callback, test that makes sure clearPosition works (how to test that a timer is getting cleared?) |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
35 |
// TODO: Need to test options object passed in. Members that need to be tested so far include: |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
36 |
// - options.frequency: this is also labelled differently on some implementations (internval on iPhone/BlackBerry currently). |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
37 |
module('Geolocation model'); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
38 |
test("should be able to define a Position object with coords and timestamp properties", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
39 |
expect(3); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
40 |
var pos = new Position({}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
41 |
ok(pos != null, "new Position() should not be null."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
42 |
ok(typeof pos.coords != 'undefined' && pos.coords != null, "new Position() should include a 'coords' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
43 |
ok(typeof pos.timestamp != 'undefined' && pos.timestamp != null, "new Position() should include a 'timestamp' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
44 |
}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
45 |
test("should be able to define a Coordinates object with latitude, longitude, accuracy, altitude, heading and speed properties", function() { |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
46 |
expect(7); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
47 |
var coords = new Coordinates(1,2,3,4,5,6,7); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
48 |
ok(coords != null, "new Coordinates() should not be null."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
49 |
ok(typeof coords.latitude != 'undefined' && coords.latitude != null, "new Coordinates() should include a 'latitude' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
50 |
ok(typeof coords.longitude != 'undefined' && coords.longitude != null, "new Coordinates() should include a 'longitude' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
51 |
ok(typeof coords.accuracy != 'undefined' && coords.accuracy != null, "new Coordinates() should include a 'accuracy' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
52 |
ok(typeof coords.altitude != 'undefined' && coords.altitude != null, "new Coordinates() should include a 'altitude' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
53 |
ok(typeof coords.heading != 'undefined' && coords.heading != null, "new Coordinates() should include a 'heading' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
54 |
ok(typeof coords.speed != 'undefined' && coords.speed != null, "new Coordinates() should include a 'speed' property."); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
55 |
}); |
54063d8b0412
initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff
changeset
|
56 |
}; |