2019-01-17 21:18:31 +03:00
|
|
|
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2012-12-31 20:36:46 +04:00
|
|
|
|
|
|
|
var httpserver = null;
|
|
|
|
var geolocation = null;
|
|
|
|
var success = false;
|
|
|
|
var watchId = -1;
|
|
|
|
|
2019-01-18 21:56:46 +03:00
|
|
|
function geoHandler(metadata, response) {
|
2012-12-31 20:36:46 +04:00
|
|
|
var georesponse = {
|
|
|
|
status: "OK",
|
|
|
|
location: {
|
|
|
|
lat: 42,
|
|
|
|
lng: 42,
|
|
|
|
},
|
|
|
|
accuracy: 42,
|
|
|
|
};
|
|
|
|
var position = JSON.stringify(georesponse);
|
|
|
|
response.processAsync();
|
|
|
|
response.setStatusLine("1.0", 200, "OK");
|
|
|
|
response.setHeader("Cache-Control", "no-cache", false);
|
|
|
|
response.setHeader("Content-Type", "aplication/x-javascript", false);
|
|
|
|
do_timeout(5000, function() {
|
|
|
|
response.write(position);
|
|
|
|
response.finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function successCallback() {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(false);
|
2012-12-31 20:36:46 +04:00
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
function errorCallback() {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(true);
|
2012-12-31 20:36:46 +04:00
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
|
2019-01-18 21:56:46 +03:00
|
|
|
function run_test() {
|
2012-12-31 20:36:46 +04:00
|
|
|
do_test_pending();
|
|
|
|
|
2019-01-18 21:56:46 +03:00
|
|
|
if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
|
2013-09-28 15:25:46 +04:00
|
|
|
// XPCShell does not get a profile by default. The geolocation service
|
|
|
|
// depends on the settings service which uses IndexedDB and IndexedDB
|
|
|
|
// needs a place where it can store databases.
|
|
|
|
do_get_profile();
|
|
|
|
|
2013-07-10 07:45:02 +04:00
|
|
|
httpserver = new HttpServer();
|
|
|
|
httpserver.registerPathHandler("/geo", geoHandler);
|
|
|
|
httpserver.start(-1);
|
2020-02-06 17:50:22 +03:00
|
|
|
Services.prefs.setBoolPref("geo.provider.network.scan", false);
|
2019-01-18 21:56:46 +03:00
|
|
|
Services.prefs.setCharPref(
|
2020-02-06 17:50:22 +03:00
|
|
|
"geo.provider.network.url",
|
2019-01-18 21:56:46 +03:00
|
|
|
"http://localhost:" + httpserver.identity.primaryPort + "/geo"
|
|
|
|
);
|
|
|
|
Services.prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
|
2012-12-31 20:36:46 +04:00
|
|
|
}
|
|
|
|
|
2013-04-03 01:28:27 +04:00
|
|
|
geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
|
2012-12-31 20:36:46 +04:00
|
|
|
geolocation.getCurrentPosition(successCallback, errorCallback, {
|
|
|
|
timeout: 2000,
|
|
|
|
});
|
|
|
|
}
|