Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 const Cc = Components.classes;
2 const Ci = Components.interfaces;
3 const Cu = Components.utils;
4 const Cr = Components.results;
6 Cu.import("resource://testing-common/httpd.js");
8 var httpserver = null;
9 var geolocation = null;
10 var success = false;
11 var watchId = -1;
13 function terminate(succ) {
14 success = succ;
15 geolocation.clearWatch(watchID);
16 }
18 function successCallback(pos){ terminate(true); }
19 function errorCallback(pos) { terminate(false); }
21 var observer = {
22 QueryInterface: function(iid) {
23 if (iid.equals(Ci.nsISupports) ||
24 iid.equals(Ci.nsIObserver))
25 return this;
26 throw Cr.NS_ERROR_NO_INTERFACE;
27 },
29 observe: function(subject, topic, data) {
30 if (data == "shutdown") {
31 do_check_true(1);
32 this._numProviders--;
33 if (!this._numProviders) {
34 httpserver.stop(function() {
35 do_check_true(success);
36 do_test_finished();
37 });
38 }
39 }
40 else if (data == "starting") {
41 do_check_true(1);
42 this._numProviders++;
43 }
44 },
46 _numProviders: 0,
47 };
49 function geoHandler(metadata, response)
50 {
51 var georesponse = {
52 status: "OK",
53 location: {
54 lat: 42,
55 lng: 42,
56 },
57 accuracy: 42,
58 };
59 var position = JSON.stringify(georesponse);
60 response.setStatusLine("1.0", 200, "OK");
61 response.setHeader("Cache-Control", "no-cache", false);
62 response.setHeader("Content-Type", "aplication/x-javascript", false);
63 response.write(position);
64 }
66 function run_test()
67 {
68 // XPCShell does not get a profile by default. The geolocation service
69 // depends on the settings service which uses IndexedDB and IndexedDB
70 // needs a place where it can store databases.
71 do_get_profile();
73 // only kill this test when shutdown is called on the provider.
74 do_test_pending();
76 httpserver = new HttpServer();
77 httpserver.registerPathHandler("/geo", geoHandler);
78 httpserver.start(-1);
80 var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
81 prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
82 httpserver.identity.primaryPort + "/geo");
83 prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
84 prefs.setBoolPref("geo.wifi.scan", false);
86 var obs = Cc["@mozilla.org/observer-service;1"].getService();
87 obs = obs.QueryInterface(Ci.nsIObserverService);
88 obs.addObserver(observer, "geolocation-device-events", false);
90 geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
91 watchID = geolocation.watchPosition(successCallback, errorCallback);
92 }