tor-browser

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

test_enableHighAccuracy.html (2855B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1765835
      5 -->
      6 <head>
      7  <title>Tests for watchPosition and getCurrentPosition with setHighAccuracy</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1765835">Mozilla Bug 1765835</a>
     13 <script class="testbody" type="text/javascript">
     14 /* global sendAsyncMessage, addMessageListener */
     15 function mockChromeScript() {
     16  function enableHighAccuracy(subject, topic, data) {
     17    sendAsyncMessage("setHighAccuracy", data == "true");
     18  };
     19  Services.obs.addObserver(enableHighAccuracy, "testing-geolocation-high-accuracy");
     20 
     21  addMessageListener("cleanup", () => {
     22    Services.obs.removeObserver(enableHighAccuracy, "testing-geolocation-high-accuracy");
     23    sendAsyncMessage("done");
     24  });
     25 
     26  sendAsyncMessage("ready");
     27 }
     28 
     29 add_task(async function test_watchPosition() {
     30  await SpecialPowers.pushPrefEnv({
     31    set: [["geo.prompt.testing", true], ["geo.prompt.testing.allow", true]],
     32  });
     33 
     34  let chromeScript = SpecialPowers.loadChromeScript(mockChromeScript);
     35  await chromeScript.promiseOneMessage("ready");
     36 
     37  let id = navigator.geolocation.watchPosition(() => {}, () => {}, { enableHighAccuracy: true });
     38  let highAccuracy = await chromeScript.promiseOneMessage("setHighAccuracy");
     39  ok(highAccuracy, "enableHighAccuracy option should be enabled");
     40  navigator.geolocation.clearWatch(id);
     41 
     42  id = navigator.geolocation.watchPosition(() => {}, () => {}, { enableHighAccuracy: false });
     43  highAccuracy = await chromeScript.promiseOneMessage("setHighAccuracy");
     44  ok(!highAccuracy, "enableHighAccuracy option should be disabled");
     45  navigator.geolocation.clearWatch(id);
     46 
     47  chromeScript.sendAsyncMessage("cleanup");
     48  await chromeScript.promiseOneMessage("done");
     49  chromeScript.destroy();
     50 });
     51 
     52 add_task(async function test_getCurrentPosition() {
     53  await SpecialPowers.pushPrefEnv({
     54    set: [["geo.prompt.testing", true], ["geo.prompt.testing.allow", true]],
     55  });
     56 
     57  let chromeScript = SpecialPowers.loadChromeScript(mockChromeScript);
     58  await chromeScript.promiseOneMessage("ready");
     59 
     60  navigator.geolocation.getCurrentPosition(() => {}, () => {}, { enableHighAccuracy: true });
     61  let highAccuracy = await chromeScript.promiseOneMessage("setHighAccuracy");
     62  ok(highAccuracy, "enableHighAccuracy option should be enabled");
     63 
     64  navigator.geolocation.getCurrentPosition(() => {}, () => {}, { enableHighAccuracy: false });
     65  highAccuracy = await chromeScript.promiseOneMessage("setHighAccuracy");
     66  ok(!highAccuracy, "enableHighAccuracy option should be disabled");
     67 
     68  chromeScript.sendAsyncMessage("cleanup");
     69  await chromeScript.promiseOneMessage("done");
     70  chromeScript.destroy();
     71 });
     72 </script>
     73 </body>
     74 </html>