electron/atom/browser/fake_location_provider.cc
Robo bce5bd87a8 fix: opt into location services once device service has been started (#14253)
* fix: opt into location services once device service has been started

* refactor: provide fake location provider to mock geolocation reponses

* chore: add spec for navigator.geolocation api using fake location provider
2018-08-23 08:51:46 -07:00

44 lines
1.2 KiB
C++

// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/fake_location_provider.h"
#include "base/callback.h"
#include "base/time/time.h"
namespace atom {
FakeLocationProvider::FakeLocationProvider() {
position_.latitude = 10;
position_.longitude = -10;
position_.accuracy = 1;
position_.error_code =
device::mojom::Geoposition::ErrorCode::POSITION_UNAVAILABLE;
}
FakeLocationProvider::~FakeLocationProvider() = default;
void FakeLocationProvider::SetUpdateCallback(
const LocationProviderUpdateCallback& callback) {
callback_ = callback;
}
void FakeLocationProvider::StartProvider(bool high_accuracy) {}
void FakeLocationProvider::StopProvider() {}
const device::mojom::Geoposition& FakeLocationProvider::GetPosition() {
return position_;
}
void FakeLocationProvider::OnPermissionGranted() {
if (!callback_.is_null()) {
// Check device::ValidateGeoPosition for range of values.
position_.error_code = device::mojom::Geoposition::ErrorCode::NONE;
position_.timestamp = base::Time::Now();
callback_.Run(this, position_);
}
}
} // namespace atom