WebSpeech: plumb through a method to generate fake speech jobs for testing
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Feb 2013 20:57:42 +0000 (20:57 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 17 Feb 2013 20:57:42 +0000 (20:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107351

Reviewed by Adam Barth.

Source/WebCore:

We can't reliably use the platforms synthesizer to test speech synthesis internals.
This patch adds an Internals method to enable a mock synthesizer, which is inherits
from the PlatformSpeechSythesizer.

The fake synthesizer goes through all the motions of a real synthesizer but doesn't do anything.
A bunch of changes were needed here to make PlatformSpeechSynthesizer subclassable so that the
right virtual are used.

The Mock synthesizer only lives in WebCoreTestSupport. Because PlatformSpeechSynthesizer uses
a RetainPtr, I needed to make WebCoreTestSupport link CoreFoundation

LayoutTests:

* platform/mac/fast/speechsynthesis/speech-synthesis-speak.html:
* platform/mac/fast/speechsynthesis/speech-synthesis-voices.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143136 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-speak.html
LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-voices.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/speech/SpeechSynthesis.cpp
Source/WebCore/Modules/speech/SpeechSynthesis.h
Source/WebCore/Target.pri
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCoreTestSupport.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/PlatformSpeechSynthesizer.cpp
Source/WebCore/platform/PlatformSpeechSynthesizer.h
Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp [new file with mode: 0644]
Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h [new file with mode: 0644]
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 34e069f..6c4d443 100644 (file)
@@ -1,3 +1,13 @@
+2013-02-17  Chris Fleizach  <cfleizach@apple.com>
+
+        WebSpeech: plumb through a method to generate fake speech jobs for testing
+        https://bugs.webkit.org/show_bug.cgi?id=107351
+
+        Reviewed by Adam Barth.
+
+        * platform/mac/fast/speechsynthesis/speech-synthesis-speak.html:
+        * platform/mac/fast/speechsynthesis/speech-synthesis-voices.html:
+
 2013-02-17  Christophe Dumez  <ch.dumez@sisa.samsung.com>
 
         Unreviewed EFL gardening.
index 82adaf7..4f9a879 100644 (file)
@@ -9,6 +9,9 @@
 
 <script>
 
+    if (window.internals)
+        window.internals.enableMockSpeechSynthesizer();
+
     description("This tests that the basic mechanisms of speaking text work, including sending the job and receving the callback.");
 
     if (window.testRunner)
index 2b79f07..c570d19 100644 (file)
@@ -8,6 +8,8 @@
 <div id="console"></div>
 
 <script>
+    if (window.internals)
+        window.internals.enableMockSpeechSynthesizer();
 
     description("This tests that we can get synthesizer voices on the Mac");
 
index 7138bf9..da6d6e5 100644 (file)
@@ -2831,6 +2831,7 @@ endif ()
 
 set(WebCoreTestSupport_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/testing"
+    "${WEBCORE_DIR}/platform/mock"
 )
 
 set(WebCoreTestSupport_IDL_INCLUDES
@@ -2847,6 +2848,7 @@ set(WebCoreTestSupport_IDL_FILES
 set(WebCoreTestSupport_SOURCES
     testing/Internals.cpp
     testing/InternalSettings.cpp
+    platform/mock/PlatformSpeechSynthesizerMock.cpp
 )
 
 # Modules that the bindings generator scripts may use
index 6116b4f..42437ef 100644 (file)
@@ -1,3 +1,21 @@
+2013-02-17  Chris Fleizach  <cfleizach@apple.com>
+
+        WebSpeech: plumb through a method to generate fake speech jobs for testing
+        https://bugs.webkit.org/show_bug.cgi?id=107351
+
+        Reviewed by Adam Barth.
+
+        We can't reliably use the platforms synthesizer to test speech synthesis internals.
+        This patch adds an Internals method to enable a mock synthesizer, which is inherits
+        from the PlatformSpeechSythesizer.
+
+        The fake synthesizer goes through all the motions of a real synthesizer but doesn't do anything.
+        A bunch of changes were needed here to make PlatformSpeechSynthesizer subclassable so that the
+        right virtual are used.
+
+        The Mock synthesizer only lives in WebCoreTestSupport. Because PlatformSpeechSynthesizer uses
+        a RetainPtr, I needed to make WebCoreTestSupport link CoreFoundation
+
 2013-02-17  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unreviewed buildfix for !USE(LIBXML) builds after r143112.
index 9ddede4..220c24d 100644 (file)
@@ -42,11 +42,16 @@ PassRefPtr<SpeechSynthesis> SpeechSynthesis::create()
 }
     
 SpeechSynthesis::SpeechSynthesis()
-    : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer(this))
+    : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this))
     , m_currentSpeechUtterance(0)
 {
 }
     
