summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/mock
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-06 11:45:16 +0100
committerSteve Block <steveblock@google.com>2011-05-12 13:44:10 +0100
commitcad810f21b803229eb11403f9209855525a25d57 (patch)
tree29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/platform/mock
parent121b0cf4517156d0ac5111caf9830c51b69bae8f (diff)
downloadexternal_webkit-cad810f21b803229eb11403f9209855525a25d57.zip
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/platform/mock')
-rw-r--r--Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp72
-rw-r--r--Source/WebCore/platform/mock/DeviceOrientationClientMock.h67
-rw-r--r--Source/WebCore/platform/mock/GeolocationClientMock.cpp177
-rw-r--r--Source/WebCore/platform/mock/GeolocationClientMock.h99
-rw-r--r--Source/WebCore/platform/mock/GeolocationServiceMock.cpp145
-rwxr-xr-xSource/WebCore/platform/mock/GeolocationServiceMock.h85
-rw-r--r--Source/WebCore/platform/mock/SpeechInputClientMock.cpp141
-rw-r--r--Source/WebCore/platform/mock/SpeechInputClientMock.h78
8 files changed, 864 insertions, 0 deletions
diff --git a/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp b/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp
new file mode 100644
index 0000000..2fa5acb
--- /dev/null
+++ b/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DeviceOrientationClientMock.h"
+
+#include "DeviceOrientationController.h"
+
+namespace WebCore {
+
+DeviceOrientationClientMock::DeviceOrientationClientMock()
+ : m_controller(0)
+ , m_timer(this, &DeviceOrientationClientMock::timerFired)
+ , m_isUpdating(false)
+{
+}
+
+void DeviceOrientationClientMock::setController(DeviceOrientationController* controller)
+{
+ ASSERT(!m_controller);
+ m_controller = controller;
+ ASSERT(m_controller);
+}
+
+void DeviceOrientationClientMock::startUpdating()
+{
+ m_isUpdating = true;
+}
+
+void DeviceOrientationClientMock::stopUpdating()
+{
+ m_isUpdating = false;
+ m_timer.stop();
+}
+
+void DeviceOrientationClientMock::setOrientation(PassRefPtr<DeviceOrientation> orientation)
+{
+ m_orientation = orientation;
+ if (m_isUpdating && !m_timer.isActive())
+ m_timer.startOneShot(0);
+}
+
+void DeviceOrientationClientMock::timerFired(Timer<DeviceOrientationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_timer);
+ m_timer.stop();
+ m_controller->didChangeDeviceOrientation(m_orientation.get());
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/mock/DeviceOrientationClientMock.h b/Source/WebCore/platform/mock/DeviceOrientationClientMock.h
new file mode 100644
index 0000000..baa4245
--- /dev/null
+++ b/Source/WebCore/platform/mock/DeviceOrientationClientMock.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DeviceOrientationClientMock_h
+#define DeviceOrientationClientMock_h
+
+#include "DeviceOrientation.h"
+#include "DeviceOrientationClient.h"
+#include "Timer.h"
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class DeviceOrientationController;
+
+// A mock implementation of DeviceOrientationClient used to test the feature in
+// DumpRenderTree. Embedders should should configure the Page object to use this
+// client when running DumpRenderTree.
+class DeviceOrientationClientMock : public DeviceOrientationClient {
+public:
+ DeviceOrientationClientMock();
+
+ // DeviceOrientationClient
+ virtual void setController(DeviceOrientationController*);
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual DeviceOrientation* lastOrientation() const { return m_orientation.get(); }
+ virtual void deviceOrientationControllerDestroyed() { }
+
+ void setOrientation(PassRefPtr<DeviceOrientation>);
+
+private:
+ void timerFired(Timer<DeviceOrientationClientMock>*);
+
+ RefPtr<DeviceOrientation> m_orientation;
+ DeviceOrientationController* m_controller;
+ Timer<DeviceOrientationClientMock> m_timer;
+ bool m_isUpdating;
+};
+
+} // namespace WebCore
+
+#endif // DeviceOrientationClientMock_h
diff --git a/Source/WebCore/platform/mock/GeolocationClientMock.cpp b/Source/WebCore/platform/mock/GeolocationClientMock.cpp
new file mode 100644
index 0000000..5255b34
--- /dev/null
+++ b/Source/WebCore/platform/mock/GeolocationClientMock.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationClientMock.h"
+
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+
+#include "GeolocationController.h"
+#include "GeolocationError.h"
+#include "GeolocationPosition.h"
+
+namespace WebCore {
+
+GeolocationClientMock::GeolocationClientMock()
+ : m_controller(0)
+ , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired)
+ , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired)
+ , m_isActive(false)
+ , m_permissionState(PermissionStateUnset)
+{
+}
+
+GeolocationClientMock::~GeolocationClientMock()
+{
+ ASSERT(!m_isActive);
+}
+
+void GeolocationClientMock::setController(GeolocationController *controller)
+{
+ ASSERT(controller && !m_controller);
+ m_controller = controller;
+}
+
+void GeolocationClientMock::setPosition(PassRefPtr<GeolocationPosition> position)
+{
+ m_lastPosition = position;
+ m_lastError = 0;
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::setError(PassRefPtr<GeolocationError> error)
+{
+ m_lastError = error;
+ m_lastPosition = 0;
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::setPermission(bool allowed)
+{
+ m_permissionState = allowed ? PermissionStateAllowed : PermissionStateDenied;
+ asyncUpdatePermission();
+}
+
+void GeolocationClientMock::requestPermission(Geolocation* geolocation)
+{
+ m_pendingPermission.add(geolocation);
+ if (m_permissionState != PermissionStateUnset)
+ asyncUpdatePermission();
+}
+
+void GeolocationClientMock::cancelPermissionRequest(Geolocation* geolocation)
+{
+ // Called from Geolocation::disconnectFrame() in response to Frame destruction.
+ m_pendingPermission.remove(geolocation);
+ if (m_pendingPermission.isEmpty() && m_permissionTimer.isActive())
+ m_permissionTimer.stop();
+}
+
+void GeolocationClientMock::asyncUpdatePermission()
+{
+ ASSERT(m_permissionState != PermissionStateUnset);
+ if (!m_permissionTimer.isActive())
+ m_permissionTimer.startOneShot(0);
+}
+
+void GeolocationClientMock::permissionTimerFired(WebCore::Timer<GeolocationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_permissionTimer);
+ ASSERT(m_permissionState != PermissionStateUnset);
+ bool allowed = m_permissionState == PermissionStateAllowed;
+ GeolocationSet::iterator end = m_pendingPermission.end();
+
+ // Once permission has been set (or denied) on a Geolocation object, there can be
+ // no further requests for permission to the mock. Consequently the callbacks
+ // which fire synchronously from Geolocation::setIsAllowed() cannot reentrantly modify
+ // m_pendingPermission.
+ for (GeolocationSet::iterator it = m_pendingPermission.begin(); it != end; ++it)
+ (*it)->setIsAllowed(allowed);
+ m_pendingPermission.clear();
+}
+
+void GeolocationClientMock::reset()
+{
+ m_lastPosition = 0;
+ m_lastError = 0;
+ m_permissionState = PermissionStateUnset;
+}
+
+void GeolocationClientMock::geolocationDestroyed()
+{
+ ASSERT(!m_isActive);
+}
+
+void GeolocationClientMock::startUpdating()
+{
+ ASSERT(!m_isActive);
+ m_isActive = true;
+ asyncUpdateController();
+}
+
+void GeolocationClientMock::stopUpdating()
+{
+ ASSERT(m_isActive);
+ m_isActive = false;
+ m_controllerTimer.stop();
+}
+
+void GeolocationClientMock::setEnableHighAccuracy(bool)
+{
+ // FIXME: We need to add some tests regarding "high accuracy" mode.
+ // See https://bugs.webkit.org/show_bug.cgi?id=49438
+}
+
+GeolocationPosition* GeolocationClientMock::lastPosition()
+{
+ return m_lastPosition.get();
+}
+
+void GeolocationClientMock::asyncUpdateController()
+{
+ ASSERT(m_controller);
+ if (m_isActive && !m_controllerTimer.isActive())
+ m_controllerTimer.startOneShot(0);
+}
+
+void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_controllerTimer);
+ ASSERT(m_controller);
+
+ if (m_lastPosition.get())
+ m_controller->positionChanged(m_lastPosition.get());
+ else if (m_lastError.get())
+ m_controller->errorOccurred(m_lastError.get());
+}
+
+} // WebCore
+
+#endif // ENABLE(CLIENT_BASED_GEOLOCATION)
diff --git a/Source/WebCore/platform/mock/GeolocationClientMock.h b/Source/WebCore/platform/mock/GeolocationClientMock.h
new file mode 100644
index 0000000..df35316
--- /dev/null
+++ b/Source/WebCore/platform/mock/GeolocationClientMock.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationClientMock_h
+#define GeolocationClientMock_h
+
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+
+#include "GeolocationClient.h"
+#include "PlatformString.h"
+#include "Timer.h"
+
+#include <wtf/HashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class GeolocationController;
+class GeolocationPosition;
+class GeolocationError;
+
+// Provides a mock object for the geolocation client
+class GeolocationClientMock : public GeolocationClient {
+public:
+ GeolocationClientMock();
+ virtual ~GeolocationClientMock();
+
+ void reset();
+ void setController(GeolocationController*);
+
+ void setError(PassRefPtr<GeolocationError>);
+ void setPosition(PassRefPtr<GeolocationPosition>);
+ void setPermission(bool allowed);
+
+ // GeolocationClient
+ virtual void geolocationDestroyed();
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual void setEnableHighAccuracy(bool);
+ virtual GeolocationPosition* lastPosition();
+ virtual void requestPermission(Geolocation*);
+ virtual void cancelPermissionRequest(Geolocation*);
+
+private:
+ void asyncUpdateController();
+ void controllerTimerFired(Timer<GeolocationClientMock>*);
+
+ void asyncUpdatePermission();
+ void permissionTimerFired(Timer<GeolocationClientMock>*);
+
+ GeolocationController* m_controller;
+ RefPtr<GeolocationPosition> m_lastPosition;
+ RefPtr<GeolocationError> m_lastError;
+ Timer<GeolocationClientMock> m_controllerTimer;
+ Timer<GeolocationClientMock> m_permissionTimer;
+ bool m_isActive;
+
+ enum PermissionState {
+ PermissionStateUnset,
+ PermissionStateAllowed,
+ PermissionStateDenied,
+ } m_permissionState;
+ typedef WTF::HashSet<RefPtr<Geolocation> > GeolocationSet;
+ GeolocationSet m_pendingPermission;
+};
+
+}
+
+#endif // ENABLE(CLIENT_BASED_GEOLOCATION)
+
+#endif
diff --git a/Source/WebCore/platform/mock/GeolocationServiceMock.cpp b/Source/WebCore/platform/mock/GeolocationServiceMock.cpp
new file mode 100644
index 0000000..c3ba7b4
--- /dev/null
+++ b/Source/WebCore/platform/mock/GeolocationServiceMock.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationServiceMock.h"
+
+#if ENABLE(GEOLOCATION)
+
+#include "Logging.h"
+#include "Geolocation.h"
+#include "Geoposition.h"
+#include "PositionError.h"
+#include "PositionOptions.h"
+
+namespace WebCore {
+
+GeolocationServiceMock::GeolocationServiceSet* GeolocationServiceMock::s_instances = 0;
+RefPtr<Geoposition>* GeolocationServiceMock::s_lastPosition;
+RefPtr<PositionError>* GeolocationServiceMock::s_lastError;
+
+GeolocationService* GeolocationServiceMock::create(GeolocationServiceClient* client)
+{
+ initStatics();
+ return new GeolocationServiceMock(client);
+}
+
+GeolocationServiceMock::GeolocationServiceMock(GeolocationServiceClient* client)
+ : GeolocationService(client)
+ , m_timer(this, &GeolocationServiceMock::timerFired)
+ , m_isActive(false)
+{
+ s_instances->add(this);
+}
+
+GeolocationServiceMock::~GeolocationServiceMock()
+{
+ GeolocationServiceSet::iterator iter = s_instances->find(this);
+ ASSERT(iter != s_instances->end());
+ s_instances->remove(iter);
+ cleanUpStatics();
+}
+
+void GeolocationServiceMock::setPosition(PassRefPtr<Geoposition> position)
+{
+ initStatics();
+ GeolocationService::useMock();
+ *s_lastPosition = position;
+ *s_lastError = 0;
+ makeGeolocationCallbackFromAllInstances();
+}
+
+void GeolocationServiceMock::setError(PassRefPtr<PositionError> error)
+{
+ initStatics();
+ GeolocationService::useMock();
+ *s_lastError = error;
+ *s_lastPosition = 0;
+ makeGeolocationCallbackFromAllInstances();
+}
+
+#if PLATFORM(ANDROID)
+// TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082
+bool GeolocationServiceMock::startUpdating(PositionOptions*, bool /* suspend */)
+#else
+bool GeolocationServiceMock::startUpdating(PositionOptions*)
+#endif
+{
+ m_isActive = true;
+ m_timer.startOneShot(0);
+ return true;
+}
+
+void GeolocationServiceMock::stopUpdating()
+{
+ m_isActive = false;
+}
+
+void GeolocationServiceMock::timerFired(Timer<GeolocationServiceMock>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_timer);
+ makeGeolocationCallback();
+}
+
+void GeolocationServiceMock::makeGeolocationCallbackFromAllInstances()
+{
+ GeolocationServiceSet::const_iterator end = s_instances->end();
+ for (GeolocationServiceSet::const_iterator iter = s_instances->begin(); iter != end; ++iter)
+ (*iter)->makeGeolocationCallback();
+}
+
+void GeolocationServiceMock::makeGeolocationCallback()
+{
+ if (!m_isActive)
+ return;
+
+ if (*s_lastPosition)
+ positionChanged();
+ else if (*s_lastError)
+ errorOccurred();
+}
+
+void GeolocationServiceMock::initStatics()
+{
+ if (s_instances == 0) {
+ s_instances = new GeolocationServiceSet;
+ s_lastPosition = new RefPtr<Geoposition>;
+ s_lastError = new RefPtr<PositionError>;
+ }
+}
+
+void GeolocationServiceMock::cleanUpStatics()
+{
+ if (s_instances->size() == 0) {
+ delete s_instances;
+ s_instances = 0;
+ delete s_lastPosition;
+ delete s_lastError;
+ }
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/mock/GeolocationServiceMock.h b/Source/WebCore/platform/mock/GeolocationServiceMock.h
new file mode 100755
index 0000000..1b4db93
--- /dev/null
+++ b/Source/WebCore/platform/mock/GeolocationServiceMock.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationServiceMock_h
+#define GeolocationServiceMock_h
+
+#include "GeolocationService.h"
+#include "Timer.h"
+#include <wtf/HashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+// This class provides a mock implementation of a GeolocationService for testing
+// purposes. It allows the position or error that will be reported by this class
+// to be set manually using the setPosition and setError methods. Objects of
+// this class call back to their respective GeolocationServiceClient with the
+// position or error every time either of these is updated.
+class GeolocationServiceMock : public GeolocationService {
+ public:
+ static GeolocationService* create(GeolocationServiceClient*);
+
+ GeolocationServiceMock(GeolocationServiceClient*);
+ virtual ~GeolocationServiceMock();
+
+#if PLATFORM(ANDROID)
+ // TODO: Upstream to webkit.org. See https://bugs.webkit.org/show_bug.cgi?id=34082
+ virtual bool startUpdating(PositionOptions*, bool suspend);
+#else
+ virtual bool startUpdating(PositionOptions*);
+#endif
+ virtual void stopUpdating();
+
+ static void setPosition(PassRefPtr<Geoposition> position);
+ static void setError(PassRefPtr<PositionError> position);
+
+ virtual Geoposition* lastPosition() const { return s_lastPosition->get(); }
+ virtual PositionError* lastError() const { return s_lastError->get(); }
+
+ private:
+ static void makeGeolocationCallbackFromAllInstances();
+ void makeGeolocationCallback();
+
+ void timerFired(Timer<GeolocationServiceMock>*);
+
+ static void initStatics();
+ static void cleanUpStatics();
+
+ typedef HashSet<GeolocationServiceMock*> GeolocationServiceSet;
+ static GeolocationServiceSet* s_instances;
+
+ static RefPtr<Geoposition>* s_lastPosition;
+ static RefPtr<PositionError>* s_lastError;
+
+ Timer<GeolocationServiceMock> m_timer;
+
+ bool m_isActive;
+};
+
+} // namespace WebCore
+
+#endif // GeolocationServiceMock_h
diff --git a/Source/WebCore/platform/mock/SpeechInputClientMock.cpp b/Source/WebCore/platform/mock/SpeechInputClientMock.cpp
new file mode 100644
index 0000000..16f2825
--- /dev/null
+++ b/Source/WebCore/platform/mock/SpeechInputClientMock.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SpeechInputClientMock.h"
+
+#if ENABLE(INPUT_SPEECH)
+
+#include "SpeechInputListener.h"
+
+namespace WebCore {
+
+SpeechInputClientMock::SpeechInputClientMock()
+ : m_recording(false)
+ , m_timer(this, &SpeechInputClientMock::timerFired)
+ , m_listener(0)
+ , m_requestId(0)
+{
+}
+
+void SpeechInputClientMock::setListener(SpeechInputListener* listener)
+{
+ m_listener = listener;
+}
+
+bool SpeechInputClientMock::startRecognition(int requestId, const IntRect& elementRect, const AtomicString& language, const String& grammar)
+{
+ if (m_timer.isActive())
+ return false;
+ m_requestId = requestId;
+ m_recording = true;
+ m_language = language;
+ m_timer.startOneShot(0);
+ return true;
+}
+
+void SpeechInputClientMock::stopRecording(int requestId)
+{
+ ASSERT(requestId == m_requestId);
+ if (m_timer.isActive() && m_recording) {
+ m_timer.stop();
+ timerFired(&m_timer);
+ }
+}
+
+void SpeechInputClientMock::cancelRecognition(int requestId)
+{
+ ASSERT(requestId == m_requestId);
+ if (m_timer.isActive()) {
+ m_timer.stop();
+ m_recording = false;
+ m_listener->didCompleteRecognition(m_requestId);
+ m_requestId = 0;
+ }
+}
+
+void SpeechInputClientMock::addRecognitionResult(const String& result, double confidence, const AtomicString& language)
+{
+ if (language.isEmpty())
+ m_resultsForEmptyLanguage.append(SpeechInputResult::create(result, confidence));
+ else {
+ if (!m_recognitionResults.contains(language))
+ m_recognitionResults.set(language, SpeechInputResultArray());
+ m_recognitionResults.find(language)->second.append(SpeechInputResult::create(result, confidence));
+ }
+}
+
+void SpeechInputClientMock::clearResults()
+{
+ m_resultsForEmptyLanguage.clear();
+ m_recognitionResults.clear();
+}
+
+void SpeechInputClientMock::timerFired(WebCore::Timer<SpeechInputClientMock>*)
+{
+ if (m_recording) {
+ m_recording = false;
+ m_listener->didCompleteRecording(m_requestId);
+ m_timer.startOneShot(0);
+ } else {
+ bool noResultsFound = false;
+
+ // Empty language case must be handled separately to avoid problems with HashMap and empty keys.
+ if (m_language.isEmpty()) {
+ if (!m_resultsForEmptyLanguage.isEmpty())
+ m_listener->setRecognitionResult(m_requestId, m_resultsForEmptyLanguage);
+ else
+ noResultsFound = true;
+ } else {
+ if (m_recognitionResults.contains(m_language))
+ m_listener->setRecognitionResult(m_requestId, m_recognitionResults.get(m_language));
+ else
+ noResultsFound = true;
+ }
+
+ if (noResultsFound) {
+ // Can't avoid setting a result even if no result was set for the given language.
+ // This would avoid generating the events used to check the results and the test would timeout.
+ String error("error: no result found for language '");
+ error.append(m_language);
+ error.append("'");
+ SpeechInputResultArray results;
+ results.append(SpeechInputResult::create(error, 1.0));
+ m_listener->setRecognitionResult(m_requestId, results);
+ }
+
+ m_listener->didCompleteRecognition(m_requestId);
+ m_requestId = 0;
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INPUT_SPEECH)
diff --git a/Source/WebCore/platform/mock/SpeechInputClientMock.h b/Source/WebCore/platform/mock/SpeechInputClientMock.h
new file mode 100644
index 0000000..6f72191
--- /dev/null
+++ b/Source/WebCore/platform/mock/SpeechInputClientMock.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SpeechInputClientMock_h
+#define SpeechInputClientMock_h
+
+#include "PlatformString.h"
+#include "SpeechInputClient.h"
+#include "SpeechInputResult.h"
+#include "Timer.h"
+#include <wtf/HashMap.h>
+#include <wtf/text/StringHash.h>
+
+#if ENABLE(INPUT_SPEECH)
+
+namespace WebCore {
+
+class SpeechInputListener;
+
+// Provides a mock object for the speech input embedder API called by WebCore.
+class SpeechInputClientMock : public SpeechInputClient {
+public:
+ SpeechInputClientMock();
+
+ void addRecognitionResult(const String& result, double confidence, const AtomicString& language);
+ void clearResults();
+
+ // SpeechInputClient methods.
+ void setListener(SpeechInputListener*);
+ bool startRecognition(int requestId, const IntRect& elementRect, const AtomicString& language, const String& grammar);
+ void stopRecording(int);
+ void cancelRecognition(int);
+
+private:
+ void timerFired(Timer<SpeechInputClientMock>*);
+
+ bool m_recording;
+ Timer<SpeechInputClientMock> m_timer;
+ SpeechInputListener* m_listener;
+ int m_requestId;
+
+ HashMap<String, SpeechInputResultArray> m_recognitionResults;
+ AtomicString m_language;
+ SpeechInputResultArray m_resultsForEmptyLanguage;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INPUT_SPEECH)
+
+#endif // SpeechInputClientMock_h