summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/geolocation/test_native_provider.html
blob: e0c26c611ab3cf521b0fa1ed6ea1b44d8ad555be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1596164
https://bugzilla.mozilla.org/show_bug.cgi?id=1765835
-->
<head>
  <title>Test for getCurrentPosition with native location provider</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1596164">Mozilla Bug 1596164</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1765835">Mozilla Bug 1765835</a>
<script type="text/javascript">
"use strict";

add_task(async function test_maximumAge() {
  await SpecialPowers.pushPrefEnv({
    set: [["geo.provider.testing", false]],
  });

  await new Promise(resolve => {
    navigator.geolocation.getCurrentPosition(() => {
      ok(true, "can get position");
      resolve();
    }, () => {
      ok(false, "error callback should not have been called");
      resolve();
    },
    { maximumAge: 10000 });
  });
});

add_task(async function test_highAccuracy() {
  await SpecialPowers.pushPrefEnv({
    set: [["geo.provider.testing", false]],
  });

  const lowAccuracy = await new Promise(resolve => {
    navigator.geolocation.getCurrentPosition((pos) => {
      resolve(pos.coords.accuracy);
    }, () => {
      ok(false, "error callback should not have been called on low accuracy call");
      resolve();
    },
    { enableHighAccuracy: false});
  });

  const highAccuracy = await new Promise(resolve => {
    navigator.geolocation.getCurrentPosition((pos) => {
      resolve(pos.coords.accuracy);
    }, () => {
      ok(false, "error callback should not have been called on high accuracy call");
      resolve();
    },
    { enableHighAccuracy: true});
  });

  // Low accuracy can sometimes be the same as high accuracy 
  // if a location provider recently provided a value
  if(highAccuracy >= lowAccuracy ){
    ok(true, "accuracy is correct");
  } else {
    ok(false, "lower accuracy calls should not out perform high accuracy calls");
  }
});
</script>
</body>
</html>