+void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesizer> synthesizer)
+{
+    m_platformSpeechSynthesizer = synthesizer;
+}
+    
 void SpeechSynthesis::voicesDidChange()
 {
     m_voiceList.clear();
@@ -58,7 +63,7 @@ const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices()
         return m_voiceList;
     
     // If the voiceList is empty, that's the cue to get the voices from the platform again.
-    const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_platformSpeechSynthesizer.voiceList();
+    const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_platformSpeechSynthesizer->voiceList();
     size_t voiceCount = platformVoices.size();
     for (size_t k = 0; k < voiceCount; k++)
         m_voiceList.append(SpeechSynthesisVoice::create(platformVoices[k]));
@@ -88,7 +93,7 @@ void SpeechSynthesis::startSpeakingImmediately(SpeechSynthesisUtterance* utteran
     ASSERT(!m_currentSpeechUtterance);
     utterance->setStartTime(monotonicallyIncreasingTime());
     m_currentSpeechUtterance = utterance;
-    m_platformSpeechSynthesizer.speak(utterance->platformUtterance());
+    m_platformSpeechSynthesizer->speak(utterance->platformUtterance());
 }
 
 void SpeechSynthesis::speak(SpeechSynthesisUtterance* utterance)
index 859b80e..bfb0ffd 100644 (file)
@@ -57,6 +57,9 @@ public:
     
     const Vector<RefPtr<SpeechSynthesisVoice> >& getVoices();
     
+    // Used in testing to use a mock platform synthesizer
+    void setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesizer>);
+    
 private:
     SpeechSynthesis();
     
@@ -70,7 +73,7 @@ private:
     void handleSpeakingCompleted(SpeechSynthesisUtterance*, bool errorOccurred);
     void fireEvent(const AtomicString& type, SpeechSynthesisUtterance*, unsigned long charIndex, const String& name);
     
-    PlatformSpeechSynthesizer m_platformSpeechSynthesizer;
+    OwnPtr<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer;
     Vector<RefPtr<SpeechSynthesisVoice> > m_voiceList;
     SpeechSynthesisUtterance* m_currentSpeechUtterance;
     Deque<RefPtr<SpeechSynthesisUtterance> > m_utteranceQueue;
index 8e4c29d..3e78b41 100644 (file)
@@ -1081,6 +1081,7 @@ SOURCES += \
     platform/mock/DeviceMotionClientMock.cpp \
     platform/mock/DeviceOrientationClientMock.cpp \
     platform/mock/GeolocationClientMock.cpp \
+    platform/mock/PlatformSpeechSynthesizerMock.cpp \
     platform/mock/ScrollbarThemeMock.cpp \
     platform/network/AuthenticationChallengeBase.cpp \
     platform/network/BlobData.cpp \
@@ -2175,6 +2176,7 @@ HEADERS += \
     platform/mock/DeviceMotionClientMock.h \
     platform/mock/DeviceOrientationClientMock.h \
     platform/mock/GeolocationClientMock.cpp \
+    platform/mock/PlatformSpeechSynthesizerMock.h \
     platform/mock/ScrollbarThemeMock.h \
     platform/graphics/BitmapImage.h \
     platform/graphics/Color.h \
index e203207..9402f70 100644 (file)
@@ -1534,6 +1534,9 @@ __ZTVN7WebCore16DatabaseStrategyE
 __ZTVN7WebCore16IconDatabaseBaseE
 __ZTVN7WebCore17FrameLoaderClientE
 __ZTVN7WebCore25HistoryPropertyListWriterE
+#if ENABLE(SPEECH_SYNTHESIS)
+__ZTVN7WebCore25PlatformSpeechSynthesizerE
+#endif
 __ZTVN7WebCore28InspectorFrontendClientLocal8SettingsE
 __ZN7WebCore16CSSParserContextC1EPNS_8DocumentERKNS_4KURLERKN3WTF6StringE
 __ZN7WebCore18StyleSheetContents11parseStringERKN3WTF6StringE
