Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / tests / unit / test_geolocation_provider.js
blobe08887bfce413ab5aa84b73d5de5d4ef0de4196c
1 const { HttpServer } = ChromeUtils.importESModule(
2 "resource://testing-common/httpd.sys.mjs"
3 );
5 var httpserver = null;
6 var geolocation = null;
7 var success = false;
8 var watchID = -1;
10 function terminate(succ) {
11 success = succ;
12 geolocation.clearWatch(watchID);
15 function successCallback() {
16 terminate(true);
18 function errorCallback() {
19 terminate(false);
22 var observer = {
23 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
25 observe(subject, topic, data) {
26 if (data == "shutdown") {
27 Assert.ok(1);
28 this._numProviders--;
29 if (!this._numProviders) {
30 httpserver.stop(function () {
31 Assert.ok(success);
32 do_test_finished();
33 });
35 } else if (data == "starting") {
36 Assert.ok(1);
37 this._numProviders++;
41 _numProviders: 0,
44 function geoHandler(metadata, response) {
45 var georesponse = {
46 status: "OK",
47 location: {
48 lat: 42,
49 lng: 42,
51 accuracy: 42,
53 var position = JSON.stringify(georesponse);
54 response.setStatusLine("1.0", 200, "OK");
55 response.setHeader("Cache-Control", "no-cache", false);
56 response.setHeader("Content-Type", "aplication/x-javascript", false);
57 response.write(position);
60 function run_test() {
61 // XPCShell does not get a profile by default. The geolocation service
62 // depends on the settings service which uses IndexedDB and IndexedDB
63 // needs a place where it can store databases.
64 do_get_profile();
66 // only kill this test when shutdown is called on the provider.
67 do_test_pending();
69 httpserver = new HttpServer();
70 httpserver.registerPathHandler("/geo", geoHandler);
71 httpserver.start(-1);
73 Services.prefs.setCharPref(
74 "geo.provider.network.url",
75 "http://localhost:" + httpserver.identity.primaryPort + "/geo"
77 Services.prefs.setBoolPref("geo.provider.network.scan", false);
79 var obs = Cc["@mozilla.org/observer-service;1"].getService();
80 obs = obs.QueryInterface(Ci.nsIObserverService);
81 obs.addObserver(observer, "geolocation-device-events");
83 geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
84 watchID = geolocation.watchPosition(successCallback, errorCallback);