summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/mock
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/mock
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/platform/mock')
-rw-r--r--Source/WebCore/platform/mock/DeviceMotionClientMock.cpp72
-rw-r--r--Source/WebCore/platform/mock/DeviceMotionClientMock.h68
-rw-r--r--Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp5
-rw-r--r--Source/WebCore/platform/mock/DeviceOrientationClientMock.h18
-rw-r--r--Source/WebCore/platform/mock/GeolocationClientMock.cpp12
-rw-r--r--Source/WebCore/platform/mock/GeolocationClientMock.h22
-rw-r--r--Source/WebCore/platform/mock/MediaConstraintsMock.cpp76
-rw-r--r--Source/WebCore/platform/mock/MediaPlaybackTargetMock.cpp68
-rw-r--r--Source/WebCore/platform/mock/MediaPlaybackTargetMock.h68
-rw-r--r--Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.cpp126
-rw-r--r--Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.h67
-rw-r--r--Source/WebCore/platform/mock/MockMediaEndpoint.cpp342
-rw-r--r--Source/WebCore/platform/mock/MockMediaEndpoint.h99
-rw-r--r--Source/WebCore/platform/mock/MockMediaStreamCenter.cpp220
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp125
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeAudioSource.h82
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp148
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeMediaSource.h97
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp136
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h (renamed from Source/WebCore/platform/mock/MockMediaStreamCenter.h)29
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp382
-rw-r--r--Source/WebCore/platform/mock/MockRealtimeVideoSource.h110
-rw-r--r--Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp96
-rw-r--r--Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h (renamed from Source/WebCore/platform/mock/mediasource/MockTracks.cpp)43
-rw-r--r--Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp9
-rw-r--r--Source/WebCore/platform/mock/RTCDataChannelHandlerMock.h36
-rw-r--r--Source/WebCore/platform/mock/RTCNotifiersMock.cpp4
-rw-r--r--Source/WebCore/platform/mock/RTCNotifiersMock.h4
-rw-r--r--Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp203
-rw-r--r--Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.h75
-rw-r--r--Source/WebCore/platform/mock/ScrollAnimatorMock.cpp145
-rw-r--r--Source/WebCore/platform/mock/ScrollAnimatorMock.h78
-rw-r--r--Source/WebCore/platform/mock/ScrollbarThemeMock.cpp25
-rw-r--r--Source/WebCore/platform/mock/ScrollbarThemeMock.h22
-rw-r--r--Source/WebCore/platform/mock/TimerEventBasedMock.h (renamed from Source/WebCore/platform/mock/MediaConstraintsMock.h)64
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockBox.cpp17
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockBox.h22
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp121
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h74
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp45
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.h34
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp122
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h47
-rw-r--r--Source/WebCore/platform/mock/mediasource/MockTracks.h19
44 files changed, 2635 insertions, 1042 deletions
diff --git a/Source/WebCore/platform/mock/DeviceMotionClientMock.cpp b/Source/WebCore/platform/mock/DeviceMotionClientMock.cpp
deleted file mode 100644
index ecc4b13fd..000000000
--- a/Source/WebCore/platform/mock/DeviceMotionClientMock.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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:
- * * 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 "DeviceMotionClientMock.h"
-
-#include "DeviceMotionController.h"
-
-namespace WebCore {
-
-DeviceMotionClientMock::DeviceMotionClientMock()
- : m_controller(0)
- , m_timer(this, &DeviceMotionClientMock::timerFired)
- , m_isUpdating(false)
-{
-}
-
-void DeviceMotionClientMock::setController(DeviceMotionController* controller)
-{
- ASSERT(!m_controller);
- m_controller = controller;
- ASSERT(m_controller);
-}
-
-void DeviceMotionClientMock::startUpdating()
-{
- m_isUpdating = true;
-}
-
-void DeviceMotionClientMock::stopUpdating()
-{
- m_isUpdating = false;
- m_timer.stop();
-}
-
-void DeviceMotionClientMock::setMotion(PassRefPtr<DeviceMotionData> motion)
-{
- m_motion = motion;
- if (m_isUpdating && !m_timer.isActive())
- m_timer.startOneShot(0);
-}
-
-void DeviceMotionClientMock::timerFired(Timer<DeviceMotionClientMock>* timer)
-{
- ASSERT_UNUSED(timer, timer == &m_timer);
- m_timer.stop();
- m_controller->didChangeDeviceMotion(m_motion.get());
-}
-
-} // namespace WebCore
diff --git a/Source/WebCore/platform/mock/DeviceMotionClientMock.h b/Source/WebCore/platform/mock/DeviceMotionClientMock.h
deleted file mode 100644
index f2e0a981a..000000000
--- a/Source/WebCore/platform/mock/DeviceMotionClientMock.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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:
- * * 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 DeviceMotionClientMock_h
-#define DeviceMotionClientMock_h
-
-#include "DeviceMotionClient.h"
-#include "DeviceMotionData.h"
-#include "Timer.h"
-
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-
-namespace WebCore {
-
-class DeviceMotionController;
-
-// A mock implementation of DeviceMotionClient used to test the feature in
-// DumpRenderTree. Embedders should should configure the Page object to use this
-// client when running DumpRenderTree.
-class DeviceMotionClientMock : public DeviceMotionClient {
-public:
- DeviceMotionClientMock();
-
- // DeviceMotionClient
- virtual void setController(DeviceMotionController*) override;
- virtual void startUpdating() override;
- virtual void stopUpdating() override;
- virtual DeviceMotionData* lastMotion() const override { return m_motion.get(); }
- // mock is owned by the testing framework, which should handle deletion
- virtual void deviceMotionControllerDestroyed() override { }
-
- void setMotion(PassRefPtr<DeviceMotionData>);
-
-private:
- void timerFired(Timer<DeviceMotionClientMock>*);
-
- RefPtr<DeviceMotionData> m_motion;
- DeviceMotionController* m_controller;
- Timer<DeviceMotionClientMock> m_timer;
- bool m_isUpdating;
-};
-
-} // namespace WebCore
-
-#endif // DeviceMotionClientMock_h
diff --git a/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp b/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp
index 9716a7e6a..af0a834c3 100644
--- a/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp
+++ b/Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp
@@ -32,7 +32,7 @@ namespace WebCore {
DeviceOrientationClientMock::DeviceOrientationClientMock()
: m_controller(0)
- , m_timer(this, &DeviceOrientationClientMock::timerFired)
+ , m_timer(*this, &DeviceOrientationClientMock::timerFired)
, m_isUpdating(false)
{
}
@@ -62,9 +62,8 @@ void DeviceOrientationClientMock::setOrientation(PassRefPtr<DeviceOrientationDat
m_timer.startOneShot(0);
}
-void DeviceOrientationClientMock::timerFired(Timer<DeviceOrientationClientMock>& timer)
+void DeviceOrientationClientMock::timerFired()
{
- ASSERT_UNUSED(timer, &timer == &m_timer);
m_timer.stop();
m_controller->didChangeDeviceOrientation(m_orientation.get());
}
diff --git a/Source/WebCore/platform/mock/DeviceOrientationClientMock.h b/Source/WebCore/platform/mock/DeviceOrientationClientMock.h
index df85b7fc9..1384af2e6 100644
--- a/Source/WebCore/platform/mock/DeviceOrientationClientMock.h
+++ b/Source/WebCore/platform/mock/DeviceOrientationClientMock.h
@@ -42,23 +42,23 @@ class DeviceOrientationController;
// client when running DumpRenderTree.
class DeviceOrientationClientMock : public DeviceOrientationClient {
public:
- DeviceOrientationClientMock();
+ WEBCORE_EXPORT DeviceOrientationClientMock();
// DeviceOrientationClient
- virtual void setController(DeviceOrientationController*) override;
- virtual void startUpdating() override;
- virtual void stopUpdating() override;
- virtual DeviceOrientationData* lastOrientation() const override { return m_orientation.get(); }
- virtual void deviceOrientationControllerDestroyed() override { }
+ void setController(DeviceOrientationController*) override;
+ void startUpdating() override;
+ void stopUpdating() override;
+ DeviceOrientationData* lastOrientation() const override { return m_orientation.get(); }
+ void deviceOrientationControllerDestroyed() override { }
- void setOrientation(PassRefPtr<DeviceOrientationData>);
+ WEBCORE_EXPORT void setOrientation(PassRefPtr<DeviceOrientationData>);
private:
- void timerFired(Timer<DeviceOrientationClientMock>&);
+ void timerFired();
RefPtr<DeviceOrientationData> m_orientation;
DeviceOrientationController* m_controller;
- Timer<DeviceOrientationClientMock> m_timer;
+ Timer m_timer;
bool m_isUpdating;
};
diff --git a/Source/WebCore/platform/mock/GeolocationClientMock.cpp b/Source/WebCore/platform/mock/GeolocationClientMock.cpp
index 9901b66aa..b7cfb9be0 100644
--- a/Source/WebCore/platform/mock/GeolocationClientMock.cpp
+++ b/Source/WebCore/platform/mock/GeolocationClientMock.cpp
@@ -43,8 +43,8 @@ namespace WebCore {
GeolocationClientMock::GeolocationClientMock()
: m_controller(0)
, m_hasError(false)
- , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired)
- , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired)
+ , m_controllerTimer(*this, &GeolocationClientMock::controllerTimerFired)
+ , m_permissionTimer(*this, &GeolocationClientMock::permissionTimerFired)
, m_isActive(false)
, m_permissionState(PermissionStateUnset)
{
@@ -109,9 +109,8 @@ void GeolocationClientMock::asyncUpdatePermission()
m_permissionTimer.startOneShot(0);
}
-void GeolocationClientMock::permissionTimerFired(WebCore::Timer<GeolocationClientMock>* timer)
+void GeolocationClientMock::permissionTimerFired()
{
- ASSERT_UNUSED(timer, timer == &m_permissionTimer);
ASSERT(m_permissionState != PermissionStateUnset);
bool allowed = m_permissionState == PermissionStateAllowed;
GeolocationSet::iterator end = m_pendingPermission.end();
@@ -127,7 +126,7 @@ void GeolocationClientMock::permissionTimerFired(WebCore::Timer<GeolocationClien
void GeolocationClientMock::reset()
{
- m_lastPosition = 0;
+ m_lastPosition = nullptr;
clearError();
m_permissionState = PermissionStateUnset;
}
@@ -169,9 +168,8 @@ void GeolocationClientMock::asyncUpdateController()
m_controllerTimer.startOneShot(0);
}
-void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* timer)
+void GeolocationClientMock::controllerTimerFired()
{
- ASSERT_UNUSED(timer, timer == &m_controllerTimer);
ASSERT(m_controller);
if (m_lastPosition.get()) {
diff --git a/Source/WebCore/platform/mock/GeolocationClientMock.h b/Source/WebCore/platform/mock/GeolocationClientMock.h
index f380c1443..b13987729 100644
--- a/Source/WebCore/platform/mock/GeolocationClientMock.h
+++ b/Source/WebCore/platform/mock/GeolocationClientMock.h
@@ -60,20 +60,20 @@ public:
int numberOfPendingPermissionRequests() const;
// 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*);
+ void geolocationDestroyed() override;
+ void startUpdating() override;
+ void stopUpdating() override;
+ void setEnableHighAccuracy(bool) override;
+ GeolocationPosition* lastPosition() override;
+ void requestPermission(Geolocation*) override;
+ void cancelPermissionRequest(Geolocation*) override;
private:
void asyncUpdateController();
- void controllerTimerFired(Timer<GeolocationClientMock>*);
+ void controllerTimerFired();
void asyncUpdatePermission();
- void permissionTimerFired(Timer<GeolocationClientMock>*);
+ void permissionTimerFired();
void clearError();
@@ -81,8 +81,8 @@ private:
RefPtr<GeolocationPosition> m_lastPosition;
bool m_hasError;
String m_errorMessage;
- Timer<GeolocationClientMock> m_controllerTimer;
- Timer<GeolocationClientMock> m_permissionTimer;
+ Timer m_controllerTimer;
+ Timer m_permissionTimer;
bool m_isActive;
enum PermissionState {
diff --git a/Source/WebCore/platform/mock/MediaConstraintsMock.cpp b/Source/WebCore/platform/mock/MediaConstraintsMock.cpp
deleted file mode 100644
index db9389516..000000000
--- a/Source/WebCore/platform/mock/MediaConstraintsMock.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
- *
- * 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 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"
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "MediaConstraintsMock.h"
-
-#include "MediaConstraints.h"
-
-namespace WebCore {
-
-bool isSupported(const String& constraint)
-{
- return notFound != constraint.find("_and_supported_");
-}
-
-bool isValid(const String& constraint)
-{
- return isSupported(constraint) || notFound != constraint.find("valid_");
-}
-
-String MediaConstraintsMock::verifyConstraints(PassRefPtr<MediaConstraints> prpConstraints)
-{
- RefPtr<MediaConstraints> constraints = prpConstraints;
-
- Vector<MediaConstraint> mandatoryConstraints;
- constraints->getMandatoryConstraints(mandatoryConstraints);
- if (mandatoryConstraints.size()) {
- for (size_t i = 0; i < mandatoryConstraints.size(); ++i) {
- const MediaConstraint& curr = mandatoryConstraints[i];
- if (!isSupported(curr.m_name) || curr.m_value != "1")
- return curr.m_name;
- }
- }
-
- Vector<MediaConstraint> optionalConstraints;
- constraints->getOptionalConstraints(optionalConstraints);
- if (optionalConstraints.size()) {
- for (size_t i = 0; i < optionalConstraints.size(); ++i) {
- const MediaConstraint& curr = optionalConstraints[i];
- if (!isValid(curr.m_name) || curr.m_value != "0")
- return curr.m_name;
- }
- }
-
- return emptyString();
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MediaPlaybackTargetMock.cpp b/Source/WebCore/platform/mock/MediaPlaybackTargetMock.cpp
new file mode 100644
index 000000000..01ff3faad
--- /dev/null
+++ b/Source/WebCore/platform/mock/MediaPlaybackTargetMock.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2015 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 "MediaPlaybackTargetMock.h"
+
+#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+namespace WebCore {
+
+Ref<MediaPlaybackTarget> MediaPlaybackTargetMock::create(const String& name, MediaPlaybackTargetContext::State state)
+{
+ return adoptRef(*new MediaPlaybackTargetMock(name, state));
+}
+
+MediaPlaybackTargetMock::MediaPlaybackTargetMock(const String& name, MediaPlaybackTargetContext::State state)
+ : MediaPlaybackTarget()
+ , m_name(name)
+ , m_state(state)
+{
+}
+
+MediaPlaybackTargetMock::~MediaPlaybackTargetMock()
+{
+}
+
+const MediaPlaybackTargetContext& MediaPlaybackTargetMock::targetContext() const
+{
+ m_context = MediaPlaybackTargetContext(m_name, m_state);
+ return m_context;
+}
+
+MediaPlaybackTargetMock* toMediaPlaybackTargetMock(MediaPlaybackTarget* rep)
+{
+ return const_cast<MediaPlaybackTargetMock*>(toMediaPlaybackTargetMock(const_cast<const MediaPlaybackTarget*>(rep)));
+}
+
+const MediaPlaybackTargetMock* toMediaPlaybackTargetMock(const MediaPlaybackTarget* rep)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(rep->targetType() == MediaPlaybackTarget::Mock);
+ return static_cast<const MediaPlaybackTargetMock*>(rep);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
diff --git a/Source/WebCore/platform/mock/MediaPlaybackTargetMock.h b/Source/WebCore/platform/mock/MediaPlaybackTargetMock.h
new file mode 100644
index 000000000..1dd97f12e
--- /dev/null
+++ b/Source/WebCore/platform/mock/MediaPlaybackTargetMock.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2015 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 MediaPlaybackTargetMock_h
+#define MediaPlaybackTargetMock_h
+
+#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+#include "MediaPlaybackTarget.h"
+#include "MediaPlaybackTargetContext.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class MediaPlaybackTargetMock : public MediaPlaybackTarget {
+public:
+ WEBCORE_EXPORT static Ref<MediaPlaybackTarget> create(const String&, MediaPlaybackTargetContext::State);
+
+ virtual ~MediaPlaybackTargetMock();
+
+ TargetType targetType() const override { return Mock; }
+
+ const MediaPlaybackTargetContext& targetContext() const override;
+
+ bool hasActiveRoute() const override { return !m_name.isEmpty(); }
+
+ String deviceName() const override { return m_name; }
+
+ MediaPlaybackTargetContext::State state() const;
+
+protected:
+ MediaPlaybackTargetMock(const String&, MediaPlaybackTargetContext::State);
+
+ String m_name;
+ MediaPlaybackTargetContext::State m_state { MediaPlaybackTargetContext::Unknown };
+ mutable MediaPlaybackTargetContext m_context;
+};
+
+MediaPlaybackTargetMock* toMediaPlaybackTargetMock(MediaPlaybackTarget*);
+const MediaPlaybackTargetMock* toMediaPlaybackTargetMock(const MediaPlaybackTarget*);
+
+}
+
+#endif // ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+#endif
diff --git a/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.cpp b/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.cpp
new file mode 100644
index 000000000..1a60ca24b
--- /dev/null
+++ b/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2015 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. 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 INC. 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 "MediaPlaybackTargetPickerMock.h"
+
+#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+#include "FloatRect.h"
+#include "Logging.h"
+#include "MediaPlaybackTargetMock.h"
+#include "WebMediaSessionManager.h"
+
+using namespace WebCore;
+
+namespace WebCore {
+
+static const double timerInterval = 1.0 / 10.0;
+
+MediaPlaybackTargetPickerMock::MediaPlaybackTargetPickerMock(MediaPlaybackTargetPicker::Client& client)
+ : MediaPlaybackTargetPicker(client)
+ , m_timer(RunLoop::main(), this, &MediaPlaybackTargetPickerMock::timerFired)
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::MediaPlaybackTargetPickerMock");
+}
+
+MediaPlaybackTargetPickerMock::~MediaPlaybackTargetPickerMock()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::~MediaPlaybackTargetPickerMock");
+ setClient(nullptr);
+}
+
+bool MediaPlaybackTargetPickerMock::externalOutputDeviceAvailable()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::externalOutputDeviceAvailable");
+ return m_state == MediaPlaybackTargetContext::OutputDeviceAvailable;
+}
+
+Ref<MediaPlaybackTarget> MediaPlaybackTargetPickerMock::playbackTarget()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::playbackTarget");
+ return WebCore::MediaPlaybackTargetMock::create(m_deviceName, m_state);
+}
+
+void MediaPlaybackTargetPickerMock::timerFired()
+{
+ m_showingMenu = false;
+ currentDeviceDidChange();
+}
+
+void MediaPlaybackTargetPickerMock::showPlaybackTargetPicker(const FloatRect&, bool checkActiveRoute)
+{
+ if (!client() || m_showingMenu)
+ return;
+
+#if LOG_DISABLED
+ UNUSED_PARAM(checkActiveRoute);
+#endif
+ LOG(Media, "MediaPlaybackTargetPickerMock::showPlaybackTargetPicker - checkActiveRoute = %i", (int)checkActiveRoute);
+
+ m_showingMenu = true;
+ m_timer.startOneShot(timerInterval);
+}
+
+void MediaPlaybackTargetPickerMock::startingMonitoringPlaybackTargets()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::startingMonitoringPlaybackTargets");
+
+ if (m_state == MediaPlaybackTargetContext::OutputDeviceAvailable)
+ availableDevicesDidChange();
+
+ if (!m_deviceName.isEmpty() && m_state != MediaPlaybackTargetContext::Unknown)
+ currentDeviceDidChange();
+}
+
+void MediaPlaybackTargetPickerMock::stopMonitoringPlaybackTargets()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::stopMonitoringPlaybackTargets");
+}
+
+void MediaPlaybackTargetPickerMock::invalidatePlaybackTargets()
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::invalidatePlaybackTargets");
+ setState(emptyString(), MediaPlaybackTargetContext::Unknown);
+}
+
+void MediaPlaybackTargetPickerMock::setState(const String& deviceName, MediaPlaybackTargetContext::State state)
+{
+ LOG(Media, "MediaPlaybackTargetPickerMock::setState - name = %s, state = 0x%x", deviceName.utf8().data(), (unsigned)state);
+
+ if (deviceName != m_deviceName && state != MediaPlaybackTargetContext::Unknown) {
+ m_deviceName = deviceName;
+ currentDeviceDidChange();
+ }
+
+ if (m_state != state) {
+ m_state = state;
+ availableDevicesDidChange();
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
diff --git a/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.h b/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.h
new file mode 100644
index 000000000..35cc954b0
--- /dev/null
+++ b/Source/WebCore/platform/mock/MediaPlaybackTargetPickerMock.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2015 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. 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 INC. 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 MediaPlaybackTargetPickerMock_h
+#define MediaPlaybackTargetPickerMock_h
+
+#if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+#include "MediaPlaybackTargetContext.h"
+#include "MediaPlaybackTargetPicker.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class MediaPlaybackTargetPickerMock final : public MediaPlaybackTargetPicker {
+ WTF_MAKE_NONCOPYABLE(MediaPlaybackTargetPickerMock);
+public:
+ explicit MediaPlaybackTargetPickerMock(MediaPlaybackTargetPicker::Client&);
+
+ virtual ~MediaPlaybackTargetPickerMock();
+
+ void showPlaybackTargetPicker(const FloatRect&, bool checkActiveRoute) override;
+ void startingMonitoringPlaybackTargets() override;
+ void stopMonitoringPlaybackTargets() override;
+ void invalidatePlaybackTargets() override;
+
+ void setState(const String&, MediaPlaybackTargetContext::State);
+
+private:
+ bool externalOutputDeviceAvailable() override;
+ Ref<MediaPlaybackTarget> playbackTarget() override;
+
+ void timerFired();
+
+ String m_deviceName;
+ RunLoop::Timer<MediaPlaybackTargetPickerMock> m_timer;
+ MediaPlaybackTargetContext::State m_state { MediaPlaybackTargetContext::Unknown };
+ bool m_showingMenu { false };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
+
+#endif // WebContextMenuProxyMac_h
diff --git a/Source/WebCore/platform/mock/MockMediaEndpoint.cpp b/Source/WebCore/platform/mock/MockMediaEndpoint.cpp
new file mode 100644
index 000000000..253b6e938
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockMediaEndpoint.cpp
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2015 Ericsson AB. 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.
+ * 3. Neither the name of Ericsson 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"
+
+#if ENABLE(WEB_RTC)
+#include "MockMediaEndpoint.h"
+
+#include "MediaEndpointSessionConfiguration.h"
+#include "MediaPayload.h"
+#include "MockRealtimeAudioSource.h"
+#include "MockRealtimeVideoSource.h"
+#include "RTCDataChannelHandlerMock.h"
+#include "RealtimeMediaSource.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+static const char* fingerprint = "8B:87:09:8A:5D:C2:F3:33:EF:C5:B1:F6:84:3A:3D:D6:A3:E2:9C:17:4C:E7:46:3B:1B:CE:84:98:DD:8E:AF:7B";
+static const char* fingerprintFunction = "sha-256";
+
+std::unique_ptr<MediaEndpoint> MockMediaEndpoint::create(MediaEndpointClient& client)
+{
+ return std::unique_ptr<MediaEndpoint>(new MockMediaEndpoint(client));
+}
+
+MockMediaEndpoint::MockMediaEndpoint(MediaEndpointClient& client)
+ : m_client(client)
+ , m_iceCandidateTimer(*this, &MockMediaEndpoint::iceCandidateTimerFired)
+ , m_iceTransportTimer(*this, &MockMediaEndpoint::iceTransportTimerFired)
+ , m_unmuteTimer(*this, &MockMediaEndpoint::unmuteTimerFired)
+ , m_weakPtrFactory(this)
+{
+}
+
+MockMediaEndpoint::~MockMediaEndpoint()
+{
+ stop();
+}
+
+std::unique_ptr<RTCDataChannelHandler> MockMediaEndpoint::createDataChannelHandler(const String& label, const RTCDataChannelInit& options)
+{
+ return std::make_unique<RTCDataChannelHandlerMock>(label, options);
+}
+
+void MockMediaEndpoint::generateDtlsInfo()
+{
+ auto weakThis = m_weakPtrFactory.createWeakPtr();
+
+ callOnMainThread([weakThis] {
+ if (weakThis)
+ weakThis->m_client.gotDtlsFingerprint(fingerprint, fingerprintFunction);
+ });
+}
+
+MediaPayloadVector MockMediaEndpoint::getDefaultAudioPayloads()
+{
+ MediaPayloadVector payloads;
+
+ MediaPayload payload1;
+ payload1.type = 111;
+ payload1.encodingName = "OPUS";
+ payload1.clockRate = 48000;
+ payload1.channels = 2;
+ payloads.append(WTFMove(payload1));
+
+ MediaPayload payload2;
+ payload2.type = 8;
+ payload2.encodingName = "PCMA";
+ payload2.clockRate = 8000;
+ payload2.channels = 1;
+ payloads.append(WTFMove(payload2));
+
+ MediaPayload payload3;
+ payload3.type = 0;
+ payload3.encodingName = "PCMU";
+ payload3.clockRate = 8000;
+ payload3.channels = 1;
+ payloads.append(WTFMove(payload3));
+
+ return payloads;
+}
+
+MediaPayloadVector MockMediaEndpoint::getDefaultVideoPayloads()
+{
+ MediaPayloadVector payloads;
+
+ MediaPayload payload1;
+ payload1.type = 103;
+ payload1.encodingName = "H264";
+ payload1.clockRate = 90000;
+ payload1.ccmfir = true;
+ payload1.nackpli = true;
+ payload1.addParameter("packetizationMode", 1);
+ payloads.append(WTFMove(payload1));
+
+ MediaPayload payload2;
+ payload2.type = 100;
+ payload2.encodingName = "VP8";
+ payload2.clockRate = 90000;
+ payload2.ccmfir = true;
+ payload2.nackpli = true;
+ payload2.nack = true;
+ payloads.append(WTFMove(payload2));
+
+ MediaPayload payload3;
+ payload3.type = 120;
+ payload3.encodingName = "RTX";
+ payload3.clockRate = 90000;
+ payload3.addParameter("apt", 100);
+ payload3.addParameter("rtxTime", 200);
+ payloads.append(WTFMove(payload3));
+
+ return payloads;
+}
+
+MediaPayloadVector MockMediaEndpoint::filterPayloads(const MediaPayloadVector& remotePayloads, const MediaPayloadVector& defaultPayloads)
+{
+ MediaPayloadVector filteredPayloads;
+
+ for (auto& remotePayload : remotePayloads) {
+ const MediaPayload* defaultPayload = nullptr;
+ for (auto& payload : defaultPayloads) {
+ if (payload.encodingName == remotePayload.encodingName.convertToASCIIUppercase()) {
+ defaultPayload = &payload;
+ break;
+ }
+ }
+ if (!defaultPayload)
+ continue;
+
+ if (defaultPayload->parameters.contains("packetizationMode") && remotePayload.parameters.contains("packetizationMode")
+ && (defaultPayload->parameters.get("packetizationMode") != defaultPayload->parameters.get("packetizationMode")))
+ continue;
+
+ filteredPayloads.append(remotePayload);
+ }
+
+ return filteredPayloads;
+}
+
+MediaEndpoint::UpdateResult MockMediaEndpoint::updateReceiveConfiguration(MediaEndpointSessionConfiguration* configuration, bool isInitiator)
+{
+ UNUSED_PARAM(isInitiator);
+
+ updateConfigurationMids(*configuration);
+ return UpdateResult::Success;
+}
+
+MediaEndpoint::UpdateResult MockMediaEndpoint::updateSendConfiguration(MediaEndpointSessionConfiguration* configuration, const RealtimeMediaSourceMap& sendSourceMap, bool isInitiator)
+{
+ UNUSED_PARAM(sendSourceMap);
+ UNUSED_PARAM(isInitiator);
+
+ updateConfigurationMids(*configuration);
+ return UpdateResult::Success;
+}
+
+void MockMediaEndpoint::addRemoteCandidate(const IceCandidate& candidate, const String& mid, const String& ufrag, const String& password)
+{
+ UNUSED_PARAM(candidate);
+ UNUSED_PARAM(mid);
+ UNUSED_PARAM(ufrag);
+ UNUSED_PARAM(password);
+}
+
+Ref<RealtimeMediaSource> MockMediaEndpoint::createMutedRemoteSource(const String& mid, RealtimeMediaSource::Type type)
+{
+ RefPtr<RealtimeMediaSource> source;
+
+ switch (type) {
+ case RealtimeMediaSource::Audio: source = MockRealtimeAudioSource::createMuted("remote audio"); break;
+ case RealtimeMediaSource::Video: source = MockRealtimeVideoSource::createMuted("remote video"); break;
+ case RealtimeMediaSource::None:
+ ASSERT_NOT_REACHED();
+ }
+
+ m_mutedRemoteSources.set(mid, source);
+ return *source;
+}
+
+void MockMediaEndpoint::replaceSendSource(RealtimeMediaSource& newSource, const String& mid)
+{
+ UNUSED_PARAM(newSource);
+ UNUSED_PARAM(mid);
+}
+
+void MockMediaEndpoint::replaceMutedRemoteSourceMid(const String& oldMid, const String& newMid)
+{
+ RefPtr<RealtimeMediaSource> remoteSource = m_mutedRemoteSources.take(oldMid);
+ m_mutedRemoteSources.set(newMid, WTFMove(remoteSource));
+}
+
+void MockMediaEndpoint::stop()
+{
+}
+
+void MockMediaEndpoint::emulatePlatformEvent(const String& action)
+{
+ if (action == "dispatch-fake-ice-candidates")
+ dispatchFakeIceCandidates();
+ else if (action == "step-ice-transport-states")
+ stepIceTransportStates();
+ else if (action == "unmute-remote-sources-by-mid")
+ unmuteRemoteSourcesByMid();
+}
+
+void MockMediaEndpoint::updateConfigurationMids(const MediaEndpointSessionConfiguration& configuration)
+{
+ Vector<String> mids;
+ for (auto& mediaDescription : configuration.mediaDescriptions())
+ mids.append(mediaDescription.mid);
+ m_mids.swap(mids);
+}
+
+void MockMediaEndpoint::dispatchFakeIceCandidates()
+{
+ m_fakeIceCandidates.append({ "host", "1", 1, "UDP", 2013266431, "192.168.0.100", 38838, { }, { }, 0 });
+ m_fakeIceCandidates.append({ "host", "2", 1, "TCP", 1019216383, "192.168.0.100", 9, "active", { }, 0 });
+ m_fakeIceCandidates.append({ "srflx", "3", 1, "UDP", 1677722111, "172.18.0.1", 47989, { }, "192.168.0.100", 47989 });
+
+ // Reverse order to use takeLast() while keeping the above order
+ m_fakeIceCandidates.reverse();
+
+ m_iceCandidateTimer.startOneShot(0);
+}
+
+void MockMediaEndpoint::iceCandidateTimerFired()
+{
+ if (m_mids.isEmpty())
+ return;
+
+ if (!m_fakeIceCandidates.isEmpty()) {
+ m_client.gotIceCandidate(m_mids[0], m_fakeIceCandidates.takeLast());
+ m_iceCandidateTimer.startOneShot(0);
+ } else
+ m_client.doneGatheringCandidates(m_mids[0]);
+}
+
+void MockMediaEndpoint::stepIceTransportStates()
+{
+ if (m_mids.size() != 3) {
+ LOG_ERROR("The 'step-ice-transport-states' action requires 3 transceivers");
+ return;
+ }
+
+ // Should go to:
+ // 'checking'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[0], MediaEndpoint::IceTransportState::Checking));
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[1], MediaEndpoint::IceTransportState::Checking));
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[2], MediaEndpoint::IceTransportState::Checking));
+
+ // 'connected'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[0], MediaEndpoint::IceTransportState::Connected));
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[1], MediaEndpoint::IceTransportState::Completed));
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[2], MediaEndpoint::IceTransportState::Closed));
+
+ // 'completed'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[0], MediaEndpoint::IceTransportState::Completed));
+
+ // 'failed'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[0], MediaEndpoint::IceTransportState::Failed));
+
+ // 'disconnected'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[1], MediaEndpoint::IceTransportState::Disconnected));
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[0], MediaEndpoint::IceTransportState::Closed));
+
+ // 'new'
+ m_iceTransportStateChanges.append(std::make_pair(m_mids[1], MediaEndpoint::IceTransportState::Closed));
+
+ // Reverse order to use takeLast() while keeping the above order
+ m_iceTransportStateChanges.reverse();
+
+ m_iceTransportTimer.startOneShot(0);
+}
+
+void MockMediaEndpoint::iceTransportTimerFired()
+{
+ if (m_iceTransportStateChanges.isEmpty() || m_mids.size() != 3)
+ return;
+
+ auto stateChange = m_iceTransportStateChanges.takeLast();
+ m_client.iceTransportStateChanged(stateChange.first, stateChange.second);
+
+ m_iceTransportTimer.startOneShot(0);
+}
+
+void MockMediaEndpoint::unmuteRemoteSourcesByMid()
+{
+ if (m_mids.isEmpty())
+ return;
+
+ // Looking up each source by its mid, instead of simply iterating over the list of muted sources,
+ // emulates remote media arriving on a media description with a specific mid (RTCRtpTransceiver).
+
+ // Copy values in reverse order to maintain the original order while using takeLast()
+ for (int i = m_mids.size() - 1; i >= 0; --i)
+ m_midsOfSourcesToUnmute.append(m_mids[i]);
+
+ m_unmuteTimer.startOneShot(0);
+}
+
+void MockMediaEndpoint::unmuteTimerFired()
+{
+ RefPtr<RealtimeMediaSource> source = m_mutedRemoteSources.get(m_midsOfSourcesToUnmute.takeLast());
+ if (source)
+ source->setMuted(false);
+
+ if (!m_midsOfSourcesToUnmute.isEmpty())
+ m_unmuteTimer.startOneShot(0);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/platform/mock/MockMediaEndpoint.h b/Source/WebCore/platform/mock/MockMediaEndpoint.h
new file mode 100644
index 000000000..7359c8d48
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockMediaEndpoint.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2015 Ericsson AB. 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.
+ * 3. Neither the name of Ericsson 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_RTC)
+
+#include "MediaEndpoint.h"
+#include "Timer.h"
+
+namespace WebCore {
+
+class MockMediaEndpoint final : public MediaEndpoint {
+public:
+ WEBCORE_EXPORT static std::unique_ptr<MediaEndpoint> create(MediaEndpointClient&);
+
+ MockMediaEndpoint(MediaEndpointClient&);
+ ~MockMediaEndpoint();
+
+ void setConfiguration(MediaEndpointConfiguration&&) final { };
+
+ void generateDtlsInfo() final;
+ MediaPayloadVector getDefaultAudioPayloads() final;
+ MediaPayloadVector getDefaultVideoPayloads() final;
+ MediaPayloadVector filterPayloads(const MediaPayloadVector& remotePayloads, const MediaPayloadVector& defaultPayloads) final;
+
+ UpdateResult updateReceiveConfiguration(MediaEndpointSessionConfiguration*, bool isInitiator) final;
+ UpdateResult updateSendConfiguration(MediaEndpointSessionConfiguration*, const RealtimeMediaSourceMap&, bool isInitiator) final;
+
+ void addRemoteCandidate(const IceCandidate&, const String& mid, const String& ufrag, const String& password) final;
+
+ Ref<RealtimeMediaSource> createMutedRemoteSource(const String& mid, RealtimeMediaSource::Type) final;
+ void replaceSendSource(RealtimeMediaSource&, const String& mid) final;
+ void replaceMutedRemoteSourceMid(const String& oldMid, const String& newMid) final;
+
+ void stop() final;
+
+ void emulatePlatformEvent(const String& action) final;
+
+private:
+ void updateConfigurationMids(const MediaEndpointSessionConfiguration&);
+
+ std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) final;
+
+ void dispatchFakeIceCandidates();
+ void iceCandidateTimerFired();
+
+ void stepIceTransportStates();
+ void iceTransportTimerFired();
+
+ void unmuteRemoteSourcesByMid();
+ void unmuteTimerFired();
+
+ MediaEndpointClient& m_client;
+ Vector<String> m_mids;
+ HashMap<String, RefPtr<RealtimeMediaSource>> m_mutedRemoteSources;
+
+ Vector<IceCandidate> m_fakeIceCandidates;
+ Timer m_iceCandidateTimer;
+
+ Vector<std::pair<String, MediaEndpoint::IceTransportState>> m_iceTransportStateChanges;
+ Timer m_iceTransportTimer;
+
+ Vector<String> m_midsOfSourcesToUnmute;
+ Timer m_unmuteTimer;
+
+ WeakPtrFactory<MockMediaEndpoint> m_weakPtrFactory;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp b/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp
deleted file mode 100644
index 20cb1ab8b..000000000
--- a/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- * Copyright (C) 2013 Apple Computer, Inc. All rights reserved.
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
- *
- * 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"
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "MockMediaStreamCenter.h"
-
-#include "MediaConstraintsMock.h"
-#include "MediaStream.h"
-#include "MediaStreamCreationClient.h"
-#include "MediaStreamPrivate.h"
-#include "MediaStreamSource.h"
-#include "MediaStreamSourceCapabilities.h"
-#include "MediaStreamTrack.h"
-#include "MediaStreamTrackSourcesRequestClient.h"
-#include <wtf/NeverDestroyed.h>
-
-namespace WebCore {
-
-class MockSource : public MediaStreamSource {
-public:
- MockSource(const AtomicString& id, const AtomicString& name, MediaStreamSource::Type type)
- : MediaStreamSource(id, type, name)
- {
- }
-
- virtual ~MockSource() { }
-
- virtual RefPtr<MediaStreamSourceCapabilities> capabilities() const { return m_capabilities; }
- virtual const MediaStreamSourceStates& states() { return m_currentStates; }
-
- RefPtr<MediaStreamSourceCapabilities> m_capabilities;
- MediaStreamSourceStates m_currentStates;
-};
-
-typedef HashMap<String, RefPtr<MockSource>> MockSourceMap;
-
-static MockSourceMap& mockSourceMap()
-{
- DEFINE_STATIC_LOCAL(MockSourceMap, mockSourceMap, ());
- return mockSourceMap;
-}
-
-static const AtomicString& mockAudioSourceID()
-{
- static NeverDestroyed<AtomicString> id("239c24b1-2b15-11e3-8224-0800200c9a66", AtomicString::ConstructFromLiteral);
- return id;
-}
-
-static const AtomicString& mockVideoSourceID()
-{
- static NeverDestroyed<AtomicString> id("239c24b0-2b15-11e3-8224-0800200c9a66", AtomicString::ConstructFromLiteral);
- return id;
-}
-
-static void initializeMockSources()
-{
- RefPtr<MockSource> mockSource1 = adoptRef(new MockSource(mockVideoSourceID(), "Mock video device", MediaStreamSource::Video));
- mockSource1->m_capabilities = MediaStreamSourceCapabilities::create();
- mockSource1->m_capabilities->setSourceId(mockSource1->id());
- mockSource1->m_capabilities->addSourceType(MediaStreamSourceStates::Camera);
- mockSource1->m_capabilities->addSourceType(MediaStreamSourceStates::Microphone);
- mockSource1->m_capabilities->addFacingMode(MediaStreamSourceStates::User);
- mockSource1->m_capabilities->addFacingMode(MediaStreamSourceStates::Environment);
- mockSource1->m_capabilities->setWidthRange(MediaStreamSourceCapabilityRange(320UL, 1920UL, true));
- mockSource1->m_capabilities->setHeightRange(MediaStreamSourceCapabilityRange(240UL, 1080UL, true));
- mockSource1->m_capabilities->setFrameRateRange(MediaStreamSourceCapabilityRange(15.0f, 60.0f, true));
- mockSource1->m_capabilities->setAspectRatioRange(MediaStreamSourceCapabilityRange(4 / 3.0f, 16 / 9.0f, true));
- mockSource1->m_capabilities->setVolumeRange(MediaStreamSourceCapabilityRange(10UL, 90UL, true));
-
- mockSource1->m_currentStates.setSourceType(MediaStreamSourceStates::Camera);
- mockSource1->m_currentStates.setSourceId(mockSource1->id());
- mockSource1->m_currentStates.setFacingMode(MediaStreamSourceStates::User);
- mockSource1->m_currentStates.setWidth(1920);
- mockSource1->m_currentStates.setHeight(1080);
- mockSource1->m_currentStates.setFrameRate(30);
- mockSource1->m_currentStates.setAspectRatio(16 / 9.0f);
- mockSource1->m_currentStates.setVolume(70);
- String mockSource1id = mockSource1->id();
- mockSourceMap().add(mockSource1id, mockSource1.release());
-
- RefPtr<MockSource> mockSource2 = adoptRef(new MockSource(mockAudioSourceID(), "Mock audio device", MediaStreamSource::Audio));
- mockSource2->m_capabilities = MediaStreamSourceCapabilities::create();
- mockSource2->m_capabilities->setSourceId(mockSource2->id());
- mockSource2->m_capabilities->setVolumeRange(MediaStreamSourceCapabilityRange(0UL, 100UL, true));
-
- mockSource2->m_currentStates.setSourceType(MediaStreamSourceStates::Microphone);
- mockSource2->m_currentStates.setSourceId(mockSource2->id());
- mockSource2->m_currentStates.setVolume(50);
- String mockSource2id = mockSource2->id();
- mockSourceMap().add(mockSource2id, mockSource2.release());
-}
-
-void MockMediaStreamCenter::registerMockMediaStreamCenter()
-{
- DEFINE_STATIC_LOCAL(MockMediaStreamCenter, center, ());
- static bool registered = false;
- if (!registered) {
- registered = true;
- MediaStreamCenter::setSharedStreamCenter(&center);
- initializeMockSources();
- }
-}
-
-void MockMediaStreamCenter::validateRequestConstraints(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints)
-{
- RefPtr<MediaStreamCreationClient> client = prpQueryClient;
-
- ASSERT(client);
-
- if (audioConstraints) {
- String invalidQuery = MediaConstraintsMock::verifyConstraints(audioConstraints);
- if (!invalidQuery.isEmpty()) {
- client->constraintsInvalid(invalidQuery);
- return;
- }
- }
-
- if (videoConstraints) {
- String invalidQuery = MediaConstraintsMock::verifyConstraints(videoConstraints);
- if (!invalidQuery.isEmpty()) {
- client->constraintsInvalid(invalidQuery);
- return;
- }
- }
-
- client->constraintsValidated();
-}
-
-void MockMediaStreamCenter::createMediaStream(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints)
-{
- RefPtr<MediaStreamCreationClient> client = prpQueryClient;
-
- ASSERT(client);
-
- Vector<RefPtr<MediaStreamSource>> audioSources;
- Vector<RefPtr<MediaStreamSource>> videoSources;
- MockSourceMap& map = mockSourceMap();
-
- if (audioConstraints) {
- String invalidQuery = MediaConstraintsMock::verifyConstraints(audioConstraints);
- if (!invalidQuery.isEmpty()) {
- client->failedToCreateStreamWithConstraintsError(invalidQuery);
- return;
- }
-
- MockSourceMap::iterator it = map.find(mockAudioSourceID());
- ASSERT(it != map.end());
-
- RefPtr<MediaStreamSource> audioSource = it->value;
- audioSource->reset();
- audioSource->setReadyState(MediaStreamSource::Live);
- audioSources.append(audioSource.release());
- }
-
- if (videoConstraints) {
- String invalidQuery = MediaConstraintsMock::verifyConstraints(videoConstraints);
- if (!invalidQuery.isEmpty()) {
- client->failedToCreateStreamWithConstraintsError(invalidQuery);
- return;
- }
-
- MockSourceMap::iterator it = map.find(mockVideoSourceID());
- ASSERT(it != map.end());
-
- RefPtr<MediaStreamSource> videoSource = it->value;
- videoSource->reset();
- videoSource->setReadyState(MediaStreamSource::Live);
- videoSources.append(videoSource.release());
- }
-
- client->didCreateStream(MediaStreamPrivate::create(audioSources, videoSources));
-}
-
-bool MockMediaStreamCenter::getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequestClient> prpClient)
-{
- RefPtr<MediaStreamTrackSourcesRequestClient> requestClient = prpClient;
- Vector<RefPtr<TrackSourceInfo>> sources;
-
- MockSourceMap& map = mockSourceMap();
- MockSourceMap::iterator end = map.end();
- for (MockSourceMap::iterator it = map.begin(); it != end; ++it) {
- MockSource* source = it->value.get();
-
- sources.append(TrackSourceInfo::create(source->id(), source->type() == MediaStreamSource::Video ? TrackSourceInfo::Video : TrackSourceInfo::Audio, source->name()));
- }
-
- requestClient->didCompleteRequest(sources);
- return true;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp b/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp
new file mode 100644
index 000000000..53a60ebb8
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. 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 "MockRealtimeAudioSource.h"
+
+#if ENABLE(MEDIA_STREAM)
+#include "Logging.h"
+#include "MediaConstraints.h"
+#include "NotImplemented.h"
+#include "RealtimeMediaSourceSettings.h"
+#include "UUID.h"
+
+namespace WebCore {
+
+#if !PLATFORM(MAC) && !PLATFORM(IOS)
+RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::create(const String& name, const MediaConstraints* constraints)
+{
+ auto source = adoptRef(new MockRealtimeAudioSource(name));
+ if (constraints && source->applyConstraints(*constraints))
+ source = nullptr;
+
+ return source;
+}
+
+RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const String& name)
+{
+ auto source = adoptRef(new MockRealtimeAudioSource(name));
+ source->m_muted = true;
+ return source;
+}
+#endif
+
+MockRealtimeAudioSource::MockRealtimeAudioSource(const String& name)
+ : MockRealtimeMediaSource(createCanonicalUUIDString(), RealtimeMediaSource::Audio, name)
+ , m_timer(RunLoop::current(), this, &MockRealtimeAudioSource::tick)
+{
+}
+
+void MockRealtimeAudioSource::updateSettings(RealtimeMediaSourceSettings& settings)
+{
+ settings.setVolume(volume());
+ settings.setEchoCancellation(echoCancellation());
+ settings.setSampleRate(44100);
+}
+
+void MockRealtimeAudioSource::initializeCapabilities(RealtimeMediaSourceCapabilities& capabilities)
+{
+ capabilities.setVolume(CapabilityValueOrRange(0.0, 1.0));
+ capabilities.setEchoCancellation(RealtimeMediaSourceCapabilities::EchoCancellation::ReadWrite);
+ capabilities.setSampleRate(CapabilityValueOrRange(44100, 44100));
+}
+
+void MockRealtimeAudioSource::initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints& supportedConstraints)
+{
+ supportedConstraints.setSupportsVolume(true);
+ supportedConstraints.setSupportsEchoCancellation(true);
+ supportedConstraints.setSupportsSampleRate(true);
+}
+
+void MockRealtimeAudioSource::startProducingData()
+{
+ MockRealtimeMediaSource::startProducingData();
+
+ m_startTime = monotonicallyIncreasingTime();
+ m_timer.startRepeating(std::chrono::milliseconds(renderInterval()));
+}
+
+void MockRealtimeAudioSource::stopProducingData()
+{
+ MockRealtimeMediaSource::stopProducingData();
+ m_timer.stop();
+ m_elapsedTime += monotonicallyIncreasingTime() - m_startTime;
+ m_startTime = NAN;
+}
+
+double MockRealtimeAudioSource::elapsedTime()
+{
+ if (std::isnan(m_startTime))
+ return m_elapsedTime;
+
+ return m_elapsedTime + (monotonicallyIncreasingTime() - m_startTime);
+}
+
+void MockRealtimeAudioSource::tick()
+{
+ if (std::isnan(m_lastRenderTime))
+ m_lastRenderTime = monotonicallyIncreasingTime();
+
+ double now = monotonicallyIncreasingTime();
+ double delta = now - m_lastRenderTime;
+ m_lastRenderTime = now;
+ render(delta);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockRealtimeAudioSource.h b/Source/WebCore/platform/mock/MockRealtimeAudioSource.h
new file mode 100644
index 000000000..b7e000866
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeAudioSource.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015-2017 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.
+ * 3. Neither the name of Ericsson 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.
+ */
+
+#pragma once
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "FontCascade.h"
+#include "ImageBuffer.h"
+#include "MockRealtimeMediaSource.h"
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+class MockRealtimeAudioSource : public MockRealtimeMediaSource {
+public:
+
+ static RefPtr<MockRealtimeAudioSource> create(const String&, const MediaConstraints*);
+ static RefPtr<MockRealtimeAudioSource> createMuted(const String& name);
+
+ virtual ~MockRealtimeAudioSource() = default;
+
+protected:
+ MockRealtimeAudioSource(const String& name = ASCIILiteral("Mock audio device"));
+
+ void startProducingData() final;
+ void stopProducingData() final;
+
+ virtual void render(double) { }
+
+ double elapsedTime();
+ static int renderInterval() { return 60; }
+
+private:
+
+ bool applyVolume(double) override { return true; }
+ bool applySampleRate(int) override { return true; }
+ bool applySampleSize(int) override { return true; }
+ bool applyEchoCancellation(bool) override { return true; }
+
+ void updateSettings(RealtimeMediaSourceSettings&) override;
+ void initializeCapabilities(RealtimeMediaSourceCapabilities&) override;
+ void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&) override;
+
+ void tick();
+
+ RunLoop::Timer<MockRealtimeAudioSource> m_timer;
+ double m_startTime { NAN };
+ double m_lastRenderTime { NAN };
+ double m_elapsedTime { 0 };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp b/Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp
new file mode 100644
index 000000000..2e03255a9
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. 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 "MockRealtimeMediaSource.h"
+
+#if ENABLE(MEDIA_STREAM)
+#include "CaptureDevice.h"
+#include "Logging.h"
+#include "MediaConstraints.h"
+#include "NotImplemented.h"
+#include "RealtimeMediaSourceSettings.h"
+#include <math.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringView.h>
+
+namespace WebCore {
+
+const AtomicString& MockRealtimeMediaSource::mockAudioSourcePersistentID()
+{
+ static NeverDestroyed<AtomicString> id("239c24b1-2b15-11e3-8224-0800200c9a66", AtomicString::ConstructFromLiteral);
+ return id;
+}
+
+const AtomicString& MockRealtimeMediaSource::mockVideoSourcePersistentID()
+{
+ static NeverDestroyed<AtomicString> id("239c24b0-2b15-11e3-8224-0800200c9a66", AtomicString::ConstructFromLiteral);
+ return id;
+}
+
+const AtomicString& MockRealtimeMediaSource::mockAudioSourceName()
+{
+ static NeverDestroyed<AtomicString> name("Mock audio device", AtomicString::ConstructFromLiteral);
+ return name;
+}
+
+const AtomicString& MockRealtimeMediaSource::mockVideoSourceName()
+{
+ static NeverDestroyed<AtomicString> name("Mock video device", AtomicString::ConstructFromLiteral);
+ return name;
+}
+
+CaptureDevice MockRealtimeMediaSource::audioDeviceInfo()
+{
+ static NeverDestroyed<CaptureDevice> deviceInfo(mockAudioSourcePersistentID(), CaptureDevice::DeviceType::Audio, mockAudioSourceName(), "");
+ return deviceInfo;
+}
+
+CaptureDevice MockRealtimeMediaSource::videoDeviceInfo()
+{
+ static NeverDestroyed<CaptureDevice> deviceInfo(mockVideoSourcePersistentID(), CaptureDevice::DeviceType::Video, mockVideoSourceName(), "");
+ return deviceInfo;
+}
+
+
+MockRealtimeMediaSource::MockRealtimeMediaSource(const String& id, RealtimeMediaSource::Type type, const String& name)
+ : BaseRealtimeMediaSourceClass(id, type, name)
+{
+ if (type == RealtimeMediaSource::Audio)
+ setPersistentID(mockAudioSourcePersistentID());
+ else
+ setPersistentID(mockVideoSourcePersistentID());
+}
+
+void MockRealtimeMediaSource::initializeCapabilities()
+{
+ m_capabilities = RealtimeMediaSourceCapabilities::create(supportedConstraints());
+ m_capabilities->setDeviceId(id());
+ initializeCapabilities(*m_capabilities.get());
+}
+
+RefPtr<RealtimeMediaSourceCapabilities> MockRealtimeMediaSource::capabilities() const
+{
+ if (!m_capabilities)
+ const_cast<MockRealtimeMediaSource&>(*this).initializeCapabilities();
+ return m_capabilities;
+}
+
+void MockRealtimeMediaSource::initializeSettings()
+{
+ if (m_currentSettings.deviceId().isEmpty()) {
+ m_currentSettings.setSupportedConstraits(supportedConstraints());
+ m_currentSettings.setDeviceId(id());
+ }
+
+ updateSettings(m_currentSettings);
+}
+
+const RealtimeMediaSourceSettings& MockRealtimeMediaSource::settings() const
+{
+ const_cast<MockRealtimeMediaSource&>(*this).initializeSettings();
+ return m_currentSettings;
+}
+
+RealtimeMediaSourceSupportedConstraints& MockRealtimeMediaSource::supportedConstraints()
+{
+ if (m_supportedConstraints.supportsDeviceId())
+ return m_supportedConstraints;
+
+ m_supportedConstraints.setSupportsDeviceId(true);
+ initializeSupportedConstraints(m_supportedConstraints);
+
+ return m_supportedConstraints;
+}
+
+void MockRealtimeMediaSource::startProducingData()
+{
+ m_isProducingData = true;
+ setMuted(false);
+}
+
+void MockRealtimeMediaSource::stopProducingData()
+{
+ m_isProducingData = false;
+ setMuted(true);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockRealtimeMediaSource.h b/Source/WebCore/platform/mock/MockRealtimeMediaSource.h
new file mode 100644
index 000000000..ddfda1e4e
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeMediaSource.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. Neither the name of Ericsson 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 MockRealtimeMediaSource_h
+#define MockRealtimeMediaSource_h
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "RealtimeMediaSource.h"
+
+#if USE(OPENWEBRTC)
+#include "RealtimeMediaSourceOwr.h"
+#endif
+
+namespace WebCore {
+
+class CaptureDevice;
+
+#if USE(OPENWEBRTC)
+using BaseRealtimeMediaSourceClass = RealtimeMediaSourceOwr;
+#else
+using BaseRealtimeMediaSourceClass = RealtimeMediaSource;
+#endif
+
+class MockRealtimeMediaSource : public BaseRealtimeMediaSourceClass {
+public:
+ virtual ~MockRealtimeMediaSource() { }
+
+ static const AtomicString& mockAudioSourcePersistentID();
+ static const AtomicString& mockAudioSourceName();
+
+ static const AtomicString& mockVideoSourcePersistentID();
+ static const AtomicString& mockVideoSourceName();
+
+ static CaptureDevice audioDeviceInfo();
+ static CaptureDevice videoDeviceInfo();
+
+protected:
+ MockRealtimeMediaSource(const String& id, Type, const String& name);
+
+ virtual void updateSettings(RealtimeMediaSourceSettings&) = 0;
+ virtual void initializeCapabilities(RealtimeMediaSourceCapabilities&) = 0;
+ virtual void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&) = 0;
+
+ void startProducingData() override;
+ void stopProducingData() override;
+
+ RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
+ const RealtimeMediaSourceSettings& settings() const override;
+
+ MediaConstraints& constraints() { return *m_constraints.get(); }
+ RealtimeMediaSourceSupportedConstraints& supportedConstraints();
+
+private:
+ void initializeCapabilities();
+ void initializeSettings();
+ bool isProducingData() const override { return m_isProducingData; }
+
+ RealtimeMediaSourceSettings m_currentSettings;
+ RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
+ RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+ RefPtr<MediaConstraints> m_constraints;
+ bool m_isProducingData { false };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
+
+#endif // MockRealtimeMediaSource_h
diff --git a/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
new file mode 100644
index 000000000..bda24d5ea
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * 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 "MockRealtimeMediaSourceCenter.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "CaptureDevice.h"
+#include "Logging.h"
+#include "MediaStream.h"
+#include "MediaStreamPrivate.h"
+#include "MediaStreamTrack.h"
+#include "MockRealtimeAudioSource.h"
+#include "MockRealtimeMediaSource.h"
+#include "MockRealtimeVideoSource.h"
+#include "RealtimeMediaSource.h"
+#include "RealtimeMediaSourceCapabilities.h"
+#include "UUID.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+void MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(bool enabled)
+{
+ static NeverDestroyed<MockRealtimeMediaSourceCenter> center;
+ static bool active = false;
+ if (active != enabled) {
+ active = enabled;
+ RealtimeMediaSourceCenter::setSharedStreamCenterOverride(enabled ? &center.get() : nullptr);
+ }
+}
+
+MockRealtimeMediaSourceCenter::MockRealtimeMediaSourceCenter()
+{
+ m_supportedConstraints.setSupportsWidth(true);
+ m_supportedConstraints.setSupportsHeight(true);
+ m_supportedConstraints.setSupportsAspectRatio(true);
+ m_supportedConstraints.setSupportsFrameRate(true);
+ m_supportedConstraints.setSupportsFacingMode(true);
+ m_supportedConstraints.setSupportsVolume(true);
+ m_supportedConstraints.setSupportsDeviceId(true);
+}
+
+void MockRealtimeMediaSourceCenter::validateRequestConstraints(ValidConstraintsHandler validHandler, InvalidConstraintsHandler invalidHandler, const MediaConstraints& audioConstraints, const MediaConstraints& videoConstraints)
+{
+ Vector<String> audioSourceIds;
+ Vector<String> videoSourceIds;
+ String invalidConstraint;
+
+ if (audioConstraints.isValid()) {
+ auto audioSource = MockRealtimeAudioSource::create(MockRealtimeMediaSource::mockAudioSourceName(), nullptr);
+ if (!audioSource->supportsConstraints(audioConstraints, invalidConstraint)) {
+ if (invalidHandler)
+ invalidHandler(invalidConstraint);
+ return;
+ }
+
+ audioSourceIds.append(MockRealtimeMediaSource::mockAudioSourcePersistentID());
+ }
+
+ if (videoConstraints.isValid()) {
+ auto videoSource = MockRealtimeVideoSource::create(MockRealtimeMediaSource::mockVideoSourceName(), nullptr);
+ if (!videoSource->supportsConstraints(videoConstraints, invalidConstraint)) {
+ if (invalidHandler)
+ invalidHandler(invalidConstraint);
+ return;
+ }
+
+
+ videoSourceIds.append(MockRealtimeMediaSource::mockVideoSourcePersistentID());
+ }
+
+ validHandler(WTFMove(audioSourceIds), WTFMove(videoSourceIds));
+}
+
+void MockRealtimeMediaSourceCenter::createMediaStream(NewMediaStreamHandler completionHandler, const String& audioDeviceID, const String& videoDeviceID, const MediaConstraints* audioConstraints, const MediaConstraints* videoConstraints)
+{
+ Vector<Ref<RealtimeMediaSource>> audioSources;
+ Vector<Ref<RealtimeMediaSource>> videoSources;
+
+ if (audioDeviceID == MockRealtimeMediaSource::mockAudioSourcePersistentID()) {
+ auto source = MockRealtimeAudioSource::create(MockRealtimeMediaSource::mockAudioSourceName(), audioConstraints);
+ if (source)
+ audioSources.append(source.releaseNonNull());
+ }
+
+ if (videoDeviceID == MockRealtimeMediaSource::mockVideoSourcePersistentID()) {
+ auto source = MockRealtimeVideoSource::create(MockRealtimeMediaSource::mockVideoSourceName(), videoConstraints);
+ if (source)
+ videoSources.append(source.releaseNonNull());
+ }
+
+ if (videoSources.isEmpty() && audioSources.isEmpty())
+ completionHandler(nullptr);
+ else
+ completionHandler(MediaStreamPrivate::create(audioSources, videoSources));
+}
+
+Vector<CaptureDevice> MockRealtimeMediaSourceCenter::getMediaStreamDevices()
+{
+ Vector<CaptureDevice> sources;
+
+ sources.append(MockRealtimeMediaSource::audioDeviceInfo());
+ sources.append(MockRealtimeMediaSource::videoDeviceInfo());
+
+ return sources;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockMediaStreamCenter.h b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h
index 741695d78..b5f76452a 100644
--- a/Source/WebCore/platform/mock/MockMediaStreamCenter.h
+++ b/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
- * Copyright (C) 2013 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -11,10 +11,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -24,29 +24,30 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef MockMediaStreamCenter_h
-#define MockMediaStreamCenter_h
+#ifndef MockRealtimeMediaSourceCenter_h
+#define MockRealtimeMediaSourceCenter_h
#if ENABLE(MEDIA_STREAM)
-#include "MediaStreamCenter.h"
+#include "RealtimeMediaSourceCenter.h"
namespace WebCore {
-class MockMediaStreamCenter final : public MediaStreamCenter {
+class MockRealtimeMediaSourceCenter final : public RealtimeMediaSourceCenter {
public:
- static void registerMockMediaStreamCenter();
-
- virtual void validateRequestConstraints(PassRefPtr<MediaStreamCreationClient>, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints);
- virtual void createMediaStream(PassRefPtr<MediaStreamCreationClient>, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints);
- virtual bool getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequestClient>) override;
+ WEBCORE_EXPORT static void setMockRealtimeMediaSourceCenterEnabled(bool);
private:
- MockMediaStreamCenter() { }
+ friend NeverDestroyed<MockRealtimeMediaSourceCenter>;
+ MockRealtimeMediaSourceCenter();
+
+ void validateRequestConstraints(ValidConstraintsHandler validHandler, InvalidConstraintsHandler invalidHandler, const MediaConstraints& audioConstraints, const MediaConstraints& videoConstraints) final;
+ Vector<CaptureDevice> getMediaStreamDevices() final;
+ void createMediaStream(NewMediaStreamHandler, const String& audioDeviceID, const String& videoDeviceID, const MediaConstraints* audioConstraints, const MediaConstraints* videoConstraints) final;
};
}
-#endif // MockMediaStreamCenter_h
+#endif // MockRealtimeMediaSourceCenter_h
#endif
diff --git a/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp b/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
new file mode 100644
index 000000000..da39e4ef9
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
@@ -0,0 +1,382 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. 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 "MockRealtimeVideoSource.h"
+
+#if ENABLE(MEDIA_STREAM)
+#include "GraphicsContext.h"
+#include "ImageBuffer.h"
+#include "IntRect.h"
+#include "Logging.h"
+#include "MediaConstraints.h"
+#include "NotImplemented.h"
+#include "PlatformLayer.h"
+#include "RealtimeMediaSourceSettings.h"
+#include "UUID.h"
+#include <math.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/text/StringView.h>
+
+namespace WebCore {
+
+#if !PLATFORM(MAC) && !PLATFORM(IOS)
+RefPtr<MockRealtimeVideoSource> MockRealtimeVideoSource::create(const String& name, const MediaConstraints* constraints)
+{
+ auto source = adoptRef(new MockRealtimeVideoSource(name));
+ if (constraints && source->applyConstraints(*constraints))
+ source = nullptr;
+
+ return source;
+}
+
+RefPtr<MockRealtimeVideoSource> MockRealtimeVideoSource::createMuted(const String& name)
+{
+ auto source = adoptRef(new MockRealtimeVideoSource(name));
+ source->m_muted = true;
+ return source;
+}
+#endif
+
+MockRealtimeVideoSource::MockRealtimeVideoSource(const String& name)
+ : MockRealtimeMediaSource(createCanonicalUUIDString(), RealtimeMediaSource::Video, name)
+ , m_timer(RunLoop::current(), this, &MockRealtimeVideoSource::generateFrame)
+{
+ setFrameRate(30);
+ m_dashWidths.reserveInitialCapacity(2);
+ m_dashWidths.uncheckedAppend(6);
+ m_dashWidths.uncheckedAppend(6);
+}
+
+void MockRealtimeVideoSource::startProducingData()
+{
+ MockRealtimeMediaSource::startProducingData();
+ if (size().isEmpty()) {
+ setWidth(640);
+ setHeight(480);
+ }
+
+ m_startTime = monotonicallyIncreasingTime();
+ m_timer.startRepeating(std::chrono::milliseconds(lround(1000 / frameRate())));
+}
+
+void MockRealtimeVideoSource::stopProducingData()
+{
+ MockRealtimeMediaSource::stopProducingData();
+ m_timer.stop();
+ m_elapsedTime += monotonicallyIncreasingTime() - m_startTime;
+ m_startTime = NAN;
+}
+
+double MockRealtimeVideoSource::elapsedTime()
+{
+ if (std::isnan(m_startTime))
+ return m_elapsedTime;
+
+ return m_elapsedTime + (monotonicallyIncreasingTime() - m_startTime);
+}
+
+void MockRealtimeVideoSource::updateSettings(RealtimeMediaSourceSettings& settings)
+{
+ settings.setFacingMode(facingMode());
+ settings.setFrameRate(frameRate());
+ IntSize size = this->size();
+ settings.setWidth(size.width());
+ settings.setHeight(size.height());
+ if (aspectRatio())
+ settings.setAspectRatio(aspectRatio());
+}
+
+void MockRealtimeVideoSource::initializeCapabilities(RealtimeMediaSourceCapabilities& capabilities)
+{
+ capabilities.addFacingMode(RealtimeMediaSourceSettings::User);
+ capabilities.addFacingMode(RealtimeMediaSourceSettings::Environment);
+ capabilities.setWidth(CapabilityValueOrRange(320, 1920));
+ capabilities.setHeight(CapabilityValueOrRange(240, 1080));
+ capabilities.setFrameRate(CapabilityValueOrRange(15.0, 60.0));
+ capabilities.setAspectRatio(CapabilityValueOrRange(4 / 3.0, 16 / 9.0));
+}
+
+void MockRealtimeVideoSource::initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints& supportedConstraints)
+{
+ supportedConstraints.setSupportsWidth(true);
+ supportedConstraints.setSupportsHeight(true);
+ supportedConstraints.setSupportsAspectRatio(true);
+ supportedConstraints.setSupportsFrameRate(true);
+ supportedConstraints.setSupportsFacingMode(true);
+}
+
+bool MockRealtimeVideoSource::applyFrameRate(double rate)
+{
+ if (m_timer.isActive())
+ m_timer.startRepeating(std::chrono::milliseconds(lround(1000 / rate)));
+
+ updateSampleBuffer();
+ return true;
+}
+
+bool MockRealtimeVideoSource::applySize(const IntSize& size)
+{
+ m_baseFontSize = size.height() * .08;
+ FontCascadeDescription fontDescription;
+ fontDescription.setOneFamily("Courier");
+ fontDescription.setSpecifiedSize(m_baseFontSize);
+ fontDescription.setComputedSize(m_baseFontSize);
+ fontDescription.setWeight(FontWeight500);
+
+ m_timeFont = FontCascade(fontDescription, 0, 0);
+ m_timeFont.update(nullptr);
+
+ m_bipBopFontSize = m_baseFontSize * 2.5;
+ fontDescription.setSpecifiedSize(m_bipBopFontSize);
+ fontDescription.setComputedSize(m_bipBopFontSize);
+ m_bipBopFont = FontCascade(fontDescription, 0, 0);
+ m_bipBopFont.update(nullptr);
+
+ m_statsFontSize = m_baseFontSize * .5;
+ fontDescription.setSpecifiedSize(m_statsFontSize);
+ fontDescription.setComputedSize(m_statsFontSize);
+ m_statsFont = FontCascade(fontDescription, 0, 0);
+ m_statsFont.update(nullptr);
+
+ m_imageBuffer = nullptr;
+
+ return true;
+}
+
+void MockRealtimeVideoSource::drawAnimation(GraphicsContext& context)
+{
+ float radius = size().width() * .09;
+ FloatPoint location(size().width() * .8, size().height() * .3);
+
+ m_path.clear();
+ m_path.moveTo(location);
+ m_path.addArc(location, radius, 0, 2 * piFloat, false);
+ m_path.closeSubpath();
+ context.setFillColor(Color::white);
+ context.setFillRule(RULE_NONZERO);
+ context.fillPath(m_path);
+
+ float endAngle = piFloat * (((fmod(m_frameNumber, frameRate()) + 0.5) * (2.0 / frameRate())) + 1);
+ m_path.clear();
+ m_path.moveTo(location);
+ m_path.addArc(location, radius, 1.5 * piFloat, endAngle, false);
+ m_path.closeSubpath();
+ context.setFillColor(Color::gray);
+ context.setFillRule(RULE_NONZERO);
+ context.fillPath(m_path);
+}
+
+void MockRealtimeVideoSource::drawBoxes(GraphicsContext& context)
+{
+ static const RGBA32 magenta = 0xffff00ff;
+ static const RGBA32 yellow = 0xffffff00;
+ static const RGBA32 blue = 0xff0000ff;
+ static const RGBA32 red = 0xffff0000;
+ static const RGBA32 green = 0xff008000;
+ static const RGBA32 cyan = 0xFF00FFFF;
+
+ IntSize size = this->size();
+ float boxSize = size.width() * .035;
+ float boxTop = size.height() * .6;
+
+ m_path.clear();
+ FloatRect frameRect(2, 2, size.width() - 3, size.height() - 3);
+ context.setStrokeColor(Color::white);
+ context.setStrokeThickness(3);
+ context.setLineDash(m_dashWidths, 0);
+ m_path.addRect(frameRect);
+ m_path.closeSubpath();
+ context.strokePath(m_path);
+
+ context.setLineDash(DashArray(), 0);
+ m_path.clear();
+ m_path.moveTo(FloatPoint(0, boxTop + boxSize));
+ m_path.addLineTo(FloatPoint(size.width(), boxTop + boxSize));
+ m_path.closeSubpath();
+ context.setStrokeColor(Color::white);
+ context.setStrokeThickness(2);
+ context.strokePath(m_path);
+
+ context.setStrokeThickness(1);
+ float boxLeft = boxSize;
+ m_path.clear();
+ for (unsigned i = 0; i < boxSize / 4; i++) {
+ m_path.moveTo(FloatPoint(boxLeft + 4 * i, boxTop));
+ m_path.addLineTo(FloatPoint(boxLeft + 4 * i, boxTop + boxSize));
+ }
+ boxLeft += boxSize + 2;
+ for (unsigned i = 0; i < boxSize / 4; i++) {
+ m_path.moveTo(FloatPoint(boxLeft, boxTop + 4 * i));
+ m_path.addLineTo(FloatPoint(boxLeft + boxSize - 1, boxTop + 4 * i));
+ }
+ context.setStrokeThickness(3);
+ boxLeft += boxSize + 2;
+ for (unsigned i = 0; i < boxSize / 8; i++) {
+ m_path.moveTo(FloatPoint(boxLeft + 8 * i, boxTop));
+ m_path.addLineTo(FloatPoint(boxLeft + 8 * i, boxTop + boxSize - 1));
+ }
+ boxLeft += boxSize + 2;
+ for (unsigned i = 0; i < boxSize / 8; i++) {
+ m_path.moveTo(FloatPoint(boxLeft, boxTop + 8 * i));
+ m_path.addLineTo(FloatPoint(boxLeft + boxSize - 1, boxTop + 8 * i));
+ }
+
+ boxTop += boxSize + 2;
+ boxLeft = boxSize;
+ Color boxColors[] = { Color::white, yellow, cyan, green, magenta, red, blue };
+ for (unsigned i = 0; i < sizeof(boxColors) / sizeof(boxColors[0]); i++) {
+ context.fillRect(FloatRect(boxLeft, boxTop, boxSize + 1, boxSize + 1), boxColors[i]);
+ boxLeft += boxSize + 1;
+ }
+ context.strokePath(m_path);
+}
+
+void MockRealtimeVideoSource::drawText(GraphicsContext& context)
+{
+ unsigned milliseconds = lround(elapsedTime() * 1000);
+ unsigned seconds = milliseconds / 1000 % 60;
+ unsigned minutes = seconds / 60 % 60;
+ unsigned hours = minutes / 60 % 60;
+
+ IntSize size = this->size();
+ FloatPoint timeLocation(size.width() * .05, size.height() * .15);
+ context.setFillColor(Color::white);
+ context.setTextDrawingMode(TextModeFill);
+ String string = String::format("%02u:%02u:%02u.%03u", hours, minutes, seconds, milliseconds % 1000);
+ context.drawText(m_timeFont, TextRun((StringView(string))), timeLocation);
+
+ string = String::format("%06u", m_frameNumber++);
+ timeLocation.move(0, m_baseFontSize);
+ context.drawText(m_timeFont, TextRun((StringView(string))), timeLocation);
+
+ FloatPoint statsLocation(size.width() * .65, size.height() * .75);
+ string = String::format("Frame rate: %ffps", frameRate());
+ context.drawText(m_statsFont, TextRun((StringView(string))), statsLocation);
+
+ string = String::format("Size: %u x %u", size.width(), size.height());
+ statsLocation.move(0, m_statsFontSize);
+ context.drawText(m_statsFont, TextRun((StringView(string))), statsLocation);
+
+ const char* camera;
+ switch (facingMode()) {
+ case RealtimeMediaSourceSettings::User:
+ camera = "User facing";
+ break;
+ case RealtimeMediaSourceSettings::Environment:
+ camera = "Environment facing";
+ break;
+ case RealtimeMediaSourceSettings::Left:
+ camera = "Left facing";
+ break;
+ case RealtimeMediaSourceSettings::Right:
+ camera = "Right facing";
+ break;
+ case RealtimeMediaSourceSettings::Unknown:
+ camera = "Unknown";
+ break;
+ }
+ string = String::format("Camera: %s", camera);
+ statsLocation.move(0, m_statsFontSize);
+ context.drawText(m_statsFont, TextRun((StringView(string))), statsLocation);
+
+ FloatPoint bipBopLocation(size.width() * .6, size.height() * .6);
+ unsigned frameMod = m_frameNumber % 60;
+ if (frameMod <= 15) {
+ context.setFillColor(Color::gray);
+ String bip(ASCIILiteral("Bip"));
+ context.drawText(m_bipBopFont, TextRun(StringView(bip)), bipBopLocation);
+ } else if (frameMod > 30 && frameMod <= 45) {
+ context.setFillColor(Color::white);
+ String bop(ASCIILiteral("Bop"));
+ context.drawText(m_bipBopFont, TextRun(StringView(bop)), bipBopLocation);
+ }
+}
+
+void MockRealtimeVideoSource::generateFrame()
+{
+ ImageBuffer* buffer = imageBuffer();
+ if (!buffer)
+ return;
+
+ GraphicsContext& context = buffer->context();
+ GraphicsContextStateSaver stateSaver(context);
+
+ IntSize size = this->size();
+ FloatRect frameRect(FloatPoint(), size);
+ context.fillRect(FloatRect(FloatPoint(), size), Color::black);
+
+ if (!m_muted && m_enabled) {
+ drawText(context);
+ drawAnimation(context);
+ drawBoxes(context);
+ }
+
+ updateSampleBuffer();
+}
+
+ImageBuffer* MockRealtimeVideoSource::imageBuffer() const
+{
+ if (m_imageBuffer)
+ return m_imageBuffer.get();
+
+ m_imageBuffer = ImageBuffer::create(size(), Unaccelerated);
+ if (!m_imageBuffer)
+ return nullptr;
+
+ m_imageBuffer->context().setImageInterpolationQuality(InterpolationDefault);
+ m_imageBuffer->context().setStrokeThickness(1);
+
+ return m_imageBuffer.get();
+}
+
+void MockRealtimeVideoSource::paintCurrentFrameInContext(GraphicsContext& context, const FloatRect& rect)
+{
+ if (context.paintingDisabled() || !imageBuffer())
+ return;
+
+ GraphicsContextStateSaver stateSaver(context);
+ context.setImageInterpolationQuality(InterpolationLow);
+ IntRect paintRect(IntPoint(0, 0), IntSize(rect.width(), rect.height()));
+
+ context.drawImage(*m_imageBuffer->copyImage(DontCopyBackingStore), rect);
+}
+
+RefPtr<Image> MockRealtimeVideoSource::currentFrameImage()
+{
+ if (!imageBuffer())
+ return nullptr;
+
+ return m_imageBuffer->copyImage(DontCopyBackingStore);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/MockRealtimeVideoSource.h b/Source/WebCore/platform/mock/MockRealtimeVideoSource.h
new file mode 100644
index 000000000..78d8f8f26
--- /dev/null
+++ b/Source/WebCore/platform/mock/MockRealtimeVideoSource.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. Neither the name of Ericsson 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 MockRealtimeVideoSource_h
+#define MockRealtimeVideoSource_h
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "FontCascade.h"
+#include "ImageBuffer.h"
+#include "MockRealtimeMediaSource.h"
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+class FloatRect;
+class GraphicsContext;
+
+class MockRealtimeVideoSource : public MockRealtimeMediaSource {
+public:
+
+ static RefPtr<MockRealtimeVideoSource> create(const String&, const MediaConstraints*);
+ static RefPtr<MockRealtimeVideoSource> createMuted(const String& name);
+
+ virtual ~MockRealtimeVideoSource() { }
+
+protected:
+ MockRealtimeVideoSource(const String&);
+ virtual void updateSampleBuffer() { }
+
+ ImageBuffer* imageBuffer() const;
+
+ double elapsedTime();
+
+private:
+ void updateSettings(RealtimeMediaSourceSettings&) override;
+ void initializeCapabilities(RealtimeMediaSourceCapabilities&) override;
+ void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&) override;
+
+ void startProducingData() final;
+ void stopProducingData() final;
+
+ void drawAnimation(GraphicsContext&);
+ void drawText(GraphicsContext&);
+ void drawBoxes(GraphicsContext&);
+
+ bool applySize(const IntSize&) override;
+ bool applyFrameRate(double) override;
+ bool applyFacingMode(RealtimeMediaSourceSettings::VideoFacingMode) override { return true; }
+ bool applyAspectRatio(double) override { return true; }
+
+ RefPtr<Image> currentFrameImage() override;
+ void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&) override;
+
+ void generateFrame();
+
+ float m_baseFontSize { 0 };
+ FontCascade m_timeFont;
+
+ float m_bipBopFontSize { 0 };
+ FontCascade m_bipBopFont;
+
+ float m_statsFontSize { 0 };
+ FontCascade m_statsFont;
+
+ mutable std::unique_ptr<ImageBuffer> m_imageBuffer;
+
+ Path m_path;
+ DashArray m_dashWidths;
+
+ double m_startTime { NAN };
+ double m_elapsedTime { 0 };
+
+ unsigned m_frameNumber { 0 };
+
+ RunLoop::Timer<MockRealtimeVideoSource> m_timer;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
+
+#endif // MockRealtimeVideoSource_h
diff --git a/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp
new file mode 100644
index 000000000..f3bc71c0f
--- /dev/null
+++ b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2013 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 "PlatformSpeechSynthesizerMock.h"
+#include "PlatformSpeechSynthesisUtterance.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+namespace WebCore {
+
+PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client)
+ : PlatformSpeechSynthesizer(client)
+ , m_speakingFinishedTimer(*this, &PlatformSpeechSynthesizerMock::speakingFinished)
+{
+}
+
+PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
+{
+}
+
+void PlatformSpeechSynthesizerMock::speakingFinished()
+{
+ ASSERT(m_utterance.get());
+ RefPtr<PlatformSpeechSynthesisUtterance> protect(m_utterance);
+ m_utterance = nullptr;
+
+ client()->didFinishSpeaking(*protect);
+}
+
+void PlatformSpeechSynthesizerMock::initializeVoiceList()
+{
+ 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(RefPtr<PlatformSpeechSynthesisUtterance>&& utterance)
+{
+ ASSERT(!m_utterance);
+ m_utterance = WTFMove(utterance);
+ client()->didStartSpeaking(*m_utterance);
+
+ // Fire a fake word and then sentence boundary event.
+ client()->boundaryEventOccurred(*m_utterance, SpeechWordBoundary, 0);
+ client()->boundaryEventOccurred(*m_utterance, SpeechSentenceBoundary, m_utterance->text().length());
+
+ // Give the fake speech job some time so that pause and other functions have time to be called.
+ m_speakingFinishedTimer.startOneShot(.1);
+}
+
+void PlatformSpeechSynthesizerMock::cancel()
+{
+ if (!m_utterance)
+ return;
+
+ m_speakingFinishedTimer.stop();
+ client()->speakingErrorOccurred(*m_utterance);
+ m_utterance = nullptr;
+}
+
+void PlatformSpeechSynthesizerMock::pause()
+{
+ client()->didPauseSpeaking(*m_utterance);
+}
+
+void PlatformSpeechSynthesizerMock::resume()
+{
+ client()->didResumeSpeaking(*m_utterance);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/platform/mock/mediasource/MockTracks.cpp b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h
index 8f8840d84..9921fbd4a 100644
--- a/Source/WebCore/platform/mock/mediasource/MockTracks.cpp
+++ b/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,18 +10,49 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config.h"
-#include "MockTracks.h"
+#ifndef PlatformSpeechSynthesizerMock_h
+#define PlatformSpeechSynthesizerMock_h
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "PlatformSpeechSynthesizer.h"
+#include "Timer.h"
+
+namespace WebCore {
+
+class PlatformSpeechSynthesizerMock : public PlatformSpeechSynthesizer {
+public:
+ explicit PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient*);
+
+ virtual ~PlatformSpeechSynthesizerMock();
+ virtual void speak(RefPtr<PlatformSpeechSynthesisUtterance>&&);
+ virtual void pause();
+ virtual void resume();
+ virtual void cancel();
+
+private:
+ virtual void initializeVoiceList();
+ void speakingFinished();
+
+ Timer m_speakingFinishedTimer;
+ RefPtr<PlatformSpeechSynthesisUtterance> m_utterance;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
+
+#endif // PlatformSpeechSynthesizer_h
diff --git a/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp b/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp
index d1c522527..8985e5c9f 100644
--- a/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp
+++ b/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp
@@ -25,7 +25,7 @@
#include "config.h"
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_RTC)
#include "RTCDataChannelHandlerMock.h"
@@ -37,11 +37,6 @@ namespace WebCore {
RTCDataChannelHandlerMock::RTCDataChannelHandlerMock(const String& label, const RTCDataChannelInit& init)
: m_label(label)
, m_protocol(init.protocol)
- , m_maxRetransmitTime(init.maxRetransmitTime)
- , m_maxRetransmits(init.maxRetransmits)
- , m_id(init.id)
- , m_ordered(init.ordered)
- , m_negotiated(init.negotiated)
{
}
@@ -75,4 +70,4 @@ void RTCDataChannelHandlerMock::close()
} // namespace WebCore
-#endif // ENABLE(MEDIA_STREAM)
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.h b/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.h
index 0f02ff2ed..9303487e6 100644
--- a/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.h
+++ b/Source/WebCore/platform/mock/RTCDataChannelHandlerMock.h
@@ -23,13 +23,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef RTCDataChannelHandlerMock_h
-#define RTCDataChannelHandlerMock_h
+#pragma once
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_RTC)
#include "RTCDataChannelHandler.h"
-#include "RTCPeerConnectionHandler.h"
#include "TimerEventBasedMock.h"
namespace WebCore {
@@ -37,37 +35,21 @@ namespace WebCore {
class RTCDataChannelHandlerMock final : public RTCDataChannelHandler, public TimerEventBasedMock {
public:
RTCDataChannelHandlerMock(const String&, const RTCDataChannelInit&);
- virtual ~RTCDataChannelHandlerMock() { }
- virtual void setClient(RTCDataChannelHandlerClient*) override;
-
- virtual String label() override { return m_label; }
- virtual bool ordered() override { return m_ordered; }
- virtual unsigned short maxRetransmitTime() override { return m_maxRetransmitTime; }
- virtual unsigned short maxRetransmits() override { return m_maxRetransmits; }
- virtual String protocol() override { return m_protocol; }
- virtual bool negotiated() override { return m_negotiated; }
- virtual unsigned short id() override { return m_id; }
- virtual unsigned long bufferedAmount() override { return 0; }
+private:
+ void setClient(RTCDataChannelHandlerClient*) final;
- virtual bool sendStringData(const String&) override;
- virtual bool sendRawData(const char*, size_t) override;
- virtual void close() override;
+ bool sendStringData(const String&) final;
+ bool sendRawData(const char*, size_t) final;
+ void close() final;
+ size_t bufferedAmount() const final { return 0; }
-private:
RTCDataChannelHandlerClient* m_client;
String m_label;
String m_protocol;
- unsigned short m_maxRetransmitTime;
- unsigned short m_maxRetransmits;
- unsigned short m_id;
- bool m_ordered;
- bool m_negotiated;
};
} // namespace WebCore
-#endif // ENABLE(MEDIA_STREAM)
-
-#endif // RTCDataChannelHandlerMock_h
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/platform/mock/RTCNotifiersMock.cpp b/Source/WebCore/platform/mock/RTCNotifiersMock.cpp
index 09a215676..d667d174b 100644
--- a/Source/WebCore/platform/mock/RTCNotifiersMock.cpp
+++ b/Source/WebCore/platform/mock/RTCNotifiersMock.cpp
@@ -25,7 +25,7 @@
#include "config.h"
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_RTC)
#include "RTCNotifiersMock.h"
@@ -114,4 +114,4 @@ void DataChannelStateNotifier::fire()
} // namespace WebCore
-#endif // ENABLE(MEDIA_STREAM)
+#endif // ENABLE(WEB_RTC)
diff --git a/Source/WebCore/platform/mock/RTCNotifiersMock.h b/Source/WebCore/platform/mock/RTCNotifiersMock.h
index 014dfb58d..f3351d99e 100644
--- a/Source/WebCore/platform/mock/RTCNotifiersMock.h
+++ b/Source/WebCore/platform/mock/RTCNotifiersMock.h
@@ -26,7 +26,7 @@
#ifndef RTCNotifiersMock_h
#define RTCNotifiersMock_h
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_RTC)
#include "RTCDataChannelHandlerClient.h"
#include "RTCPeerConnectionHandlerClient.h"
@@ -111,6 +111,6 @@ private:
} // namespace WebCore
-#endif // ENABLE(MEDIA_STREAM)
+#endif // ENABLE(WEB_RTC)
#endif // RTCNotifiersMock_h
diff --git a/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp b/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp
deleted file mode 100644
index cae318625..000000000
--- a/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
- *
- * 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 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"
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "RTCPeerConnectionHandlerMock.h"
-
-#include "MediaConstraintsMock.h"
-#include "NotImplemented.h"
-#include "RTCDTMFSenderHandler.h"
-#include "RTCDataChannelHandler.h"
-#include "RTCDataChannelHandlerMock.h"
-#include "RTCNotifiersMock.h"
-#include "RTCSessionDescriptionRequest.h"
-#include "RTCVoidRequest.h"
-#include <wtf/text/CString.h>
-
-namespace WebCore {
-
-std::unique_ptr<RTCPeerConnectionHandler> RTCPeerConnectionHandlerMock::create(RTCPeerConnectionHandlerClient* client)
-{
- return std::make_unique<RTCPeerConnectionHandlerMock>(client);
-}
-
-RTCPeerConnectionHandlerMock::RTCPeerConnectionHandlerMock(RTCPeerConnectionHandlerClient* client)
- : m_client(client)
-{
-}
-
-bool RTCPeerConnectionHandlerMock::initialize(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints> constraints)
-{
- String invalidQuery = MediaConstraintsMock::verifyConstraints(constraints);
- if (!invalidQuery.isEmpty())
- return false;
-
- RefPtr<IceConnectionNotifier> notifier = adoptRef(new IceConnectionNotifier(m_client, RTCPeerConnectionHandlerClient::IceConnectionStateCompleted, RTCPeerConnectionHandlerClient::IceGatheringStateComplete));
- m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
- return true;
-}
-
-void RTCPeerConnectionHandlerMock::createOffer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints)
-{
- String succeedValue;
- RefPtr<SessionRequestNotifier> notifier;
- if (constraints->getMandatoryConstraintValue("succeed", succeedValue) && succeedValue == "false")
- notifier = adoptRef(new SessionRequestNotifier(request, 0, RTCPeerConnectionHandler::incompatibleConstraintsErrorName()));
- else
- notifier = adoptRef(new SessionRequestNotifier(request, RTCSessionDescriptionDescriptor::create("offer", "local")));
-
- m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
-}
-
-void RTCPeerConnectionHandlerMock::createAnswer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints)
-{
- RefPtr<SessionRequestNotifier> notifier;
- // We can only create an answer if we have already had an offer and the remote session description is stored.
- String succeedValue;
- if (constraints->getMandatoryConstraintValue("succeed", succeedValue) && succeedValue == "false")
- notifier = adoptRef(new SessionRequestNotifier(request, 0, RTCPeerConnectionHandler::incompatibleConstraintsErrorName()));
- else
- notifier = adoptRef(new SessionRequestNotifier(request, RTCSessionDescriptionDescriptor::create("answer", "local")));
-
- m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
-}
-
-RTCPeerConnectionHandlerClient::SignalingState RTCPeerConnectionHandlerMock::signalingStateFromSDP(RTCSessionDescriptionDescriptor* descriptor)
-{
- if (descriptor->type() == "offer" && descriptor->sdp() == "local")
- return RTCPeerConnectionHandlerClient::SignalingStateHaveLocalOffer;
- if (descriptor->type() == "offer" && descriptor->sdp() == "remote")
- return RTCPeerConnectionHandlerClient::SignalingStateHaveRemoteOffer;
- if (descriptor->type() == "pranswer" && descriptor->sdp() == "local")
- return RTCPeerConnectionHandlerClient::SignalingStateHaveLocalPrAnswer;
- if (descriptor->type() == "pranswer" && descriptor->sdp() == "remote")
- return RTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer;
-
- return RTCPeerConnectionHandlerClient::SignalingStateStable;
-}
-
-void RTCPeerConnectionHandlerMock::setLocalDescription(PassRefPtr<RTCVoidRequest> request, PassRefPtr<RTCSessionDescriptionDescriptor> descriptor)
-{
- RefPtr<VoidRequestNotifier> voidNotifier;
- RefPtr<SignalingStateNotifier> signalingNotifier;
- if (!descriptor.get() || descriptor->sdp() != "local")
- voidNotifier = adoptRef(new VoidRequestNotifier(request, false, RTCPeerConnectionHandler::internalErrorName()));
- else {
- m_localSessionDescription = descriptor;
- signalingNotifier = adoptRef(new SignalingStateNotifier(m_client, signalingStateFromSDP(m_localSessionDescription.get())));
- voidNotifier = adoptRef(new VoidRequestNotifier(request, true));
- m_timerEvents.append(adoptRef(new TimerEvent(this, signalingNotifier)));
- }
-
- m_timerEvents.append(adoptRef(new TimerEvent(this, voidNotifier)));
-}
-
-void RTCPeerConnectionHandlerMock::setRemoteDescription(PassRefPtr<RTCVoidRequest> request, PassRefPtr<RTCSessionDescriptionDescriptor> descriptor)
-{
- RefPtr<VoidRequestNotifier> voidNotifier;
- RefPtr<SignalingStateNotifier> signalingNotifier;
- if (!descriptor.get() || descriptor->sdp() != "remote")
- voidNotifier = adoptRef(new VoidRequestNotifier(request, false, RTCPeerConnectionHandler::internalErrorName()));
- else {
- m_remoteSessionDescription = descriptor;
- signalingNotifier = adoptRef(new SignalingStateNotifier(m_client, signalingStateFromSDP(m_remoteSessionDescription.get())));
- voidNotifier = adoptRef(new VoidRequestNotifier(request, true));
- m_timerEvents.append(adoptRef(new TimerEvent(this, signalingNotifier)));
- }
-
- m_timerEvents.append(adoptRef(new TimerEvent(this, voidNotifier)));
-}
-
-PassRefPtr<RTCSessionDescriptionDescriptor> RTCPeerConnectionHandlerMock::localDescription()
-{
- return m_localSessionDescription;
-}
-
-PassRefPtr<RTCSessionDescriptionDescriptor> RTCPeerConnectionHandlerMock::remoteDescription()
-{
- return m_remoteSessionDescription;
-}
-
-bool RTCPeerConnectionHandlerMock::updateIce(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints>)
-{
- return true;
-}
-
-bool RTCPeerConnectionHandlerMock::addIceCandidate(PassRefPtr<RTCVoidRequest> request, PassRefPtr<RTCIceCandidateDescriptor>)
-{
- RefPtr<VoidRequestNotifier> notifier = adoptRef(new VoidRequestNotifier(request, true));
- m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
- return true;
-}
-
-bool RTCPeerConnectionHandlerMock::addStream(PassRefPtr<MediaStreamPrivate>, PassRefPtr<MediaConstraints> constraints)
-{
- String invalidQuery = MediaConstraintsMock::verifyConstraints(constraints);
- if (!invalidQuery.isEmpty())
- return false;
-
- // Spec states that every time a stream is added, a negotiationneeded event must be fired.
- m_client->negotiationNeeded();
- return true;
-}
-
-void RTCPeerConnectionHandlerMock::removeStream(PassRefPtr<MediaStreamPrivate>)
-{
- // Spec states that every time a stream is removed, a negotiationneeded event must be fired.
- m_client->negotiationNeeded();
-}
-
-void RTCPeerConnectionHandlerMock::getStats(PassRefPtr<RTCStatsRequest>)
-{
- // Current tests does not support getUserMedia and this function requires it.
- // Once WebKit has test support to getUserMedia, this must be fixed.
- notImplemented();
-}
-
-std::unique_ptr<RTCDataChannelHandler> RTCPeerConnectionHandlerMock::createDataChannel(const String& label, const RTCDataChannelInit& init)
-{
- RefPtr<RemoteDataChannelNotifier> notifier = adoptRef(new RemoteDataChannelNotifier(m_client));
- m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
- return std::make_unique<RTCDataChannelHandlerMock>(label, init);
-}
-
-std::unique_ptr<RTCDTMFSenderHandler> RTCPeerConnectionHandlerMock::createDTMFSender(PassRefPtr<MediaStreamSource>)
-{
- // Requires a mock implementation of RTCDTMFSenderHandler.
- // This must be implemented once the mock implementation of RTCDataChannelHandler is ready.
- notImplemented();
- return nullptr;
-}
-
-void RTCPeerConnectionHandlerMock::stop()
-{
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.h b/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.h
deleted file mode 100644
index 4de3539b4..000000000
--- a/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
- *
- * 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 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 RTCPeerConnectionHandlerMock_h
-#define RTCPeerConnectionHandlerMock_h
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "RTCPeerConnectionHandler.h"
-#include "RTCPeerConnectionHandlerClient.h"
-#include "RTCSessionDescriptionDescriptor.h"
-#include "TimerEventBasedMock.h"
-
-namespace WebCore {
-
-class RTCPeerConnectionHandlerMock final : public RTCPeerConnectionHandler, public TimerEventBasedMock {
-public:
- static std::unique_ptr<RTCPeerConnectionHandler> create(RTCPeerConnectionHandlerClient*);
-
- virtual ~RTCPeerConnectionHandlerMock() { }
-
- virtual bool initialize(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints>) override;
-
- virtual void createOffer(PassRefPtr<RTCSessionDescriptionRequest>, PassRefPtr<MediaConstraints>) override;
- virtual void createAnswer(PassRefPtr<RTCSessionDescriptionRequest>, PassRefPtr<MediaConstraints>) override;
- virtual void setLocalDescription(PassRefPtr<RTCVoidRequest>, PassRefPtr<RTCSessionDescriptionDescriptor>) override;
- virtual void setRemoteDescription(PassRefPtr<RTCVoidRequest>, PassRefPtr<RTCSessionDescriptionDescriptor>) override;
- virtual PassRefPtr<RTCSessionDescriptionDescriptor> localDescription() override;
- virtual PassRefPtr<RTCSessionDescriptionDescriptor> remoteDescription() override;
- virtual bool updateIce(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints>) override;
- virtual bool addIceCandidate(PassRefPtr<RTCVoidRequest>, PassRefPtr<RTCIceCandidateDescriptor>) override;
- virtual bool addStream(PassRefPtr<MediaStreamPrivate>, PassRefPtr<MediaConstraints>) override;
- virtual void removeStream(PassRefPtr<MediaStreamPrivate>) override;
- virtual void getStats(PassRefPtr<RTCStatsRequest>) override;
- virtual std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) override;
- virtual std::unique_ptr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamSource>) override;
- virtual void stop() override;
-
- explicit RTCPeerConnectionHandlerMock(RTCPeerConnectionHandlerClient*);
-
-private:
- RTCPeerConnectionHandlerClient::SignalingState signalingStateFromSDP(RTCSessionDescriptionDescriptor*);
- RTCPeerConnectionHandlerClient* m_client;
-
- RefPtr<RTCSessionDescriptionDescriptor> m_localSessionDescription;
- RefPtr<RTCSessionDescriptionDescriptor> m_remoteSessionDescription;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
-
-#endif // RTCPeerConnectionHandlerMock_h
diff --git a/Source/WebCore/platform/mock/ScrollAnimatorMock.cpp b/Source/WebCore/platform/mock/ScrollAnimatorMock.cpp
new file mode 100644
index 000000000..c0803810e
--- /dev/null
+++ b/Source/WebCore/platform/mock/ScrollAnimatorMock.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2016 Igalia S.L.
+ *
+ * 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 "ScrollAnimatorMock.h"
+
+#include "ScrollableArea.h"
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+ScrollAnimatorMock::ScrollAnimatorMock(ScrollableArea& scrollableArea, std::function<void(const String&)>&& logger)
+ : ScrollAnimator(scrollableArea)
+ , m_logger(WTFMove(logger))
+{
+}
+
+ScrollAnimatorMock::~ScrollAnimatorMock()
+{
+}
+
+void ScrollAnimatorMock::didAddVerticalScrollbar(Scrollbar* scrollbar)
+{
+ m_verticalScrollbar = scrollbar;
+ m_logger("didAddVerticalScrollbar");
+ ScrollAnimator::didAddVerticalScrollbar(scrollbar);
+}
+
+void ScrollAnimatorMock::didAddHorizontalScrollbar(Scrollbar* scrollbar)
+{
+ m_horizontalScrollbar = scrollbar;
+ m_logger("didAddHorizontalScrollbar");
+ ScrollAnimator::didAddHorizontalScrollbar(scrollbar);
+}
+
+void ScrollAnimatorMock::willRemoveVerticalScrollbar(Scrollbar* scrollbar)
+{
+ m_logger("willRemoveVerticalScrollbar");
+ ScrollAnimator::willRemoveVerticalScrollbar(scrollbar);
+ m_verticalScrollbar = nullptr;
+}
+
+void ScrollAnimatorMock::willRemoveHorizontalScrollbar(Scrollbar* scrollbar)
+{
+ m_logger("willRemoveHorizontalScrollbar");
+ ScrollAnimator::willRemoveHorizontalScrollbar(scrollbar);
+ m_horizontalScrollbar = nullptr;
+}
+
+void ScrollAnimatorMock::mouseEnteredContentArea()
+{
+ m_logger("mouseEnteredContentArea");
+ ScrollAnimator::mouseEnteredContentArea();
+}
+
+void ScrollAnimatorMock::mouseMovedInContentArea()
+{
+ m_logger("mouseMovedInContentArea");
+ ScrollAnimator::mouseMovedInContentArea();
+}
+
+void ScrollAnimatorMock::mouseExitedContentArea()
+{
+ m_logger("mouseExitedContentArea");
+ ScrollAnimator::mouseExitedContentArea();
+}
+
+void ScrollAnimatorMock::mouseEnteredScrollbar(Scrollbar* scrollbar) const
+{
+ StringBuilder message;
+ message.appendLiteral("mouseEntered");
+ if (scrollbar == m_verticalScrollbar)
+ message.appendLiteral("Vertical");
+ else if (scrollbar == m_horizontalScrollbar)
+ message.appendLiteral("Horizontal");
+ else
+ message.appendLiteral("Unknown");
+ message.appendLiteral("Scrollbar");
+ m_logger(message.toString());
+ ScrollAnimator::mouseEnteredScrollbar(scrollbar);
+}
+
+void ScrollAnimatorMock::mouseExitedScrollbar(Scrollbar* scrollbar) const
+{
+ StringBuilder message;
+ message.appendLiteral("mouseExited");
+ if (scrollbar == m_verticalScrollbar)
+ message.appendLiteral("Vertical");
+ else if (scrollbar == m_horizontalScrollbar)
+ message.appendLiteral("Horizontal");
+ else
+ message.appendLiteral("Unknown");
+ message.appendLiteral("Scrollbar");
+ m_logger(message.toString());
+ ScrollAnimator::mouseExitedScrollbar(scrollbar);
+}
+
+void ScrollAnimatorMock::mouseIsDownInScrollbar(Scrollbar* scrollbar, bool isPressed) const
+{
+ StringBuilder message;
+ message.appendLiteral("mouseIs");
+ if (isPressed)
+ message.appendLiteral("Down");
+ else
+ message.appendLiteral("Up");
+ message.appendLiteral("In");
+ if (scrollbar == m_verticalScrollbar)
+ message.appendLiteral("Vertical");
+ else if (scrollbar == m_horizontalScrollbar)
+ message.appendLiteral("Horizontal");
+ else
+ message.appendLiteral("Unknown");
+ message.appendLiteral("Scrollbar");
+ m_logger(message.toString());
+ ScrollAnimator::mouseIsDownInScrollbar(scrollbar, isPressed);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/mock/ScrollAnimatorMock.h b/Source/WebCore/platform/mock/ScrollAnimatorMock.h
new file mode 100644
index 000000000..85dc4f6ed
--- /dev/null
+++ b/Source/WebCore/platform/mock/ScrollAnimatorMock.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016 Igalia S.L.
+ *
+ * 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 ScrollAnimatorMock_h
+#define ScrollAnimatorMock_h
+
+#include "ScrollAnimator.h"
+
+namespace WebCore {
+
+// A Mock implementation of ScrollAnimator used to test the scroll events
+// received by the scroll animator. Tests can enable this scroll animator using
+// the internal setting enableMockScrollAnimator.
+class ScrollAnimatorMock final : public ScrollAnimator {
+public:
+ ScrollAnimatorMock(ScrollableArea&, std::function<void(const String&)>&&);
+ virtual ~ScrollAnimatorMock();
+
+#if ENABLE(RUBBER_BANDING)
+ bool allowsHorizontalStretching(const PlatformWheelEvent&) override { return false; }
+ bool allowsVerticalStretching(const PlatformWheelEvent&) override { return false; }
+ IntSize stretchAmount() override { return IntSize(); }
+ bool pinnedInDirection(const FloatSize&) override { return false; }
+ bool canScrollHorizontally() override { return false; }
+ bool canScrollVertically() override { return false; }
+ bool shouldRubberBandInDirection(ScrollDirection) override { return false; }
+ void immediateScrollBy(const FloatSize&) override { }
+ void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override { }
+ void adjustScrollPositionToBoundsIfNecessary() override { }
+#endif
+
+private:
+ void didAddVerticalScrollbar(Scrollbar*) override;
+ void didAddHorizontalScrollbar(Scrollbar*) override;
+ void willRemoveVerticalScrollbar(Scrollbar*) override;
+ void willRemoveHorizontalScrollbar(Scrollbar*) override;
+ void mouseEnteredContentArea() override;
+ void mouseMovedInContentArea() override;
+ void mouseExitedContentArea() override;
+ void mouseEnteredScrollbar(Scrollbar*) const override;
+ void mouseExitedScrollbar(Scrollbar*) const override;
+ void mouseIsDownInScrollbar(Scrollbar*, bool) const override;
+
+ std::function<void(const String&)> m_logger;
+ Scrollbar* m_verticalScrollbar { nullptr };
+ Scrollbar* m_horizontalScrollbar { nullptr };
+};
+
+} // namespace WebCore
+
+#endif // ScrollAnimatorMock_h
diff --git a/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp b/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp
index 6de91ccb8..171dfd5c0 100644
--- a/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp
+++ b/Source/WebCore/platform/mock/ScrollbarThemeMock.cpp
@@ -27,14 +27,16 @@
#include "ScrollbarThemeMock.h"
#include "Scrollbar.h"
+// FIXME: This is a layering violation.
+#include "Settings.h"
namespace WebCore {
-static int cScrollbarThickness[] = { 15, 11 };
+static const int cScrollbarThickness[] = { 15, 11 };
-IntRect ScrollbarThemeMock::trackRect(ScrollbarThemeClient* scrollbar, bool)
+IntRect ScrollbarThemeMock::trackRect(Scrollbar& scrollbar, bool)
{
- return scrollbar->frameRect();
+ return scrollbar.frameRect();
}
int ScrollbarThemeMock::scrollbarThickness(ScrollbarControlSize controlSize)
@@ -42,15 +44,22 @@ int ScrollbarThemeMock::scrollbarThickness(ScrollbarControlSize controlSize)
return cScrollbarThickness[controlSize];
}
-void ScrollbarThemeMock::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& trackRect)
+void ScrollbarThemeMock::paintTrackBackground(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& trackRect)
{
- context->fillRect(trackRect, scrollbar->enabled() ? Color::lightGray : Color(0xFFE0E0E0), ColorSpaceDeviceRGB);
+ context.fillRect(trackRect, scrollbar.enabled() ? Color::lightGray : Color(0xFFE0E0E0));
}
-void ScrollbarThemeMock::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& thumbRect)
+void ScrollbarThemeMock::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& thumbRect)
{
- if (scrollbar->enabled())
- context->fillRect(thumbRect, Color::darkGray, ColorSpaceDeviceRGB);
+ if (scrollbar.enabled())
+ context.fillRect(thumbRect, Color::darkGray);
+}
+
+bool ScrollbarThemeMock::usesOverlayScrollbars() const
+{
+ // FIXME: This is a layering violation, but ScrollbarThemeMock is also created depending on settings in platform layer,
+ // we should fix it in both places.
+ return Settings::usesOverlayScrollbars();
}
}
diff --git a/Source/WebCore/platform/mock/ScrollbarThemeMock.h b/Source/WebCore/platform/mock/ScrollbarThemeMock.h
index 6333841ab..7fd039214 100644
--- a/Source/WebCore/platform/mock/ScrollbarThemeMock.h
+++ b/Source/WebCore/platform/mock/ScrollbarThemeMock.h
@@ -33,21 +33,23 @@ namespace WebCore {
// Scrollbar theme used in image snapshots, to eliminate appearance differences between platforms.
class ScrollbarThemeMock : public ScrollbarThemeComposite {
public:
- virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar);
+ int scrollbarThickness(ScrollbarControlSize = RegularScrollbar) override;
protected:
- virtual bool hasButtons(ScrollbarThemeClient*) { return false; }
- virtual bool hasThumb(ScrollbarThemeClient*) { return true; }
+ bool hasButtons(Scrollbar&) override { return false; }
+ bool hasThumb(Scrollbar&) override { return true; }
- virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool /*painting*/ = false) { return IntRect(); }
- virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool /*painting*/ = false) { return IntRect(); }
- virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false);
-
- virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&);
- virtual void paintThumb(GraphicsContext*, ScrollbarThemeClient*, const IntRect&);
+ IntRect backButtonRect(Scrollbar&, ScrollbarPart, bool /*painting*/ = false) override { return IntRect(); }
+ IntRect forwardButtonRect(Scrollbar&, ScrollbarPart, bool /*painting*/ = false) override { return IntRect(); }
+ IntRect trackRect(Scrollbar&, bool painting = false) override;
+ void paintTrackBackground(GraphicsContext&, Scrollbar&, const IntRect&) override;
+ void paintThumb(GraphicsContext&, Scrollbar&, const IntRect&) override;
+ int maxOverlapBetweenPages() override { return 40; }
+
+ bool usesOverlayScrollbars() const override;
private:
- virtual bool isMockTheme() const { return true; }
+ bool isMockTheme() const override { return true; }
};
}
diff --git a/Source/WebCore/platform/mock/MediaConstraintsMock.h b/Source/WebCore/platform/mock/TimerEventBasedMock.h
index 1c96c619b..de0e8a9fd 100644
--- a/Source/WebCore/platform/mock/MediaConstraintsMock.h
+++ b/Source/WebCore/platform/mock/TimerEventBasedMock.h
@@ -1,6 +1,5 @@
/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,25 +23,68 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef MediaConstraintsMock_h
-#define MediaConstraintsMock_h
+#ifndef TimerEventBasedMock_h
+#define TimerEventBasedMock_h
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(WEB_RTC)
+#include "Timer.h"
#include <wtf/PassRefPtr.h>
-#include <wtf/text/WTFString.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
namespace WebCore {
-class MediaConstraints;
+class TimerEvent;
-class MediaConstraintsMock {
+class MockNotifier : public RefCounted<MockNotifier> {
public:
- static String verifyConstraints(PassRefPtr<MediaConstraints>);
+ virtual ~MockNotifier() { }
+ virtual void fire() = 0;
+};
+
+class TimerEventBasedMock {
+public:
+ void removeEvent(PassRefPtr<TimerEvent> event)
+ {
+ size_t pos = m_timerEvents.find(event);
+ m_timerEvents.remove(pos);
+ }
+
+protected:
+ Vector<RefPtr<TimerEvent> > m_timerEvents;
+};
+
+class TimerEvent : public RefCounted<TimerEvent> {
+public:
+ TimerEvent(TimerEventBasedMock* mock, PassRefPtr<MockNotifier> notifier)
+ : m_mock(mock)
+ , m_timer(*this, &TimerEvent::timerFired)
+ , m_notifier(notifier)
+ {
+ m_timer.startOneShot(0.5);
+ }
+
+ virtual ~TimerEvent()
+ {
+ m_mock = nullptr;
+ }
+
+ void timerFired()
+ {
+ m_notifier->fire();
+ m_mock->removeEvent(this);
+ }
+
+private:
+ TimerEventBasedMock* m_mock;
+ Timer m_timer;
+ RefPtr<MockNotifier> m_notifier;
};
} // namespace WebCore
-#endif // MockMediaConstraints_h
+#endif // ENABLE(WEB_RTC)
-#endif // ENABLE(MEDIA_STREAM)
+#endif // TimerEventBasedMock_h
diff --git a/Source/WebCore/platform/mock/mediasource/MockBox.cpp b/Source/WebCore/platform/mock/mediasource/MockBox.cpp
index 286e81b49..c8b134e51 100644
--- a/Source/WebCore/platform/mock/mediasource/MockBox.cpp
+++ b/Source/WebCore/platform/mock/mediasource/MockBox.cpp
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -28,9 +28,13 @@
#if ENABLE(MEDIA_SOURCE)
+#include <JavaScriptCore/HeapInlines.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/TypedArrayInlines.h>
#include <runtime/ArrayBuffer.h>
#include <runtime/DataView.h>
#include <runtime/Int8Array.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -76,7 +80,7 @@ MockTrackBox::MockTrackBox(ArrayBuffer* data)
const String& MockTrackBox::type()
{
- DEFINE_STATIC_LOCAL(String, trak, (ASCIILiteral("trak")));
+ static NeverDestroyed<String> trak(ASCIILiteral("trak"));
return trak;
}
@@ -105,14 +109,14 @@ MockInitializationBox::MockInitializationBox(ArrayBuffer* data)
const String& MockInitializationBox::type()
{
- DEFINE_STATIC_LOCAL(String, init, (ASCIILiteral("init")));
+ static NeverDestroyed<String> init(ASCIILiteral("init"));
return init;
}
MockSampleBox::MockSampleBox(ArrayBuffer* data)
: MockBox(data)
{
- ASSERT(m_length == 29);
+ ASSERT(m_length == 30);
RefPtr<JSC::DataView> view = JSC::DataView::create(data, 0, data->byteLength());
int32_t timeScale = view->get<int32_t>(8, true);
@@ -128,11 +132,12 @@ MockSampleBox::MockSampleBox(ArrayBuffer* data)
m_trackID = view->get<int32_t>(24, true);
m_flags = view->get<uint8_t>(28, true);
+ m_generation = view->get<uint8_t>(29, true);
}
const String& MockSampleBox::type()
{
- DEFINE_STATIC_LOCAL(String, smpl, (ASCIILiteral("smpl")));
+ static NeverDestroyed<String> smpl(ASCIILiteral("smpl"));
return smpl;
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockBox.h b/Source/WebCore/platform/mock/mediasource/MockBox.h
index 6ddc21c47..2cc530fe3 100644
--- a/Source/WebCore/platform/mock/mediasource/MockBox.h
+++ b/Source/WebCore/platform/mock/mediasource/MockBox.h
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -117,6 +117,7 @@ protected:
// 4 bytes : signed : duration time value
// 4 bytes : signed : track ID
// 1 byte : unsigned : flags
+// 1 byte : unsigned : generation
//
class MockSampleBox final : public MockBox {
public:
@@ -128,17 +129,33 @@ public:
MediaTime duration() const { return m_duration; }
int32_t trackID() const { return m_trackID; }
uint8_t flags() const { return m_flags; }
+ uint8_t generation() const { return m_generation; }
+ void offsetTimestampsBy(const MediaTime& offset)
+ {
+ m_presentationTimestamp += offset;
+ m_decodeTimestamp += offset;
+ }
+ void setTimestamps(const MediaTime& presentationTimestamp, const MediaTime& decodeTimestamp)
+ {
+ m_presentationTimestamp = presentationTimestamp;
+ m_decodeTimestamp = decodeTimestamp;
+ }
+
+ void clearFlag(uint8_t flag) { m_flags &= ~flag; }
+ void setFlag(uint8_t flag) { m_flags |= flag; }
enum {
IsSync = 1 << 0,
IsCorrupted = 1 << 1,
IsDropped = 1 << 2,
IsDelayed = 1 << 3,
+ IsNonDisplaying = 1 << 4,
};
bool isSync() const { return m_flags & IsSync; }
bool isCorrupted() const { return m_flags & IsCorrupted; }
bool isDropped() const { return m_flags & IsDropped; }
bool isDelayed() const { return m_flags & IsDelayed; }
+ bool isNonDisplaying() const { return m_flags & IsNonDisplaying; }
protected:
MediaTime m_presentationTimestamp;
@@ -146,6 +163,7 @@ protected:
MediaTime m_duration;
int32_t m_trackID;
uint8_t m_flags;
+ uint8_t m_generation;
};
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp
index e0fc51c9f..4e40c8e73 100644
--- a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp
+++ b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -28,12 +28,11 @@
#if ENABLE(MEDIA_SOURCE)
-#include "ExceptionCodePlaceholder.h"
-#include "HTMLMediaSource.h"
#include "MediaPlayer.h"
+#include "MediaSourcePrivateClient.h"
#include "MockMediaSourcePrivate.h"
-#include <wtf/Functional.h>
#include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -41,28 +40,25 @@ namespace WebCore {
// MediaPlayer Enigne Support
void MockMediaPlayerMediaSource::registerMediaEngine(MediaEngineRegistrar registrar)
{
- registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
+ registrar([](MediaPlayer* player) { return std::make_unique<MockMediaPlayerMediaSource>(player); }, getSupportedTypes,
+ supportsType, 0, 0, 0, 0);
}
-PassOwnPtr<MediaPlayerPrivateInterface> MockMediaPlayerMediaSource::create(MediaPlayer* player)
+static const HashSet<String, ASCIICaseInsensitiveHash>& mimeTypeCache()
{
- return adoptPtr(new MockMediaPlayerMediaSource(player));
-}
-
-static HashSet<String> mimeTypeCache()
-{
- DEFINE_STATIC_LOCAL(HashSet<String>, cache, ());
+ static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> cache;
static bool isInitialized = false;
if (!isInitialized) {
isInitialized = true;
- cache.add(ASCIILiteral("video/mock"));
+ cache.get().add(ASCIILiteral("video/mock"));
+ cache.get().add(ASCIILiteral("audio/mock"));
}
return cache;
}
-void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String>& supportedTypes)
+void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& supportedTypes)
{
supportedTypes = mimeTypeCache();
}
@@ -72,7 +68,7 @@ MediaPlayer::SupportsType MockMediaPlayerMediaSource::supportsType(const MediaEn
if (!parameters.isMediaSource)
return MediaPlayer::IsNotSupported;
- if (!mimeTypeCache().contains(parameters.type))
+ if (parameters.type.isEmpty() || !mimeTypeCache().contains(parameters.type))
return MediaPlayer::IsNotSupported;
if (parameters.codecs.isEmpty())
@@ -84,10 +80,10 @@ MediaPlayer::SupportsType MockMediaPlayerMediaSource::supportsType(const MediaEn
MockMediaPlayerMediaSource::MockMediaPlayerMediaSource(MediaPlayer* player)
: m_player(player)
, m_currentTime(MediaTime::zeroTime())
- , m_duration(0)
, m_readyState(MediaPlayer::HaveNothing)
, m_networkState(MediaPlayer::Empty)
, m_playing(false)
+ , m_seekCompleted(true)
{
}
@@ -100,11 +96,9 @@ void MockMediaPlayerMediaSource::load(const String&)
ASSERT_NOT_REACHED();
}
-void MockMediaPlayerMediaSource::load(const String&, PassRefPtr<HTMLMediaSource> source)
+void MockMediaPlayerMediaSource::load(const String&, MediaSourcePrivateClient* source)
{
- m_mediaSource = source;
- m_mediaSourcePrivate = MockMediaSourcePrivate::create(this);
- m_mediaSource->setPrivateAndOpen(*m_mediaSourcePrivate);
+ m_mediaSourcePrivate = MockMediaSourcePrivate::create(this, source);
}
void MockMediaPlayerMediaSource::cancelLoad()
@@ -114,7 +108,9 @@ void MockMediaPlayerMediaSource::cancelLoad()
void MockMediaPlayerMediaSource::play()
{
m_playing = 1;
- callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this));
+ callOnMainThread([this] {
+ advanceCurrentTime();
+ });
}
void MockMediaPlayerMediaSource::pause()
@@ -122,9 +118,9 @@ void MockMediaPlayerMediaSource::pause()
m_playing = 0;
}
-IntSize MockMediaPlayerMediaSource::naturalSize() const
+FloatSize MockMediaPlayerMediaSource::naturalSize() const
{
- return IntSize();
+ return FloatSize();
}
bool MockMediaPlayerMediaSource::hasVideo() const
@@ -143,7 +139,7 @@ void MockMediaPlayerMediaSource::setVisible(bool)
bool MockMediaPlayerMediaSource::seeking() const
{
- return false;
+ return !m_seekCompleted;
}
bool MockMediaPlayerMediaSource::paused() const
@@ -161,14 +157,17 @@ MediaPlayer::ReadyState MockMediaPlayerMediaSource::readyState() const
return m_readyState;
}
-double MockMediaPlayerMediaSource::maxTimeSeekableDouble() const
+MediaTime MockMediaPlayerMediaSource::maxMediaTimeSeekable() const
{
return m_duration;
}
-PassRefPtr<TimeRanges> MockMediaPlayerMediaSource::buffered() const
+std::unique_ptr<PlatformTimeRanges> MockMediaPlayerMediaSource::buffered() const
{
- return m_mediaSource ? m_mediaSource->buffered() : TimeRanges::create();
+ if (m_mediaSourcePrivate)
+ return m_mediaSourcePrivate->buffered();
+
+ return std::make_unique<PlatformTimeRanges>();
}
bool MockMediaPlayerMediaSource::didLoadingProgress() const
@@ -180,45 +179,54 @@ void MockMediaPlayerMediaSource::setSize(const IntSize&)
{
}
-void MockMediaPlayerMediaSource::paint(GraphicsContext*, const IntRect&)
+void MockMediaPlayerMediaSource::paint(GraphicsContext&, const FloatRect&)
{
}
-double MockMediaPlayerMediaSource::currentTimeDouble() const
+MediaTime MockMediaPlayerMediaSource::currentMediaTime() const
{
- return m_currentTime.toDouble();
+ return m_currentTime;
}
-double MockMediaPlayerMediaSource::durationDouble() const
+MediaTime MockMediaPlayerMediaSource::durationMediaTime() const
{
- return m_duration;
+ return m_mediaSourcePrivate ? m_mediaSourcePrivate->duration() : MediaTime::zeroTime();
}
-void MockMediaPlayerMediaSource::seekWithTolerance(double time, double negativeTolerance, double positiveTolerance)
+void MockMediaPlayerMediaSource::seekWithTolerance(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance)
{
if (!negativeTolerance && !positiveTolerance) {
- m_currentTime = MediaTime::createWithDouble(time);
- m_mediaSourcePrivate->seekToTime(MediaTime::createWithDouble(time));
+ m_currentTime = time;
+ m_mediaSourcePrivate->seekToTime(time);
} else
- m_currentTime = m_mediaSourcePrivate->seekToTime(MediaTime::createWithDouble(time), MediaTime::createWithDouble(negativeTolerance), MediaTime::createWithDouble(positiveTolerance));
- m_player->timeChanged();
+ m_currentTime = m_mediaSourcePrivate->seekToTime(time, negativeTolerance, positiveTolerance);
- if (m_playing)
- callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this));
+ if (m_seekCompleted) {
+ m_player->timeChanged();
+
+ if (m_playing)
+ callOnMainThread([this] {
+ advanceCurrentTime();
+ });
+ }
}
void MockMediaPlayerMediaSource::advanceCurrentTime()
{
- RefPtr<TimeRanges> buffered = this->buffered();
- size_t pos = buffered->find(m_currentTime.toDouble());
+ if (!m_mediaSourcePrivate)
+ return;
+
+ auto buffered = m_mediaSourcePrivate->buffered();
+ size_t pos = buffered->find(m_currentTime);
if (pos == notFound)
return;
- m_currentTime = MediaTime::createWithDouble(std::min(m_duration, buffered->end(pos, IGNORE_EXCEPTION)));
+ bool ignoreError;
+ m_currentTime = std::min(m_duration, buffered->end(pos, ignoreError));
m_player->timeChanged();
}
-void MockMediaPlayerMediaSource::updateDuration(double duration)
+void MockMediaPlayerMediaSource::updateDuration(const MediaTime& duration)
{
if (m_duration == duration)
return;
@@ -245,6 +253,25 @@ void MockMediaPlayerMediaSource::setNetworkState(MediaPlayer::NetworkState netwo
m_player->networkStateChanged();
}
+void MockMediaPlayerMediaSource::waitForSeekCompleted()
+{
+ m_seekCompleted = false;
+}
+
+void MockMediaPlayerMediaSource::seekCompleted()
+{
+ if (m_seekCompleted)
+ return;
+ m_seekCompleted = true;
+
+ m_player->timeChanged();
+
+ if (m_playing)
+ callOnMainThread([this] {
+ advanceCurrentTime();
+ });
+}
+
unsigned long MockMediaPlayerMediaSource::totalVideoFrames()
{
return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalVideoFrames() : 0;
@@ -260,9 +287,9 @@ unsigned long MockMediaPlayerMediaSource::corruptedVideoFrames()
return m_mediaSourcePrivate ? m_mediaSourcePrivate->corruptedVideoFrames() : 0;
}
-double MockMediaPlayerMediaSource::totalFrameDelay()
+MediaTime MockMediaPlayerMediaSource::totalFrameDelay()
{
- return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalFrameDelay() : 0;
+ return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalFrameDelay() : MediaTime::zeroTime();
}
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h
index cd8d794ab..d03e4a06e 100644
--- a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h
+++ b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -38,59 +38,63 @@ class MockMediaSourcePrivate;
class MockMediaPlayerMediaSource : public MediaPlayerPrivateInterface {
public:
+ explicit MockMediaPlayerMediaSource(MediaPlayer*);
+
// MediaPlayer Engine Support
- static void registerMediaEngine(MediaEngineRegistrar);
- static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
- static void getSupportedTypes(HashSet<String>& types);
+ WEBCORE_EXPORT static void registerMediaEngine(MediaEngineRegistrar);
+ static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types);
static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);
virtual ~MockMediaPlayerMediaSource();
void advanceCurrentTime();
- void updateDuration(double);
+ void updateDuration(const MediaTime&);
- virtual MediaPlayer::ReadyState readyState() const override;
+ MediaPlayer::ReadyState readyState() const override;
void setReadyState(MediaPlayer::ReadyState);
void setNetworkState(MediaPlayer::NetworkState);
+ void waitForSeekCompleted();
+ void seekCompleted();
private:
- MockMediaPlayerMediaSource(MediaPlayer*);
-
// MediaPlayerPrivate Overrides
- virtual void load(const String& url) override;
- virtual void load(const String& url, PassRefPtr<HTMLMediaSource>) override;
- virtual void cancelLoad() override;
- virtual void play() override;
- virtual void pause() override;
- virtual IntSize naturalSize() const override;
- virtual bool hasVideo() const override;
- virtual bool hasAudio() const override;
- virtual void setVisible(bool) override;
- virtual bool seeking() const override;
- virtual bool paused() const override;
- virtual MediaPlayer::NetworkState networkState() const override;
- virtual double maxTimeSeekableDouble() const override;
- virtual PassRefPtr<TimeRanges> buffered() const override;
- virtual bool didLoadingProgress() const override;
- virtual void setSize(const IntSize&) override;
- virtual void paint(GraphicsContext*, const IntRect&) override;
- virtual double currentTimeDouble() const override;
- virtual double durationDouble() const override;
- virtual void seekWithTolerance(double time, double, double) override;
- virtual unsigned long totalVideoFrames() override;
- virtual unsigned long droppedVideoFrames() override;
- virtual unsigned long corruptedVideoFrames() override;
- virtual double totalFrameDelay() override;
+ void load(const String& url) override;
+ void load(const String& url, MediaSourcePrivateClient*) override;
+#if ENABLE(MEDIA_STREAM)
+ void load(MediaStreamPrivate&) override { }
+#endif
+ void cancelLoad() override;
+ void play() override;
+ void pause() override;
+ FloatSize naturalSize() const override;
+ bool hasVideo() const override;
+ bool hasAudio() const override;
+ void setVisible(bool) override;
+ bool seeking() const override;
+ bool paused() const override;
+ MediaPlayer::NetworkState networkState() const override;
+ MediaTime maxMediaTimeSeekable() const override;
+ std::unique_ptr<PlatformTimeRanges> buffered() const override;
+ bool didLoadingProgress() const override;
+ void setSize(const IntSize&) override;
+ void paint(GraphicsContext&, const FloatRect&) override;
+ MediaTime currentMediaTime() const override;
+ MediaTime durationMediaTime() const override;
+ void seekWithTolerance(const MediaTime&, const MediaTime&, const MediaTime&) override;
+ unsigned long totalVideoFrames() override;
+ unsigned long droppedVideoFrames() override;
+ unsigned long corruptedVideoFrames() override;
+ MediaTime totalFrameDelay() override;
MediaPlayer* m_player;
- RefPtr<HTMLMediaSource> m_mediaSource;
RefPtr<MockMediaSourcePrivate> m_mediaSourcePrivate;
MediaTime m_currentTime;
- double m_duration;
+ MediaTime m_duration;
MediaPlayer::ReadyState m_readyState;
MediaPlayer::NetworkState m_networkState;
bool m_playing;
+ bool m_seekCompleted;
};
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp b/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp
index 811173dfa..eb2ff784c 100644
--- a/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp
+++ b/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.cpp
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -29,25 +29,26 @@
#if ENABLE(MEDIA_SOURCE)
#include "ContentType.h"
-#include "ExceptionCodePlaceholder.h"
+#include "MediaSourcePrivateClient.h"
#include "MockMediaPlayerMediaSource.h"
#include "MockSourceBufferPrivate.h"
namespace WebCore {
-RefPtr<MockMediaSourcePrivate> MockMediaSourcePrivate::create(MockMediaPlayerMediaSource* parent)
+RefPtr<MockMediaSourcePrivate> MockMediaSourcePrivate::create(MockMediaPlayerMediaSource* parent, MediaSourcePrivateClient* client)
{
- return adoptRef(new MockMediaSourcePrivate(parent));
+ RefPtr<MockMediaSourcePrivate> mediaSourcePrivate = adoptRef(new MockMediaSourcePrivate(parent, client));
+ client->setPrivateAndOpen(*mediaSourcePrivate);
+ return mediaSourcePrivate;
}
-MockMediaSourcePrivate::MockMediaSourcePrivate(MockMediaPlayerMediaSource* parent)
+MockMediaSourcePrivate::MockMediaSourcePrivate(MockMediaPlayerMediaSource* parent, MediaSourcePrivateClient* client)
: m_player(parent)
- , m_duration(std::numeric_limits<float>::quiet_NaN())
+ , m_client(client)
, m_isEnded(false)
, m_totalVideoFrames(0)
, m_droppedVideoFrames(0)
, m_corruptedVideoFrames(0)
- , m_totalFrameDelay(0)
{
}
@@ -84,18 +85,19 @@ void MockMediaSourcePrivate::removeSourceBuffer(SourceBufferPrivate* buffer)
m_sourceBuffers.remove(pos);
}
-double MockMediaSourcePrivate::duration()
+MediaTime MockMediaSourcePrivate::duration()
{
- return m_duration;
+ return m_client->duration();
}
-void MockMediaSourcePrivate::setDuration(double duration)
+std::unique_ptr<PlatformTimeRanges> MockMediaSourcePrivate::buffered()
{
- if (duration == m_duration)
- return;
+ return m_client->buffered();
+}
- m_duration = duration;
- m_player->updateDuration(duration);
+void MockMediaSourcePrivate::durationChanged()
+{
+ m_player->updateDuration(duration());
}
void MockMediaSourcePrivate::markEndOfStream(EndOfStreamStatus status)
@@ -120,6 +122,16 @@ void MockMediaSourcePrivate::setReadyState(MediaPlayer::ReadyState readyState)
m_player->setReadyState(readyState);
}
+void MockMediaSourcePrivate::waitForSeekCompleted()
+{
+ m_player->waitForSeekCompleted();
+}
+
+void MockMediaSourcePrivate::seekCompleted()
+{
+ m_player->seekCompleted();
+}
+
void MockMediaSourcePrivate::sourceBufferPrivateDidChangeActiveState(MockSourceBufferPrivate* buffer, bool active)
{
if (active && !m_activeSourceBuffers.contains(buffer))
@@ -154,8 +166,7 @@ bool MockMediaSourcePrivate::hasVideo() const
void MockMediaSourcePrivate::seekToTime(const MediaTime& time)
{
- for (auto it = m_activeSourceBuffers.begin(), end = m_activeSourceBuffers.end(); it != end; ++it)
- (*it)->seekToTime(time);
+ m_client->seekToTime(time);
}
MediaTime MockMediaSourcePrivate::seekToTime(const MediaTime& targetTime, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold)
diff --git a/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.h b/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.h
index 9cc3da2eb..8c7169ea0 100644
--- a/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.h
+++ b/Source/WebCore/platform/mock/mediasource/MockMediaSourcePrivate.h
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -39,7 +39,7 @@ class TimeRanges;
class MockMediaSourcePrivate final : public MediaSourcePrivate {
public:
- static RefPtr<MockMediaSourcePrivate> create(MockMediaPlayerMediaSource*);
+ static RefPtr<MockMediaSourcePrivate> create(MockMediaPlayerMediaSource*, MediaSourcePrivateClient*);
virtual ~MockMediaSourcePrivate();
const Vector<MockSourceBufferPrivate*>& activeSourceBuffers() const { return m_activeSourceBuffers; }
@@ -47,6 +47,9 @@ public:
bool hasAudio() const;
bool hasVideo() const;
+ MediaTime duration();
+ std::unique_ptr<PlatformTimeRanges> buffered();
+
MockMediaPlayerMediaSource* player() const { return m_player; }
void seekToTime(const MediaTime&);
@@ -55,24 +58,25 @@ public:
unsigned long totalVideoFrames() const { return m_totalVideoFrames; }
unsigned long droppedVideoFrames() const { return m_droppedVideoFrames; }
unsigned long corruptedVideoFrames() const { return m_corruptedVideoFrames; }
- double totalFrameDelay() const { return m_totalFrameDelay; }
+ MediaTime totalFrameDelay() const { return m_totalFrameDelay; }
void incrementTotalVideoFrames() { ++m_totalVideoFrames; }
void incrementDroppedFrames() { ++m_droppedVideoFrames; }
void incrementCorruptedFrames() { ++m_corruptedVideoFrames; }
- void incrementTotalFrameDelayBy(double delay) { m_totalFrameDelay += delay; }
+ void incrementTotalFrameDelayBy(const MediaTime& delay) { m_totalFrameDelay += delay; }
private:
- MockMediaSourcePrivate(MockMediaPlayerMediaSource*);
+ MockMediaSourcePrivate(MockMediaPlayerMediaSource*, MediaSourcePrivateClient*);
// MediaSourcePrivate Overrides
- virtual AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) override;
- virtual double duration() override;
- virtual void setDuration(double) override;
- virtual void markEndOfStream(EndOfStreamStatus) override;
- virtual void unmarkEndOfStream() override;
- virtual MediaPlayer::ReadyState readyState() const override;
- virtual void setReadyState(MediaPlayer::ReadyState) override;
+ AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) override;
+ void durationChanged() override;
+ void markEndOfStream(EndOfStreamStatus) override;
+ void unmarkEndOfStream() override;
+ MediaPlayer::ReadyState readyState() const override;
+ void setReadyState(MediaPlayer::ReadyState) override;
+ void waitForSeekCompleted() override;
+ void seekCompleted() override;
void sourceBufferPrivateDidChangeActiveState(MockSourceBufferPrivate*, bool active);
void removeSourceBuffer(SourceBufferPrivate*);
@@ -80,7 +84,7 @@ private:
friend class MockSourceBufferPrivate;
MockMediaPlayerMediaSource* m_player;
- double m_duration;
+ RefPtr<MediaSourcePrivateClient> m_client;
Vector<RefPtr<MockSourceBufferPrivate>> m_sourceBuffers;
Vector<MockSourceBufferPrivate*> m_activeSourceBuffers;
bool m_isEnded;
@@ -88,7 +92,7 @@ private:
unsigned long m_totalVideoFrames;
unsigned long m_droppedVideoFrames;
unsigned long m_corruptedVideoFrames;
- double m_totalFrameDelay;
+ MediaTime m_totalFrameDelay;
};
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp
index 643ae76cd..e031a9b5d 100644
--- a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp
+++ b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,17 +10,17 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
@@ -38,29 +38,40 @@
#include "SourceBufferPrivateClient.h"
#include <map>
#include <runtime/ArrayBuffer.h>
+#include <wtf/StringPrintStream.h>
namespace WebCore {
class MockMediaSample final : public MediaSample {
public:
- static RefPtr<MockMediaSample> create(const MockSampleBox& box) { return adoptRef(new MockMediaSample(box)); }
+ static Ref<MockMediaSample> create(const MockSampleBox& box) { return adoptRef(*new MockMediaSample(box)); }
virtual ~MockMediaSample() { }
- virtual MediaTime presentationTime() const override { return m_box.presentationTimestamp(); }
- virtual MediaTime decodeTime() const override { return m_box.decodeTimestamp(); }
- virtual MediaTime duration() const override { return m_box.duration(); }
- virtual AtomicString trackID() const override { return m_id; }
-
- virtual SampleFlags flags() const override;
- virtual PlatformSample platformSample() override;
-
-protected:
+private:
MockMediaSample(const MockSampleBox& box)
: m_box(box)
, m_id(String::format("%d", box.trackID()))
{
}
+ MediaTime presentationTime() const override { return m_box.presentationTimestamp(); }
+ MediaTime decodeTime() const override { return m_box.decodeTimestamp(); }
+ MediaTime duration() const override { return m_box.duration(); }
+ AtomicString trackID() const override { return m_id; }
+ void setTrackID(const String& id) override { m_id = id; }
+ size_t sizeInBytes() const override { return sizeof(m_box); }
+ SampleFlags flags() const override;
+ PlatformSample platformSample() override;
+ FloatSize presentationSize() const override { return FloatSize(); }
+ void dump(PrintStream&) const override;
+ void offsetTimestampsBy(const MediaTime& offset) override { m_box.offsetTimestampsBy(offset); }
+ void setTimestamps(const MediaTime& presentationTimestamp, const MediaTime& decodeTimestamp) override { m_box.setTimestamps(presentationTimestamp, decodeTimestamp); }
+ bool isDivisable() const override { return false; }
+ std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime&) override { return {nullptr, nullptr}; }
+ Ref<MediaSample> createNonDisplayingCopy() const override;
+
+ unsigned generation() const { return m_box.generation(); }
+
MockSampleBox m_box;
AtomicString m_id;
};
@@ -68,8 +79,10 @@ protected:
MediaSample::SampleFlags MockMediaSample::flags() const
{
unsigned flags = None;
- if (m_box.flags() & MockSampleBox::IsSync)
+ if (m_box.isSync())
flags |= IsSync;
+ if (m_box.isNonDisplaying())
+ flags |= IsNonDisplaying;
return SampleFlags(flags);
}
@@ -79,15 +92,27 @@ PlatformSample MockMediaSample::platformSample()
return sample;
}
+void MockMediaSample::dump(PrintStream& out) const
+{
+ out.print("{PTS(", presentationTime(), "), DTS(", decodeTime(), "), duration(", duration(), "), flags(", (int)flags(), "), generation(", generation(), ")}");
+}
+
+Ref<MediaSample> MockMediaSample::createNonDisplayingCopy() const
+{
+ auto copy = MockMediaSample::create(m_box);
+ copy->m_box.setFlag(MockSampleBox::IsNonDisplaying);
+ return WTFMove(copy);
+}
+
class MockMediaDescription final : public MediaDescription {
public:
static RefPtr<MockMediaDescription> create(const MockTrackBox& box) { return adoptRef(new MockMediaDescription(box)); }
virtual ~MockMediaDescription() { }
- virtual AtomicString codec() const override { return m_box.codec(); }
- virtual bool isVideo() const override { return m_box.kind() == MockTrackBox::Video; }
- virtual bool isAudio() const override { return m_box.kind() == MockTrackBox::Audio; }
- virtual bool isText() const override { return m_box.kind() == MockTrackBox::Text; }
+ AtomicString codec() const override { return m_box.codec(); }
+ bool isVideo() const override { return m_box.kind() == MockTrackBox::Video; }
+ bool isAudio() const override { return m_box.kind() == MockTrackBox::Audio; }
+ bool isText() const override { return m_box.kind() == MockTrackBox::Text; }
protected:
MockMediaDescription(const MockTrackBox& box) : m_box(box) { }
@@ -114,12 +139,12 @@ void MockSourceBufferPrivate::setClient(SourceBufferPrivateClient* client)
m_client = client;
}
-SourceBufferPrivate::AppendResult MockSourceBufferPrivate::append(const unsigned char* data, unsigned length)
+void MockSourceBufferPrivate::append(const unsigned char* data, unsigned length)
{
m_inputBuffer.append(data, length);
- AppendResult result = AppendSucceeded;
+ SourceBufferPrivateClient::AppendResult result = SourceBufferPrivateClient::AppendSucceeded;
- while (m_inputBuffer.size() && result == AppendSucceeded) {
+ while (m_inputBuffer.size() && result == SourceBufferPrivateClient::AppendSucceeded) {
RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_inputBuffer.data(), m_inputBuffer.size());
size_t boxLength = MockBox::peekLength(buffer.get());
if (boxLength > buffer->byteLength())
@@ -133,12 +158,13 @@ SourceBufferPrivate::AppendResult MockSourceBufferPrivate::append(const unsigned
MockSampleBox sampleBox = MockSampleBox(buffer.get());
didReceiveSample(sampleBox);
} else
- result = ParsingFailed;
+ result = SourceBufferPrivateClient::ParsingFailed;
m_inputBuffer.remove(0, boxLength);
}
- return result;
+ if (m_client)
+ m_client->sourceBufferPrivateAppendComplete(result);
}
void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitializationBox& initBox)
@@ -169,7 +195,7 @@ void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitiali
}
}
- m_client->sourceBufferPrivateDidReceiveInitializationSegment(this, segment);
+ m_client->sourceBufferPrivateDidReceiveInitializationSegment(segment);
}
@@ -178,13 +204,17 @@ void MockSourceBufferPrivate::didReceiveSample(const MockSampleBox& sampleBox)
if (!m_client)
return;
- m_client->sourceBufferPrivateDidReceiveSample(this, MockMediaSample::create(sampleBox));
+ m_client->sourceBufferPrivateDidReceiveSample(MockMediaSample::create(sampleBox));
}
void MockSourceBufferPrivate::abort()
{
}
+void MockSourceBufferPrivate::resetParserState()
+{
+}
+
void MockSourceBufferPrivate::removedFromMediaSource()
{
if (m_mediaSource)
@@ -202,32 +232,27 @@ void MockSourceBufferPrivate::setReadyState(MediaPlayer::ReadyState readyState)
m_mediaSource->player()->setReadyState(readyState);
}
-void MockSourceBufferPrivate::evictCodedFrames()
-{
- // No-op.
-}
-
-bool MockSourceBufferPrivate::isFull()
-{
- return false;
-}
-
void MockSourceBufferPrivate::setActive(bool isActive)
{
if (m_mediaSource)
m_mediaSource->sourceBufferPrivateDidChangeActiveState(this, isActive);
}
-void MockSourceBufferPrivate::enqueueSample(PassRefPtr<MediaSample> sample, AtomicString)
+Vector<String> MockSourceBufferPrivate::enqueuedSamplesForTrackID(const AtomicString&)
+{
+ return m_enqueuedSamples;
+}
+
+void MockSourceBufferPrivate::enqueueSample(Ref<MediaSample>&& sample, const AtomicString&)
{
- if (!m_mediaSource || !sample)
+ if (!m_mediaSource)
return;
PlatformSample platformSample = sample->platformSample();
if (platformSample.type != PlatformSample::MockSampleBoxType)
return;
- MockSampleBox* box = platformSample.sample.mockSampleBox;
+ auto* box = platformSample.sample.mockSampleBox;
if (!box)
return;
@@ -237,37 +262,32 @@ void MockSourceBufferPrivate::enqueueSample(PassRefPtr<MediaSample> sample, Atom
if (box->isDropped())
m_mediaSource->incrementDroppedFrames();
if (box->isDelayed())
- m_mediaSource->incrementTotalFrameDelayBy(1);
+ m_mediaSource->incrementTotalFrameDelayBy(MediaTime(1, 1));
+
+ m_enqueuedSamples.append(toString(sample.get()));
}
bool MockSourceBufferPrivate::hasVideo() const
{
- if (!m_client)
- return false;
-
- return m_client->sourceBufferPrivateHasVideo(this);
+ return m_client && m_client->sourceBufferPrivateHasVideo();
}
bool MockSourceBufferPrivate::hasAudio() const
{
- if (!m_client)
- return false;
-
- return m_client->sourceBufferPrivateHasAudio(this);
+ return m_client && m_client->sourceBufferPrivateHasAudio();
}
-
MediaTime MockSourceBufferPrivate::fastSeekTimeForMediaTime(const MediaTime& time, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold)
{
if (m_client)
- return m_client->sourceBufferPrivateFastSeekTimeForMediaTime(this, time, negativeThreshold, positiveThreshold);
+ return m_client->sourceBufferPrivateFastSeekTimeForMediaTime(time, negativeThreshold, positiveThreshold);
return time;
}
void MockSourceBufferPrivate::seekToTime(const MediaTime& time)
{
if (m_client)
- m_client->sourceBufferPrivateSeekToTime(this, time);
+ m_client->sourceBufferPrivateSeekToTime(time);
}
}
diff --git a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h
index 109d032db..49650553b 100644
--- a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h
+++ b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -23,17 +23,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef MockSourceBufferPrivate_h
-#define MockSourceBufferPrivate_h
+#pragma once
#if ENABLE(MEDIA_SOURCE)
#include "SourceBufferPrivate.h"
-#include <wtf/HashMap.h>
-#include <wtf/MediaTime.h>
-#include <wtf/RefPtr.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
namespace WebCore {
@@ -45,7 +39,7 @@ class MockSampleBox;
class TimeRanges;
class VideoTrackPrivate;
-class MockSourceBufferPrivate : public SourceBufferPrivate {
+class MockSourceBufferPrivate final : public SourceBufferPrivate {
public:
static RefPtr<MockSourceBufferPrivate> create(MockMediaSourcePrivate*);
virtual ~MockSourceBufferPrivate();
@@ -62,25 +56,27 @@ private:
explicit MockSourceBufferPrivate(MockMediaSourcePrivate*);
// SourceBufferPrivate overrides
- virtual void setClient(SourceBufferPrivateClient*) override;
- virtual AppendResult append(const unsigned char* data, unsigned length) override;
- virtual void abort() override;
- virtual void removedFromMediaSource() override;
- virtual MediaPlayer::ReadyState readyState() const override;
- virtual void setReadyState(MediaPlayer::ReadyState) override;
- virtual void evictCodedFrames() override;
- virtual bool isFull() override;
-
- virtual void flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString) override { }
- virtual void enqueueSample(PassRefPtr<MediaSample>, AtomicString) override;
- virtual bool isReadyForMoreSamples(AtomicString) override { return true; }
- virtual void setActive(bool) override;
+ void setClient(SourceBufferPrivateClient*) final;
+ void append(const unsigned char* data, unsigned length) final;
+ void abort() final;
+ void resetParserState() final;
+ void removedFromMediaSource() final;
+ MediaPlayer::ReadyState readyState() const final;
+ void setReadyState(MediaPlayer::ReadyState) final;
+
+ void flush(const AtomicString&) final { m_enqueuedSamples.clear(); }
+ void enqueueSample(Ref<MediaSample>&&, const AtomicString&) final;
+ bool isReadyForMoreSamples(const AtomicString&) final { return true; }
+ void setActive(bool) final;
+
+ Vector<String> enqueuedSamplesForTrackID(const AtomicString&) final;
void didReceiveInitializationSegment(const MockInitializationBox&);
void didReceiveSample(const MockSampleBox&);
MockMediaSourcePrivate* m_mediaSource;
SourceBufferPrivateClient* m_client;
+ Vector<String> m_enqueuedSamples;
Vector<char> m_inputBuffer;
};
@@ -88,6 +84,3 @@ private:
}
#endif // ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION)
-
-#endif
-
diff --git a/Source/WebCore/platform/mock/mediasource/MockTracks.h b/Source/WebCore/platform/mock/mediasource/MockTracks.h
index 3f8eded74..073f36863 100644
--- a/Source/WebCore/platform/mock/mediasource/MockTracks.h
+++ b/Source/WebCore/platform/mock/mediasource/MockTracks.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* 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
+ * 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 COMPUTER, INC. OR
+ * 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
@@ -23,8 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef MockTracks_h
-#define MockTracks_h
+#pragma once
#if ENABLE(MEDIA_SOURCE)
@@ -37,7 +36,7 @@ namespace WebCore {
class MockAudioTrackPrivate : public AudioTrackPrivate {
public:
- static RefPtr<MockAudioTrackPrivate> create(const MockTrackBox& box) { return adoptRef(new MockAudioTrackPrivate(box)); }
+ static Ref<MockAudioTrackPrivate> create(const MockTrackBox& box) { return adoptRef(*new MockAudioTrackPrivate(box)); }
virtual ~MockAudioTrackPrivate() { }
virtual AtomicString id() const { return m_id; }
@@ -45,7 +44,7 @@ public:
protected:
MockAudioTrackPrivate(const MockTrackBox& box)
: m_box(box)
- , m_id(String::format("%d", box.trackID()))
+ , m_id(AtomicString::number(box.trackID()))
{
}
MockTrackBox m_box;
@@ -63,7 +62,7 @@ protected:
MockTextTrackPrivate(const MockTrackBox& box)
: InbandTextTrackPrivate(InbandTextTrackPrivate::Generic)
, m_box(box)
- , m_id(String::format("%d", box.trackID()))
+ , m_id(AtomicString::number(box.trackID()))
{
}
MockTrackBox m_box;
@@ -81,7 +80,7 @@ public:
protected:
MockVideoTrackPrivate(const MockTrackBox& box)
: m_box(box)
- , m_id(String::format("%d", box.trackID()))
+ , m_id(AtomicString::number(box.trackID()))
{
}
MockTrackBox m_box;
@@ -91,5 +90,3 @@ protected:
}
#endif
-
-#endif