tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_native_provider.html (2104B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1596164
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=1765835
      6 -->
      7 <head>
      8  <title>Test for getCurrentPosition with native location provider</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1596164">Mozilla Bug 1596164</a>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1765835">Mozilla Bug 1765835</a>
     15 <script type="text/javascript">
     16 "use strict";
     17 
     18 add_task(async function test_maximumAge() {
     19  await SpecialPowers.pushPrefEnv({
     20    set: [["geo.provider.testing", false]],
     21  });
     22 
     23  await new Promise(resolve => {
     24    navigator.geolocation.getCurrentPosition(() => {
     25      ok(true, "can get position");
     26      resolve();
     27    }, () => {
     28      ok(false, "error callback should not have been called");
     29      resolve();
     30    },
     31    { maximumAge: 10000 });
     32  });
     33 });
     34 
     35 add_task(async function test_highAccuracy() {
     36  await SpecialPowers.pushPrefEnv({
     37    set: [["geo.provider.testing", false]],
     38  });
     39 
     40  const lowAccuracy = await new Promise(resolve => {
     41    navigator.geolocation.getCurrentPosition((pos) => {
     42      resolve(pos.coords.accuracy);
     43    }, () => {
     44      ok(false, "error callback should not have been called on low accuracy call");
     45      resolve();
     46    },
     47    { enableHighAccuracy: false});
     48  });
     49 
     50  const highAccuracy = await new Promise(resolve => {
     51    navigator.geolocation.getCurrentPosition((pos) => {
     52      resolve(pos.coords.accuracy);
     53    }, () => {
     54      ok(false, "error callback should not have been called on high accuracy call");
     55      resolve();
     56    },
     57    { enableHighAccuracy: true});
     58  });
     59 
     60  // Low accuracy can sometimes be the same as high accuracy
     61  // if a location provider recently provided a value
     62  if(highAccuracy >= lowAccuracy ){
     63    ok(true, "accuracy is correct");
     64  } else {
     65    ok(false, "lower accuracy calls should not out perform high accuracy calls");
     66  }
     67 });
     68 </script>
     69 </body>
     70 </html>