1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "WebGeolocationClientMock.h"
33
34 #include "WebGeolocationController.h"
35 #include "WebGeolocationError.h"
36 #include "WebGeolocationPermissionRequest.h"
37 #include "WebGeolocationPosition.h"
38 #include "core/platform/mock/GeolocationClientMock.h"
39 #include "modules/geolocation/Geolocation.h"
40 #include "modules/geolocation/GeolocationError.h"
41 #include "modules/geolocation/GeolocationPosition.h"
42 #include "modules/geolocation/PositionError.h"
43 #include "public/platform/WebString.h"
44 #include "wtf/CurrentTime.h"
45
46 using namespace WebCore;
47
48 namespace blink {
49
create()50 WebGeolocationClientMock* WebGeolocationClientMock::create()
51 {
52 return new WebGeolocationClientMock();
53 }
54
setPosition(double latitude,double longitude,double accuracy)55 void WebGeolocationClientMock::setPosition(double latitude, double longitude, double accuracy)
56 {
57 WebGeolocationPosition webPosition(currentTime(), latitude, longitude, accuracy,
58 false, 0, false, 0, false, 0, false, 0);
59 m_clientMock->setPosition(webPosition);
60 }
61
setPositionUnavailableError(const WebString & message)62 void WebGeolocationClientMock::setPositionUnavailableError(const WebString& message)
63 {
64 m_clientMock->setPositionUnavailableError(message);
65 }
66
setPermission(bool allowed)67 void WebGeolocationClientMock::setPermission(bool allowed)
68 {
69 m_clientMock->setPermission(allowed);
70 }
71
numberOfPendingPermissionRequests() const72 int WebGeolocationClientMock::numberOfPendingPermissionRequests() const
73 {
74 return m_clientMock->numberOfPendingPermissionRequests();
75 }
76
resetMock()77 void WebGeolocationClientMock::resetMock()
78 {
79 m_clientMock->reset();
80 }
81
startUpdating()82 void WebGeolocationClientMock::startUpdating()
83 {
84 m_clientMock->startUpdating();
85 }
86
stopUpdating()87 void WebGeolocationClientMock::stopUpdating()
88 {
89 m_clientMock->stopUpdating();
90 }
91
setEnableHighAccuracy(bool accuracy)92 void WebGeolocationClientMock::setEnableHighAccuracy(bool accuracy)
93 {
94 m_clientMock->setEnableHighAccuracy(accuracy);
95 }
96
geolocationDestroyed()97 void WebGeolocationClientMock::geolocationDestroyed()
98 {
99 m_clientMock->geolocationDestroyed();
100 }
101
setController(WebGeolocationController * controller)102 void WebGeolocationClientMock::setController(WebGeolocationController* controller)
103 {
104 m_clientMock->setController(controller->controller());
105 delete controller;
106 }
107
requestPermission(const WebGeolocationPermissionRequest & request)108 void WebGeolocationClientMock::requestPermission(const WebGeolocationPermissionRequest& request)
109 {
110 m_clientMock->requestPermission(request.geolocation());
111 }
112
cancelPermissionRequest(const WebGeolocationPermissionRequest & request)113 void WebGeolocationClientMock::cancelPermissionRequest(const WebGeolocationPermissionRequest& request)
114 {
115 m_clientMock->cancelPermissionRequest(request.geolocation());
116 }
117
lastPosition(WebGeolocationPosition & webPosition)118 bool WebGeolocationClientMock::lastPosition(WebGeolocationPosition& webPosition)
119 {
120 RefPtr<GeolocationPosition> position = m_clientMock->lastPosition();
121 if (!position)
122 return false;
123
124 webPosition = position.release();
125 return true;
126 }
127
WebGeolocationClientMock()128 WebGeolocationClientMock::WebGeolocationClientMock()
129 {
130 m_clientMock.reset(new GeolocationClientMock());
131 }
132
reset()133 void WebGeolocationClientMock::reset()
134 {
135 m_clientMock.reset(0);
136 }
137
138 } // WebKit
139