Title: [159823] trunk
Revision
159823
Author
[email protected]
Date
2013-11-27 13:03:51 -0800 (Wed, 27 Nov 2013)

Log Message

Adding MediaConstraintsMock class
https://bugs.webkit.org/show_bug.cgi?id=124902

Patch by Thiago de Barros Lacerda <[email protected]> on 2013-11-27
Reviewed by Eric Carlson.

Validate constraints used in RTCPeerConnection LayoutTests

Source/WebCore:

Existing test was updated.

* CMakeLists.txt:
* GNUmakefile.list.am:
* platform/mock/MediaConstraintsMock.cpp: Added.
* platform/mock/MediaConstraintsMock.h: Added.
* platform/mock/MockMediaStreamCenter.cpp:
(WebCore::MockMediaStreamCenter::validateRequestConstraints): Now using MediaConstraintsMock
(WebCore::MockMediaStreamCenter::createMediaStream): Ditto.
* platform/mock/RTCPeerConnectionHandlerMock.cpp:
(WebCore::RTCPeerConnectionHandlerMock::initialize): Ditto.

LayoutTests:

* fast/mediastream/RTCPeerConnection-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (159822 => 159823)


--- trunk/LayoutTests/ChangeLog	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/LayoutTests/ChangeLog	2013-11-27 21:03:51 UTC (rev 159823)
@@ -1,3 +1,14 @@
+2013-11-27  Thiago de Barros Lacerda  <[email protected]>
+
+        Adding MediaConstraintsMock class
+        https://bugs.webkit.org/show_bug.cgi?id=124902
+
+        Reviewed by Eric Carlson.
+
+        Validate constraints used in RTCPeerConnection LayoutTests
+
+        * fast/mediastream/RTCPeerConnection-expected.txt:
+
 2013-11-27  Bear Travis  <[email protected]>
 
         [CSS Shapes] Shape-Inside Should Default to 'auto'

Modified: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-expected.txt (159822 => 159823)


--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-expected.txt	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-expected.txt	2013-11-27 21:03:51 UTC (rev 159823)
@@ -45,16 +45,16 @@
 PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{valid_and_supported_1:0}]}); did not throw exception.
 PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{valid_and_supported_1:0},{valid_and_supported_2:0}]}); did not throw exception.
 PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{valid_but_unsupported_1:0},{valid_but_unsupported_2:0}]}); did not throw exception.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_and_supported_1:66}}); threw exception Error: NotSupportedError: DOM Exception 9.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{invalid:1}}); threw exception Error: NotSupportedError: DOM Exception 9.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_but_unsupported_1:1}}); threw exception Error: NotSupportedError: DOM Exception 9.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_but_unsupported_1:1, valid_and_supported_1:1}}); threw exception Error: NotSupportedError: DOM Exception 9.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:{valid_and_supported_1:0}}); threw exception Error: TypeMismatchError: DOM Exception 17.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{valid_and_supported_1:0,valid_and_supported_2:0}]}); threw exception Error: TypeMismatchError: DOM Exception 17.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{invalid:0}]}); threw exception Error: NotSupportedError: DOM Exception 9.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_and_supported_1:1}); threw exception Error: TypeMismatchError: DOM Exception 17.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_but_unsupported_1:1}); threw exception Error: TypeMismatchError: DOM Exception 17.
-PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_and_supported_2:1, mandatory:{valid_and_supported_1:1}}); threw exception Error: TypeMismatchError: DOM Exception 17.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_and_supported_1:66}}); threw exception TypeError: Error creating RTCPeerConnection.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{invalid:1}}); threw exception TypeError: Error creating RTCPeerConnection.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_but_unsupported_1:1}}); threw exception TypeError: Error creating RTCPeerConnection.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {mandatory:{valid_but_unsupported_1:1, valid_and_supported_1:1}}); threw exception TypeError: Error creating RTCPeerConnection.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:{valid_and_supported_1:0}}); threw exception TypeError: Invalid RTCPeerConnection constructor arguments.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{valid_and_supported_1:0,valid_and_supported_2:0}]}); threw exception TypeError: Invalid RTCPeerConnection constructor arguments.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {optional:[{invalid:0}]}); threw exception TypeError: Error creating RTCPeerConnection.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_and_supported_1:1}); threw exception TypeError: Invalid RTCPeerConnection constructor arguments.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_but_unsupported_1:1}); threw exception TypeError: Invalid RTCPeerConnection constructor arguments.
+PASS new webkitRTCPeerConnection({iceServers:[]}, {valid_and_supported_2:1, mandatory:{valid_and_supported_1:1}}); threw exception TypeError: Invalid RTCPeerConnection constructor arguments.
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/Source/WebCore/CMakeLists.txt (159822 => 159823)


