Commit 884eb27d authored by Ryan VanderMeulen's avatar Ryan VanderMeulen
Browse files

Backed out changeset 403bbc5e127f (bug 914888) for intermittent xpcshell failures.

parent 1c2211c8
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ class nsGeolocationRequest
  void Shutdown();

  void SendLocation(nsIDOMGeoPosition* location);
  bool WantsHighAccuracy() {return !mShutdown && mOptions && mOptions->mEnableHighAccuracy;}
  bool WantsHighAccuracy() {return mOptions && mOptions->mEnableHighAccuracy;}
  void SetTimeoutTimer();
  nsIPrincipal* GetPrincipal();

@@ -445,7 +445,7 @@ nsGeolocationRequest::Allow()
      maximumAge = mOptions->mMaximumAge;
    }
  }
  gs->UpdateAccuracy(WantsHighAccuracy());
  gs->SetHigherAccuracy(mOptions && mOptions->mEnableHighAccuracy);

  bool canUseCache = lastPosition && maximumAge > 0 &&
    (PRTime(PR_Now() / PR_USEC_PER_MSEC) - maximumAge <=
@@ -585,12 +585,12 @@ nsGeolocationRequest::Shutdown()
    mTimeoutTimer = nullptr;
  }

  // If there are no other high accuracy requests, the geolocation service will
  // notify the provider to switch to the default accuracy.
  // This should happen last, to ensure that this request isn't taken into consideration
  // when deciding whether existing requests still require high accuracy.
  if (mOptions && mOptions->mEnableHighAccuracy) {
    nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
    if (gs) {
      gs->UpdateAccuracy();
      gs->SetHigherAccuracy(false);
    }
  }
}
@@ -901,9 +901,9 @@ nsGeolocationService::HighAccuracyRequested()
}

