Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / geolocation / basic_geolocation.js
blob19c5d305032fb5dffbbff63e5f6635e4f399c06b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var last_position = 0;
6 var last_error = 0;
7 var watch_id = 0;
8 var position_initialized = false;
9 var position_updated = false;
11 function sendString(string) {
12   window.domAutomationController.send(string);
14 function geoSuccessCallback(position) {
15   last_position = position;
17 function geoErrorCallback(error) {
18   last_error = error;
20 function geoSuccessCallbackWithResponse(position) {
21   last_position = position;
23   if (!position_initialized) {  // First time callback invoked.
24     position_initialized = true;
25     sendString('request-callback-success');
26     return;
27   }
29   if (!position_updated) {  // Second time callback invoked.
30     position_updated = true;
31     sendString('geoposition-updated');
32   }
34 function geoErrorCallbackWithResponse(error) {
35   last_error = error;
36   sendString('request-callback-error');
38 function geoStart() {
39   watch_id = navigator.geolocation.watchPosition(
40       geoSuccessCallback, geoErrorCallback,
41       {maximumAge:600000, timeout:100000, enableHighAccuracy:true});
42   return watch_id;
44 function geoStartWithAsyncResponse() {
45   navigator.geolocation.watchPosition(
46             geoSuccessCallbackWithResponse, geoErrorCallbackWithResponse,
47             {maximumAge:600000, timeout:100000, enableHighAccuracy:true});
49 function geoStartWithSyncResponse() {
50   navigator.geolocation.watchPosition(
51             geoSuccessCallback, geoErrorCallback,
52             {maximumAge:600000, timeout:100000, enableHighAccuracy:true});
53   sendString('requested');
55 function checkIfGeopositionUpdated() {
56   if (position_updated)
57     sendString('geoposition-updated');
59 function geoGetLastPositionLatitude() {
60   return "" + last_position.coords.latitude;
62 function geoGetLastPositionLongitude() {
63   return "" + last_position.coords.longitude;
65 function geoGetLastError() {
66   return "" + (last_error ? last_error.code : 0);
68 function geoAccessNavigatorGeolocation() {
69   return "" + typeof(navigator.geolocation);