michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: const Cr = Components.results; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: var httpserver = null; michael@0: var geolocation = null; michael@0: var success = false; michael@0: var watchId = -1; michael@0: michael@0: function geoHandler(metadata, response) michael@0: { michael@0: var georesponse = { michael@0: status: "OK", michael@0: location: { michael@0: lat: 42, michael@0: lng: 42, michael@0: }, michael@0: accuracy: 42, michael@0: }; michael@0: var position = JSON.stringify(georesponse); michael@0: response.processAsync(); michael@0: response.setStatusLine("1.0", 200, "OK"); michael@0: response.setHeader("Cache-Control", "no-cache", false); michael@0: response.setHeader("Content-Type", "aplication/x-javascript", false); michael@0: do_timeout(5000, function() { michael@0: response.write(position); michael@0: response.finish(); michael@0: }); michael@0: } michael@0: michael@0: function successCallback() { michael@0: do_check_true(false); michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function errorCallback() { michael@0: do_check_true(true); michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: do_test_pending(); michael@0: michael@0: if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) michael@0: .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { michael@0: // XPCShell does not get a profile by default. The geolocation service michael@0: // depends on the settings service which uses IndexedDB and IndexedDB michael@0: // needs a place where it can store databases. michael@0: do_get_profile(); michael@0: michael@0: httpserver = new HttpServer(); michael@0: httpserver.registerPathHandler("/geo", geoHandler); michael@0: httpserver.start(-1); michael@0: var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); michael@0: prefs.setBoolPref("geo.wifi.scan", false); michael@0: prefs.setCharPref("geo.wifi.uri", "http://localhost:" + michael@0: httpserver.identity.primaryPort + "/geo"); michael@0: prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); michael@0: } michael@0: michael@0: geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); michael@0: geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000}); michael@0: }