@@ -1689,6 +1692,9 @@ __ZN7WebCore12PopupMenuMacC1EPNS_15PopupMenuClientE
 __ZN7WebCore13toDeviceSpaceERKNS_9FloatRectEP8NSWindow
 __ZN7WebCore15GraphicsContextC1EP9CGContext
 __ZN7WebCore15GraphicsContext15drawNativeImageEP7CGImageRKNS_9FloatSizeENS_10ColorSpaceERKNS_9FloatRectES9_NS_17CompositeOperatorENS_9BlendModeENS_16ImageOrientationE
+#if ENABLE(SPEECH_SYNTHESIS)
+__ZN7WebCore15SpeechSynthesis22setPlatformSynthesizerEN3WTF10PassOwnPtrINS_25PlatformSpeechSynthesizerEEE
+#endif
 __ZN7WebCore16FontPlatformDataC1EP6NSFontfbbbNS_15FontOrientationENS_16FontWidthVariantE
 __ZN7WebCore16FontPlatformDataC2EP6NSFontfbbbNS_15FontOrientationENS_16FontWidthVariantE
 __ZN7WebCore16colorFromNSColorEP7NSColor
@@ -1708,6 +1714,10 @@ __ZN7WebCore22contextMenuItemTagBoldEv
 __ZN7WebCore24contextMenuItemTagItalicEv
 __ZN7WebCore24contextMenuItemTagStylesEv
 __ZN7WebCore24keyIdentifierForKeyEventEP7NSEvent
+#if ENABLE(SPEECH_SYNTHESIS)
+__ZN7WebCore24DOMWindowSpeechSynthesis15speechSynthesisEPNS_9DOMWindowE
+__ZN7WebCore25PlatformSpeechSynthesizerC2EPNS_31PlatformSpeechSynthesizerClientE
+#endif
 __ZN7WebCore25PluginMainThreadScheduler12scheduleCallEP4_NPPPFvPvES3_
 __ZN7WebCore25PluginMainThreadScheduler14registerPluginEP4_NPP
 __ZN7WebCore25PluginMainThreadScheduler16unregisterPluginEP4_NPP
@@ -1726,6 +1736,9 @@ __ZN7WebCore28contextMenuItemTagCapitalizeEv
 __ZN7WebCore28contextMenuItemTagShowColorsEv
 __ZN7WebCore28contextMenuItemTagSmartLinksEv
 __ZN7WebCore28contextMenuItemTagSpeechMenuEv
+#if ENABLE(SPEECH_SYNTHESIS)
+__ZN7WebCore28PlatformSpeechSynthesisVoice6createERKN3WTF6StringES4_S4_bb
+#endif
 __ZN7WebCore29applicationIsMicrosoftOutlookEv
 __ZN7WebCore29contextMenuItemTagLeftToRightEv
 __ZN7WebCore29contextMenuItemTagRightToLeftEv
index 302ef65..6d28a1c 100644 (file)
             'platform/mock/DeviceMotionClientMock.cpp',
             'platform/mock/DeviceOrientationClientMock.cpp',
             'platform/mock/GeolocationClientMock.cpp',
+            'platform/mock/PlatformSpeechSynthesizerMock.cpp',
+            'platform/mock/PlatformSpeechSynthesizerMock.h',
             'platform/mock/ScrollbarThemeMock.cpp',
             'platform/mock/ScrollbarThemeMock.h',
             'platform/network/AuthenticationChallengeBase.cpp',
         'webcore_test_support_files': [
             'inspector/InspectorFrontendClientLocal.cpp',
             'inspector/InspectorFrontendClientLocal.h',
+            'platform/mock/PlatformSpeechSynthesizerMock.cpp',
+            'platform/mock/PlatformSpeechSynthesizerMock.h',
             'testing/v8/WebCoreTestSupport.cpp',
             'testing/v8/WebCoreTestSupport.h',
             'testing/js/WebCoreTestSupport.cpp',
index f601e69..6a421a4 100644 (file)
                        </File>
                </Filter>
                <Filter
+                       Name="platform"
+                       >
+                       <Filter
+                               Name="mock"
+                               >
+                               <File
+                                       RelativePath="..\platform\mock\PlatformSpeechSynthesizerMock.cpp"
+                                       >
+                                       <FileConfiguration
+                                               Name="Debug|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                                       <FileConfiguration
+                                               Name="Release|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                                       <FileConfiguration
+                                               Name="Debug_Cairo_CFLite|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                                       <FileConfiguration
+                                               Name="Release_Cairo_CFLite|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                                       <FileConfiguration
+                                               Name="Debug_All|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                                       <FileConfiguration
+                                               Name="Production|Win32"
+                                               >
+                                               <Tool
+                                                       Name="VCCLCompilerTool"
+                                                       UsePrecompiledHeader="0"
+                                                       DisableSpecificWarnings="4065;4273;4565;4701;4702"
+                                                       ForcedIncludeFiles="$(NOINHERIT)"
+                                               />
+                                       </FileConfiguration>
+                               </File>
+                               <File
+                                       RelativePath="..\platform\mock\PlatformSpeechSynthesizerMock.h"
+                                       >
+                               </File>
+                       </Filter>
+               </Filter>
+               <Filter
                        Name="testing"
                        >
                        <File
index c0fe1ef..11c9ece 100644 (file)
                AA478A8016CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA478A7E16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm */; };
                AA4C3A760B2B1679002334A2 /* StyleElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA4C3A740B2B1679002334A2 /* StyleElement.cpp */; };
                AA4C3A770B2B1679002334A2 /* StyleElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AA4C3A750B2B1679002334A2 /* StyleElement.h */; };
