Bug 1566312 - Add a wpt checking that microtask checkpoints happen in between render quantum. r=karlt

Differential Revision: https://phabricator.services.mozilla.com/D61728

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Adenot 2020-02-10 08:53:29 +00:00
Родитель 678d895cf5
Коммит b41ba52970
2 изменённых файлов: 84 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>
Test micro task checkpoints in AudioWorkletGlobalScope
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<meta charset=utf-8>
</head>
<body>
<script id="layout-test-code">
promise_test(async () => {
const context = new AudioContext();
let filePath = 'processors/promise-processor.js';
await context.audioWorklet.addModule(filePath);
await context.suspend();
let node1 = new AudioWorkletNode(context, 'promise-processor');
let node2 = new AudioWorkletNode(context, 'promise-processor');
// Connecting to the destination is not strictly necessary in theory,
// but see
// https://bugs.chromium.org/p/chromium/issues/detail?id=1045926
// for why it is in practice.
node1.connect(node2).connect(context.destination);
await context.resume();
// The second node is the one that is going to receive the message,
// per spec: it is the second that will be processed, each time.
const e = await new Promise((resolve) => {
node2.port.onmessage = resolve;
});
context.close();
assert_true(e.data == "ok",
`Microtask checkpoints are performed
in between render quantum`);
});
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,40 @@
/**
* @class PromiseProcessor
* @extends AudioWorkletProcessor
*
* This processor creates and resolves a promise in its `process` method. When
* the handler passed to `then()` is called, a counter that is global in the
* global scope is incremented. There are two copies of this
* AudioWorkletNode/Processor, so the counter should always be even in the
* process method of the AudioWorklet processing, since the Promise completion
* handler are resolved in between render quanta.
*
* After a few iterations of the test, one of the worklet posts back the string
* "ok" to the main thread, and the test is considered a success.
*/
var idx = 0;
class PromiseProcessor extends AudioWorkletProcessor {
constructor(options) {
super(options);
}
process(inputs, outputs) {
if (idx % 2 != 0) {
this.port.postMessage("ko");
// Don't bother continuing calling process in this case, the test has
// already failed.
return false;
}
Promise.resolve().then(() => {
idx++;
if (idx == 100) {
this.port.postMessage("ok");
}
});
// Ensure process is called again.
return true;
}
}
registerProcessor('promise-processor', PromiseProcessor);