1 const { HttpServer } = ChromeUtils.importESModule(
2 "resource://testing-common/httpd.sys.mjs"
5 let geolocation = null;
12 function geoHandler(metadata, response) {
13 let [lat, lng] = locations.shift();
14 response.setStatusLine("1.0", 200, "OK");
15 response.setHeader("Cache-Control", "no-cache", false);
16 response.setHeader("Content-Type", "application/x-javascript", false);
20 location: { lat, lng },
26 function toJSON(pos) {
27 return { lat: pos.coords.latitude, lng: pos.coords.longitude };
30 function getPosition() {
31 return new Promise(function (resolve, reject) {
32 geolocation.getCurrentPosition(resolve, reject);
36 function watchPosition() {
38 return new Promise(function (resolve, reject) {
39 let id = geolocation.watchPosition(position => {
42 Assert.deepEqual(toJSON(position), { lat: 3, lng: 4 });
43 Assert.deepEqual(observer._lastData, { lat: 3, lng: 4 });
44 Assert.equal(observer._countEvents, 2);
45 } else if (seen === 2) {
46 Assert.deepEqual(toJSON(position), { lat: 5, lng: 6 });
47 Assert.deepEqual(observer._lastData, { lat: 5, lng: 6 });
48 Assert.equal(observer._countEvents, 3);
49 geolocation.clearWatch(id);
57 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
59 observe(subject, topic) {
60 Assert.equal(topic, "geolocation-position-events");
61 observer._countEvents++;
62 observer._lastData = toJSON(subject);
69 add_task(async function test_resetClient() {
71 geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
73 let server = new HttpServer();
74 server.registerPathHandler("/geo", geoHandler);
77 Services.prefs.setCharPref(
78 "geo.provider.network.url",
79 "http://localhost:" + server.identity.primaryPort + "/geo"
81 Services.prefs.setBoolPref(
82 "geo.provider.network.debug.requestCache.enabled",
85 Services.prefs.setBoolPref("geo.provider.network.scan", false);
87 var obs = Cc["@mozilla.org/observer-service;1"].getService();
88 obs = obs.QueryInterface(Ci.nsIObserverService);
89 obs.addObserver(observer, "geolocation-position-events");
91 let position = await getPosition();
92 Assert.deepEqual(toJSON(position), { lat: 1, lng: 2 });
93 Assert.equal(observer._countEvents, 1);
94 Assert.deepEqual(observer._lastData, { lat: 1, lng: 2 });
96 await watchPosition();
98 await new Promise(resolve => server.stop(resolve));