Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / test / data / media / peerconnection-call.html
index 511380d..c1ba136 100644 (file)
   var maybeForceIsac16K = function(sdp) { return sdp; };
   function forceIsac16KInSdp() {
     maybeForceIsac16K = function(sdp) {
+      if (sdp.search('m=audio') == -1)
+        return sdp;
+
       sdp = sdp.replace(/m=audio (\d+) RTP\/SAVPF.*\r\n/g,
                         'm=audio $1 RTP/SAVPF 103 126\r\n');
       sdp = sdp.replace('a=fmtp:111 minptime=10', 'a=fmtp:103 minptime=10');
       if (sdp.search('a=rtpmap:103 ISAC/16000') == -1)
         failTest('Missing iSAC 16K codec on Android; cannot force codec.');
+
       return sdp;
     };
     sendValueToTest('isac-forced');
     waitForVideo('remote-view-2');
   }
 
+  // Test that we can setup a call with a video track and that the remote peer
+  // receives black frames if the local video track is disabled.
+  function callAndDisableLocalVideo(constraints) {
+    createConnections(null);
+    navigator.webkitGetUserMedia(constraints,
+        addStreamToBothConnectionsAndNegotiate, printGetUserMediaError);
+    detectVideoPlaying('remote-view-1',
+        function () {
+          assertEquals(gLocalStream.getVideoTracks().length, 1);
+          gLocalStream.getVideoTracks()[0].enabled = false;
+          waitForBlackVideo('remote-view-1');
+        });
+  }
+
   // Test that we can setup call with an audio and video track and check that
   // the video resolution is as expected.
   function callAndExpectResolution(constraints,
       waitForVideo('remote-view-2');
     });
   }
-  
+
   // Test that we can setup call with an audio and video track and
   // simulate that the remote peer don't support MSID.
   function callWithoutMsidAndBundle() {
         offerOptions);
   }
 
+  function callAndEnsureAudioIsPlaying(beLenient, constraints) {
+    createConnections(null);
+
+    // Add the local stream to gFirstConnection to play one-way audio.
+    navigator.webkitGetUserMedia(constraints,
+      addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError);
+
+    var onCallEstablished = function() {
+      ensureAudioPlaying(gSecondConnection, beLenient);
+    };
+
+    waitForConnectionToStabilize(gFirstConnection, onCallEstablished);
+  }
+
   function enableRemoteVideo(peerConnection, enabled) {
     remoteStream = peerConnection.getRemoteStreams()[0];
-    remoteVideoTrack = remoteStream.getVideoTracks()[0];
-    remoteVideoTrack.enabled = enabled;
+    remoteStream.getVideoTracks()[0].enabled = enabled;
   }
 
   function enableRemoteAudio(peerConnection, enabled) {
     remoteStream = peerConnection.getRemoteStreams()[0];
-    remoteAudioTrack = remoteStream.getAudioTracks()[0];
-    remoteAudioTrack.enabled = enabled;
+    remoteStream.getAudioTracks()[0].enabled = enabled;
   }
 
