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
45using namespace WebCore;
46
47namespace WebKit {
48
49WebGeolocationClientMock* WebGeolocationClientMock::create()
50{
51    return new WebGeolocationClientMock();
52}
53
54void 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
61void 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
80void WebGeolocationClientMock::setPermission(bool allowed)
81{
82    m_clientMock->setPermission(allowed);
83}
84
85int WebGeolocationClientMock::numberOfPendingPermissionRequests() const
86{
87    return m_clientMock->numberOfPendingPermissionRequests();
88}
89
90void WebGeolocationClientMock::resetMock()
91{
92    m_clientMock->reset();
93}
94
95void WebGeolocationClientMock::startUpdating()
96{
97    m_clientMock->startUpdating();
98}
99
100void WebGeolocationClientMock::stopUpdating()
101{
102    m_clientMock->stopUpdating();
103}
104
105void WebGeolocationClientMock::setEnableHighAccuracy(bool accuracy)
106{
107    m_clientMock->setEnableHighAccuracy(accuracy);
108}
109
110void WebGeolocationClientMock::geolocationDestroyed()
111{
112    m_clientMock->geolocationDestroyed();
113}
114
115void WebGeolocationClientMock::setController(WebGeolocationController* controller)
116{
117    m_clientMock->setController(controller->controller());
118    delete controller;
119}
120
121void WebGeolocationClientMock::requestPermission(const WebGeolocationPermissionRequest& request)
122{
123    m_clientMock->requestPermission(request.geolocation());
124}
125
126void WebGeolocationClientMock::cancelPermissionRequest(const WebGeolocationPermissionRequest& request)
127{
128    m_clientMock->cancelPermissionRequest(request.geolocation());
129}
130
131bool 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
141WebGeolocationClientMock::WebGeolocationClientMock()
142{
143    m_clientMock.reset(new GeolocationClientMock());
144}
145
146void WebGeolocationClientMock::reset()
147{
148    m_clientMock.reset(0);
149}
150
151} // WebKit
152