Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_send_remote_message('high_acc_enabled'); |
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 | function run_test() |
michael@0 | 43 | { |
michael@0 | 44 | // XPCShell does not get a profile by default. The geolocation service |
michael@0 | 45 | // depends on the settings service which uses IndexedDB and IndexedDB |
michael@0 | 46 | // needs a place where it can store databases. |
michael@0 | 47 | do_get_profile(); |
michael@0 | 48 | |
michael@0 | 49 | Components.manager.nsIComponentRegistrar.registerFactory(providerCID, |
michael@0 | 50 | "Unit test geo provider", providerContract, provider); |
michael@0 | 51 | var catMan = Components.classes["@mozilla.org/categorymanager;1"] |
michael@0 | 52 | .getService(Components.interfaces.nsICategoryManager); |
michael@0 | 53 | catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test", |
michael@0 | 54 | providerContract, false, true); |
michael@0 | 55 | |
michael@0 | 56 | var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); |
michael@0 | 57 | prefs.setBoolPref("dom.testing.ignore_ipc_principal", true); |
michael@0 | 58 | prefs.setBoolPref("geo.wifi.scan", false); |
michael@0 | 59 | |
michael@0 | 60 | run_test_in_child("test_geolocation_reset_accuracy.js", check_results); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function check_results() |
michael@0 | 64 | { |
michael@0 | 65 | // check the provider was set to high accuracy during the test |
michael@0 | 66 | do_check_true(provider._seenHigh); |
michael@0 | 67 | // check the provider is not currently set to high accuracy |
michael@0 | 68 | do_check_false(provider._isHigh); |
michael@0 | 69 | |
michael@0 | 70 | do_test_finished(); |
michael@0 | 71 | } |