Bug 1822232 [wpt PR 38974] - compute pressure: Add support for Workers, a=testonly

Automatic update from web-platform-tests
compute pressure: Add support for Workers

Implementation of compute pressure for dedicated workers and
shared workers.[1]

WPT tests have been updated accordingly.

[1]: https://w3c.github.io/compute-pressure/#supporting-algorithms

Bug: 1421715
Change-Id: Ia8a9b8c13677f6eeb0d302838e8d20224aa5512f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4204027
Reviewed-by: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: Fr <beaufort.francois@gmail.com>
Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1118524}

--

wpt-commits: 19d101562394344018f4ea72bc6cb5220a4148b2
wpt-pr: 38974
This commit is contained in:
Arnaud Mandy 2023-03-20 20:16:15 +00:00 коммит произвёл moz-wptsync-bot
Родитель b84174d31d
Коммит ae4bbc4900
8 изменённых файлов: 102 добавлений и 0 удалений

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

@ -7,3 +7,29 @@ promise_test(async t => {
observer.observe('cpu').catch(reject);
});
}, 'An active PressureObserver calls its callback at least once');
promise_test(async t => {
await new Promise(resolve => {
const myDedicatedWorker = new Worker(
'/compute-pressure/resources/observer-in-dedicated-worker.js');
myDedicatedWorker.onmessage = event => {
assert_equals(typeof event.data.time, 'number');
assert_equals('cpu', event.data.source);
resolve();
};
});
}, 'Test receives updates from dedicated worker');
promise_test(async t => {
await new Promise(resolve => {
const mySharedWorker = new SharedWorker(
'/compute-pressure/resources/observer-in-shared-worker.js');
mySharedWorker.port.start();
mySharedWorker.port.postMessage('observe');
mySharedWorker.port.onmessage = event => {
assert_equals(typeof event.data.time, 'number');
assert_equals('cpu', event.data.source);
resolve();
};
});
}, 'Test receives updates from shared worker');

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

@ -1,5 +1,6 @@
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
// META: global=window,dedicatedworker,sharedworker
// https://wicg.github.io/compute-pressure/

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

@ -51,5 +51,7 @@ async_test(t => {
);
}, `${header} allows cross-origin iframes with ${attribute}.`);
fetch_tests_from_worker(new Worker(
'/compute-pressure/resources/compute-pressure-allowed-by-permissions-policy-worker.js'));
</script>
</body>

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

@ -58,5 +58,7 @@ async_test(t => {
);
}, `${header} disallows cross-origin iframes despite the ${attribute}.`);
fetch_tests_from_worker(new Worker(
'/compute-pressure/resources/compute-pressure-disabled-by-permissions-policy-worker.js'));
</script>
</body>

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

@ -0,0 +1,22 @@
'use strict';
importScripts('/resources/testharness.js');
const header = 'permissions policy header "compute-pressure=*"';
let workerType;
if (typeof postMessage === 'function') {
workerType = 'dedicated';
}
promise_test(async () => {
try {
const observer = new PressureObserver(() => {});
await observer.observe('cpu');
observer.disconnect();
} catch (e) {
assert_unreached('expected promise to resolve.');
}
}, `$Inherited ${header} allows ${workerType} workers.`);
done();

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

@ -0,0 +1,18 @@
'use strict';
importScripts('/resources/testharness.js');
const header = 'Permissions-Policy header compute-pressure=()';
let workerType;
if (typeof postMessage === 'function') {
workerType = 'dedicated';
}
promise_test(async t => {
const observer =
new PressureObserver(t.unreached_func('oops should not end up here'));
await promise_rejects_dom(t, 'NotAllowedError', observer.observe('cpu'));
}, `$Inherited ${header} disallows ${workerType} workers.`);
done();

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

@ -0,0 +1,10 @@
'use strict';
function pressureCallback(update) {
postMessage(update[0].toJSON());
};
const observerWorker =
new PressureObserver(pressureCallback, {sampleRate: 0.5});
observerWorker.observe('cpu');

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

@ -0,0 +1,21 @@
'use strict';
onconnect = function(e) {
const port = e.ports[0]; // get the port
let started = false;
port.start(); // Open the port connection to enable two-way communication
let observerWorker =
new PressureObserver(pressureCallback, {sampleRate: 0.5});
port.onmessage = function(e) {
if (started === false)
observerWorker.observe('cpu');
started = true;
};
function pressureCallback(update) {
port.postMessage(update[0].toJSON());
};
}