michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); michael@0: const providerContract = "@mozilla.org/geolocation/provider;1"; michael@0: michael@0: const categoryName = "geolocation-provider"; michael@0: michael@0: var provider = { michael@0: QueryInterface: function eventsink_qi(iid) { michael@0: if (iid.equals(Components.interfaces.nsISupports) || michael@0: iid.equals(Components.interfaces.nsIFactory) || michael@0: iid.equals(Components.interfaces.nsIGeolocationProvider)) michael@0: return this; michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: createInstance: function eventsink_ci(outer, iid) { michael@0: if (outer) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return this.QueryInterface(iid); michael@0: }, michael@0: lockFactory: function eventsink_lockf(lock) { michael@0: throw Components.results.NS_ERROR_NOT_IMPLEMENTED; michael@0: }, michael@0: startup: function() { michael@0: }, michael@0: watch: function() { michael@0: }, michael@0: shutdown: function() { michael@0: }, michael@0: setHighAccuracy: function(enable) { michael@0: this._isHigh = enable; michael@0: if (enable) { michael@0: this._seenHigh = true; michael@0: do_execute_soon(stop_high_accuracy_watch); michael@0: } michael@0: }, michael@0: _isHigh: false, michael@0: _seenHigh: false michael@0: }; michael@0: michael@0: let runningInParent = true; michael@0: try { michael@0: runningInParent = Components.classes["@mozilla.org/xre/runtime;1"]. michael@0: getService(Components.interfaces.nsIXULRuntime).processType michael@0: == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT; michael@0: } michael@0: catch (e) { } michael@0: michael@0: function successCallback() michael@0: { michael@0: do_check_true(false); michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function errorCallback() michael@0: { michael@0: do_check_true(false); michael@0: do_test_finished(); michael@0: } michael@0: michael@0: var geolocation; michael@0: var watchID2; michael@0: michael@0: function run_test() michael@0: { michael@0: if (runningInParent) { michael@0: // XPCShell does not get a profile by default. The geolocation service michael@0: // depends on the settings service which uses IndexedDB and IndexedDB michael@0: // needs a place where it can store databases. michael@0: do_get_profile(); michael@0: michael@0: Components.manager.nsIComponentRegistrar.registerFactory(providerCID, michael@0: "Unit test geo provider", providerContract, provider); michael@0: var catMan = Components.classes["@mozilla.org/categorymanager;1"] michael@0: .getService(Components.interfaces.nsICategoryManager); michael@0: catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", michael@0: providerContract, false, true); michael@0: michael@0: var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); michael@0: prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); michael@0: prefs.setBoolPref("geo.wifi.scan", false); michael@0: } michael@0: michael@0: do_test_pending(); michael@0: michael@0: geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports); michael@0: let watchID1 = geolocation.watchPosition(successCallback, errorCallback); michael@0: watchID2 = geolocation.watchPosition(successCallback, errorCallback, michael@0: {enableHighAccuracy: true}); michael@0: michael@0: if (!runningInParent) { michael@0: do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch); michael@0: } michael@0: } michael@0: michael@0: function stop_high_accuracy_watch() { michael@0: geolocation.clearWatch(watchID2); michael@0: check_results(); michael@0: } michael@0: michael@0: function check_results() michael@0: { michael@0: if (runningInParent) { michael@0: // check the provider was set to high accuracy during the test michael@0: do_check_true(provider._seenHigh); michael@0: // check the provider is not currently set to high accuracy michael@0: do_check_false(provider._isHigh); michael@0: } michael@0: do_test_finished(); michael@0: }