Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / geolocation / two_watches.html
blobca2b0ab9f17049b63b5abeaf7af7da405807a8fc
1 <html>
2 <head>
3 <script>
4 var position_1 = 0;
5 var position_2 = 0;
6 var watch_1_id = 0;
7 var watch_2_id = 0;
8 var last_error = 0;
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)
22 return;
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);
30 return;
32 sendString('request-callback-success');
35 function checkIfGeopositionUpdated() {
36 if (position_updated)
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();
49 return;
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();
65 return;
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) {
74 last_error = 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;
97 return 'ok';
99 </script>
100 </head>
101 <body>
102 <input type="button" value="manual" onclick="geoStart()"/>
103 </body>
104 </html>