test_geolocation_reset_accuracy.js (2009B)
1 const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}"); 2 const providerContract = "@mozilla.org/geolocation/provider;1"; 3 4 const categoryName = "geolocation-provider"; 5 6 var provider = { 7 QueryInterface: ChromeUtils.generateQI([ 8 "nsIFactory", 9 "nsIGeolocationProvider", 10 ]), 11 createInstance: function eventsink_ci(iid) { 12 return this.QueryInterface(iid); 13 }, 14 startup() {}, 15 watch() {}, 16 shutdown() {}, 17 setHighAccuracy(enable) { 18 this._isHigh = enable; 19 if (enable) { 20 this._seenHigh = true; 21 executeSoon(stop_high_accuracy_watch); 22 } 23 }, 24 _isHigh: false, 25 _seenHigh: false, 26 }; 27 28 function successCallback() { 29 Assert.ok(false); 30 do_test_finished(); 31 } 32 33 function errorCallback() { 34 Assert.ok(false); 35 do_test_finished(); 36 } 37 38 var geolocation; 39 var watchID2; 40 41 function run_test() { 42 if (runningInParent) { 43 Components.manager.nsIComponentRegistrar.registerFactory( 44 providerCID, 45 "Unit test geo provider", 46 providerContract, 47 provider 48 ); 49 50 Services.catMan.addCategoryEntry( 51 categoryName, 52 "unit test", 53 providerContract, 54 false, 55 true 56 ); 57 58 Services.prefs.setBoolPref("geo.provider.network.scan", false); 59 } 60 61 do_test_pending(); 62 63 geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports); 64 geolocation.watchPosition(successCallback, errorCallback); 65 watchID2 = geolocation.watchPosition(successCallback, errorCallback, { 66 enableHighAccuracy: true, 67 }); 68 69 if (!runningInParent) { 70 do_await_remote_message("high_acc_enabled", stop_high_accuracy_watch); 71 } 72 } 73 74 function stop_high_accuracy_watch() { 75 geolocation.clearWatch(watchID2); 76 check_results(); 77 do_test_finished(); 78 } 79 80 function check_results() { 81 if (runningInParent) { 82 // check the provider was set to high accuracy during the test 83 Assert.ok(provider._seenHigh); 84 // check the provider is not currently set to high accuracy 85 Assert.ok(!provider._isHigh); 86 } 87 do_test_finished(); 88 }