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 "CurrentTime.h"
35 #include "Geolocation.h"
36 #include "GeolocationClientMock.h"
37 #include "GeolocationError.h"
38 #include "GeolocationPosition.h"
39 #include "PositionError.h"
40 #include "WebGeolocationController.h"
41 #include "WebGeolocationError.h"
42 #include "WebGeolocationPermissionRequest.h"
43 #include "WebGeolocationPosition.h"
44
45 using namespace WebCore;
46
47 namespace WebKit {
48
create()49 WebGeolocationClientMock* WebGeolocationClientMock::create()
50 {
51 return new WebGeolocationClientMock();
52 }
53
setPosition(double latitude,double longitude,double accuracy)54 void WebGeolocationClientMock::setPosition(double latitude, double longitude, double accuracy)
55 {
56 WebGeolocationPosition webPosition(currentTime(), latitude, longitude, accuracy,
57 false, 0, false, 0, false, 0, false, 0);
58 m_clientMock->setPosition(webPosition);
59 }
60
setError(int errorCode,const WebString & message)61 void WebGeolocationClientMock::setError(int errorCode, const WebString& message)
62 {
63 WebGeolocationError::Error code;
64 switch (errorCode) {
65 case PositionError::PERMISSION_DENIED:
66 code = WebGeolocationError::ErrorPermissionDenied;
67 break;
68 case PositionError::POSITION_UNAVAILABLE:
69 code = WebGeolocationError::ErrorPositionUnavailable;
70 break;
71 default:
72 ASSERT_NOT_REACHED();
73 return;
74 }
75
76 WebGeolocationError webError(code, message);
77 m_clientMock->setError(webError);
78 }
79
setPermission(bool allowed)80 void WebGeolocationClientMock::setPermission(bool allowed)
81 {
82 m_clientMock->setPermission(allowed);
83 }
84
numberOfPendingPermissionRequests() const85 int WebGeolocationClientMock::numberOfPendingPermissionRequests() const
86 {
87 return m_clientMock->numberOfPendingPermissionRequests();
88 }
89
resetMock()90 void WebGeolocationClientMock::resetMock()
91 {
92 m_clientMock->reset();
93 }
94
startUpdating()95 void WebGeolocationClientMock::startUpdating()
96 {
97 m_clientMock->startUpdating();
98 }
99
stopUpdating()100 void WebGeolocationClientMock::stopUpdating()
101 {
102 m_clientMock->stopUpdating();
103 }
104
setEnableHighAccuracy(bool accuracy)105 void WebGeolocationClientMock::setEnableHighAccuracy(bool accuracy)
106 {
107 m_clientMock->setEnableHighAccuracy(accuracy);
108 }
109
geolocationDestroyed()110 void WebGeolocationClientMock::geolocationDestroyed()
111 {
112 m_clientMock->geolocationDestroyed();
113 }
114
setController(WebGeolocationController * controller)115 void WebGeolocationClientMock::setController(WebGeolocationController* controller)
116 {
117 m_clientMock->setController(controller->controller());
118 delete controller;
119 }
120
requestPermission(const WebGeolocationPermissionRequest & request)121 void WebGeolocationClientMock::requestPermission(const WebGeolocationPermissionRequest& request)
122 {
123 m_clientMock->requestPermission(request.geolocation());
124 }
125
cancelPermissionRequest(const WebGeolocationPermissionRequest & request)126 void WebGeolocationClientMock::cancelPermissionRequest(const WebGeolocationPermissionRequest& request)
127 {
128 m_clientMock->cancelPermissionRequest(request.geolocation());
129 }
130
lastPosition(WebGeolocationPosition & webPosition)131 bool WebGeolocationClientMock::lastPosition(WebGeolocationPosition& webPosition)
132 {
133 RefPtr<GeolocationPosition> position = m_clientMock->lastPosition();
134 if (!position)
135 return false;
136
137 webPosition = position.release();
138 return true;
139 }
140
WebGeolocationClientMock()141 WebGeolocationClientMock::WebGeolocationClientMock()
142 {
143 m_clientMock.reset(new GeolocationClientMock());
144 }
145
reset()146 void WebGeolocationClientMock::reset()
147 {
148 m_clientMock.reset(0);
149 }
150
151 } // WebKit
152