tor-browser

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

test_geolocation.xhtml (1542B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      4 <!--
      5  Test for Geolocation in chrome
      6  -->
      7 <window
      8  id="sample-window"
      9  width="400"
     10  height="400"
     11  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     12 >
     13  <script
     14    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"
     15  ></script>
     16 
     17  <script>
     18    SimpleTest.waitForExplicitFinish();
     19    async function test() {
     20      /** @type {Geolocation} */
     21      const geolocation = Cc["@mozilla.org/geolocation;1"].getService(
     22        Ci.nsISupports
     23      );
     24      try {
     25        // Watch position
     26        let watchId;
     27        let position = await new Promise((resolve, reject) => {
     28          watchId = geolocation.watchPosition(resolve, reject, { timeout: 0 });
     29        });
     30        ok(position, "watchPosition() callable from chrome");
     31        geolocation.clearWatch(watchId);
     32 
     33        // Get position
     34        position = await new Promise((resolve, reject) =>
     35          geolocation.getCurrentPosition(resolve, reject)
     36        );
     37        ok(position, "getCurrentPosition() callable from chrome");
     38      } catch (err) {
     39        ok(
     40          false,
     41          "error occurred trying to get geolocation from chrome: " + err.message
     42        );
     43      } finally {
     44        SimpleTest.finish();
     45      }
     46    }
     47  </script>
     48 
     49  <body
     50    xmlns="http://www.w3.org/1999/xhtml"
     51    style="height: 300px; overflow: auto;"
     52    onload="test()"
     53  />
     54 </window>