1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/unit/test_geolocation_timeout.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +const Cc = Components.classes; 1.5 +const Ci = Components.interfaces; 1.6 +const Cu = Components.utils; 1.7 +const Cr = Components.results; 1.8 + 1.9 +Cu.import("resource://testing-common/httpd.js"); 1.10 + 1.11 +var httpserver = null; 1.12 +var geolocation = null; 1.13 +var success = false; 1.14 +var watchId = -1; 1.15 + 1.16 +function geoHandler(metadata, response) 1.17 +{ 1.18 + var georesponse = { 1.19 + status: "OK", 1.20 + location: { 1.21 + lat: 42, 1.22 + lng: 42, 1.23 + }, 1.24 + accuracy: 42, 1.25 + }; 1.26 + var position = JSON.stringify(georesponse); 1.27 + response.processAsync(); 1.28 + response.setStatusLine("1.0", 200, "OK"); 1.29 + response.setHeader("Cache-Control", "no-cache", false); 1.30 + response.setHeader("Content-Type", "aplication/x-javascript", false); 1.31 + do_timeout(5000, function() { 1.32 + response.write(position); 1.33 + response.finish(); 1.34 + }); 1.35 +} 1.36 + 1.37 +function successCallback() { 1.38 + do_check_true(false); 1.39 + do_test_finished(); 1.40 +} 1.41 + 1.42 +function errorCallback() { 1.43 + do_check_true(true); 1.44 + do_test_finished(); 1.45 +} 1.46 + 1.47 +function run_test() 1.48 +{ 1.49 + do_test_pending(); 1.50 + 1.51 + if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) 1.52 + .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { 1.53 + // XPCShell does not get a profile by default. The geolocation service 1.54 + // depends on the settings service which uses IndexedDB and IndexedDB 1.55 + // needs a place where it can store databases. 1.56 + do_get_profile(); 1.57 + 1.58 + httpserver = new HttpServer(); 1.59 + httpserver.registerPathHandler("/geo", geoHandler); 1.60 + httpserver.start(-1); 1.61 + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); 1.62 + prefs.setBoolPref("geo.wifi.scan", false); 1.63 + prefs.setCharPref("geo.wifi.uri", "http://localhost:" + 1.64 + httpserver.identity.primaryPort + "/geo"); 1.65 + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); 1.66 + } 1.67 + 1.68 + geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); 1.69 + geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000}); 1.70 +}