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

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

Issue 13496009: Hookup the MediaStream glue for Adding and Removing tracks to an existing MediaStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments on content_browsertest Created 7 years, 8 months 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..b9cceeb38c395864c3a5fdcac8eb3d1ba402f486
--- /dev/null
+++ b/content/test/data/media/webrtc_test_utilities.js
@@ -0,0 +1,70 @@
+// These must match with how the video and canvas tags are declared in html.
+const VIDEO_TAG_WIDTH = 320;
+const VIDEO_TAG_HEIGHT = 240;
+
+// Number of test events to occur before the test pass. When the test pass,
+// the function gAllEventsOccured is called.
+var gNumberOfExpectedEvents = 0;
+
+// Number of events that currently have occurred.
+var gNumberOfEvents = 0;
+
phoglund_chromium 2013/04/11 11:16:48 Write a small accessor to overwrite this guy which
perkj_chrome 2013/04/11 11:50:48 Done.
+var gAllEventsOccured = function () {};
+
+function detectVideoIn(videoElementName, callback) {
+ var width = VIDEO_TAG_WIDTH;
+ var height = VIDEO_TAG_HEIGHT;
+ var videoElement = $(videoElementName);
+ var canvas = $(videoElementName + '-canvas');
+ 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)) {
+ clearInterval(waitVideo);
+ callback();
+ }
+ }, 100);
+}
+
+function waitForVideo(videoElement) {
+ document.title = 'Waiting for video...';
+ addExpectedEvent();
+ detectVideoIn(videoElement, function () { eventOccured(); });
+}
+
+function addExpectedEvent() {
+ ++gNumberOfExpectedEvents;
+}
+
+function eventOccured() {
+ ++gNumberOfEvents;
+ if (gNumberOfEvents == gNumberOfExpectedEvents) {
+ gAllEventsOccured();
+ }
+}
+
+// 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) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// This function matches |left| and |right| and throws an exception if the
+// values don't match.
+function expectEquals(left, right) {
+ if (left != right) {
+ var s = "expectEquals failed left: " + left + " right: " + right;
+ document.title = s;
+ throw s;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698