Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | const Cc = Components.classes; |
michael@0 | 2 | const Ci = Components.interfaces; |
michael@0 | 3 | const Cu = Components.utils; |
michael@0 | 4 | const Cr = Components.results; |
michael@0 | 5 | |
michael@0 | 6 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 7 | |
michael@0 | 8 | var httpserver = null; |
michael@0 | 9 | var geolocation = null; |
michael@0 | 10 | var success = false; |
michael@0 | 11 | var watchId = -1; |
michael@0 | 12 | |
michael@0 | 13 | function geoHandler(metadata, response) |
michael@0 | 14 | { |
michael@0 | 15 | var georesponse = { |
michael@0 | 16 | status: "OK", |
michael@0 | 17 | location: { |
michael@0 | 18 | lat: 42, |
michael@0 | 19 | lng: 42, |
michael@0 | 20 | }, |
michael@0 | 21 | accuracy: 42, |
michael@0 | 22 | }; |
michael@0 | 23 | var position = JSON.stringify(georesponse); |
michael@0 | 24 | response.processAsync(); |
michael@0 | 25 | response.setStatusLine("1.0", 200, "OK"); |
michael@0 | 26 | response.setHeader("Cache-Control", "no-cache", false); |
michael@0 | 27 | response.setHeader("Content-Type", "aplication/x-javascript", false); |
michael@0 | 28 | do_timeout(5000, function() { |
michael@0 | 29 | response.write(position); |
michael@0 | 30 | response.finish(); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function successCallback() { |
michael@0 | 35 | do_check_true(false); |
michael@0 | 36 | do_test_finished(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function errorCallback() { |
michael@0 | 40 | do_check_true(true); |
michael@0 | 41 | do_test_finished(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function run_test() |
michael@0 | 45 | { |
michael@0 | 46 | do_test_pending(); |
michael@0 | 47 | |
michael@0 | 48 | if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) |
michael@0 | 49 | .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { |
michael@0 | 50 | // XPCShell does not get a profile by default. The geolocation service |
michael@0 | 51 | // depends on the settings service which uses IndexedDB and IndexedDB |
michael@0 | 52 | // needs a place where it can store databases. |
michael@0 | 53 | do_get_profile(); |
michael@0 | 54 | |
michael@0 | 55 | httpserver = new HttpServer(); |
michael@0 | 56 | httpserver.registerPathHandler("/geo", geoHandler); |
michael@0 | 57 | httpserver.start(-1); |
michael@0 | 58 | var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); |
michael@0 | 59 | prefs.setBoolPref("geo.wifi.scan", false); |
michael@0 | 60 | prefs.setCharPref("geo.wifi.uri", "http://localhost:" + |
michael@0 | 61 | httpserver.identity.primaryPort + "/geo"); |
michael@0 | 62 | prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); |
michael@0 | 66 | geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000}); |
michael@0 | 67 | } |