Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Unified Diff: content/test/data/media/webrtc_test_utilities.js

Issue 68263016: Add simple test for VideoTrack.stop(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/data/media/peerconnection-call.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/data/media/webrtc_test_utilities.js
diff --git a/content/test/data/media/webrtc_test_utilities.js b/content/test/data/media/webrtc_test_utilities.js
index ba894cd56bf09cf0f4ff920fe7eaf0ac5fda5097..1377ca8c1ba2ce106dfdce90b62636bc94ca3df3 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;
}
}
« no previous file with comments | « content/test/data/media/peerconnection-call.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698