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