From c3d2bcbb9a713bb3fe06174be7b46d706f6ae407 Mon Sep 17 00:00:00 2001 From: "hans@chromium.org" Date: Tue, 31 Jan 2012 11:59:43 +0000 Subject: [PATCH] Speech Input: move MockSpeechInputClient into Chromium DumpRenderTree implementation https://bugs.webkit.org/show_bug.cgi?id=77083 Reviewed by Darin Fisher. Source/WebCore: Remove SpeechInputClientMock. The mock is moving to the DumpRenderTree implementation. No new tests, just refactoring. * GNUmakefile.list.am: * Target.pri: * WebCore.gypi: * WebCore.vcproj/WebCore.vcproj: * WebCore.xcodeproj/project.pbxproj: * platform/mock/SpeechInputClientMock.cpp: Removed. * platform/mock/SpeechInputClientMock.h: Removed. Source/WebKit/chromium: Remove the WebSpeechInputControllerMock interface and proxy implementation. The mock is moving to the DumpRenderTree implementation instead, which removes the need to expose this interface in the WebKit API. Also add a proper copy constructor for WebSpeechInputResult. The default one doesn't do a proper copy. * WebKit.gyp: * public/WebSpeechInputControllerMock.h: Removed. * public/WebSpeechInputResult.h: (WebKit::WebSpeechInputResult::WebSpeechInputResult): (WebSpeechInputResult): * src/WebSpeechInputControllerMockImpl.cpp: Removed. * src/WebSpeechInputControllerMockImpl.h: Removed. * src/WebSpeechInputResult.cpp: (WebKit::WebSpeechInputResult::set): (WebKit): Tools: Add MockWebSpeechInputController which provides a mock implementation of the WebSpeechInputController interface, and use that in DumpRenderTree. * DumpRenderTree/DumpRenderTree.gypi: * DumpRenderTree/chromium/LayoutTestController.cpp: (LayoutTestController::addMockSpeechInputResult): * DumpRenderTree/chromium/LayoutTestController.h: (): * DumpRenderTree/chromium/MockWebSpeechInputController.cpp: Added. (MockWebSpeechInputController::create): (MockWebSpeechInputController::addMockRecognitionResult): (MockWebSpeechInputController::clearResults): (MockWebSpeechInputController::startRecognition): (MockWebSpeechInputController::cancelRecognition): (MockWebSpeechInputController::stopRecording): (MockWebSpeechInputController::MockWebSpeechInputController): (MockWebSpeechInputController::speechTaskFired): (MockWebSpeechInputController::SpeechTask::SpeechTask): (MockWebSpeechInputController::SpeechTask::stop): (MockWebSpeechInputController::SpeechTask::runIfValid): * DumpRenderTree/chromium/MockWebSpeechInputController.h: Added. (WebKit): (MockWebSpeechInputController): (MockWebSpeechInputController::taskList): (SpeechTask): * DumpRenderTree/chromium/TestShell.cpp: * DumpRenderTree/chromium/WebViewHost.cpp: (WebViewHost::speechInputController): * DumpRenderTree/chromium/WebViewHost.h: (WebKit): (WebViewHost::speechInputControllerMock): (WebViewHost): (): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106353 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 20 +++ Source/WebCore/GNUmakefile.list.am | 2 - Source/WebCore/Target.pri | 2 - Source/WebCore/WebCore.gypi | 2 - Source/WebCore/WebCore.vcproj/WebCore.vcproj | 8 - Source/WebCore/WebCore.xcodeproj/project.pbxproj | 8 - .../platform/mock/SpeechInputClientMock.cpp | 146 ------------------ .../WebCore/platform/mock/SpeechInputClientMock.h | 78 ---------- Source/WebKit/chromium/ChangeLog | 26 ++++ Source/WebKit/chromium/WebKit.gyp | 3 - .../chromium/public/WebSpeechInputControllerMock.h | 54 ------- .../WebKit/chromium/public/WebSpeechInputResult.h | 2 + .../src/WebSpeechInputControllerMockImpl.cpp | 117 --------------- .../src/WebSpeechInputControllerMockImpl.h | 79 ---------- .../WebKit/chromium/src/WebSpeechInputResult.cpp | 5 + Tools/ChangeLog | 42 ++++++ Tools/DumpRenderTree/DumpRenderTree.gypi | 2 + .../chromium/LayoutTestController.cpp | 4 +- .../DumpRenderTree/chromium/LayoutTestController.h | 6 - .../chromium/MockWebSpeechInputController.cpp | 167 +++++++++++++++++++++ .../chromium/MockWebSpeechInputController.h | 90 +++++++++++ Tools/DumpRenderTree/chromium/TestShell.cpp | 1 - Tools/DumpRenderTree/chromium/WebViewHost.cpp | 4 +- Tools/DumpRenderTree/chromium/WebViewHost.h | 6 +- 24 files changed, 361 insertions(+), 513 deletions(-) delete mode 100644 Source/WebCore/platform/mock/SpeechInputClientMock.cpp delete mode 100644 Source/WebCore/platform/mock/SpeechInputClientMock.h delete mode 100644 Source/WebKit/chromium/public/WebSpeechInputControllerMock.h delete mode 100644 Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.cpp delete mode 100644 Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.h create mode 100644 Tools/DumpRenderTree/chromium/MockWebSpeechInputController.cpp create mode 100644 Tools/DumpRenderTree/chromium/MockWebSpeechInputController.h diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index d4aa92e..fb3eb0c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,23 @@ +2012-01-26 Hans Wennborg + + Speech Input: move MockSpeechInputClient into Chromium DumpRenderTree implementation + https://bugs.webkit.org/show_bug.cgi?id=77083 + + Reviewed by Darin Fisher. + + Remove SpeechInputClientMock. The mock is moving to the DumpRenderTree + implementation. + + No new tests, just refactoring. + + * GNUmakefile.list.am: + * Target.pri: + * WebCore.gypi: + * WebCore.vcproj/WebCore.vcproj: + * WebCore.xcodeproj/project.pbxproj: + * platform/mock/SpeechInputClientMock.cpp: Removed. + * platform/mock/SpeechInputClientMock.h: Removed. + 2012-01-31 Pavel Feldman Web Inspector: boost protocol version to 1.0 diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am index 61509e5..e3e8e9b 100644 --- a/Source/WebCore/GNUmakefile.list.am +++ b/Source/WebCore/GNUmakefile.list.am @@ -3147,8 +3147,6 @@ webcore_sources += \ Source/WebCore/platform/mock/GeolocationServiceMock.h \ Source/WebCore/platform/mock/ScrollbarThemeMock.cpp \ Source/WebCore/platform/mock/ScrollbarThemeMock.h \ - Source/WebCore/platform/mock/SpeechInputClientMock.cpp \ - Source/WebCore/platform/mock/SpeechInputClientMock.h \ Source/WebCore/platform/network/AuthenticationChallengeBase.cpp \ Source/WebCore/platform/network/AuthenticationChallengeBase.h \ Source/WebCore/platform/network/AuthenticationClient.h \ diff --git a/Source/WebCore/Target.pri b/Source/WebCore/Target.pri index 09129fa..fafd8e2 100644 --- a/Source/WebCore/Target.pri +++ b/Source/WebCore/Target.pri @@ -1107,7 +1107,6 @@ SOURCES += \ platform/mock/DeviceOrientationClientMock.cpp \ platform/mock/GeolocationClientMock.cpp \ platform/mock/GeolocationServiceMock.cpp \ - platform/mock/SpeechInputClientMock.cpp \ platform/mock/ScrollbarThemeMock.cpp \ platform/network/AuthenticationChallengeBase.cpp \ platform/network/BlobData.cpp \ @@ -2102,7 +2101,6 @@ HEADERS += \ platform/mock/DeviceOrientationClientMock.h \ platform/mock/GeolocationClientMock.cpp \ platform/mock/GeolocationServiceMock.h \ - platform/mock/SpeechInputClientMock.h \ platform/mock/ScrollbarThemeMock.h \ platform/graphics/BitmapImage.h \ platform/graphics/Color.h \ diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi index 9c0dac2..e1fef5a 100644 --- a/Source/WebCore/WebCore.gypi +++ b/Source/WebCore/WebCore.gypi @@ -3853,8 +3853,6 @@ 'platform/mock/GeolocationServiceMock.h', 'platform/mock/ScrollbarThemeMock.cpp', 'platform/mock/ScrollbarThemeMock.h', - 'platform/mock/SpeechInputClientMock.cpp', - 'platform/mock/SpeechInputClientMock.h', 'platform/network/AuthenticationChallengeBase.cpp', 'platform/network/BlobData.cpp', 'platform/network/BlobData.h', diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj index 84bbad4..132a454 100755 --- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj +++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj @@ -32624,14 +32624,6 @@ RelativePath="..\platform\mock\ScrollbarThemeMock.h" > - - - - 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*) -{ - if (m_recording) { - m_recording = false; - m_listener->didCompleteRecording(m_requestId); - m_timer.startOneShot(0); - } else { - bool noResultsFound = false; - - // We take a copy of the requestId here so that if scripts destroyed the input element - // inside one of the callbacks below, we'll still know what this session's requestId was. - int requestId = m_requestId; - m_requestId = 0; - - // 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(requestId, m_resultsForEmptyLanguage); - else - noResultsFound = true; - } else { - if (m_recognitionResults.contains(m_language)) - m_listener->setRecognitionResult(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(requestId, results); - } - - m_listener->didCompleteRecognition(requestId); - } -} - -} // namespace WebCore - -#endif // ENABLE(INPUT_SPEECH) diff --git a/Source/WebCore/platform/mock/SpeechInputClientMock.h b/Source/WebCore/platform/mock/SpeechInputClientMock.h deleted file mode 100644 index 4e13242..0000000 --- a/Source/WebCore/platform/mock/SpeechInputClientMock.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 -#include - -#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, SecurityOrigin*); - void stopRecording(int); - void cancelRecognition(int); - -private: - void timerFired(Timer*); - - bool m_recording; - Timer m_timer; - SpeechInputListener* m_listener; - int m_requestId; - - HashMap m_recognitionResults; - AtomicString m_language; - SpeechInputResultArray m_resultsForEmptyLanguage; -}; - -} // namespace WebCore - -#endif // ENABLE(INPUT_SPEECH) - -#endif // SpeechInputClientMock_h diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog index e959ee0..828deed 100644 --- a/Source/WebKit/chromium/ChangeLog +++ b/Source/WebKit/chromium/ChangeLog @@ -1,3 +1,29 @@ +2012-01-26 Hans Wennborg + + Speech Input: move MockSpeechInputClient into Chromium DumpRenderTree implementation + https://bugs.webkit.org/show_bug.cgi?id=77083 + + Reviewed by Darin Fisher. + + Remove the WebSpeechInputControllerMock interface and proxy + implementation. The mock is moving to the DumpRenderTree + implementation instead, which removes the need to expose this + interface in the WebKit API. + + Also add a proper copy constructor for WebSpeechInputResult. + The default one doesn't do a proper copy. + + * WebKit.gyp: + * public/WebSpeechInputControllerMock.h: Removed. + * public/WebSpeechInputResult.h: + (WebKit::WebSpeechInputResult::WebSpeechInputResult): + (WebSpeechInputResult): + * src/WebSpeechInputControllerMockImpl.cpp: Removed. + * src/WebSpeechInputControllerMockImpl.h: Removed. + * src/WebSpeechInputResult.cpp: + (WebKit::WebSpeechInputResult::set): + (WebKit): + 2012-01-31 Sheriff Bot Unreviewed. Rolled DEPS. diff --git a/Source/WebKit/chromium/WebKit.gyp b/Source/WebKit/chromium/WebKit.gyp index 2d92ba5..71e57e3 100644 --- a/Source/WebKit/chromium/WebKit.gyp +++ b/Source/WebKit/chromium/WebKit.gyp @@ -245,7 +245,6 @@ 'public/WebSocket.h', 'public/WebSocketClient.h', 'public/WebSpeechInputController.h', - 'public/WebSpeechInputControllerMock.h', 'public/WebSpeechInputListener.h', 'public/WebSpeechInputResult.h', 'public/WebSpellCheckClient.h', @@ -642,8 +641,6 @@ 'src/WebSocketImpl.h', 'src/WebSolidColorLayer.cpp', 'src/WebSolidColorLayerImpl.cpp', - 'src/WebSpeechInputControllerMockImpl.cpp', - 'src/WebSpeechInputControllerMockImpl.h', 'src/WebSpeechInputResult.cpp', 'src/WebStorageAreaImpl.cpp', 'src/WebStorageAreaImpl.h', diff --git a/Source/WebKit/chromium/public/WebSpeechInputControllerMock.h b/Source/WebKit/chromium/public/WebSpeechInputControllerMock.h deleted file mode 100644 index d4e543f..0000000 --- a/Source/WebKit/chromium/public/WebSpeechInputControllerMock.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 WebSpeechInputControllerMock_h -#define WebSpeechInputControllerMock_h - -#include "WebSpeechInputController.h" - -namespace WebKit { - -class WebString; -class WebSpeechInputListener; - -class WebSpeechInputControllerMock : public WebSpeechInputController { -public: - WEBKIT_EXPORT static WebSpeechInputControllerMock* create( - WebSpeechInputListener* listener); - virtual ~WebSpeechInputControllerMock() { } - - virtual void addMockRecognitionResult(const WebString& result, double confidence, const WebString& language) = 0; - - virtual void clearResults() = 0; -}; - -} // namespace WebKit - -#endif diff --git a/Source/WebKit/chromium/public/WebSpeechInputResult.h b/Source/WebKit/chromium/public/WebSpeechInputResult.h index a316fd2..8d02a49 100644 --- a/Source/WebKit/chromium/public/WebSpeechInputResult.h +++ b/Source/WebKit/chromium/public/WebSpeechInputResult.h @@ -42,9 +42,11 @@ namespace WebKit { class WebSpeechInputResult { public: WebSpeechInputResult() { } + WebSpeechInputResult(const WebSpeechInputResult& other) { assign(other); } ~WebSpeechInputResult() { reset(); } WEBKIT_EXPORT void set(const WebString& utterance, double confidence); + WEBKIT_EXPORT void assign(const WebSpeechInputResult& other); WEBKIT_EXPORT void reset(); #if WEBKIT_IMPLEMENTATION diff --git a/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.cpp b/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.cpp deleted file mode 100644 index 4f1f074..0000000 --- a/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 "WebSpeechInputControllerMockImpl.h" - -#if ENABLE(INPUT_SPEECH) - -#include "PlatformString.h" -#include "SecurityOrigin.h" -#include "SpeechInputClientMock.h" -#include "platform/WebRect.h" -#include "WebSecurityOrigin.h" -#include - -namespace WebKit { - -WebSpeechInputControllerMock* WebSpeechInputControllerMock::create(WebSpeechInputListener* listener) -{ - return new WebSpeechInputControllerMockImpl(listener); -} - -WebSpeechInputControllerMockImpl::WebSpeechInputControllerMockImpl( - WebSpeechInputListener* listener) - : m_webcoreMock(adoptPtr(new WebCore::SpeechInputClientMock())) - , m_listener(listener) -{ - m_webcoreMock->setListener(this); -} - -WebSpeechInputControllerMockImpl::~WebSpeechInputControllerMockImpl() -{ - m_webcoreMock->setListener(0); -} - -void WebSpeechInputControllerMockImpl::addMockRecognitionResult(const WebString& result, double confidence, const WebString &language) -{ - m_webcoreMock->addRecognitionResult(result, confidence, language); -} - -void WebSpeechInputControllerMockImpl::clearResults() -{ - m_webcoreMock->clearResults(); -} - -void WebSpeechInputControllerMockImpl::didCompleteRecording(int requestId) -{ - m_listener->didCompleteRecording(requestId); -} - -void WebSpeechInputControllerMockImpl::didCompleteRecognition(int requestId) -{ - m_listener->didCompleteRecognition(requestId); -} - -void WebSpeechInputControllerMockImpl::setRecognitionResult(int requestId, const WebCore::SpeechInputResultArray& result) -{ - m_listener->setRecognitionResult(requestId, result); -} - -bool WebSpeechInputControllerMockImpl::startRecognition(int requestId, const WebRect& elementRect, const WebString& language, const WebString& grammar, const WebSecurityOrigin& origin) -{ - return m_webcoreMock->startRecognition(requestId, elementRect, language, grammar, origin.get()); -} - -void WebSpeechInputControllerMockImpl::cancelRecognition(int requestId) -{ - m_webcoreMock->cancelRecognition(requestId); -} - -void WebSpeechInputControllerMockImpl::stopRecording(int requestId) -{ - m_webcoreMock->stopRecording(requestId); -} - -} // namespace WebKit - -#else - -namespace WebKit { - -WebSpeechInputControllerMock* WebSpeechInputControllerMock::create(WebSpeechInputListener* listener) -{ - return 0; -} - -} // namespace WebKit - -#endif // ENABLE(INPUT_SPEECH) - diff --git a/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.h b/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.h deleted file mode 100644 index 05bfd52..0000000 --- a/Source/WebKit/chromium/src/WebSpeechInputControllerMockImpl.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 WebSpeechInputControllerMockImpl_h -#define WebSpeechInputControllerMockImpl_h - -#include "SpeechInputListener.h" -#include "WebSpeechInputControllerMock.h" -#include "WebSpeechInputListener.h" -#include "platform/WebString.h" -#include - -#if ENABLE(INPUT_SPEECH) - -namespace WebCore { -class SpeechInputClientMock; -} - -namespace WebKit { - -struct WebRect; - -class WebSpeechInputControllerMockImpl : public WebCore::SpeechInputListener - , public WebSpeechInputControllerMock { -public: - WebSpeechInputControllerMockImpl(WebSpeechInputListener*); - virtual ~WebSpeechInputControllerMockImpl(); - - // WebCore::SpeechInputListener methods. - void didCompleteRecording(int requestId); - void didCompleteRecognition(int requestId); - void setRecognitionResult(int requestId, const WebCore::SpeechInputResultArray& result); - - // WebSpeechInputController methods. - bool startRecognition(int requestId, const WebRect& elementRect, const WebString& language, const WebString& grammar, const WebSecurityOrigin&); - void cancelRecognition(int requestId); - void stopRecording(int requestId); - - // WebSpeechInputControllerMock methods. - void addMockRecognitionResult(const WebString& result, double confidence, const WebString& language); - void clearResults(); - -private: - OwnPtr m_webcoreMock; - WebSpeechInputListener* m_listener; -}; - -} // namespace WebKit - -#endif // ENABLE(INPUT_SPEECH) - -#endif // WebSpeechInputControllerMockImpl_h diff --git a/Source/WebKit/chromium/src/WebSpeechInputResult.cpp b/Source/WebKit/chromium/src/WebSpeechInputResult.cpp index 9b13144..693538f 100644 --- a/Source/WebKit/chromium/src/WebSpeechInputResult.cpp +++ b/Source/WebKit/chromium/src/WebSpeechInputResult.cpp @@ -48,6 +48,11 @@ void WebSpeechInputResult::set(const WebString& utterance, double confidence) m_private = WebCore::SpeechInputResult::create(utterance, confidence); } +void WebSpeechInputResult::assign(const WebSpeechInputResult& other) +{ + m_private = WebCore::SpeechInputResult::create(*other.m_private.get()); +} + WebSpeechInputResult::operator PassRefPtr() const { return m_private.get(); diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 72f0b04..4ea3d2b 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,45 @@ +2012-01-26 Hans Wennborg + + Speech Input: move MockSpeechInputClient into Chromium DumpRenderTree implementation + https://bugs.webkit.org/show_bug.cgi?id=77083 + + Reviewed by Darin Fisher. + + Add MockWebSpeechInputController which provides a mock implementation + of the WebSpeechInputController interface, and use that in + DumpRenderTree. + + * DumpRenderTree/DumpRenderTree.gypi: + * DumpRenderTree/chromium/LayoutTestController.cpp: + (LayoutTestController::addMockSpeechInputResult): + * DumpRenderTree/chromium/LayoutTestController.h: + (): + * DumpRenderTree/chromium/MockWebSpeechInputController.cpp: Added. + (MockWebSpeechInputController::create): + (MockWebSpeechInputController::addMockRecognitionResult): + (MockWebSpeechInputController::clearResults): + (MockWebSpeechInputController::startRecognition): + (MockWebSpeechInputController::cancelRecognition): + (MockWebSpeechInputController::stopRecording): + (MockWebSpeechInputController::MockWebSpeechInputController): + (MockWebSpeechInputController::speechTaskFired): + (MockWebSpeechInputController::SpeechTask::SpeechTask): + (MockWebSpeechInputController::SpeechTask::stop): + (MockWebSpeechInputController::SpeechTask::runIfValid): + * DumpRenderTree/chromium/MockWebSpeechInputController.h: Added. + (WebKit): + (MockWebSpeechInputController): + (MockWebSpeechInputController::taskList): + (SpeechTask): + * DumpRenderTree/chromium/TestShell.cpp: + * DumpRenderTree/chromium/WebViewHost.cpp: + (WebViewHost::speechInputController): + * DumpRenderTree/chromium/WebViewHost.h: + (WebKit): + (WebViewHost::speechInputControllerMock): + (WebViewHost): + (): + 2012-01-31 Hajime Morrita [PerformanceTests] Add landing html for Dromaeo dom-query test diff --git a/Tools/DumpRenderTree/DumpRenderTree.gypi b/Tools/DumpRenderTree/DumpRenderTree.gypi index b707464..0736c03 100644 --- a/Tools/DumpRenderTree/DumpRenderTree.gypi +++ b/Tools/DumpRenderTree/DumpRenderTree.gypi @@ -22,6 +22,8 @@ 'chromium/LayoutTestController.h', 'chromium/MockSpellCheck.cpp', 'chromium/MockSpellCheck.h', + 'chromium/MockWebSpeechInputController.cpp', + 'chromium/MockWebSpeechInputController.h', 'chromium/NotificationPresenter.h', 'chromium/NotificationPresenter.cpp', 'chromium/PlainTextController.cpp', diff --git a/Tools/DumpRenderTree/chromium/LayoutTestController.cpp b/Tools/DumpRenderTree/chromium/LayoutTestController.cpp index de394a9..37480b0 100644 --- a/Tools/DumpRenderTree/chromium/LayoutTestController.cpp +++ b/Tools/DumpRenderTree/chromium/LayoutTestController.cpp @@ -33,6 +33,7 @@ #include "LayoutTestController.h" #include "DRTDevToolsAgent.h" +#include "MockWebSpeechInputController.h" #include "TestShell.h" #include "WebAnimationController.h" #include "WebBindings.h" @@ -55,7 +56,6 @@ #include "WebSecurityPolicy.h" #include "WebSettings.h" #include "platform/WebSize.h" -#include "WebSpeechInputControllerMock.h" #include "platform/WebURL.h" #include "WebView.h" #include "WebViewHost.h" @@ -1934,7 +1934,7 @@ void LayoutTestController::addMockSpeechInputResult(const CppArgumentList& argum if (arguments.size() < 3 || !arguments[0].isString() || !arguments[1].isNumber() || !arguments[2].isString()) return; - if (WebSpeechInputControllerMock* controller = m_shell->webViewHost()->speechInputControllerMock()) + if (MockWebSpeechInputController* controller = m_shell->webViewHost()->speechInputControllerMock()) controller->addMockRecognitionResult(cppVariantToWebString(arguments[0]), arguments[1].toDouble(), cppVariantToWebString(arguments[2])); } diff --git a/Tools/DumpRenderTree/chromium/LayoutTestController.h b/Tools/DumpRenderTree/chromium/LayoutTestController.h index 2c7df80..e37ff7d 100644 --- a/Tools/DumpRenderTree/chromium/LayoutTestController.h +++ b/Tools/DumpRenderTree/chromium/LayoutTestController.h @@ -52,9 +52,6 @@ namespace WebKit { class WebGeolocationClientMock; -class WebSpeechInputController; -class WebSpeechInputControllerMock; -class WebSpeechInputListener; } namespace webkit_support { @@ -442,7 +439,6 @@ public: // The following methods are not exposed to JavaScript. void setWorkQueueFrozen(bool frozen) { m_workQueue.setFrozen(frozen); } - WebKit::WebSpeechInputController* speechInputController(WebKit::WebSpeechInputListener*); bool shouldDumpAsAudio() const { return m_dumpAsAudio; } void setShouldDumpAsAudio(bool dumpAsAudio) { m_dumpAsAudio = dumpAsAudio; } bool shouldDumpAsText() { return m_dumpAsText; } @@ -699,8 +695,6 @@ private: WebKit::WebURL m_userStyleSheetLocation; - OwnPtr m_speechInputControllerMock; - // WAV audio data is stored here. WebKit::WebArrayBufferView m_audioData; diff --git a/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.cpp b/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.cpp new file mode 100644 index 0000000..cb0b066 --- /dev/null +++ b/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2012 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: + * + * 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 AND ITS 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 APPLE OR ITS 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 "MockWebSpeechInputController.h" + +#include "WebSpeechInputListener.h" +#include "platform/WebCString.h" +#include + +using namespace WebKit; + +PassOwnPtr MockWebSpeechInputController::create(WebSpeechInputListener* listener) +{ + return adoptPtr(new MockWebSpeechInputController(listener)); +} + +void MockWebSpeechInputController::addMockRecognitionResult(const WebString& result, double confidence, const WebString& language) +{ + WebSpeechInputResult res; + res.set(result, confidence); + + if (language.isEmpty()) + m_resultsForEmptyLanguage.append(res); + else { + String langString = String::fromUTF8(language.utf8().data()); + if (!m_recognitionResults.contains(langString)) + m_recognitionResults.set(langString, Vector()); + m_recognitionResults.find(langString)->second.append(res); + } +} + +void MockWebSpeechInputController::clearResults() +{ + m_resultsForEmptyLanguage.clear(); + m_recognitionResults.clear(); +} + +bool MockWebSpeechInputController::startRecognition(int requestId, const WebRect& elementRect, const WebString& language, const WebString& grammar, const WebSecurityOrigin& origin) +{ + if (m_speechTask) + return false; + + m_requestId = requestId; + m_recording = true; + m_language = String::fromUTF8(language.utf8().data()); + + m_speechTask = new SpeechTask(this); + postTask(m_speechTask); + + return true; +} + +void MockWebSpeechInputController::cancelRecognition(int requestId) +{ + if (m_speechTask) { + ASSERT(requestId == m_requestId); + + m_speechTask->stop(); + m_recording = false; + m_listener->didCompleteRecognition(m_requestId); + m_requestId = 0; + } +} + +void MockWebSpeechInputController::stopRecording(int requestId) +{ + ASSERT(requestId == m_requestId); + if (m_speechTask && m_recording) { + m_speechTask->stop(); + speechTaskFired(); + } +} + +MockWebSpeechInputController::MockWebSpeechInputController(WebSpeechInputListener* listener) + : m_listener(listener) + , m_speechTask(0) + , m_recording(false) + , m_requestId(-1) +{ +} + +void MockWebSpeechInputController::speechTaskFired() +{ + if (m_recording) { + m_recording = false; + m_listener->didCompleteRecording(m_requestId); + + m_speechTask = new SpeechTask(this); + postTask(m_speechTask); + } else { + bool noResultsFound = false; + // We take a copy of the requestId here so that if scripts destroyed the input element + // inside one of the callbacks below, we'll still know what this session's requestId was. + int requestId = m_requestId; + m_requestId = 0; + + // 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(requestId, m_resultsForEmptyLanguage); + else + noResultsFound = true; + } else { + if (m_recognitionResults.contains(m_language)) + m_listener->setRecognitionResult(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("'"); + + WebSpeechInputResult res; + res.set(WebString::fromUTF8(error.utf8().data()), 1.0); + + Vector results; + results.append(res); + + m_listener->setRecognitionResult(requestId, results); + } + } +} + +MockWebSpeechInputController::SpeechTask::SpeechTask(MockWebSpeechInputController* mock) + : MethodTask::MethodTask(mock) +{ +} + +void MockWebSpeechInputController::SpeechTask::stop() +{ + m_object->m_speechTask = 0; + cancel(); + delete(this); +} + +void MockWebSpeechInputController::SpeechTask::runIfValid() +{ + m_object->m_speechTask = 0; + m_object->speechTaskFired(); +} diff --git a/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.h b/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.h new file mode 100644 index 0000000..96aadff --- /dev/null +++ b/Tools/DumpRenderTree/chromium/MockWebSpeechInputController.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2012 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: + * + * 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 AND ITS 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 APPLE OR ITS 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 MockWebSpeechInputController_h +#define MockWebSpeechInputController_h + +#if ENABLE(INPUT_SPEECH) + +#include "Task.h" +#include "WebSpeechInputController.h" +#include "WebSpeechInputResult.h" +#include +#include +#include +#include +#include +#include + +namespace WebKit { +struct WebRect; +class WebSecurityOrigin; +class WebSpeechInputListener; +class WebString; +} + +class MockWebSpeechInputController : public WebKit::WebSpeechInputController { +public: + static PassOwnPtr create(WebKit::WebSpeechInputListener*); + + void addMockRecognitionResult(const WebKit::WebString& result, double confidence, const WebKit::WebString& language); + void clearResults(); + + // WebSpeechInputController implementation: + virtual bool startRecognition(int requestId, const WebKit::WebRect& elementRect, const WebKit::WebString& language, const WebKit::WebString& grammar, const WebKit::WebSecurityOrigin&) OVERRIDE; + virtual void cancelRecognition(int requestId) OVERRIDE; + virtual void stopRecording(int requestId) OVERRIDE; + + TaskList* taskList() { return &m_taskList; } + +private: + MockWebSpeechInputController(WebKit::WebSpeechInputListener*); + void speechTaskFired(); + + class SpeechTask : public MethodTask { + public: + SpeechTask(MockWebSpeechInputController*); + void stop(); + + private: + virtual void runIfValid() OVERRIDE; + }; + + WebKit::WebSpeechInputListener* m_listener; + + TaskList m_taskList; + SpeechTask* m_speechTask; + + bool m_recording; + int m_requestId; + String m_language; + + HashMap > m_recognitionResults; + Vector m_resultsForEmptyLanguage; +}; + +#endif // ENABLE(INPUT_SPEECH) + +#endif // MockWebSpeechInputController_h diff --git a/Tools/DumpRenderTree/chromium/TestShell.cpp b/Tools/DumpRenderTree/chromium/TestShell.cpp index 45cbc1e..501e78b 100644 --- a/Tools/DumpRenderTree/chromium/TestShell.cpp +++ b/Tools/DumpRenderTree/chromium/TestShell.cpp @@ -52,7 +52,6 @@ #include "WebScriptController.h" #include "WebSettings.h" #include "platform/WebSize.h" -#include "WebSpeechInputControllerMock.h" #include "platform/WebString.h" #include "platform/WebURLRequest.h" #include "platform/WebURLResponse.h" diff --git a/Tools/DumpRenderTree/chromium/WebViewHost.cpp b/Tools/DumpRenderTree/chromium/WebViewHost.cpp index f8ee472..2e68030 100644 --- a/Tools/DumpRenderTree/chromium/WebViewHost.cpp +++ b/Tools/DumpRenderTree/chromium/WebViewHost.cpp @@ -32,6 +32,7 @@ #include "WebViewHost.h" #include "LayoutTestController.h" +#include "MockWebSpeechInputController.h" #include "TestNavigationController.h" #include "TestShell.h" #include "TestWebPlugin.h" @@ -55,7 +56,6 @@ #include "platform/WebRect.h" #include "WebScreenInfo.h" #include "platform/WebSize.h" -#include "WebSpeechInputControllerMock.h" #include "WebStorageNamespace.h" #include "WebTextCheckingCompletion.h" #include "WebTextCheckingResult.h" @@ -678,7 +678,7 @@ WebKit::WebGeolocationClientMock* WebViewHost::geolocationClientMock() WebSpeechInputController* WebViewHost::speechInputController(WebKit::WebSpeechInputListener* listener) { if (!m_speechInputControllerMock) - m_speechInputControllerMock = adoptPtr(WebSpeechInputControllerMock::create(listener)); + m_speechInputControllerMock = MockWebSpeechInputController::create(listener); return m_speechInputControllerMock.get(); } diff --git a/Tools/DumpRenderTree/chromium/WebViewHost.h b/Tools/DumpRenderTree/chromium/WebViewHost.h index 1d0954a..eb21369 100644 --- a/Tools/DumpRenderTree/chromium/WebViewHost.h +++ b/Tools/DumpRenderTree/chromium/WebViewHost.h @@ -45,6 +45,7 @@ #include class LayoutTestController; +class MockWebSpeechInputController; class SkCanvas; class TestShell; @@ -57,7 +58,6 @@ class WebGeolocationClientMock; class WebGeolocationServiceMock; class WebSharedWorkerClient; class WebSpeechInputController; -class WebSpeechInputControllerMock; class WebSpeechInputListener; class WebURL; class WebUserMediaClientMock; @@ -108,7 +108,7 @@ class WebViewHost : public WebKit::WebSpellCheckClient, public WebKit::WebViewCl WebKit::WebContextMenuData* lastContextMenuData() const; void clearContextMenuData(); - WebKit::WebSpeechInputControllerMock* speechInputControllerMock() { return m_speechInputControllerMock.get(); } + MockWebSpeechInputController* speechInputControllerMock() { return m_speechInputControllerMock.get(); } #if ENABLE(POINTER_LOCK) void didLosePointerLock(); @@ -382,7 +382,7 @@ private: OwnPtr m_geolocationClientMock; OwnPtr m_deviceOrientationClientMock; - OwnPtr m_speechInputControllerMock; + OwnPtr m_speechInputControllerMock; OwnPtr m_userMediaClientMock; OwnPtr m_testMediaStreamClient; -- 2.7.4