-  function callAndEnsureAudioIsPlaying(beLenient, constraints) {
-    createConnections(null);
-    navigator.webkitGetUserMedia(constraints,
-      addStreamToBothConnectionsAndNegotiate, printGetUserMediaError);
-
-    // Wait until we have gathered samples and can conclude if audio is playing.
-    addExpectedEvent();
-    var onCallEstablished = function() {
-      // Gather 50 samples per second for 2 seconds.
-      gatherAudioLevelSamples(gSecondConnection, 100, 50, function(samples) {
-        verifyAudioIsPlaying(samples, beLenient);
-        eventOccured();
-      });
-    };
+  function enableLocalVideo(peerConnection, enabled) {
+    localStream = peerConnection.getLocalStreams()[0];
+    localStream.getVideoTracks()[0].enabled = enabled;
+  }
 
-    waitForConnectionToStabilize(gFirstConnection, onCallEstablished);
+  function enableLocalAudio(peerConnection, enabled) {
+    localStream = peerConnection.getLocalStreams()[0];
+    localStream.getAudioTracks()[0].enabled = enabled;
   }
 
-  function callAndEnsureAudioTrackMutingWorks(beLenient) {
+  function callAndEnsureRemoteAudioTrackMutingWorks(beLenient) {
     callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
     setAllEventsOccuredHandler(function() {
-      // Call is up, now mute the track and check everything goes silent (give
-      // it a small delay though, we don't expect it to happen instantly).
+      setAllEventsOccuredHandler(reportTestSuccess);
+
+      // Call is up, now mute the remote track and check we stop playing out
+      // audio (after a small delay, we don't expect it to happen instantly).
       enableRemoteAudio(gSecondConnection, false);
+      ensureSilence(gSecondConnection);
+    });
+  }
 
-      setTimeout(function() {
-        gatherAudioLevelSamples(gSecondConnection, 100, 50, function(samples) {
-          verifyIsSilent(samples);
-          reportTestSuccess();
-        });
-      }, 500);
+  function callAndEnsureLocalAudioTrackMutingWorks(beLenient) {
+    callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
+    setAllEventsOccuredHandler(function() {
+      setAllEventsOccuredHandler(reportTestSuccess);
+
+      // Call is up, now mute the local track of the sending side and ensure
+      // the receiving side stops receiving audio.
+      enableLocalAudio(gFirstConnection, false);
+      ensureSilence(gSecondConnection);
     });
   }
 
   function callAndEnsureAudioTrackUnmutingWorks(beLenient) {
     callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
     setAllEventsOccuredHandler(function() {
+      setAllEventsOccuredHandler(reportTestSuccess);
+
       // Mute, wait a while, unmute, verify audio gets back up.
       // (Also, ensure video muting doesn't affect audio).
       enableRemoteAudio(gSecondConnection, false);
       }, 500);
 
       setTimeout(function() {
-        // Sample for four seconds here; it can take a bit of time for audio to
-        // get back up after the unmute.
-        gatherAudioLevelSamples(gSecondConnection, 200, 50, function(samples) {
-          verifyAudioIsPlaying(samples, beLenient);
-          reportTestSuccess();
-        });
+        ensureAudioPlaying(gSecondConnection, beLenient);
       }, 1500);
     });
   }
 
+  function callAndEnsureLocalVideoMutingDoesntMuteAudio(beLenient) {
+    callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
+    setAllEventsOccuredHandler(function() {
+      setAllEventsOccuredHandler(reportTestSuccess);
+      enableLocalVideo(gFirstConnection, false);
+      ensureAudioPlaying(gSecondConnection, beLenient);
+    });
+  }
+
+  function callAndEnsureRemoteVideoMutingDoesntMuteAudio(beLenient) {
+    callAndEnsureAudioIsPlaying(beLenient, {audio: true, video: true});
+    setAllEventsOccuredHandler(function() {
+      setAllEventsOccuredHandler(reportTestSuccess);
+      enableRemoteVideo(gSecondConnection, false);
+      ensureAudioPlaying(gSecondConnection, beLenient);
+    });
+  }
+
   function callAndEnsureVideoTrackMutingWorks() {
     createConnections(null);
     navigator.webkitGetUserMedia({audio: true, video: true},
   }
 
   function receiveOffer(offerSdp, caller, callee) {
-    console.log("Receiving offer...\n" + offerSdp);
+    console.log("Receiving offer...");
     offerSdp = transformRemoteSdp(offerSdp);
 
     var parsedOffer = new RTCSessionDescription({ type: 'offer',
       <td>Remote Stream for Connection 4</td>
     </tr>
     <tr>
-      <td><video width="320" height="240" id="local-view"
-          autoplay="autoplay"></video></td>
-      <td><video width="320" height="240" id="remote-view-1"
-          autoplay="autoplay"></video></td>
-      <td><video width="320" height="240" id="remote-view-2"
-          autoplay="autoplay"></video></td>
-      <td><video width="320" height="240" id="remote-view-3"
-          autoplay="autoplay"></video></td>
-      <td><video width="320" height="240" id="remote-view-4"
-          autoplay="autoplay"></video></td>
+      <td><video width="320" height="240" id="local-view" autoplay muted>
+          </video></td>
+      <td><video width="320" height="240" id="remote-view-1" autoplay>
+          </video></td>
+      <td><video width="320" height="240" id="remote-view-2" autoplay>
+          </video></td>
+      <td><video width="320" height="240" id="remote-view-3" autoplay>
+          </video></td>
+      <td><video width="320" height="240" id="remote-view-4" autoplay>
+          </video></td>
       <!-- Canvases are named after their corresponding video elements. -->
       <td><canvas width="320" height="240" id="remote-view-1-canvas"
           style="display:none"></canvas></td>