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
This commit is contained in:
parent
c8f506a8aa
commit
bce5bd87a8
13 changed files with 209 additions and 11 deletions
44
atom/browser/fake_location_provider.cc
Normal file
44
atom/browser/fake_location_provider.cc
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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
|
Loading…
Add table
Add a link
Reference in a new issue