Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/webaudio/resources/autoplay-crossorigin-iframe.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/webaudio/resources/autoplay-crossorigin-iframe.html b/third_party/WebKit/LayoutTests/http/tests/webaudio/resources/autoplay-crossorigin-iframe.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..49a6c93f5e8971d7cba86727c33ae51e92dc39f5 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/webaudio/resources/autoplay-crossorigin-iframe.html |
| @@ -0,0 +1,79 @@ |
| +<!DOCTYPE html> |
| +<body></body> |
| +<script> |
| +function synthesizeClick(callback) { |
| + var button = document.createElement('input'); |
| + button.type = 'button'; |
| + button.value = 'click me'; |
| + button.onclick = callback; |
| + document.body.appendChild(button); |
| + |
| + if ('eventSender' in window) { |
| + var boundingRect = button.getBoundingClientRect(); |
| + var x = boundingRect.left + boundingRect.width / 2; |
| + var y = boundingRect.top + boundingRect.height / 2; |
| + |
| + eventSender.mouseMoveTo(x, y); |
| + eventSender.mouseDown(); |
| + eventSender.mouseUp(); |
| + } |
| + // else, the user should manually click. |
| +} |
| + |
| +// AudioContext will start as suspended when lacking a user gesture. |
| +var audioContext = new AudioContext(); |
| +window.parent.postMessage({ msg: 'initialState', value: audioContext.state }, |
| + '*'); |
| + |
| +// OfflineAudioContext has no user gesture requirement but is always suspended. |
| +var offlineAudioContext = new OfflineAudioContext(1, 512, 3000); |
| +window.parent.postMessage({ msg: 'initialOfflineState', |
| + value: offlineAudioContext.state }, '*'); |
| + |
| +// Calling 'resume()' will fail to start the AudioContext. |
| +audioContext.resume(); |
| +window.parent.postMessage({ msg: 'afterResume', value: audioContext.state }, |
| + '*'); |
| + |
| +// Calling 'start()' will fail to start on a Node the associated AudioContext. |
|
Raymond Toy
2016/09/26 16:09:54
How is this determined here (that start() failed t
mlamouri (slow - plz ping)
2016/09/26 17:01:24
I mean to start an AudioContext. Below, it's testi
|
| +var oscillator = audioContext.createOscillator(); |
| +oscillator.type = 'square'; |
| +oscillator.frequency.value = 2000; |
| +oscillator.connect(audioContext.destination); |
| +oscillator.start(); |
| +window.parent.postMessage({ msg: 'afterOscillator', value: audioContext.state }, |
| + '*'); |
| + |
| +var otherAudioContext = new AudioContext(); |
| + |
| +synthesizeClick(_ => { |
| + // Calling 'resume()' from a click event will start the audio context. |
| + audioContext.resume(); |
| + window.parent.postMessage({ msg: 'stateAfterClick', |
| + value: audioContext.state }, '*'); |
| + |
| + window.parent.postMessage({ msg: 'stateOtherContextAfterClick', |
| + value: otherAudioContext.state }, '*'); |
| + |
| + synthesizeClick(_ => { |
| + var oscillator = otherAudioContext.createOscillator(); |
| + oscillator.type = 'square'; |
| + oscillator.frequency.value = 2000; |
| + oscillator.connect(otherAudioContext.destination); |
| + // Calling 'start()' from a click event will not start the audio context. |
| + oscillator.start(); |
| + |
| + window.parent.postMessage({ msg: 'stateOtherContextAfterSecondClick', |
| + value: otherAudioContext.state }, '*'); |
| + |
| + synthesizeClick(_ => { |
| + // Creating an AudioContext from a click event will start it. |
| + var lastAudioContext = new AudioContext(); |
| + window.parent.postMessage({ msg: 'stateCreatedAfterClick', |
| + value: lastAudioContext.state }, '*'); |
| + |
| + window.parent.postMessage({ msg: 'done' }, '*'); |
| + }); |
| + }); |
| +}); |
| +</script> |