Changeset 160693 in webkit


Ignore:
Timestamp:
Dec 16, 2013 8:12:19 PM (10 years ago)
Author:
thiago.lacerda@openbossa.org
Message:

Checking RTCPeerConnection signalingState before setting local/remoteDescription
https://bugs.webkit.org/show_bug.cgi?id=125655

Reviewed by Eric Carlson.

Before setting a session description RTCPeerConnection must check if it is in valid state for that SDP type.

Source/WebCore:

New tests: fast/mediastream/RTCPeerConnection-have-local-answer.html

fast/mediastream/RTCPeerConnection-have-local-offer.html
fast/mediastream/RTCPeerConnection-have-local-pranswer.html
fast/mediastream/RTCPeerConnection-have-remote-offer.html
fast/mediastream/RTCPeerConnection-have-remote-pranswer.html
fast/mediastream/RTCPeerConnection-stable.html

Modified: fast/mediastream/RTCPeerConnection-remoteDescription.html

  • Modules/mediastream/RTCPeerConnection.cpp:

(WebCore::RTCPeerConnection::checkStateForLocalDescription): Checks if the current state of RTCPeerConnection is
valid for the local SDP that is being set.
(WebCore::RTCPeerConnection::checkStateForRemoteDescription): Checks if the current state of RTCPeerConnection
is valid for the remote SDP that is being set.
(WebCore::RTCPeerConnection::setLocalDescription): Now calls checkStateForLocalDescription prior to set the
local SDP.
(WebCore::RTCPeerConnection::setRemoteDescription): Now Calls checkStateForRemoteDescription prior to set the
remote SDP.

  • Modules/mediastream/RTCPeerConnection.h:
  • platform/mock/RTCNotifiersMock.cpp: Adding new class to notify RTCPeerConnection about a signaling state

change: SignalingStateNotifier.
(WebCore::SignalingStateNotifier::SignalingStateNotifier):
(WebCore::SignalingStateNotifier::fire):

  • platform/mock/RTCNotifiersMock.h:
  • platform/mock/RTCPeerConnectionHandlerMock.cpp:

(WebCore::RTCPeerConnectionHandlerMock::signalingStateFromSDP): Defines the new state that RTCPeerConnection
should be, according the SDP that is being set.
(WebCore::RTCPeerConnectionHandlerMock::setLocalDescription): Calls signalingStateFromSDP, in order to get the
new signaling state and notify RTCPeerConnection object.
(WebCore::RTCPeerConnectionHandlerMock::setRemoteDescription): Ditto.

  • platform/mock/RTCPeerConnectionHandlerMock.h:

LayoutTests:

  • fast/mediastream/RTCPeerConnection-have-local-answer.html: Added.
  • fast/mediastream/RTCPeerConnection-have-local-offer-expected.txt: Added.
  • fast/mediastream/RTCPeerConnection-have-local-offer.html: Added.
  • fast/mediastream/RTCPeerConnection-have-local-pranswer-expected.txt: Added.
  • fast/mediastream/RTCPeerConnection-have-local-pranswer.html: Added.
  • fast/mediastream/RTCPeerConnection-have-remote-offer-expected.txt: Added.
  • fast/mediastream/RTCPeerConnection-have-remote-offer.html: Added.
  • fast/mediastream/RTCPeerConnection-have-remote-pranswer-expected.txt: Added.
  • fast/mediastream/RTCPeerConnection-have-remote-pranswer.html: Added.
  • fast/mediastream/RTCPeerConnection-remoteDescription-expected.txt:
  • fast/mediastream/RTCPeerConnection-remoteDescription.html:
  • fast/mediastream/RTCPeerConnection-stable-expected.txt: Added.
  • fast/mediastream/RTCPeerConnection-stable.html: Added.