--- trunk/Source/WebCore/CMakeLists.txt	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/Source/WebCore/CMakeLists.txt	2013-11-27 21:03:51 UTC (rev 159823)
@@ -2028,6 +2028,7 @@
     platform/mock/DeviceMotionClientMock.cpp
     platform/mock/DeviceOrientationClientMock.cpp
     platform/mock/GeolocationClientMock.cpp
+    platform/mock/MediaConstraintsMock.cpp
     platform/mock/MockMediaStreamCenter.cpp
     platform/mock/RTCDataChannelHandlerMock.cpp
     platform/mock/RTCNotifiersMock.cpp

Modified: trunk/Source/WebCore/ChangeLog (159822 => 159823)


--- trunk/Source/WebCore/ChangeLog	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/Source/WebCore/ChangeLog	2013-11-27 21:03:51 UTC (rev 159823)
@@ -1,3 +1,24 @@
+2013-11-27  Thiago de Barros Lacerda  <[email protected]>
+
+        Adding MediaConstraintsMock class
+        https://bugs.webkit.org/show_bug.cgi?id=124902
+
+        Reviewed by Eric Carlson.
+
+        Validate constraints used in RTCPeerConnection LayoutTests
+
+        Existing test was updated.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * platform/mock/MediaConstraintsMock.cpp: Added.
+        * platform/mock/MediaConstraintsMock.h: Added.
+        * platform/mock/MockMediaStreamCenter.cpp:
+        (WebCore::MockMediaStreamCenter::validateRequestConstraints): Now using MediaConstraintsMock
+        (WebCore::MockMediaStreamCenter::createMediaStream): Ditto.
+        * platform/mock/RTCPeerConnectionHandlerMock.cpp:
+        (WebCore::RTCPeerConnectionHandlerMock::initialize): Ditto.
+
 2013-11-27  Bear Travis  <[email protected]>
 
         [CSS Shapes] Shape-Inside Should Default to 'auto'

Modified: trunk/Source/WebCore/GNUmakefile.list.am (159822 => 159823)


--- trunk/Source/WebCore/GNUmakefile.list.am	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2013-11-27 21:03:51 UTC (rev 159823)
@@ -5449,6 +5449,8 @@
 	Source/WebCore/platform/mock/DeviceOrientationClientMock.h \
 	Source/WebCore/platform/mock/GeolocationClientMock.cpp \
 	Source/WebCore/platform/mock/GeolocationClientMock.h \
+	Source/WebCore/platform/mock/MediaConstraintsMock.cpp \
+	Source/WebCore/platform/mock/MediaConstraintsMock.h \
 	Source/WebCore/platform/mock/MockMediaStreamCenter.cpp \
 	Source/WebCore/platform/mock/MockMediaStreamCenter.h \
 	Source/WebCore/platform/mock/RTCDataChannelHandlerMock.cpp \

Added: trunk/Source/WebCore/platform/mock/MediaConstraintsMock.cpp (0 => 159823)


--- trunk/Source/WebCore/platform/mock/MediaConstraintsMock.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mock/MediaConstraintsMock.cpp	2013-11-27 21:03:51 UTC (rev 159823)
@@ -0,0 +1,76 @@
+/*
+ * 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)

Added: trunk/Source/WebCore/platform/mock/MediaConstraintsMock.h (0 => 159823)


--- trunk/Source/WebCore/platform/mock/MediaConstraintsMock.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mock/MediaConstraintsMock.h	2013-11-27 21:03:51 UTC (rev 159823)
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+#ifndef MediaConstraintsMock_h
+#define MediaConstraintsMock_h
+
+#if ENABLE(MEDIA_STREAM)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class MediaConstraints;
+
+class MediaConstraintsMock {
+public:
+    static String verifyConstraints(PassRefPtr<MediaConstraints>);
+};
+
+} // namespace WebCore
+
+#endif // MockMediaConstraints_h
+
+#endif // ENABLE(MEDIA_STREAM)

Modified: trunk/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp (159822 => 159823)


--- trunk/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/Source/WebCore/platform/mock/MockMediaStreamCenter.cpp	2013-11-27 21:03:51 UTC (rev 159823)
@@ -1,6 +1,7 @@
 /*
  * 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
@@ -25,10 +26,12 @@
  */
 
 #include "config.h"
