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

Side by Side Diff: trunk/src/content/test/data/media/webrtc_test_utilities.js

Issue 466983002: Revert 288702 "Content browsertest for verifying that a black fr..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/content/test/data/media/peerconnection-call.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // These must match with how the video and canvas tags are declared in html. 5 // These must match with how the video and canvas tags are declared in html.
6 const VIDEO_TAG_WIDTH = 320; 6 const VIDEO_TAG_WIDTH = 320;
7 const VIDEO_TAG_HEIGHT = 240; 7 const VIDEO_TAG_HEIGHT = 240;
8 8
9 // Fake video capture background green is of value 135. 9 // Fake video capture background green is of value 135.
10 const COLOR_BACKGROUND_GREEN = 135; 10 const COLOR_BACKGROUND_GREEN = 135;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 function detectVideoStopped(videoElementName, callback) { 47 function detectVideoStopped(videoElementName, callback) {
48 detectVideo(videoElementName, 48 detectVideo(videoElementName,
49 function (pixels, previous_pixels) { 49 function (pixels, previous_pixels) {
50 return !isVideoPlaying(pixels, previous_pixels); 50 return !isVideoPlaying(pixels, previous_pixels);
51 }, 51 },
52 callback); 52 callback);
53 } 53 }
54 54
55 function detectBlackVideo(videoElementName, callback) {
56 detectVideo(videoElementName,
57 function (pixels, previous_pixels) {
58 return isVideoBlack(pixels);
59 },
60 callback);
61 }
62
63 function detectVideo(videoElementName, predicate, callback) { 55 function detectVideo(videoElementName, predicate, callback) {
64 console.log('Looking at video in element ' + videoElementName); 56 console.log('Looking at video in element ' + videoElementName);
65 57
66 var width = VIDEO_TAG_WIDTH; 58 var width = VIDEO_TAG_WIDTH;
67 var height = VIDEO_TAG_HEIGHT; 59 var height = VIDEO_TAG_HEIGHT;
68 var videoElement = $(videoElementName); 60 var videoElement = $(videoElementName);
69 var canvas = $(videoElementName + '-canvas'); 61 var canvas = $(videoElementName + '-canvas');
70 var oldPixels = []; 62 var oldPixels = [];
71 var waitVideo = setInterval(function() { 63 var waitVideo = setInterval(function() {
72 var context = canvas.getContext('2d'); 64 var context = canvas.getContext('2d');
(...skipping 25 matching lines...) Expand all
98 function waitForVideo(videoElement) { 90 function waitForVideo(videoElement) {
99 addExpectedEvent(); 91 addExpectedEvent();
100 detectVideoPlaying(videoElement, function () { eventOccured(); }); 92 detectVideoPlaying(videoElement, function () { eventOccured(); });
101 } 93 }
102 94
103 function waitForVideoToStop(videoElement) { 95 function waitForVideoToStop(videoElement) {
104 addExpectedEvent(); 96 addExpectedEvent();
105 detectVideoStopped(videoElement, function () { eventOccured(); }); 97 detectVideoStopped(videoElement, function () { eventOccured(); });
106 } 98 }
107 99
108 function waitForBlackVideo(videoElement) {
109 addExpectedEvent();
110 detectBlackVideo(videoElement, function () { eventOccured(); });
111 }
112
113 // Calculates the current frame rate and compares to |expected_frame_rate| 100 // Calculates the current frame rate and compares to |expected_frame_rate|
114 // |callback| is triggered with value |true| if the calculated frame rate 101 // |callback| is triggered with value |true| if the calculated frame rate
115 // is +-1 the expected or |false| if five calculations fail to match 102 // is +-1 the expected or |false| if five calculations fail to match
116 // |expected_frame_rate|. 103 // |expected_frame_rate|.
117 function validateFrameRate(videoElementName, expected_frame_rate, callback) { 104 function validateFrameRate(videoElementName, expected_frame_rate, callback) {
118 var videoElement = $(videoElementName); 105 var videoElement = $(videoElementName);
119 var startTime = new Date().getTime(); 106 var startTime = new Date().getTime();
120 var decodedFrames = videoElement.webkitDecodedFrameCount; 107 var decodedFrames = videoElement.webkitDecodedFrameCount;
121 var attempts = 0; 108 var attempts = 0;
122 109
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // pixels are changed. 164 // pixels are changed.
178 function isVideoPlaying(pixels, previousPixels) { 165 function isVideoPlaying(pixels, previousPixels) {
179 for (var i = 0; i < pixels.length; i++) { 166 for (var i = 0; i < pixels.length; i++) {
180 if (pixels[i] != previousPixels[i]) { 167 if (pixels[i] != previousPixels[i]) {
181 return true; 168 return true;
182 } 169 }
183 } 170 }
184 return false; 171 return false;
185 } 172 }
186 173
187 function isVideoBlack(pixels) {
188 for (var i = 0; i < pixels.length; i++) {
189 // |pixels| is in RGBA. Ignore the alpha channel.
190 if (pixels[i] != 0 && (i + 1) % 4 != 0) {
191 return false;
192 }
193 }
194 return true;
195 }
196
197 // This function matches |left| and |right| and fails the test if the 174 // This function matches |left| and |right| and fails the test if the
198 // values don't match using normal javascript equality (i.e. the hard 175 // values don't match using normal javascript equality (i.e. the hard
199 // types of the operands aren't checked). 176 // types of the operands aren't checked).
200 function assertEquals(expected, actual) { 177 function assertEquals(expected, actual) {
201 if (actual != expected) { 178 if (actual != expected) {
202 failTest("expected '" + expected + "', got '" + actual + "'."); 179 failTest("expected '" + expected + "', got '" + actual + "'.");
203 } 180 }
204 } 181 }
205 182
206 function assertNotEquals(expected, actual) { 183 function assertNotEquals(expected, actual) {
207 if (actual === expected) { 184 if (actual === expected) {
208 failTest("expected '" + expected + "', got '" + actual + "'."); 185 failTest("expected '" + expected + "', got '" + actual + "'.");
209 } 186 }
210 } 187 }
211 188
OLDNEW
« no previous file with comments | « trunk/src/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