forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_geolocation.cc
53 lines (42 loc) · 1.71 KB
/
mock_geolocation.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/test/mock_geolocation.h"
#include "base/logging.h"
#include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h"
#include "content/browser/geolocation/location_arbitrator.h"
#include "content/browser/geolocation/mock_location_provider.h"
#include "content/common/geoposition.h"
namespace content {
MockGeolocation::MockGeolocation() {
dependency_factory_ =
new GeolocationArbitratorDependencyFactoryWithLocationProvider(
&NewAutoSuccessMockLocationProvider);
}
MockGeolocation::~MockGeolocation() {
}
void MockGeolocation::Setup() {
GeolocationArbitrator::SetDependencyFactoryForTest(
dependency_factory_.get());
}
void MockGeolocation::TearDown() {
GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
}
void MockGeolocation::GetCurrentPosition(double* latitude,
double* longitude) const {
*latitude = MockLocationProvider::instance_->position_.latitude;
*longitude = MockLocationProvider::instance_->position_.longitude;
}
void MockGeolocation::SetCurrentPosition(double latitude, double longitude) {
Geoposition geoposition;
geoposition.latitude = latitude;
geoposition.longitude = longitude;
geoposition.accuracy = 0;
geoposition.error_code = Geoposition::ERROR_CODE_NONE;
// Webkit compares the timestamp to wall clock time, so we need
// it to be contemporary.
geoposition.timestamp = base::Time::Now();
DCHECK(geoposition.IsValidFix());
MockLocationProvider::instance_->HandlePositionChanged(geoposition);
}
} // namespace content