-#include "MockMediaStreamCenter.h"
 
 #if ENABLE(MEDIA_STREAM)
 
+#include "MockMediaStreamCenter.h"
+
+#include "MediaConstraintsMock.h"
 #include "MediaStream.h"
 #include "MediaStreamCreationClient.h"
 #include "MediaStreamPrivate.h"
@@ -125,43 +128,6 @@
     }
 }
 
-static bool isSupportedMockConstraint(const String& constraintName)
-{
-    return notFound != constraintName.find("_and_supported_");
-}
-
-static bool isValidMockConstraint(const String& constraintName)
-{
-    if (isSupportedMockConstraint(constraintName))
-        return true;
-    return notFound != constraintName.find("_but_unsupported_");
-}
-
-static String verifyConstraints(MediaConstraints* constraints)
-{
-    Vector<MediaConstraint> mandatoryConstraints;
-    constraints->getMandatoryConstraints(mandatoryConstraints);
-    if (mandatoryConstraints.size()) {
-        for (size_t i = 0; i < mandatoryConstraints.size(); ++i) {
-            const MediaConstraint& constraint = mandatoryConstraints[i];
-            if (!isSupportedMockConstraint(constraint.m_name) || constraint.m_value != "1")
-                return constraint.m_name;
-        }
-    }
-    
-    Vector<MediaConstraint> optionalConstraints;
-    constraints->getOptionalConstraints(optionalConstraints);
-    if (optionalConstraints.size()) {
-        for (size_t i = 0; i < optionalConstraints.size(); ++i) {
-            const MediaConstraint& constraint = optionalConstraints[i];
-            if (!isValidMockConstraint(constraint.m_name) || constraint.m_value != "0")
-                return constraint.m_name;
-        }
-    }
-    
-    return emptyString();
-}
-
 void MockMediaStreamCenter::validateRequestConstraints(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints)
 {
     RefPtr<MediaStreamCreationClient> client = prpQueryClient;
@@ -169,7 +135,7 @@
     ASSERT(client);
     
     if (audioConstraints) {
-        String invalidQuery = verifyConstraints(audioConstraints.get());
+        String invalidQuery = MediaConstraintsMock::verifyConstraints(audioConstraints);
         if (!invalidQuery.isEmpty()) {
             client->constraintsInvalid(invalidQuery);
             return;
@@ -177,7 +143,7 @@
     }
     
     if (videoConstraints) {
-        String invalidQuery = verifyConstraints(videoConstraints.get());
+        String invalidQuery = MediaConstraintsMock::verifyConstraints(videoConstraints);
         if (!invalidQuery.isEmpty()) {
             client->constraintsInvalid(invalidQuery);
             return;
@@ -198,7 +164,7 @@
     MockSourceMap& map = mockSourceMap();
 
     if (audioConstraints) {
-        String invalidQuery = verifyConstraints(audioConstraints.get());
+        String invalidQuery = MediaConstraintsMock::verifyConstraints(audioConstraints);
         if (!invalidQuery.isEmpty()) {
             client->failedToCreateStreamWithConstraintsError(invalidQuery);
             return;
@@ -214,7 +180,7 @@
     }
 
     if (videoConstraints) {
-        String invalidQuery = verifyConstraints(videoConstraints.get());
+        String invalidQuery = MediaConstraintsMock::verifyConstraints(videoConstraints);
         if (!invalidQuery.isEmpty()) {
             client->failedToCreateStreamWithConstraintsError(invalidQuery);
             return;

Modified: trunk/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp (159822 => 159823)


--- trunk/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp	2013-11-27 20:19:48 UTC (rev 159822)
+++ trunk/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp	2013-11-27 21:03:51 UTC (rev 159823)
@@ -29,6 +29,7 @@
 
 #include "RTCPeerConnectionHandlerMock.h"
 
+#include "MediaConstraintsMock.h"
 #include "NotImplemented.h"
 #include "RTCDTMFSenderHandler.h"
 #include "RTCDataChannelHandler.h"
@@ -45,11 +46,12 @@
 {
 }
 
-bool RTCPeerConnectionHandlerMock::initialize(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints>)
+bool RTCPeerConnectionHandlerMock::initialize(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints> constraints)
 {
-    // FIXME: once there is support in RTCPeerConnection + constraints, this should be taken into account here
-    // and a LayouTest for that must be added.
-    // https://bugs.webkit.org/show_bug.cgi?id=123093
+    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;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to