9 var expected_final_position_latitude
= 0;
10 var expected_final_position_longitude
= 0;
11 var first_position_received
= false;
12 var position_updated
= false;
14 function sendString(string
) {
15 window
.domAutomationController
.send(string
);
18 // The permission request is not considered complete until both of the
19 // watches have been set.
20 function possiblyNotifyFirstPositionReceived() {
21 if (position_1
== 0 || position_2
== 0 || first_position_received
)
23 first_position_received
= true;
24 if (position_1
.coords
.latitude
!= position_2
.coords
.latitude
||
25 position_1
.coords
.longitude
!= position_2
.coords
.longitude
) {
26 last_error
= "TEST FAIL: watches received different locations. " +
27 " Watch 1 (" + watch_1_id
+ ") got " + position_1
+
28 " Watch 2 (" + watch_2_id
+ ") got " + position_2
;
29 sendString(last_error
);
32 sendString('request-callback-success');
35 function checkIfGeopositionUpdated() {
37 sendString('geoposition-updated');
40 // This will be triggered twice:
41 // 1. When the permission request is approved, it will receive an initial
42 // value. At this point, the callback does not directly notify success
43 // because success won't be complete until both callbacks are invoked.
44 // 2. When a new geolocation value is supplied.
45 function geoSuccessCallback1(position
) {
46 position_1
= position
;
47 if (!first_position_received
) {
48 possiblyNotifyFirstPositionReceived();
51 if (position
.coords
.latitude
== expected_final_position_latitude
&&
52 position
.coords
.longitude
== expected_final_position_longitude
) {
53 position_updated
= true;
54 sendString('geoposition-updated');
58 // This callback will be triggered once, when the permission request is
59 // approved. After that, it unregisters itself.
60 function geoSuccessCallback2(position
) {
61 navigator
.geolocation
.clearWatch(watch_2_id
);
62 position_2
= position
;
63 if (!first_position_received
) {
64 possiblyNotifyFirstPositionReceived();
67 if (position
.coords
.latitude
== expected_final_position_latitude
||
68 position
.coords
.longitude
== expected_final_position_longitude
) {
69 last_error
= "TEST FAIL: watch 2 received the final position";
73 function geoErrorCallback(error
) {
75 sendString('request-callback-error');
77 function geoStartWithAsyncResponse() {
78 watch_1_id
= navigator
.geolocation
.watchPosition(
79 geoSuccessCallback1
, geoErrorCallback
,
80 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:false});
81 watch_2_id
= navigator
.geolocation
.watchPosition(
82 geoSuccessCallback2
, geoErrorCallback
,
83 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:true});
85 function geoGetLastPositionLatitude() {
86 return "" + position_1
.coords
.latitude
;
88 function geoGetLastPositionLongitude() {
89 return "" + position_1
.coords
.longitude
;
91 function geoGetLastError() {
92 return "" + (last_error
? last_error
: 0);
94 function geoSetFinalPosition(latitude
, longitude
) {
95 expected_final_position_latitude
= latitude
;
96 expected_final_position_longitude
= longitude
;
102 <input type=
"button" value=
"manual" onclick=
"geoStart()"/>