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