+               AA5F3B8D16CC33D100455EB0 /* PlatformSpeechSynthesizerMock.h in Headers */ = {isa = PBXBuildFile; fileRef = AAE27B7516CBFC0D00623043 /* PlatformSpeechSynthesizerMock.h */; };
+               AA5F3B8F16CC4B3900455EB0 /* PlatformSpeechSynthesizerMock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAE27B7416CBFC0D00623043 /* PlatformSpeechSynthesizerMock.cpp */; };
+               AA5F3B9116CC5BEB00455EB0 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA5F3B9016CC5BEB00455EB0 /* CoreFoundation.framework */; };
                AA73183E159255B900A93E6E /* InjectedScriptCanvasModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA73183C159255B900A93E6E /* InjectedScriptCanvasModule.cpp */; };
                AA73183F159255B900A93E6E /* InjectedScriptCanvasModule.h in Headers */ = {isa = PBXBuildFile; fileRef = AA73183D159255B900A93E6E /* InjectedScriptCanvasModule.h */; };
                AA7FEEA416A4E6F3004C0C33 /* JSSpeechSynthesis.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA7FEE9C16A4E6F3004C0C33 /* JSSpeechSynthesis.cpp */; };
                AA478A7E16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebAccessibilityObjectWrapperMac.mm; sourceTree = "<group>"; };
                AA4C3A740B2B1679002334A2 /* StyleElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = StyleElement.cpp; sourceTree = "<group>"; };
                AA4C3A750B2B1679002334A2 /* StyleElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StyleElement.h; sourceTree = "<group>"; };
+               AA5F3B9016CC5BEB00455EB0 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = ../../../../../System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<group>"; };
                AA73183C159255B900A93E6E /* InjectedScriptCanvasModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedScriptCanvasModule.cpp; sourceTree = "<group>"; };
                AA73183D159255B900A93E6E /* InjectedScriptCanvasModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScriptCanvasModule.h; sourceTree = "<group>"; };
                AA7FEE9C16A4E6F3004C0C33 /* JSSpeechSynthesis.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSpeechSynthesis.cpp; sourceTree = "<group>"; };
                AAD766E8157E502F00E85423 /* InspectorCanvasAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCanvasAgent.cpp; sourceTree = "<group>"; };
                AAD766E9157E502F00E85423 /* InspectorCanvasAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCanvasAgent.h; sourceTree = "<group>"; };
                AAD766EA157E502F00E85423 /* InspectorCanvasInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCanvasInstrumentation.h; sourceTree = "<group>"; };
+               AAE27B7416CBFC0D00623043 /* PlatformSpeechSynthesizerMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformSpeechSynthesizerMock.cpp; path = mock/PlatformSpeechSynthesizerMock.cpp; sourceTree = "<group>"; };
+               AAE27B7516CBFC0D00623043 /* PlatformSpeechSynthesizerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformSpeechSynthesizerMock.h; path = mock/PlatformSpeechSynthesizerMock.h; sourceTree = "<group>"; };
                AAF5B7B11524B4BD0004CB49 /* WebSocketFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebSocketFrame.cpp; path = Modules/websockets/WebSocketFrame.cpp; sourceTree = "<group>"; };
                AB23A32509BBA7D00067CC53 /* BeforeTextInsertedEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = BeforeTextInsertedEvent.cpp; sourceTree = "<group>"; };
                AB23A32609BBA7D00067CC53 /* BeforeTextInsertedEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = BeforeTextInsertedEvent.h; sourceTree = "<group>"; };
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               AA5F3B9116CC5BEB00455EB0 /* CoreFoundation.framework in Frameworks */,
                                41230913138C42FF00BCCFCA /* JavaScriptCore.framework in Frameworks */,
                                4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */,
                        );
                0867D69AFE84028FC02AAC07 /* Frameworks */ = {
                        isa = PBXGroup;
                        children = (
+                               AA5F3B9016CC5BEB00455EB0 /* CoreFoundation.framework */,
                                FD2DBF0E12B048A300ED98C6 /* Accelerate.framework */,
                                F5C2869302846DCD018635CA /* ApplicationServices.framework */,
                                FD2DBF0F12B048A300ED98C6 /* AudioToolbox.framework */,
                        children = (
                                59309A1011F4AE5800250603 /* DeviceOrientationClientMock.cpp */,
                                59309A1211F4AE6A00250603 /* DeviceOrientationClientMock.h */,
+                               AAE27B7416CBFC0D00623043 /* PlatformSpeechSynthesizerMock.cpp */,
+                               AAE27B7516CBFC0D00623043 /* PlatformSpeechSynthesizerMock.h */,
                                0FE71403142170B800DB33BA /* ScrollbarThemeMock.cpp */,
                                0FE71404142170B800DB33BA /* ScrollbarThemeMock.h */,
                        );
                                417DA6DA13734E6E007C57FB /* Internals.h in Headers */,
                                A7BF7EE014C9175A0014489D /* InternalSettings.h in Headers */,
                                53E29E5F167A8A1900586D3D /* InternalSettingsGenerated.h in Headers */,
+                               AA5F3B8D16CC33D100455EB0 /* PlatformSpeechSynthesizerMock.h in Headers */,
                                417DA71E13735DFA007C57FB /* JSInternals.h in Headers */,
                                A740B5A514C935AB00A77FA4 /* JSInternalSettings.h in Headers */,
                                53ED3FDF167A88E7006762E6 /* JSInternalSettingsGenerated.h in Headers */,
                                A740B59714C935AF00A77FA4 /* JSMallocStatistics.cpp in Sources */,
                                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */,
                                CDC26B40160A8CC60026757B /* MockCDM.cpp in Sources */,
+                               AA5F3B8F16CC4B3900455EB0 /* PlatformSpeechSynthesizerMock.cpp in Sources */,
                                41815C1E138319830057AAA4 /* WebCoreTestSupport.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index edcb124..66123d5 100644 (file)
 
 namespace WebCore {
     
+PassOwnPtr<PlatformSpeechSynthesizer> PlatformSpeechSynthesizer::create(PlatformSpeechSynthesizerClient* client)
+{
+    return adoptPtr(new PlatformSpeechSynthesizer(client));
+}
+
 PlatformSpeechSynthesizer::PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient* client)
     : m_speechSynthesizerClient(client)
 {
index a119ce2..7313c97 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(SPEECH_SYNTHESIS)
 
 #include "PlatformSpeechSynthesisVoice.h"
+#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 #if PLATFORM(MAC)
@@ -53,18 +54,22 @@ protected:
     
 class PlatformSpeechSynthesizer {
 public:
-    explicit PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient*);
+    static PassOwnPtr<PlatformSpeechSynthesizer> create(PlatformSpeechSynthesizerClient*);
+
+    virtual ~PlatformSpeechSynthesizer() { }
     
     const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voiceList() const { return m_voiceList; }
-    void speak(const PlatformSpeechSynthesisUtterance&);
+    virtual void speak(const PlatformSpeechSynthesisUtterance&);
     
     PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
     
-private:
-    PlatformSpeechSynthesizerClient* m_speechSynthesizerClient;
+protected:
+    explicit PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient*);
     Vector<RefPtr<PlatformSpeechSynthesisVoice> > m_voiceList;
     
-    void initializeVoiceList();
+private:
+    PlatformSpeechSynthesizerClient* m_speechSynthesizerClient;
+    virtual void initializeVoiceList();
     
 #if PLATFORM(MAC)
     RetainPtr<WebSpeechSynthesisWrapper> m_platformSpeechWrapper;
diff --git a/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp
new file mode 100644 (file)
index 0000000..890708b
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2013 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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 "PlatformSpeechSynthesizerMock.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+namespace WebCore {
+
+PassOwnPtr<PlatformSpeechSynthesizerMock> PlatformSpeechSynthesizerMock::create(PlatformSpeechSynthesizerClient* client)
+{
+    return adoptPtr(new PlatformSpeechSynthesizerMock(client));
+}
+    
+PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client)
+    : PlatformSpeechSynthesizer(client)
+    , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished)
+    , m_utterance(0)
+{
+}
+    
+PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
+{
+    m_speakingFinishedTimer.stop();
+}
+
+void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthesizerMock>*)
+{
+    client()->didFinishSpeaking(m_utterance);
+    m_utterance = 0;
+}
+    
+void PlatformSpeechSynthesizerMock::initializeVoiceList()
+{
+    m_voiceList.clear();
+    m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.bruce"), String("bruce"), String("en-US"), true, true));
+    m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.clark"), String("clark"), String("en-US"), true, false));
+    m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.logan"), String("logan"), String("fr-CA"), true, true));
+}
+
+void PlatformSpeechSynthesizerMock::speak(const PlatformSpeechSynthesisUtterance& utterance)
+{
+    m_utterance = &utterance;
+    client()->didStartSpeaking(m_utterance);
+    m_speakingFinishedTimer.startOneShot(0);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h
new file mode 100644 (file)
index 0000000..46e95ae
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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 PlatformSpeechSynthesizerMock_h
+#define PlatformSpeechSynthesizerMock_h
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "PlatformSpeechSynthesizer.h"
+#include "Timer.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+    
+class PlatformSpeechSynthesizerMock : public PlatformSpeechSynthesizer {
+public:
+    static PassOwnPtr<PlatformSpeechSynthesizerMock> create(PlatformSpeechSynthesizerClient*);
+    
+    virtual ~PlatformSpeechSynthesizerMock();
+    virtual void speak(const PlatformSpeechSynthesisUtterance&);
+    
+private:
+    explicit PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient*);
+    virtual void initializeVoiceList();
+    void speakingFinished(Timer<PlatformSpeechSynthesizerMock>*);
+    
+    Timer<PlatformSpeechSynthesizerMock> m_speakingFinishedTimer;
+    const PlatformSpeechSynthesisUtterance* m_utterance;
+};
+    
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
+
+#endif // PlatformSpeechSynthesizer_h
index 3c79dea..3834410 100644 (file)
 #include "PageGroup.h"
 #endif
 
+#if ENABLE(SPEECH_SYNTHESIS)
+#include "DOMWindowSpeechSynthesis.h"
+#include "PlatformSpeechSynthesizerMock.h"
+#include "SpeechSynthesis.h"
+#endif
+
 namespace WebCore {
 
 #if ENABLE(PAGE_POPUP)
@@ -827,6 +833,20 @@ void Internals::setFormControlStateOfPreviousHistoryItem(const Vector<String>& s
         ec = INVALID_ACCESS_ERR;
 }
 
+#if ENABLE(SPEECH_SYNTHESIS)
+void Internals::enableMockSpeechSynthesizer()
+{
+    Document* document = contextDocument();
+    if (!document || !document->domWindow())
+        return;
+    SpeechSynthesis* synthesis = DOMWindowSpeechSynthesis::speechSynthesis(document->domWindow());
+    if (!synthesis)
+        return;
+    
+    synthesis->setPlatformSynthesizer(PlatformSpeechSynthesizerMock::create(synthesis));
+}
+#endif
+    
 void Internals::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
 {
 #if ENABLE(PAGE_POPUP)
index e70ac6c..3cada19 100644 (file)
@@ -285,6 +285,10 @@ public:
     void initializeMockCDM();
 #endif
 
+#if ENABLE(SPEECH_SYNTHESIS)
+    void enableMockSpeechSynthesizer();
+#endif
+                    
 private:
     explicit Internals(Document*);
     Document* contextDocument() const;
index bf63479..85efd94 100644 (file)
     void setUsesOverlayScrollbars(in boolean enabled);
 
     [Conditional=ENCRYPTED_MEDIA_V2] void initializeMockCDM();
+    
+    [Conditional=SPEECH_SYNTHESIS] void enableMockSpeechSynthesizer();
 };