Commit 6801c797 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Web Audio autoplay: add tests for feature policy and cross origin.

Bug: 852212
Change-Id: I4ed79cc13f48aaaac4a68c33e976fdab834deb61
Reviewed-on: https://chromium-review.googlesource.com/1098467
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567314}
parent ec442739
PASS undefined is undefined. PASS undefined is undefined.
PASS results.webAudio is "running"
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
testRunner.waitUntilDone(); testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required'); internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
eventSender.mouseDown(); eventSender.mouseDown();
document.location.href = 'resources/test-autoplay.html'; document.location.href = 'resources/test-autoplay.html';
......
PASS undefined is undefined. PASS undefined is undefined.
PASS results.webAudio is "running"
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
testRunner.waitUntilDone(); testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required'); internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
document.querySelector('#target').focus(); document.querySelector('#target').focus();
eventSender.keyDown('a'); eventSender.keyDown('a');
......
CONSOLE WARNING: line 28: The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
FAIL NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD should be undefined. Was NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD FAIL NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD should be undefined. Was NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD
FAIL results.webAudio should be running. Was suspended.
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
testRunner.waitUntilDone(); testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required'); internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
document.location.href = 'resources/test-autoplay.html'; document.location.href = 'resources/test-autoplay.html';
</script> </script>
PASS undefined is undefined. PASS undefined is undefined.
PASS results.webAudio is "running"
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
testRunner.waitUntilDone(); testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required'); internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
var bounds = document.querySelector('#target').getBoundingClientRect(); var bounds = document.querySelector('#target').getBoundingClientRect();
var x = bounds.left + bounds.width / 2; var x = bounds.left + bounds.width / 2;
var y = bounds.top + bounds.height / 2; var y = bounds.top + bounds.height / 2;
......
...@@ -4,20 +4,26 @@ ...@@ -4,20 +4,26 @@
// Tracks the results and how many active tests we have running. // Tracks the results and how many active tests we have running.
let testExpectations = {}; let testExpectations = {};
let callback; let doneCallback;
let resultCallback = (data) => { top.postMessage(data, '*') }; let resultCallback = (data) => { top.postMessage(data, '*') };
let completedTestResults = []; let completedTestResults = [];
let results = {};
function tearDown(result) { function tearDown() {
// Reset the flag state. // Reset the flag state.
internals.settings.setAutoplayPolicy('no-user-gesture-required'); internals.settings.setAutoplayPolicy('no-user-gesture-required');
let canAutoplay = true;
// Ensure that play failed because autoplay was blocked. If playback failed // Ensure that play failed because autoplay was blocked. If playback failed
// for another reason then we don't care because autoplay is always checked // for another reason then we don't care because autoplay is always checked
// first. // first.
if (result && result.name == 'NotAllowedError') const canAutoplayMedia = !results.media ||
canAutoplay = false; results.media.name != 'NotAllowedError';
const canAutoplayWebAudio = results.webAudio == 'running';
// `canAutoplay` must match autoplay for both media element and Web Audio.
// Special value `undefined` will be propagated otherwise.
const canAutoplay = canAutoplayMedia == canAutoplayWebAudio ? canAutoplayMedia
: undefined;
receivedResult({ receivedResult({
url: window.location.href, url: window.location.href,
...@@ -27,7 +33,7 @@ function tearDown(result) { ...@@ -27,7 +33,7 @@ function tearDown(result) {
function receivedResult(data) { function receivedResult(data) {
// Forward the result to the top frame. // Forward the result to the top frame.
if (!callback) { if (!doneCallback) {
top.postMessage(data, '*'); top.postMessage(data, '*');
return; return;
} }
...@@ -45,13 +51,28 @@ function processTestResults() { ...@@ -45,13 +51,28 @@ function processTestResults() {
assert_equals(testExpectations[data.url], data.message); assert_equals(testExpectations[data.url], data.message);
}); });
callback(); doneCallback();
}
function runMediaTest() {
return new Promise(resolve => {
const video = document.createElement('video');
video.src = '/media-resources/content/test.ogv';
video.play().then(result => results.media = result,
result => results.media = result)
.then(resolve);
});
}
function runWebAudioTest() {
const audioContext = new AudioContext();
results.webAudio = audioContext.state;
} }
function runVideoTest() { async function runAutoplayTest() {
const video = document.createElement('video'); await runMediaTest();
video.src = '/media-resources/content/test.ogv'; runWebAudioTest();
video.play().then(tearDown, tearDown); tearDown();
} }
function simulateViewportClick(callback) { function simulateViewportClick(callback) {
...@@ -89,11 +110,11 @@ function runTest(pointerSequence, expectations) { ...@@ -89,11 +110,11 @@ function runTest(pointerSequence, expectations) {
// Run the test. // Run the test.
async_test((t) => { async_test((t) => {
callback = t.step_func_done(); doneCallback = t.step_func_done();
// Fire the pointer sequence and then run the video test. // Fire the pointer sequence and then run the video test.
pointerSequence(t.step_func(() => { pointerSequence(t.step_func(() => {
runVideoTest(); runAutoplayTest();
// Navigate the iframe now we have the gesture. // Navigate the iframe now we have the gesture.
document.getElementsByTagName('iframe')[0].src = document.getElementsByTagName('iframe')[0].src =
...@@ -106,10 +127,11 @@ function runTest(pointerSequence, expectations) { ...@@ -106,10 +127,11 @@ function runTest(pointerSequence, expectations) {
// Setup the flags before the test is run. // Setup the flags before the test is run.
internals.settings.setAutoplayPolicy('document-user-activation-required'); internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
// Setup the event listener to forward messages. // Setup the event listener to forward messages.
window.addEventListener('message', (e) => { resultCallback(e.data); }); window.addEventListener('message', (e) => { resultCallback(e.data); });
// If we are on an iframe then run the video test automatically. // If we are on an iframe then run the video test automatically.
if (window.self !== window.top) if (window.self !== window.top)
runVideoTest(); runAutoplayTest();
...@@ -3,23 +3,43 @@ ...@@ -3,23 +3,43 @@
<script src="/js-test-resources/js-test.js"></script> <script src="/js-test-resources/js-test.js"></script>
<script> <script>
var jsTestIsAsync = true; var jsTestIsAsync = true;
function tearDown(result) { let results = {};
function tearDown() {
internals.settings.setAutoplayPolicy('no-user-gesture-required'); internals.settings.setAutoplayPolicy('no-user-gesture-required');
shouldBeUndefined(result);
shouldBeUndefined(results.media);
shouldBeEqualToString('results.webAudio', 'running');
finishJSTest(); finishJSTest();
} }
function runVideoTest() { function runMediaTests() {
var video = document.createElement('video'); return new Promise(resolve => {
video.src = "/resources/test.ogv"; const video = document.createElement('video');
video.play().then(tearDown, tearDown); video.src = "/resources/test.ogv";
video.play().then(result => { results.media = result },
result => { results.media = result })
.then(resolve);
});
}
function runWebAudioTests() {
const audioContext = new AudioContext();
results.webAudio = audioContext.state;
}
async function runTests() {
await runMediaTests();
runWebAudioTests();
} }
window.addEventListener('load', function() { window.addEventListener('load', async function() {
if (window.testRunner) { if (window.testRunner) {
testRunner.dumpAsText(); testRunner.dumpAsText();
runVideoTest(); await runTests();
testRunner.dumpBackForwardList(); testRunner.dumpBackForwardList();
tearDown();
} }
}, false); }, false);
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment