| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src=../../resources/testharness.js></script> | 2 <script src=../../resources/testharness.js></script> |
| 3 <script src=../../resources/testharnessreport.js></script> | 3 <script src=../../resources/testharnessreport.js></script> |
| 4 <script src=../../resources/testharness-helpers.js></script> | 4 <script src=../../resources/testharness-helpers.js></script> |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 // This test verifies that ImageCapture can be created (or not) with different | 7 // This test verifies that ImageCapture can be created (or not) with different |
| 8 // Media Stream Track types (audio, video). The simplest API method grabFrame() | 8 // Media Stream Track types (audio, video). |
| 9 // is also exercised here. | |
| 10 | 9 |
| 11 var test = async_test('exercises the ImageCapture API creation and grabFrame().'
); | 10 var testVideo = promise_test(function() { |
| 12 | 11 const gotStream = this.step_func(function(stream) { |
| 13 gotStream = test.step_func(function(stream) { | 12 assert_equals(stream.getAudioTracks().length, 0); |
| 14 assert_equals(stream.getAudioTracks().length, 1); | |
| 15 assert_equals(stream.getVideoTracks().length, 1); | 13 assert_equals(stream.getVideoTracks().length, 1); |
| 16 assert_throws("NotSupportedError", | |
| 17 function() { | |
| 18 capturer = new ImageCapture(stream.getAudioTracks()[0]); | |
| 19 }, | |
| 20 'an ImageCapturer can only be created from a video track'); | |
| 21 | |
| 22 assert_equals(stream.getVideoTracks()[0].readyState, 'live'); | 14 assert_equals(stream.getVideoTracks()[0].readyState, 'live'); |
| 23 assert_true(stream.getVideoTracks()[0].enabled); | 15 assert_true(stream.getVideoTracks()[0].enabled); |
| 24 assert_false(stream.getVideoTracks()[0].muted); | 16 assert_false(stream.getVideoTracks()[0].muted); |
| 25 capturer = new ImageCapture(stream.getVideoTracks()[0]); | |
| 26 | 17 |
| 18 var capturer = new ImageCapture(stream.getVideoTracks()[0]); |
| 27 assert_equals(capturer.videoStreamTrack, stream.getVideoTracks()[0]); | 19 assert_equals(capturer.videoStreamTrack, stream.getVideoTracks()[0]); |
| 28 | 20 |
| 29 // TODO(mcasas): Remove this assert after the method is implemented, and | |
| 30 // substitute with something more relevant. | |
| 31 stream.getVideoTracks()[0].enabled = true; | |
| 32 assert_promise_rejects(capturer.grabFrame(), | |
| 33 'NotSupportedError', | |
| 34 'ImageCapturer grabFrame() is not implemented'); | |
| 35 | |
| 36 // Assert that grabFrame() is rejected if the associated video track is | 21 // Assert that grabFrame() is rejected if the associated video track is |
| 37 // disabled, or ended. grabFrame() would also reject if the video Track is | 22 // disabled, or ended. grabFrame() would also reject if the video Track is |
| 38 // muted but that's a read-only property. | 23 // muted but that's a read-only property. |
| 39 stream.getVideoTracks()[0].enabled = false; | 24 stream.getVideoTracks()[0].enabled = false; |
| 40 assert_promise_rejects(capturer.grabFrame(), | 25 assert_promise_rejects(capturer.grabFrame(), |
| 41 'InvalidStateError', | 26 'InvalidStateError', |
| 42 'ImageCapturer cannot grabFrame() of a disabled Track
'); | 27 'ImageCapturer cannot grabFrame() of a disabled Track
'); |
| 43 | 28 |
| 44 stream.getVideoTracks()[0].stop(); | 29 stream.getVideoTracks()[0].stop(); |
| 45 assert_equals(stream.getVideoTracks()[0].readyState, 'ended'); | 30 assert_equals(stream.getVideoTracks()[0].readyState, 'ended'); |
| 46 assert_promise_rejects(capturer.grabFrame(), | 31 assert_promise_rejects(capturer.grabFrame(), |
| 47 'InvalidStateError', | 32 'InvalidStateError', |
| 48 'ImageCapturer cannot grabFrame() of a non-live Track
'); | 33 'ImageCapturer cannot grabFrame() of a non-live Track
'); |
| 49 | 34 |
| 50 test.done(); | 35 this.done(); |
| 51 }); | 36 }); |
| 52 | 37 |
| 53 onError = test.step_func(function() { | 38 const onError = this.step_func(function() { |
| 54 assert_unreached('Error creating MediaStream'); | 39 assert_unreached('Error creating MediaStream'); |
| 55 }); | 40 }); |
| 56 | 41 |
| 57 navigator.webkitGetUserMedia({video:true, audio:true}, gotStream, onError); | 42 navigator.webkitGetUserMedia({video:true}, gotStream, onError); |
| 43 }, 'verifies that ImageCapture API rejects grabFrame() in certain Track states.'
); |
| 44 |
| 45 var testAudio = promise_test(function() { |
| 46 const onError = this.step_func(function() { |
| 47 assert_unreached('Error creating MediaStream'); |
| 48 }); |
| 49 |
| 50 navigator.webkitGetUserMedia({audio:true}, |
| 51 this.step_func(function(stream) { |
| 52 assert_equals(stream.getAudioTracks().length, 1); |
| 53 assert_equals(stream.getVideoTracks().length, 0); |
| 54 assert_throws("NotSupportedError", |
| 55 function() { |
| 56 var capturer = new ImageCapture(stream.getAudioTracks()[0]
); |
| 57 }, |
| 58 'an ImageCapturer can only be created from a video track'); |
| 59 |
| 60 this.done(); |
| 61 }), onError); |
| 62 }, 'verifies that an ImageCapture cannot be created out of an Audio Track'); |
| 58 | 63 |
| 59 </script> | 64 </script> |
| OLD | NEW |