Location:
trunk
Files:
11 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r160670 r160693  
     12013-12-16  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
     2
     3        Checking RTCPeerConnection signalingState before setting local/remoteDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=125655
     5
     6        Reviewed by Eric Carlson.
     7
     8        Before setting a session description RTCPeerConnection must check if it is in valid state for that SDP type.
     9
     10        * fast/mediastream/RTCPeerConnection-have-local-answer.html: Added.
     11        * fast/mediastream/RTCPeerConnection-have-local-offer-expected.txt: Added.
     12        * fast/mediastream/RTCPeerConnection-have-local-offer.html: Added.
     13        * fast/mediastream/RTCPeerConnection-have-local-pranswer-expected.txt: Added.
     14        * fast/mediastream/RTCPeerConnection-have-local-pranswer.html: Added.
     15        * fast/mediastream/RTCPeerConnection-have-remote-offer-expected.txt: Added.
     16        * fast/mediastream/RTCPeerConnection-have-remote-offer.html: Added.
     17        * fast/mediastream/RTCPeerConnection-have-remote-pranswer-expected.txt: Added.
     18        * fast/mediastream/RTCPeerConnection-have-remote-pranswer.html: Added.
     19        * fast/mediastream/RTCPeerConnection-remoteDescription-expected.txt:
     20        * fast/mediastream/RTCPeerConnection-remoteDescription.html:
     21        * fast/mediastream/RTCPeerConnection-stable-expected.txt: Added.
     22        * fast/mediastream/RTCPeerConnection-stable.html: Added.
     23
    1242013-12-16  Oliver Hunt  <oliver@apple.com>
    225
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-remoteDescription-expected.txt

    r144808 r160693  
    88PASS pc.setRemoteDescription(sessionDescription, requestSucceeded2, requestFailed2); did not throw exception.
    99PASS requestFailed was called.
    10 PASS pc.remoteDescription.type is "answer"
     10PASS pc.remoteDescription.type is "offer"
    1111PASS pc.remoteDescription.sdp is "remote"
    12 PASS pc.remoteDescription.type is "answer"
     12PASS pc.remoteDescription.type is "offer"
    1313PASS pc.remoteDescription.sdp is "remote"
    1414PASS successfullyParsed is true
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-remoteDescription.html

    r158991 r160693  
    1414                testPassed('requestFailed was called.');
    1515
    16                 shouldBeEqualToString('pc.remoteDescription.type', "answer");
     16                shouldBeEqualToString('pc.remoteDescription.type', "offer");
    1717                shouldBeEqualToString('pc.remoteDescription.sdp', "remote");
    1818                pc.close();
    19                 shouldBeEqualToString('pc.remoteDescription.type', "answer");
     19                shouldBeEqualToString('pc.remoteDescription.type', "offer");
    2020                shouldBeEqualToString('pc.remoteDescription.sdp', "remote");
    2121
     
    3939                testPassed('requestSucceeded was called.');
    4040
    41                 sessionDescription = new RTCSessionDescription({type:"offer", sdp:"local"});
     41                sessionDescription = new RTCSessionDescription({type:"answer", sdp:"local"});
    4242                shouldNotThrow('pc.setRemoteDescription(sessionDescription, requestSucceeded2, requestFailed2);');
    4343            }
    4444
    4545            pc = new webkitRTCPeerConnection({iceServers:[]});
    46             var sessionDescription = new RTCSessionDescription({type:"answer", sdp:"remote"});
     46            var sessionDescription = new RTCSessionDescription({type:"offer", sdp:"remote"});
    4747            shouldNotThrow('pc.setRemoteDescription(sessionDescription, requestSucceeded1, requestFailed1);');
    4848
  • trunk/Source/WebCore/ChangeLog

    r160690 r160693  
     12013-12-16  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
     2
     3        Checking RTCPeerConnection signalingState before setting local/remoteDescription
     4        https://bugs.webkit.org/show_bug.cgi?id=125655
     5
     6        Reviewed by Eric Carlson.
     7
     8        Before setting a session description RTCPeerConnection must check if it is in valid state for that SDP type.
     9
     10        New tests: fast/mediastream/RTCPeerConnection-have-local-answer.html
     11               fast/mediastream/RTCPeerConnection-have-local-offer.html
     12               fast/mediastream/RTCPeerConnection-have-local-pranswer.html
     13               fast/mediastream/RTCPeerConnection-have-remote-offer.html
     14               fast/mediastream/RTCPeerConnection-have-remote-pranswer.html
     15               fast/mediastream/RTCPeerConnection-stable.html
     16
     17        Modified: fast/mediastream/RTCPeerConnection-remoteDescription.html
     18
     19        * Modules/mediastream/RTCPeerConnection.cpp:
     20        (WebCore::RTCPeerConnection::checkStateForLocalDescription): Checks if the current state of RTCPeerConnection is
     21        valid for the local SDP that is being set.
     22        (WebCore::RTCPeerConnection::checkStateForRemoteDescription): Checks if the current state of RTCPeerConnection
     23        is valid for the remote SDP that is being set.
     24        (WebCore::RTCPeerConnection::setLocalDescription): Now calls checkStateForLocalDescription prior to set the
     25        local SDP.
     26        (WebCore::RTCPeerConnection::setRemoteDescription): Now Calls checkStateForRemoteDescription prior to set the
     27        remote SDP.
     28        * Modules/mediastream/RTCPeerConnection.h:
     29        * platform/mock/RTCNotifiersMock.cpp: Adding new class to notify RTCPeerConnection about a signaling state
     30        change: SignalingStateNotifier.
     31        (WebCore::SignalingStateNotifier::SignalingStateNotifier):
     32        (WebCore::SignalingStateNotifier::fire):
     33        * platform/mock/RTCNotifiersMock.h:
     34        * platform/mock/RTCPeerConnectionHandlerMock.cpp:
     35        (WebCore::RTCPeerConnectionHandlerMock::signalingStateFromSDP): Defines the new state that RTCPeerConnection
     36        should be, according the SDP that is being set.
     37        (WebCore::RTCPeerConnectionHandlerMock::setLocalDescription): Calls signalingStateFromSDP, in order to get the
     38        new signaling state and notify RTCPeerConnection object.
     39        (WebCore::RTCPeerConnectionHandlerMock::setRemoteDescription): Ditto.
     40        * platform/mock/RTCPeerConnectionHandlerMock.h:
     41
    1422013-12-16  Tim Horton  <timothy_horton@apple.com>
    243
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

    r160553 r160693  
    6363#include "ScriptExecutionContext.h"
    6464#include "VoidCallback.h"
     65#include <wtf/Functional.h>
     66#include <wtf/MainThread.h>
    6567
    6668namespace WebCore {
     
    211213}
    212214
     215bool RTCPeerConnection::checkStateForLocalDescription(RTCSessionDescription* localDescription)
     216{
     217    if (localDescription->type() == "offer")
     218        return m_signalingState == SignalingStateStable || m_signalingState == SignalingStateHaveLocalOffer;
     219    if (localDescription->type() == "answer")
     220        return m_signalingState == SignalingStateHaveRemoteOffer || m_signalingState == SignalingStateHaveLocalPrAnswer;
     221    if (localDescription->type() == "pranswer")
     222        return m_signalingState == SignalingStateHaveLocalPrAnswer || m_signalingState == SignalingStateHaveRemoteOffer;
     223
     224    return false;
     225}
     226
     227bool RTCPeerConnection::checkStateForRemoteDescription(RTCSessionDescription* remoteDescription)
     228{
     229    if (remoteDescription->type() == "offer")
     230        return m_signalingState == SignalingStateStable || m_signalingState == SignalingStateHaveRemoteOffer;
     231    if (remoteDescription->type() == "answer")
     232        return m_signalingState == SignalingStateHaveLocalOffer || m_signalingState == SignalingStateHaveRemotePrAnswer;
     233    if (remoteDescription->type() == "pranswer")
     234        return m_signalingState == SignalingStateHaveRemotePrAnswer || m_signalingState == SignalingStateHaveLocalOffer;
     235
     236    return false;
     237}
     238
    213239void RTCPeerConnection::setLocalDescription(PassRefPtr<RTCSessionDescription> prpSessionDescription, PassRefPtr<VoidCallback> successCallback, PassRefPtr<RTCPeerConnectionErrorCallback> errorCallback, ExceptionCode& ec)
    214240{
     
    224250    }
    225251
     252    if (!checkStateForLocalDescription(sessionDescription.get())) {
     253        RefPtr<DOMError> error = DOMError::create(RTCPeerConnectionHandler::invalidSessionDescriptionErrorName());
     254        callOnMainThread(bind(&RTCPeerConnectionErrorCallback::handleEvent, errorCallback.get(), error.release()));
     255        return;
     256    }
     257
    226258    RefPtr<RTCVoidRequestImpl> request = RTCVoidRequestImpl::create(scriptExecutionContext(), successCallback, errorCallback);
    227259    m_peerHandler->setLocalDescription(request.release(), sessionDescription->descriptor());
     
    250282    if (!sessionDescription) {
    251283        ec = TYPE_MISMATCH_ERR;
     284        return;
     285    }
     286
     287    if (!checkStateForRemoteDescription(sessionDescription.get())) {
     288        RefPtr<DOMError> error = DOMError::create(RTCPeerConnectionHandler::invalidSessionDescriptionErrorName());
     289        callOnMainThread(bind(&RTCPeerConnectionErrorCallback::handleEvent, errorCallback.get(), error.release()));
    252290        return;
    253291    }
  • trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h

    r160553 r160693  
    150150    void changeIceConnectionState(IceConnectionState);
    151151
     152    bool checkStateForLocalDescription(RTCSessionDescription*);
     153    bool checkStateForRemoteDescription(RTCSessionDescription*);
     154
    152155    SignalingState m_signalingState;
    153156    IceGatheringState m_iceGatheringState;
  • trunk/Source/WebCore/platform/mock/RTCNotifiersMock.cpp

    r160553 r160693  
    8181}
    8282
     83SignalingStateNotifier::SignalingStateNotifier(RTCPeerConnectionHandlerClient* client, RTCPeerConnectionHandlerClient::SignalingState signalingState)
     84    : m_client(client)
     85    , m_signalingState(signalingState)
     86{
     87}
     88
     89void SignalingStateNotifier::fire()
     90{
     91    m_client->didChangeSignalingState(m_signalingState);
     92}
     93
    8394RemoteDataChannelNotifier::RemoteDataChannelNotifier(RTCPeerConnectionHandlerClient* client)
    8495    : m_client(client)
  • trunk/Source/WebCore/platform/mock/RTCNotifiersMock.h

    r160553 r160693  
    7878};
    7979
     80class SignalingStateNotifier : public MockNotifier {
     81public:
     82    SignalingStateNotifier(RTCPeerConnectionHandlerClient*, RTCPeerConnectionHandlerClient::SignalingState);
     83
     84    void fire() OVERRIDE;
     85
     86private:
     87    RTCPeerConnectionHandlerClient* m_client;
     88    RTCPeerConnectionHandlerClient::SignalingState m_signalingState;
     89};
     90
    8091class RemoteDataChannelNotifier : public MockNotifier {
    8192public:
  • trunk/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.cpp

    r160553 r160693  
    8888}
    8989
     90RTCPeerConnectionHandlerClient::SignalingState RTCPeerConnectionHandlerMock::signalingStateFromSDP(RTCSessionDescriptionDescriptor* descriptor)
     91{
     92    if (descriptor->type() == "offer" && descriptor->sdp() == "local")
     93        return RTCPeerConnectionHandlerClient::SignalingStateHaveLocalOffer;
     94    if (descriptor->type() == "offer" && descriptor->sdp() == "remote")
     95        return RTCPeerConnectionHandlerClient::SignalingStateHaveRemoteOffer;
     96    if (descriptor->type() == "pranswer" && descriptor->sdp() == "local")
     97        return RTCPeerConnectionHandlerClient::SignalingStateHaveLocalPrAnswer;
     98    if (descriptor->type() == "pranswer" && descriptor->sdp() == "remote")
     99        return RTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer;
     100
     101    return RTCPeerConnectionHandlerClient::SignalingStateStable;
     102}
     103
    90104void RTCPeerConnectionHandlerMock::setLocalDescription(PassRefPtr<RTCVoidRequest> request, PassRefPtr<RTCSessionDescriptionDescriptor> descriptor)
    91105{
    92     RefPtr<VoidRequestNotifier> notifier;
     106    RefPtr<VoidRequestNotifier> voidNotifier;
     107    RefPtr<SignalingStateNotifier> signalingNotifier;
    93108    if (!descriptor.get() || descriptor->sdp() != "local")
    94         notifier = adoptRef(new VoidRequestNotifier(request, false));
     109        voidNotifier = adoptRef(new VoidRequestNotifier(request, false, RTCPeerConnectionHandler::internalErrorName()));
    95110    else {
    96111        m_localSessionDescription = descriptor;
    97         notifier = adoptRef(new VoidRequestNotifier(request, true));
     112        signalingNotifier = adoptRef(new SignalingStateNotifier(m_client, signalingStateFromSDP(m_localSessionDescription.get())));
     113        voidNotifier = adoptRef(new VoidRequestNotifier(request, true));
     114        m_timerEvents.append(adoptRef(new TimerEvent(this, signalingNotifier)));
    98115    }
    99116
    100     m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
     117    m_timerEvents.append(adoptRef(new TimerEvent(this, voidNotifier)));
    101118}
    102119
    103120void RTCPeerConnectionHandlerMock::setRemoteDescription(PassRefPtr<RTCVoidRequest> request, PassRefPtr<RTCSessionDescriptionDescriptor> descriptor)
    104121{
    105     RefPtr<VoidRequestNotifier> notifier;
     122    RefPtr<VoidRequestNotifier> voidNotifier;
     123    RefPtr<SignalingStateNotifier> signalingNotifier;
    106124    if (!descriptor.get() || descriptor->sdp() != "remote")
    107         notifier = adoptRef(new VoidRequestNotifier(request, false));
     125        voidNotifier = adoptRef(new VoidRequestNotifier(request, false, RTCPeerConnectionHandler::internalErrorName()));
    108126    else {
    109127        m_remoteSessionDescription = descriptor;
    110         notifier = adoptRef(new VoidRequestNotifier(request, true));
     128        signalingNotifier = adoptRef(new SignalingStateNotifier(m_client, signalingStateFromSDP(m_remoteSessionDescription.get())));
     129        voidNotifier = adoptRef(new VoidRequestNotifier(request, true));
     130        m_timerEvents.append(adoptRef(new TimerEvent(this, signalingNotifier)));
    111131    }
    112132
    113     m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
     133    m_timerEvents.append(adoptRef(new TimerEvent(this, voidNotifier)));
    114134}
    115135
  • trunk/Source/WebCore/platform/mock/RTCPeerConnectionHandlerMock.h

    r159840 r160693  
    3030
    3131#include "RTCPeerConnectionHandler.h"
     32#include "RTCPeerConnectionHandlerClient.h"
    3233#include "RTCSessionDescriptionDescriptor.h"
    3334#include "TimerEventBasedMock.h"
     
    6162
    6263private:
     64    RTCPeerConnectionHandlerClient::SignalingState signalingStateFromSDP(RTCSessionDescriptionDescriptor*);
    6365    RTCPeerConnectionHandlerClient* m_client;
    6466
Note: See TracChangeset for help on using the changeset viewer.