11import TKUnit = require( "Tests/TKUnit" ) ;
22import locationModule = require( "location/location" ) ;
3+ import types = require( "location/location_types" ) ;
34
45var LocationManager = locationModule . LocationManager ;
56var Location = locationModule . Location ;
@@ -16,17 +17,19 @@ export var testLocation = function () {
1617 locationManager . startLocationMonitoring ( function ( location ) {
1718 locationReceived = true ;
1819 } , function ( error ) {
19- console . log ( 'Location error received: ' + error ) ;
20+ // console.log('Location error received: ' + error);
2021 locationReceived = error ;
2122 }
22- ) ;
23+ ) ;
2324
2425 var isReady = function ( ) {
2526 return locationReceived ;
2627 }
2728
28- TKUnit . waitUntilReady ( isReady , 3 ) ;
29+ TKUnit . waitUntilReady ( isReady , 10 ) ;
30+
2931 locationManager . stopLocationMonitoring ( ) ;
32+
3033 TKUnit . assert ( true === locationReceived , locationReceived ) ;
3134} ;
3235
@@ -46,4 +49,44 @@ export var testLastKnownLocation = function () {
4649 var lastKnownLocation = locationManager . lastKnownLocation ;
4750 TKUnit . assert ( ( lastKnownLocation != null ) , "There is no last known location" ) ;
4851} ;
49-
52+
53+ function doOnce ( options : locationModule . Options ) {
54+ var locationReceived ;
55+ locationModule . getLocation ( options ) . then ( function ( location ) {
56+ locationReceived = true ;
57+ } ) . fail ( function ( error ) {
58+ //console.log('Location error received: ' + error);
59+ locationReceived = error ;
60+ } ) ;
61+
62+ var isReady = function ( ) {
63+ return locationReceived ;
64+ }
65+
66+ TKUnit . waitUntilReady ( isReady , 10 ) ;
67+
68+ TKUnit . assert ( true === locationReceived , locationReceived ) ;
69+ }
70+
71+ export var testLocationOnce = function ( ) {
72+ doOnce ( undefined ) ;
73+ } ;
74+
75+ export var testLocationOnceTimeout0 = function ( ) {
76+ doOnce ( { timeout : 0 } ) ;
77+ } ;
78+
79+ export var testLocationOnceMaximumAge = function ( ) {
80+ TKUnit . waitUntilReady ( function ( ) { return false ; } , 2 ) ;
81+ doOnce ( { maximumAge : 3000 , timeout : 0 } ) ; // this should pass
82+ try {
83+ doOnce ( { maximumAge : 1000 , timeout : 0 } ) ;
84+ TKUnit . assert ( false , "maximumAge check failed" ) ;
85+ }
86+ catch ( e ) {
87+ }
88+ } ;
89+
90+ export var testLocationOnceTimeout1000 = function ( ) {
91+ doOnce ( { timeout : 1000 } ) ;
92+ } ;
0 commit comments