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

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

Issue 442313002: Contentbrowsertest for verifying that a black frame is sent on a peerconnection if a track is disab… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nit. 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 | « 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
55 function detectVideo(videoElementName, predicate, callback) { 63 function detectVideo(videoElementName, predicate, callback) {
56 console.log('Looking at video in element ' + videoElementName); 64 console.log('Looking at video in element ' + videoElementName);
57 65
58 var width = VIDEO_TAG_WIDTH; 66 var width = VIDEO_TAG_WIDTH;
59 var height = VIDEO_TAG_HEIGHT; 67 var height = VIDEO_TAG_HEIGHT;
60 var videoElement = $(videoElementName); 68 var videoElement = $(videoElementName);
61 var canvas = $(videoElementName + '-canvas'); 69 var canvas = $(videoElementName + '-canvas');
62 var oldPixels = []; 70 var oldPixels = [];
63 var waitVideo = setInterval(function() { 71 var waitVideo = setInterval(function() {
64 var context = canvas.getContext('2d'); 72 var context = canvas.getContext('2d');
(...skipping 25 matching lines...) Expand all
90 function waitForVideo(videoElement) { 98 function waitForVideo(videoElement) {
91 addExpectedEvent(); 99 addExpectedEvent();
92 detectVideoPlaying(videoElement, function () { eventOccured(); }); 100 detectVideoPlaying(videoElement, function () { eventOccured(); });
93 } 101 }
94 102
95 function waitForVideoToStop(videoElement) { 103 function waitForVideoToStop(videoElement) {
96 addExpectedEvent(); 104 addExpectedEvent();
97 detectVideoStopped(videoElement, function () { eventOccured(); }); 105 detectVideoStopped(videoElement, function () { eventOccured(); });
98 } 106 }
99 107
108 function waitForBlackVideo(videoElement) {
109 addExpectedEvent();
110 detectBlackVideo(videoElement, function () { eventOccured(); });
111 }
112
100 // Calculates the current frame rate and compares to |expected_frame_rate| 113 // Calculates the current frame rate and compares to |expected_frame_rate|
101 // |callback| is triggered with value |true| if the calculated frame rate 114 // |callback| is triggered with value |true| if the calculated frame rate
102 // is +-1 the expected or |false| if five calculations fail to match 115 // is +-1 the expected or |false| if five calculations fail to match
103 // |expected_frame_rate|. 116 // |expected_frame_rate|.
104 function validateFrameRate(videoElementName, expected_frame_rate, callback) { 117 function validateFrameRate(videoElementName, expected_frame_rate, callback) {
105 var videoElement = $(videoElementName); 118 var videoElement = $(videoElementName);
106 var startTime = new Date().getTime(); 119 var startTime = new Date().getTime();
107 var decodedFrames = videoElement.webkitDecodedFrameCount; 120 var decodedFrames = videoElement.webkitDecodedFrameCount;
108 var attempts = 0; 121 var attempts = 0;
109 122
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // pixels are changed. 177 // pixels are changed.
165 function isVideoPlaying(pixels, previousPixels) { 178 function isVideoPlaying(pixels, previousPixels) {
166 for (var i = 0; i < pixels.length; i++) { 179 for (var i = 0; i < pixels.length; i++) {
167 if (pixels[i] != previousPixels[i]) { 180 if (pixels[i] != previousPixels[i]) {
168 return true; 181 return true;
169 } 182 }
170 } 183 }
171 return false; 184 return false;
172 } 185 }
173 186
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
174 // This function matches |left| and |right| and fails the test if the 197 // This function matches |left| and |right| and fails the test if the
175 // values don't match using normal javascript equality (i.e. the hard 198 // values don't match using normal javascript equality (i.e. the hard
176 // types of the operands aren't checked). 199 // types of the operands aren't checked).
177 function assertEquals(expected, actual) { 200 function assertEquals(expected, actual) {
178 if (actual != expected) { 201 if (actual != expected) {
179 failTest("expected '" + expected + "', got '" + actual + "'."); 202 failTest("expected '" + expected + "', got '" + actual + "'.");
180 } 203 }
181 } 204 }
182 205
183 function assertNotEquals(expected, actual) { 206 function assertNotEquals(expected, actual) {
184 if (actual === expected) { 207 if (actual === expected) {
185 failTest("expected '" + expected + "', got '" + actual + "'."); 208 failTest("expected '" + expected + "', got '" + actual + "'.");
186 } 209 }
187 } 210 }
188 211
OLDNEW
« 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