OLD | NEW |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 var context = canvas.getContext('2d'); | 65 var context = canvas.getContext('2d'); |
66 context.drawImage(videoElement, 0, 0, width, height); | 66 context.drawImage(videoElement, 0, 0, width, height); |
67 var pixels = context.getImageData(0, 0 , width, height / 3).data; | 67 var pixels = context.getImageData(0, 0 , width, height / 3).data; |
68 // Check that there is an old and a new picture with the same size to | 68 // Check that there is an old and a new picture with the same size to |
69 // compare and use the function |predicate| to detect the video state in | 69 // compare and use the function |predicate| to detect the video state in |
70 // that case. | 70 // that case. |
71 if (oldPixels.length == pixels.length && | 71 if (oldPixels.length == pixels.length && |
72 predicate(pixels, oldPixels)) { | 72 predicate(pixels, oldPixels)) { |
73 console.log('Done looking at video in element ' + videoElementName); | 73 console.log('Done looking at video in element ' + videoElementName); |
74 clearInterval(waitVideo); | 74 clearInterval(waitVideo); |
75 callback(); | 75 callback(videoElement.videoWidth, videoElement.videoHeight); |
76 } | 76 } |
77 oldPixels = pixels; | 77 oldPixels = pixels; |
78 }, 200); | 78 }, 200); |
79 } | 79 } |
80 | 80 |
| 81 function waitForVideoWithResolution(element, expected_width, expected_height) { |
| 82 addExpectedEvent(); |
| 83 detectVideoPlaying(element, |
| 84 function (width, height) { |
| 85 assertEquals(expected_width, width); |
| 86 assertEquals(expected_height, height); |
| 87 eventOccured(); |
| 88 }); |
| 89 } |
| 90 |
81 function waitForVideo(videoElement) { | 91 function waitForVideo(videoElement) { |
82 addExpectedEvent(); | 92 addExpectedEvent(); |
83 detectVideoPlaying(videoElement, function () { eventOccured(); }); | 93 detectVideoPlaying(videoElement, function () { eventOccured(); }); |
84 } | 94 } |
85 | 95 |
86 function waitForVideoToStop(videoElement) { | 96 function waitForVideoToStop(videoElement) { |
87 addExpectedEvent(); | 97 addExpectedEvent(); |
88 detectVideoStopped(videoElement, function () { eventOccured(); }); | 98 detectVideoStopped(videoElement, function () { eventOccured(); }); |
89 } | 99 } |
90 | 100 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 failTest("expected '" + expected + "', got '" + actual + "'."); | 142 failTest("expected '" + expected + "', got '" + actual + "'."); |
133 } | 143 } |
134 } | 144 } |
135 | 145 |
136 function assertNotEquals(expected, actual) { | 146 function assertNotEquals(expected, actual) { |
137 if (actual === expected) { | 147 if (actual === expected) { |
138 failTest("expected '" + expected + "', got '" + actual + "'."); | 148 failTest("expected '" + expected + "', got '" + actual + "'."); |
139 } | 149 } |
140 } | 150 } |
141 | 151 |
OLD | NEW |