diff options
Diffstat (limited to 'WebCore/platform/mock')
-rw-r--r-- | WebCore/platform/mock/DeviceOrientationClientMock.cpp | 71 | ||||
-rw-r--r-- | WebCore/platform/mock/DeviceOrientationClientMock.h | 66 | ||||
-rw-r--r-- | WebCore/platform/mock/SpeechInputClientMock.cpp | 95 | ||||
-rw-r--r-- | WebCore/platform/mock/SpeechInputClientMock.h | 69 |
4 files changed, 301 insertions, 0 deletions
diff --git a/WebCore/platform/mock/DeviceOrientationClientMock.cpp b/WebCore/platform/mock/DeviceOrientationClientMock.cpp new file mode 100644 index 0000000..c2c9316 --- /dev/null +++ b/WebCore/platform/mock/DeviceOrientationClientMock.cpp @@ -0,0 +1,71 @@ +/* + * 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) +{ + 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/WebCore/platform/mock/DeviceOrientationClientMock.h b/WebCore/platform/mock/DeviceOrientationClientMock.h new file mode 100644 index 0000000..6691130 --- /dev/null +++ b/WebCore/platform/mock/DeviceOrientationClientMock.h @@ -0,0 +1,66 @@ +/* + * 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(); } + + 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/WebCore/platform/mock/SpeechInputClientMock.cpp b/WebCore/platform/mock/SpeechInputClientMock.cpp new file mode 100644 index 0000000..74a3151 --- /dev/null +++ b/WebCore/platform/mock/SpeechInputClientMock.cpp @@ -0,0 +1,95 @@ +/* + * 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) +{ +} + +bool SpeechInputClientMock::startRecognition(SpeechInputListener* listener) +{ + if (m_timer.isActive()) + return false; + m_listener = listener; + m_recording = true; + m_timer.startOneShot(0); + return true; +} + +void SpeechInputClientMock::stopRecording() +{ + if (m_timer.isActive() && m_recording) { + m_timer.stop(); + timerFired(&m_timer); + } +} + +void SpeechInputClientMock::cancelRecognition() +{ + if (m_timer.isActive()) { + m_timer.stop(); + m_recording = false; + m_listener->didCompleteRecognition(); + m_listener = 0; + } +} + +void SpeechInputClientMock::setRecognitionResult(const String& result) +{ + m_recognitionResult = result; +} + +void SpeechInputClientMock::timerFired(WebCore::Timer<SpeechInputClientMock>*) +{ + if (m_recording) { + m_recording = false; + m_listener->didCompleteRecording(); + m_timer.startOneShot(0); + } else { + m_listener->setRecognitionResult(m_recognitionResult); + m_listener->didCompleteRecognition(); + m_listener = 0; + } +} + +} // namespace WebCore + +#endif // ENABLE(INPUT_SPEECH) diff --git a/WebCore/platform/mock/SpeechInputClientMock.h b/WebCore/platform/mock/SpeechInputClientMock.h new file mode 100644 index 0000000..faca444 --- /dev/null +++ b/WebCore/platform/mock/SpeechInputClientMock.h @@ -0,0 +1,69 @@ +/* + * 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 "Timer.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 setRecognitionResult(const String& result); + + // SpeechInputClient methods. + bool startRecognition(SpeechInputListener*); + void stopRecording(); + void cancelRecognition(); + +private: + void timerFired(Timer<SpeechInputClientMock>*); + + bool m_recording; + Timer<SpeechInputClientMock> m_timer; + SpeechInputListener* m_listener; + String m_recognitionResult; +}; + +} // namespace WebCore + +#endif // ENABLE(INPUT_SPEECH) + +#endif // SpeechInputClientMock_h |