Bug 1505726 [wpt PR 13980] - [media] Treat cross-origin redirect as TAINTED only for no-cors requests, a=testonly

Automatic update from web-platform-tests[media] Treat cross-origin redirect as TAINTED only for no-cors requests

With https://crrev.com/a9cbaa7a40e2b2723cfc2f266c42f4980038a949,
WebMediaPlayer blindly treats a resource experiencing cross-origin
redirects as TAINTED. In fact, it should be treated as TAINTED only
when its request mode is "no-cors".

The added tests are provided by hongchan@chromium.org.

Bug: 899745, 901383
Change-Id: Idb66407552085b053818f3e4a9d8d5ff3ddeaf45
Reviewed-on: https://chromium-review.googlesource.com/c/1325281
Reviewed-by: Hongchan Choi <hongchan@chromium.org>
Reviewed-by: Fredrik Hubinette <hubbe@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606681}

--

wpt-commits: d5be80a86d4f938250c075ac12414ad47516969c
wpt-pr: 13980
This commit is contained in:
Yutaka Hirano 2018-11-13 13:40:44 +00:00 committed by moz-wptsync-bot
parent 1ec2acd378
commit 811f17bfdf
4 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,54 @@
/**
* @class RecorderProcessor
* @extends AudioWorkletProcessor
*
* A simple recorder AudioWorkletProcessor. Returns the recorded buffer to the
* node when recording is finished.
*/
class RecorderProcessor extends AudioWorkletProcessor {
/**
* @param {*} options
* @param {number} options.duration A duration to record in seconds.
* @param {number} options.channelCount A channel count to record.
*/
constructor(options) {
super();
this._createdAt = currentTime;
this._elapsed = 0;
this._recordDuration = options.duration || 1;
this._recordChannelCount = options.channelCount || 1;
this._recordBufferLength = sampleRate * this._recordDuration;
this._recordBuffer = [];
for (let i = 0; i < this._recordChannelCount; ++i) {
this._recordBuffer[i] = new Float32Array(this._recordBufferLength);
}
}
process(inputs, outputs) {
if (this._recordBufferLength <= currentFrame) {
this.port.postMessage({
type: 'recordfinished',
recordBuffer: this._recordBuffer
});
return false;
}
// Records the incoming data from |inputs| and also bypasses the data to
// |outputs|.
const input = inputs[0];
const output = outputs[0];
for (let channel = 0; channel < input.length; ++channel) {
const inputChannel = input[channel];
const outputChannel = output[channel];
outputChannel.set(inputChannel);
const buffer = this._recordBuffer[channel];
const capacity = buffer.length - currentFrame;
buffer.set(inputChannel.slice(0, capacity), currentFrame);
}
return true;
}
}
registerProcessor('recorder-processor', RecorderProcessor);

View File

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<title>
Test if MediaElementAudioSourceNode works for cross-origin redirects with
"cors" request mode.
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script id="layout-test-code">
const audit = Audit.createTaskRunner();
const context = new AudioContext();
context.suspend();
const host_info = get_host_info();
const audioElement = document.createElement('audio');
audioElement.loop = true;
audioElement.crossOrigin = 'anonymous';
const wav =
host_info.HTTPS_ORIGIN + '/webaudio/resources/4ch-440.wav?' +
'pipe=header(access-control-allow-origin,*)';
audioElement.src =
host_info.HTTPS_REMOTE_ORIGIN +
'/fetch/api/resources/redirect.py?location=' +
encodeURIComponent(wav);
let source;
let workletRecorder;
audit.define(
{label: 'setting-up-graph'},
(task, should) => {
source = new MediaElementAudioSourceNode(context, {
mediaElement: audioElement
});
workletRecorder = new AudioWorkletNode(
context, 'recorder-processor', {channelCount: 4});
source.connect(workletRecorder).connect(context.destination);
task.done();
});
// The recorded data from MESN must be non-zero. The source file contains
// 4 channels of sine wave.
audit.define(
{label: 'start-playback-and-capture'},
(task, should) => {
workletRecorder.port.onmessage = (event) => {
if (event.data.type === 'recordfinished') {
for (let i = 0; i < event.data.recordBuffer.length; ++i) {
const channelData = event.data.recordBuffer[i];
should(channelData, `Recorded channel #${i}`)
.notBeConstantValueOf(0);
}
}
task.done();
};
context.resume();
audioElement.play();
});
Promise.all([
context.audioWorklet.addModule('/webaudio/js/worklet-recorder.js')
]).then(() => {
audit.run();
});
</script>
</body>
</html>

View File

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<title>
Test if MediaElementAudioSourceNode works for cross-origin redirects with
"no-cors" request mode.
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script id="layout-test-code">
const audit = Audit.createTaskRunner();
const context = new AudioContext();
context.suspend();
const host_info = get_host_info();
const audioElement = document.createElement('audio');
audioElement.loop = true;
const wav =
host_info.HTTPS_ORIGIN + '/webaudio/resources/4ch-440.wav?' +
'pipe=header(access-control-allow-origin,*)';
audioElement.src =
host_info.HTTPS_REMOTE_ORIGIN +
'/fetch/api/resources/redirect.py?location=' +
encodeURIComponent(wav);
let source;
let workletRecorder;
audit.define(
{label: 'setting-up-graph'},
(task, should) => {
source = new MediaElementAudioSourceNode(context, {
mediaElement: audioElement
});
workletRecorder = new AudioWorkletNode(
context, 'recorder-processor', {channelCount: 4});
source.connect(workletRecorder).connect(context.destination);
task.done();
});
// The recorded data from MESN must be non-zero. The source file contains
// 4 channels of sine wave.
audit.define(
{label: 'start-playback-and-capture'},
(task, should) => {
workletRecorder.port.onmessage = (event) => {
if (event.data.type === 'recordfinished') {
for (let i = 0; i < event.data.recordBuffer.length; ++i) {
const channelData = event.data.recordBuffer[i];
should(channelData, `Recorded channel #${i}`)
.beConstantValueOf(0);
}
}
task.done();
};
context.resume();
audioElement.play();
});
Promise.all([
context.audioWorklet.addModule('/webaudio/js/worklet-recorder.js')
]).then(() => {
audit.run();
});
</script>
</body>
</html>