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 results.webAudio is "running"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -6,6 +6,7 @@
<script>
testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
eventSender.mouseDown();
document.location.href = 'resources/test-autoplay.html';
......
PASS undefined is undefined.
PASS results.webAudio is "running"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -6,6 +6,7 @@
<script>
testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
document.querySelector('#target').focus();
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 results.webAudio should be running. Was suspended.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -6,6 +6,7 @@
<script>
testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
document.location.href = 'resources/test-autoplay.html';
</script>
PASS undefined is undefined.
PASS results.webAudio is "running"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -6,6 +6,7 @@
<script>
testRunner.waitUntilDone();
internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
var bounds = document.querySelector('#target').getBoundingClientRect();
var x = bounds.left + bounds.width / 2;
var y = bounds.top + bounds.height / 2;
......
......@@ -4,20 +4,26 @@
// Tracks the results and how many active tests we have running.
let testExpectations = {};
let callback;
let doneCallback;
let resultCallback = (data) => { top.postMessage(data, '*') };
let completedTestResults = [];
let results = {};
function tearDown(result) {
function tearDown() {
// Reset the flag state.
internals.settings.setAutoplayPolicy('no-user-gesture-required');
let canAutoplay = true;
// Ensure that play failed because autoplay was blocked. If playback failed
// for another reason then we don't care because autoplay is always checked
// first.
if (result && result.name == 'NotAllowedError')
canAutoplay = false;
const canAutoplayMedia = !results.media ||
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({
url: window.location.href,
......@@ -27,7 +33,7 @@ function tearDown(result) {
function receivedResult(data) {
// Forward the result to the top frame.
if (!callback) {
if (!doneCallback) {
top.postMessage(data, '*');
return;
}
......@@ -45,13 +51,28 @@ function processTestResults() {
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() {
const video = document.createElement('video');
video.src = '/media-resources/content/test.ogv';
video.play().then(tearDown, tearDown);
async function runAutoplayTest() {
await runMediaTest();
runWebAudioTest();
tearDown();
}
function simulateViewportClick(callback) {
......@@ -89,11 +110,11 @@ function runTest(pointerSequence, expectations) {
// Run the test.
async_test((t) => {
callback = t.step_func_done();
doneCallback = t.step_func_done();
// Fire the pointer sequence and then run the video test.
pointerSequence(t.step_func(() => {
runVideoTest();
runAutoplayTest();
// Navigate the iframe now we have the gesture.
document.getElementsByTagName('iframe')[0].src =
......@@ -106,10 +127,11 @@ function runTest(pointerSequence, expectations) {
// Setup the flags before the test is run.
internals.settings.setAutoplayPolicy('document-user-activation-required');
internals.runtimeFlags.autoplayIgnoresWebAudioEnabled = false;
// Setup the event listener to forward messages.
window.addEventListener('message', (e) => { resultCallback(e.data); });
// If we are on an iframe then run the video test automatically.
if (window.self !== window.top)
runVideoTest();
runAutoplayTest();
......@@ -3,23 +3,43 @@
<script src="/js-test-resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;
function tearDown(result) {
let results = {};
function tearDown() {
internals.settings.setAutoplayPolicy('no-user-gesture-required');
shouldBeUndefined(result);
shouldBeUndefined(results.media);
shouldBeEqualToString('results.webAudio', 'running');
finishJSTest();
}
function runVideoTest() {
var video = document.createElement('video');
video.src = "/resources/test.ogv";
video.play().then(tearDown, tearDown);
function runMediaTests() {
return new Promise(resolve => {
const video = document.createElement('video');
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) {
testRunner.dumpAsText();
runVideoTest();
await runTests();
testRunner.dumpBackForwardList();
tearDown();
}
}, false);
</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