dom/tests/unit/test_geolocation_reset_accuracy.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 const Cc = Components.classes;
michael@0 2 const Ci = Components.interfaces;
michael@0 3
michael@0 4 const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
michael@0 5 const providerContract = "@mozilla.org/geolocation/provider;1";
michael@0 6
michael@0 7 const categoryName = "geolocation-provider";
michael@0 8
michael@0 9 var provider = {
michael@0 10 QueryInterface: function eventsink_qi(iid) {
michael@0 11 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 12 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 13 iid.equals(Components.interfaces.nsIGeolocationProvider))
michael@0 14 return this;
michael@0 15 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 16 },
michael@0 17 createInstance: function eventsink_ci(outer, iid) {
michael@0 18 if (outer)
michael@0 19 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 20 return this.QueryInterface(iid);
michael@0 21 },
michael@0 22 lockFactory: function eventsink_lockf(lock) {
michael@0 23 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 24 },
michael@0 25 startup: function() {
michael@0 26 },
michael@0 27 watch: function() {
michael@0 28 },
michael@0 29 shutdown: function() {
michael@0 30 },
michael@0 31 setHighAccuracy: function(enable) {
michael@0 32 this._isHigh = enable;
michael@0 33 if (enable) {
michael@0 34 this._seenHigh = true;
michael@0 35 do_execute_soon(stop_high_accuracy_watch);
michael@0 36 }
michael@0 37 },
michael@0 38 _isHigh: false,
michael@0 39 _seenHigh: false
michael@0 40 };
michael@0 41
michael@0 42 let runningInParent = true;
michael@0 43 try {
michael@0 44 runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
michael@0 45 getService(Components.interfaces.nsIXULRuntime).processType
michael@0 46 == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
michael@0 47 }
michael@0 48 catch (e) { }
michael@0 49
michael@0 50 function successCallback()
michael@0 51 {
michael@0 52 do_check_true(false);
michael@0 53 do_test_finished();
michael@0 54 }
michael@0 55
michael@0 56 function errorCallback()
michael@0 57 {
michael@0 58 do_check_true(false);
michael@0 59 do_test_finished();
michael@0 60 }
michael@0 61
michael@0 62 var geolocation;
michael@0 63 var watchID2;
michael@0 64
michael@0 65 function run_test()
michael@0 66 {
michael@0 67 if (runningInParent) {
michael@0 68 // XPCShell does not get a profile by default. The geolocation service
michael@0 69 // depends on the settings service which uses IndexedDB and IndexedDB
michael@0 70 // needs a place where it can store databases.
michael@0 71 do_get_profile();
michael@0 72
michael@0 73 Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
michael@0 74 "Unit test geo provider", providerContract, provider);
michael@0 75 var catMan = Components.classes["@mozilla.org/categorymanager;1"]
michael@0 76 .getService(Components.interfaces.nsICategoryManager);
michael@0 77 catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
michael@0 78 providerContract, false, true);
michael@0 79
michael@0 80 var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
michael@0 81 prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
michael@0 82 prefs.setBoolPref("geo.wifi.scan", false);
michael@0 83 }
michael@0 84
michael@0 85 do_test_pending();
michael@0 86
michael@0 87 geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
michael@0 88 let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
michael@0 89 watchID2 = geolocation.watchPosition(successCallback, errorCallback,
michael@0 90 {enableHighAccuracy: true});
michael@0 91
michael@0 92 if (!runningInParent) {
michael@0 93 do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch);
michael@0 94 }
michael@0 95 }
michael@0 96
michael@0 97 function stop_high_accuracy_watch() {
michael@0 98 geolocation.clearWatch(watchID2);
michael@0 99 check_results();
michael@0 100 }
michael@0 101
michael@0 102 function check_results()
michael@0 103 {
michael@0 104 if (runningInParent) {
michael@0 105 // check the provider was set to high accuracy during the test
michael@0 106 do_check_true(provider._seenHigh);
michael@0 107 // check the provider is not currently set to high accuracy
michael@0 108 do_check_false(provider._isHigh);
michael@0 109 }
michael@0 110 do_test_finished();
michael@0 111 }

mercurial