Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | 2 |
| 3 <html> | 3 <html> |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <div id="description"></div> | 12 <script> |
| 12 <div id="console"></div> | 13 let audit = Audit.createTaskRunner(); |
| 13 | 14 |
| 14 <script> | 15 audit.define( |
| 15 description("Basic tests for MediaStreamAudioSourceNode API."); | 16 { |
| 17 label: 'test', | |
| 18 description: 'Basic tests for MediaStreamAudioSourceNode API' | |
| 19 }, | |
| 20 (task, should) => { | |
| 21 should( | |
| 22 () => {navigator.webkitGetUserMedia( | |
| 23 {audio: true}, | |
| 24 (stream) => { | |
| 25 gotStream(stream, should); | |
| 26 task.done(); | |
| 27 }, | |
| 28 () => { | |
| 29 should(false, 'Stream generation') | |
| 30 .message('succeeded', 'failed'); | |
| 31 task.done(); | |
| 32 })}, | |
| 33 'getUserMedia()') | |
| 34 .notThrow(); | |
|
hongchan
2017/02/24 23:28:09
If clang-format did this, it is really bad. I woul
Raymond Toy
2017/02/24 23:35:30
I think it's really ugly too, but we discussed thi
hongchan
2017/02/24 23:48:18
Yes, but this getUserMedia() part really threw me
| |
| 35 }); | |
| 16 | 36 |
| 17 var context = 0; | 37 audit.run(); |
| 18 | 38 |
| 19 function error() { | 39 function gotStream(stream, should) { |
| 20 testFailed('Stream generation failed.'); | 40 should(true, '{audio:true} generated stream').message('correctly', ''); |
| 21 finishJSTest(); | 41 |
| 42 let context = new AudioContext(); | |
| 43 | |
| 44 // Create an AudioNode from the stream. | |
| 45 let mediaStreamSource = context.createMediaStreamSource(stream); | |
| 46 | |
| 47 // Check number of inputs and outputs. | |
| 48 should(mediaStreamSource.numberOfInputs, 'mediaStreamSource.numberOfInputs') | |
| 49 .beEqualTo(0); | |
| 50 should(mediaStreamSource.numberOfOutputs, 'mediaStreamSource.numberOfOutputs') | |
| 51 .beEqualTo(1); | |
| 52 | |
| 53 // Try calling connect() method with illegal values. | |
| 54 should( | |
| 55 () => mediaStreamSource.connect(0, 0, 0), | |
| 56 'mediaStreamSource.connect(0, 0, 0)') | |
| 57 .throw(); | |
| 58 should( | |
| 59 () => mediaStreamSource.connect(context.destination, 5, 0), | |
| 60 'mediaStreamSource.connect(context.destination, 5, 0)') | |
| 61 .throw(); | |
| 62 should( | |
| 63 () => mediaStreamSource.connect(context.destination, 0, 5), | |
| 64 'mediaStreamSource.connect(context.destination, 0, 5)') | |
| 65 .throw(); | |
| 66 | |
| 67 // Try calling connect() with proper values. | |
| 68 should( | |
| 69 () => mediaStreamSource.connect(context.destination, 0, 0), | |
| 70 'mediaStreamSource.connect(context.destination, 0, 0)') | |
| 71 .notThrow(); | |
| 22 } | 72 } |
| 23 | 73 |
| 24 function getUserMedia(dictionary, callback) { | |
| 25 try { | |
| 26 navigator.webkitGetUserMedia(dictionary, callback, error); | |
| 27 } catch (e) { | |
| 28 testFailed('webkitGetUserMedia threw exception :' + e); | |
| 29 finishJSTest(); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 function gotStream(stream) { | |
| 34 s = stream; | |
| 35 testPassed('{audio:true} generated stream'); | |
| 36 shouldBe('s.getAudioTracks().length', '1'); | |
| 37 shouldBe('s.getVideoTracks().length', '0'); | |
| 38 | |
| 39 context = new AudioContext(); | |
| 40 | |
| 41 // Create an AudioNode from the stream. | |
| 42 var mediaStreamSource = context.createMediaStreamSource(stream); | |
| 43 | |
| 44 // Check number of inputs and outputs. | |
| 45 if (mediaStreamSource.numberOfInputs == 0) | |
| 46 testPassed("Source AudioNode has no inputs."); | |
| 47 else | |
| 48 testFailed("Source AudioNode should not have inputs."); | |
| 49 | |
| 50 if (mediaStreamSource.numberOfOutputs == 1) | |
| 51 testPassed("Source AudioNode has one output."); | |
| 52 else | |
| 53 testFailed("Source AudioNode should have one output."); | |
| 54 | |
| 55 // Try calling connect() method with illegal values. | |
| 56 | |
| 57 try { | |
| 58 mediaStreamSource.connect(0, 0, 0); | |
| 59 testFailed("connect() exception should be thrown for illegal destination AudioNode."); | |
| 60 } catch(e) { | |
| 61 testPassed("connect() exception thrown for illegal destination AudioNode ."); | |
| 62 } | |
| 63 | |
| 64 try { | |
| 65 mediaStreamSource.connect(context.destination, 5, 0); | |
| 66 testFailed("connect() exception should be thrown for illegal output inde x."); | |
| 67 } catch(e) { | |
| 68 testPassed("connect() exception thrown for illegal output index."); | |
| 69 } | |
| 70 | |
| 71 try { | |
| 72 mediaStreamSource.connect(context.destination, 0, 5); | |
| 73 testFailed("connect() exception should be thrown for illegal input index ."); | |
| 74 } catch(e) { | |
| 75 testPassed("connect() exception thrown for illegal input index."); | |
| 76 } | |
| 77 | |
| 78 // Try calling connect() with proper values. | |
| 79 try { | |
| 80 mediaStreamSource.connect(context.destination, 0, 0); | |
| 81 testPassed("mediaStreamSource.connect(context.destination) succeeded."); | |
| 82 } catch(e) { | |
| 83 testFailed("mediaStreamSource.connect(context.destination) failed."); | |
| 84 } | |
| 85 | |
| 86 finishJSTest(); | |
| 87 } | |
| 88 | |
| 89 getUserMedia({audio:true}, gotStream); | |
| 90 window.jsTestIsAsync = true; | |
| 91 window.successfullyParsed = true; | |
| 92 | 74 |
| 93 </script> | 75 </script> |
| 94 | 76 |
| 95 </body> | 77 </body> |
| 96 </html> | 78 </html> |
| OLD | NEW |