OLD | NEW |
1 /** | 1 /** |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 // This file requires the functions defined in test_functions.js. | 7 // This file requires the functions defined in test_functions.js. |
8 | 8 |
9 var gFingerprints = []; | 9 var gFingerprints = []; |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 gFingerprints.push(fingerprint_(context, width, height)); | 41 gFingerprints.push(fingerprint_(context, width, height)); |
42 if (gFingerprints.length > NUM_FINGERPRINTS_TO_SAVE) { | 42 if (gFingerprints.length > NUM_FINGERPRINTS_TO_SAVE) { |
43 gFingerprints.shift(); | 43 gFingerprints.shift(); |
44 } | 44 } |
45 }, 100); | 45 }, 100); |
46 | 46 |
47 returnToTest('ok-started'); | 47 returnToTest('ok-started'); |
48 } | 48 } |
49 | 49 |
50 /** | 50 /** |
| 51 * Verifies that the video stream connected to a video tag has the right width |
| 52 * and height. |
| 53 * |
| 54 * @param {string} videoElementId The video element to analyze. |
| 55 * @param {int} width The expected video width. |
| 56 * @param {int} width The expected video height. |
| 57 * |
| 58 * @return {string} Returns 'ok' if passing (exception is thrown on failure). |
| 59 */ |
| 60 function verifyVideoStreamSize(videoElementId, expectedWidth, expectedHeight) { |
| 61 var videoTag = document.getElementById(videoElementId); |
| 62 console.log('videoTag' + videoTag); |
| 63 if (videoTag.videoWidth == expectedWidth && |
| 64 videoTag.videoHeight == expectedHeight) { |
| 65 returnToTest('ok-video-stream-size'); |
| 66 } |
| 67 else { |
| 68 throw failTest('Invalid video stream size: ' + videoTag.videoWidth + |
| 69 'x' + videoTag.videoHeight + ' (expected: ' + expectedWidth + 'x' + |
| 70 expectedHeight + ')'); |
| 71 } |
| 72 } |
| 73 |
| 74 /** |
51 * Checks if we have detected any video so far. | 75 * Checks if we have detected any video so far. |
52 * | 76 * |
53 * @return {string} video-playing if we detected video, otherwise | 77 * @return {string} video-playing if we detected video, otherwise |
54 * video-not-playing. | 78 * video-not-playing. |
55 */ | 79 */ |
56 function isVideoPlaying() { | 80 function isVideoPlaying() { |
57 // Video is considered to be playing if at least one finger print has changed | 81 // Video is considered to be playing if at least one finger print has changed |
58 // since the oldest fingerprint. Even small blips in the pixel data will cause | 82 // since the oldest fingerprint. Even small blips in the pixel data will cause |
59 // this check to pass. We only check for rough equality though to account for | 83 // this check to pass. We only check for rough equality though to account for |
60 // rounding errors. | 84 // rounding errors. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 function fingerprint_(canvasContext, width, height) { | 135 function fingerprint_(canvasContext, width, height) { |
112 var imageData = canvasContext.getImageData(0, 0, width, height); | 136 var imageData = canvasContext.getImageData(0, 0, width, height); |
113 var pixels = imageData.data; | 137 var pixels = imageData.data; |
114 | 138 |
115 var fingerprint = 0; | 139 var fingerprint = 0; |
116 for (var i = 0; i < pixels.length; i++) { | 140 for (var i = 0; i < pixels.length; i++) { |
117 fingerprint += pixels[i]; | 141 fingerprint += pixels[i]; |
118 } | 142 } |
119 return fingerprint; | 143 return fingerprint; |
120 } | 144 } |
OLD | NEW |