Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / test / data / media / webrtc_test_utilities.js
index 3d54359..02aac59 100644 (file)
@@ -52,6 +52,14 @@ function detectVideoStopped(videoElementName, callback) {
               callback);
 }
 
+function detectBlackVideo(videoElementName, callback) {
+  detectVideo(videoElementName,
+              function (pixels, previous_pixels) {
+                return isVideoBlack(pixels);
+              },
+              callback);
+}
+
 function detectVideo(videoElementName, predicate, callback) {
   console.log('Looking at video in element ' + videoElementName);
 
@@ -97,6 +105,11 @@ function waitForVideoToStop(videoElement) {
   detectVideoStopped(videoElement, function () { eventOccured(); });
 }
 
+function waitForBlackVideo(videoElement) {
+  addExpectedEvent();
+  detectBlackVideo(videoElement, function () { eventOccured(); });
+}
+
 // Calculates the current frame rate and compares to |expected_frame_rate|
 // |callback| is triggered with value |true| if the calculated frame rate
 // is +-1 the expected or |false| if five calculations fail to match
@@ -171,6 +184,18 @@ function isVideoPlaying(pixels, previousPixels) {
   return false;
 }
 
+function isVideoBlack(pixels) {
+  for (var i = 0; i < pixels.length; i++) {
+    // |pixels| is in RGBA. Ignore the alpha channel.
+    // We allow it to be off by 1, to account for rounding errors in YUV
+    // conversion.
+    if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) {
+      return false;
+    }
+  }
+  return true;
+}
+
 // This function matches |left| and |right| and fails the test if the
 // values don't match using normal javascript equality (i.e. the hard
 // types of the operands aren't checked).