1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/unit/test_geolocation_reset_accuracy_wrap.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +const Cc = Components.classes; 1.5 +const Ci = Components.interfaces; 1.6 + 1.7 +const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); 1.8 +const providerContract = "@mozilla.org/geolocation/provider;1"; 1.9 + 1.10 +const categoryName = "geolocation-provider"; 1.11 + 1.12 +var provider = { 1.13 + QueryInterface: function eventsink_qi(iid) { 1.14 + if (iid.equals(Components.interfaces.nsISupports) || 1.15 + iid.equals(Components.interfaces.nsIFactory) || 1.16 + iid.equals(Components.interfaces.nsIGeolocationProvider)) 1.17 + return this; 1.18 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.19 + }, 1.20 + createInstance: function eventsink_ci(outer, iid) { 1.21 + if (outer) 1.22 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.23 + return this.QueryInterface(iid); 1.24 + }, 1.25 + lockFactory: function eventsink_lockf(lock) { 1.26 + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; 1.27 + }, 1.28 + startup: function() { 1.29 + }, 1.30 + watch: function() { 1.31 + }, 1.32 + shutdown: function() { 1.33 + }, 1.34 + setHighAccuracy: function(enable) { 1.35 + this._isHigh = enable; 1.36 + if (enable) { 1.37 + this._seenHigh = true; 1.38 + do_send_remote_message('high_acc_enabled'); 1.39 + } 1.40 + }, 1.41 + _isHigh: false, 1.42 + _seenHigh: false 1.43 +}; 1.44 + 1.45 +function run_test() 1.46 +{ 1.47 + // XPCShell does not get a profile by default. The geolocation service 1.48 + // depends on the settings service which uses IndexedDB and IndexedDB 1.49 + // needs a place where it can store databases. 1.50 + do_get_profile(); 1.51 + 1.52 + Components.manager.nsIComponentRegistrar.registerFactory(providerCID, 1.53 + "Unit test geo provider", providerContract, provider); 1.54 + var catMan = Components.classes["@mozilla.org/categorymanager;1"] 1.55 + .getService(Components.interfaces.nsICategoryManager); 1.56 + catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", 1.57 + providerContract, false, true); 1.58 + 1.59 + var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); 1.60 + prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); 1.61 + prefs.setBoolPref("geo.wifi.scan", false); 1.62 + 1.63 + run_test_in_child("test_geolocation_reset_accuracy.js", check_results); 1.64 +} 1.65 + 1.66 +function check_results() 1.67 +{ 1.68 + // check the provider was set to high accuracy during the test 1.69 + do_check_true(provider._seenHigh); 1.70 + // check the provider is not currently set to high accuracy 1.71 + do_check_false(provider._isHigh); 1.72 + 1.73 + do_test_finished(); 1.74 +}