summaryrefslogtreecommitdiffstats
path: root/content/test
diff options
context:
space:
mode:
authorperkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 11:16:24 +0000
committerperkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 11:16:24 +0000
commit3a2a5fb9626ab6cbab9ffc8e10fe12d7c2226596 (patch)
tree11ff3e0e8f98a363971b393f0f45bfb89a79737a /content/test
parentfd0bf12219648789e985c0ee0100b90c4374ad6c (diff)
downloadchromium_src-3a2a5fb9626ab6cbab9ffc8e10fe12d7c2226596.zip
chromium_src-3a2a5fb9626ab6cbab9ffc8e10fe12d7c2226596.tar.gz
chromium_src-3a2a5fb9626ab6cbab9ffc8e10fe12d7c2226596.tar.bz2
Add simple test for VideoTrack.stop().
BUG= 293304 Review URL: https://codereview.chromium.org/68263016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235698 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/test')
-rw-r--r--content/test/data/media/getusermedia.html40
-rw-r--r--content/test/data/media/peerconnection-call.html6
-rw-r--r--content/test/data/media/webrtc_test_utilities.js46
3 files changed, 60 insertions, 32 deletions
diff --git a/content/test/data/media/getusermedia.html b/content/test/data/media/getusermedia.html
index 14ce8d5..6fbe5e5 100644
--- a/content/test/data/media/getusermedia.html
+++ b/content/test/data/media/getusermedia.html
@@ -5,19 +5,19 @@
$ = function(id) {
return document.getElementById(id);
};
-
+
var gLocalStream = null;
-
+
setAllEventsOccuredHandler(function() {
gLocalStream.stop();
- document.title = 'OK';
+ document.title = 'OK';
});
-
- // This test that a MediaStream can be created and a local preview
+
+ // This test that a MediaStream can be created and a local preview
// rendered.
function getUserMedia(constraints) {
- navigator.webkitGetUserMedia(constraints, displayAndWaitForVideo,
- failedCallback);
+ navigator.webkitGetUserMedia(constraints,
+ displayAndWaitForVideoToStartAndStop, failedCallback);
}
function getUserMediaWithAnalysis(constraints) {
@@ -25,22 +25,25 @@
constraints, displayAndWaitForAndAnalyzeVideo, failedCallback);
}
- // This test that a MediaStream can be cloned and that the clone can
+ // This test that a MediaStream can be cloned and that the clone can
// be rendered.
function getUserMediaAndClone() {
navigator.webkitGetUserMedia({video: true, audio: true},
createAndRenderClone, failedCallback);
}
-
+
function failedCallback(error) {
document.title = 'GetUserMedia call failed with code ' + error.code;
}
- function displayAndWaitForVideo(stream) {
+ function displayAndWaitForVideoToStartAndStop(stream) {
gLocalStream = stream;
var localStreamUrl = webkitURL.createObjectURL(stream);
$('local-view').src = localStreamUrl;
- waitForVideo('local-view');
+ document.title = 'Waiting for video...';
+ // Wait for video to play, then stop the track and wait for video to stop
+ // playing.
+ detectVideoPlaying('local-view', stopVideoTrack);
}
function displayAndWaitForAndAnalyzeVideo(stream) {
@@ -53,7 +56,7 @@
function createAndRenderClone(stream) {
gLocalStream = stream;
// TODO(perkj): --use-fake-device-for-media-stream do not currently
- // work with audio devices and not all bots has a microphone.
+ // work with audio devices and not all bots has a microphone.
new_stream = new webkitMediaStream();
new_stream.addTrack(stream.getVideoTracks()[0]);
expectEquals(new_stream.getVideoTracks().length, 1);
@@ -63,12 +66,17 @@
new_stream.removeTrack(new_stream.getAudioTracks()[0]);
expectEquals(new_stream.getAudioTracks().length, 0);
}
-
+
var newStreamUrl = webkitURL.createObjectURL(new_stream);
- $('local-view').src = newStreamUrl;
+ $('local-view').src = newStreamUrl;
waitForVideo('local-view');
}
+ function stopVideoTrack() {
+ gLocalStream.getVideoTracks()[0].stop();
+ waitForVideoToStop('local-view');
+ }
+
function analyzeVideo() {
document.title = 'Waiting for video...';
addExpectedEvent();
@@ -78,7 +86,7 @@
});
}
- </script>
+ </script>
</head>
<body>
<table border="0">
@@ -87,7 +95,7 @@
</tr>
<tr>
<td><video width="320" height="240" id="local-view"
- autoplay="autoplay"></video></td>
+ autoplay="autoplay"></video></td>
<!-- Canvases are named after their corresponding video elements. -->
<td><canvas width="320" height="240" id="local-view-canvas"
style="display:none"></canvas></td>
diff --git a/content/test/data/media/peerconnection-call.html b/content/test/data/media/peerconnection-call.html
index 535498f..a2ee6b4 100644
--- a/content/test/data/media/peerconnection-call.html
+++ b/content/test/data/media/peerconnection-call.html
@@ -102,8 +102,8 @@
}
// Do the forwarding after we have received video.
- detectVideoIn('remote-view-1', onRemoteStream1);
- detectVideoIn('remote-view-2', onRemoteStream2);
+ detectVideoPlaying('remote-view-1', onRemoteStream1);
+ detectVideoPlaying('remote-view-2', onRemoteStream2);
}
// Test that we can setup call with an audio and video track and
@@ -212,7 +212,7 @@
}
// Do the DTMF test after we have received video.
- detectVideoIn('remote-view-2', onCallEstablished);
+ detectVideoPlaying('remote-view-2', onCallEstablished);
}
// Test call with a new Video MediaStream that has been created based on a
diff --git a/content/test/data/media/webrtc_test_utilities.js b/content/test/data/media/webrtc_test_utilities.js
index ba894cd..1377ca8 100644
--- a/content/test/data/media/webrtc_test_utilities.js
+++ b/content/test/data/media/webrtc_test_utilities.js
@@ -24,27 +24,50 @@ function setAllEventsOccuredHandler(handler) {
gAllEventsOccured = handler;
}
-function detectVideoIn(videoElementName, callback) {
+function detectVideoPlaying(videoElementName, callback) {
+ detectVideo(videoElementName, isVideoPlaying, callback);
+}
+
+function detectVideoStopped(videoElementName, callback) {
+ detectVideo(videoElementName,
+ function (pixels, previous_pixels) {
+ return !isVideoPlaying(pixels, previous_pixels);
+ },
+ callback);
+}
+
+function detectVideo(videoElementName, predicate, callback) {
var width = VIDEO_TAG_WIDTH;
var height = VIDEO_TAG_HEIGHT;
var videoElement = $(videoElementName);
var canvas = $(videoElementName + '-canvas');
+ var old_pixels = [];
var waitVideo = setInterval(function() {
var context = canvas.getContext('2d');
context.drawImage(videoElement, 0, 0, width, height);
- var pixels = context.getImageData(0, 0, width, height).data;
-
- if (isVideoPlaying(pixels, width, height)) {
+ var pixels = context.getImageData(0, 0 , width, height / 3).data;
+ // Check that there is an old and a new picture with the same size to
+ // compare and use the function |predicate| to detect the video state in
+ // that case.
+ if (old_pixels.length == pixels.length &&
+ predicate(pixels, old_pixels)) {
clearInterval(waitVideo);
callback();
}
- }, 100);
+ old_pixels = pixels;
+ }, 200);
}
function waitForVideo(videoElement) {
document.title = 'Waiting for video...';
addExpectedEvent();
- detectVideoIn(videoElement, function () { eventOccured(); });
+ detectVideoPlaying(videoElement, function () { eventOccured(); });
+}
+
+function waitForVideoToStop(videoElement) {
+ document.title = 'Waiting for video to stop...';
+ addExpectedEvent();
+ detectVideoStopped(videoElement, function () { eventOccured(); });
}
function waitForConnectionToStabilize(peerConnection) {
@@ -69,13 +92,10 @@ function eventOccured() {
}
// This very basic video verification algorithm will be satisfied if any
-// pixels are nonzero in a small sample area in the middle. It relies on the
-// assumption that a video element with null source just presents zeroes.
-function isVideoPlaying(pixels, width, height) {
- // Sample somewhere near the middle of the image.
- var middle = width * height / 2;
- for (var i = 0; i < 20; i++) {
- if (pixels[middle + i] > 0) {
+// pixels are changed.
+function isVideoPlaying(pixels, previous_pixels) {
+ for (var i = 0; i < pixels.length; i++) {
+ if (pixels[i] != previous_pixels[i]) {
return true;
}
}