void
nsGeolocationService::UpdateAccuracy(bool aForceHigh)
nsGeolocationService::SetHigherAccuracy(bool aEnable)
{
  bool highRequired = aForceHigh || HighAccuracyRequested();
  bool highRequired = aEnable || HighAccuracyRequested();

  if (XRE_GetProcessType() == GeckoProcessType_Content) {
    ContentChild* cpc = ContentChild::GetSingleton();
@@ -1061,7 +1061,6 @@ Geolocation::Shutdown()

  if (mService) {
    mService->RemoveLocator(this);
    mService->UpdateAccuracy();
  }

  mService = nullptr;
+2 −2
Original line number Diff line number Diff line
@@ -85,8 +85,8 @@ public:
  // create, or reinitalize the callback timer
  void     SetDisconnectTimer();

  // Update the accuracy and notify the provider if changed
  void     UpdateAccuracy(bool aForceHigh = false);
  // request higher accuracy, if possible
  void     SetHigherAccuracy(bool aEnable);
  bool     HighAccuracyRequested();

private:
+1 −6
Original line number Diff line number Diff line
@@ -73,9 +73,6 @@ function WifiGeoPositionProvider() {
  this.timer = null;
  this.hasSeenWiFi = false;
  this.started = false;
  // this is only used when logging is enabled, to debug interactions with the
  // geolocation service
  this.highAccuracy = false;
}

WifiGeoPositionProvider.prototype = {
@@ -135,12 +132,10 @@ WifiGeoPositionProvider.prototype = {
  },

  setHighAccuracy: function(enable) {
    this.highAccuracy = enable;
    LOG("setting highAccuracy to " + (this.highAccuracy?"TRUE":"FALSE"));
  },

  onChange: function(accessPoints) {
    LOG("onChange called, highAccuracy = " + (this.highAccuracy?"TRUE":"FALSE"));
    LOG("onChange called");
    this.hasSeenWiFi = true;

    let url = Services.urlFormatter.formatURLPref("geo.wifi.uri");
+0 −104
Original line number Diff line number Diff line
const Cc = Components.classes;
const Ci = Components.interfaces;

const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
const providerContract = "@mozilla.org/geolocation/provider;1";

const categoryName = "geolocation-provider";

var provider = {
  QueryInterface: function eventsink_qi(iid) {
    if (iid.equals(Components.interfaces.nsISupports) ||
        iid.equals(Components.interfaces.nsIFactory) ||
        iid.equals(Components.interfaces.nsIGeolocationProvider))
      return this;
    throw Components.results.NS_ERROR_NO_INTERFACE;
  },
  createInstance: function eventsink_ci(outer, iid) {
    if (outer)
      throw Components.results.NS_ERROR_NO_AGGREGATION;
    return this.QueryInterface(iid);
  },
  lockFactory: function eventsink_lockf(lock) {
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  },
  startup: function() {
  },
  watch: function() {
  },
  shutdown: function() {
  },
  setHighAccuracy: function(enable) {
    this._isHigh = enable;
    if (enable) {
      this._seenHigh = true;
    }
  },
  _isHigh: false,
  _seenHigh: false
};

let runningInParent = true;
try {
  runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
                    getService(Components.interfaces.nsIXULRuntime).processType
                    == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
}
catch (e) { }

function successCallback()
{
  do_check_true(false);
  do_test_finished();
}

function errorCallback()
{
  do_check_true(false);
  do_test_finished();
}

function run_test()
{
  if (runningInParent) {
    // XPCShell does not get a profile by default. The geolocation service
    // depends on the settings service which uses IndexedDB and IndexedDB
    // needs a place where it can store databases.
    do_get_profile();

    Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
      "Unit test geo provider", providerContract, provider);
    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
                           .getService(Components.interfaces.nsICategoryManager);
    catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
                                               providerContract, false, true);

    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
    prefs.setBoolPref("geo.wifi.scan", false);
  }

  let geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);

  do_test_pending();

  let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
  let watchID2 = geolocation.watchPosition(successCallback, errorCallback,
                                           {enableHighAccuracy: true});

  do_timeout(1000, function() {
    geolocation.clearWatch(watchID2);
    do_timeout(1000, check_results);
  });
}

function check_results()
{
  if (runningInParent) {
    // check the provider was set to high accuracy during the test
    do_check_true(provider._seenHigh);
    // check the provider is not currently set to high accuracy
    do_check_false(provider._isHigh);
  }
  do_test_finished();
}
+0 −70
Original line number Diff line number Diff line
const Cc = Components.classes;
const Ci = Components.interfaces;

const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
const providerContract = "@mozilla.org/geolocation/provider;1";

const categoryName = "geolocation-provider";

var provider = {
  QueryInterface: function eventsink_qi(iid) {
    if (iid.equals(Components.interfaces.nsISupports) ||
        iid.equals(Components.interfaces.nsIFactory) ||
        iid.equals(Components.interfaces.nsIGeolocationProvider))
      return this;
    throw Components.results.NS_ERROR_NO_INTERFACE;
  },
  createInstance: function eventsink_ci(outer, iid) {
    if (outer)
      throw Components.results.NS_ERROR_NO_AGGREGATION;
    return this.QueryInterface(iid);
  },
  lockFactory: function eventsink_lockf(lock) {
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  },
  startup: function() {
  },
  watch: function() {
  },
  shutdown: function() {
  },
  setHighAccuracy: function(enable) {
    this._isHigh = enable;
    if (enable) {
      this._seenHigh = true;
    }
  },
  _isHigh: false,
  _seenHigh: false
};

function run_test()
{
  // XPCShell does not get a profile by default. The geolocation service
  // depends on the settings service which uses IndexedDB and IndexedDB
  // needs a place where it can store databases.
  do_get_profile();

  Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
    "Unit test geo provider", providerContract, provider);
  var catMan = Components.classes["@mozilla.org/categorymanager;1"]
                         .getService(Components.interfaces.nsICategoryManager);
  catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
                                             providerContract, false, true);

  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
  prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
  prefs.setBoolPref("geo.wifi.scan", false);

  run_test_in_child("test_geolocation_reset_accuracy.js", check_results);
}

function check_results()
{
  // check the provider was set to high accuracy during the test
  do_check_true(provider._seenHigh);
  // check the provider is not currently set to high accuracy
  do_check_false(provider._isHigh);

  do_test_finished();
}
Loading