dom/tests/unit/test_geolocation_reset_accuracy.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/unit/test_geolocation_reset_accuracy.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     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_execute_soon(stop_high_accuracy_watch);
    1.39 +    }
    1.40 +  },
    1.41 +  _isHigh: false,
    1.42 +  _seenHigh: false
    1.43 +};
    1.44 +
    1.45 +let runningInParent = true;
    1.46 +try {
    1.47 +  runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
    1.48 +                    getService(Components.interfaces.nsIXULRuntime).processType
    1.49 +                    == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
    1.50 +}
    1.51 +catch (e) { }
    1.52 +
    1.53 +function successCallback()
    1.54 +{
    1.55 +  do_check_true(false);
    1.56 +  do_test_finished();
    1.57 +}
    1.58 +
    1.59 +function errorCallback()
    1.60 +{
    1.61 +  do_check_true(false);
    1.62 +  do_test_finished();
    1.63 +}
    1.64 +
    1.65 +var geolocation;
    1.66 +var watchID2;
    1.67 +
    1.68 +function run_test()
    1.69 +{
    1.70 +  if (runningInParent) {
    1.71 +    // XPCShell does not get a profile by default. The geolocation service
    1.72 +    // depends on the settings service which uses IndexedDB and IndexedDB
    1.73 +    // needs a place where it can store databases.
    1.74 +    do_get_profile();
    1.75 +
    1.76 +    Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
    1.77 +      "Unit test geo provider", providerContract, provider);
    1.78 +    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
    1.79 +                           .getService(Components.interfaces.nsICategoryManager);
    1.80 +    catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
    1.81 +                                               providerContract, false, true);
    1.82 +
    1.83 +    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    1.84 +    prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
    1.85 +    prefs.setBoolPref("geo.wifi.scan", false);
    1.86 +  }
    1.87 +
    1.88 +  do_test_pending();
    1.89 +
    1.90 +  geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
    1.91 +  let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
    1.92 +  watchID2 = geolocation.watchPosition(successCallback, errorCallback,
    1.93 +                                       {enableHighAccuracy: true});
    1.94 +
    1.95 +  if (!runningInParent) {
    1.96 +    do_await_remote_message('high_acc_enabled', stop_high_accuracy_watch);
    1.97 +  }
    1.98 +}
    1.99 +
   1.100 +function stop_high_accuracy_watch() {
   1.101 +    geolocation.clearWatch(watchID2);
   1.102 +    check_results();
   1.103 +}
   1.104 +
   1.105 +function check_results()
   1.106 +{
   1.107 +  if (runningInParent) {
   1.108 +    // check the provider was set to high accuracy during the test
   1.109 +    do_check_true(provider._seenHigh);
   1.110 +    // check the provider is not currently set to high accuracy
   1.111 +    do_check_false(provider._isHigh);
   1.112 +  }
   1.113 +  do_test_finished();
   1.114 +}

mercurial