Skip to content

Commit

Permalink
Compute-Pressure: Initial web API for reporting compute pressure
Browse files Browse the repository at this point in the history
This tracks the initial blink implementation of the compute pressure API.
The interface presented in this CL follows the EventEmitter pattern.

Events will be emitted periodically after the developer has requested
that compute data be sent via the API.

Fixed: 1183600
Change-Id: I4fd929950b2a0d7810780e5af8d85063f4a3c6e3
  • Loading branch information
oyiptong authored and chromium-wpt-export-bot committed Mar 12, 2021
1 parent 05aed25 commit 13fd120
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compute-pressure/README.md
@@ -0,0 +1,2 @@
This directory contains (tentative) tests for the
[Compute Pressure](https://oyiptong.github.io/compute-pressure/) specification.
22 changes: 22 additions & 0 deletions compute-pressure/compute_pressure.tentative.https.window.js
@@ -0,0 +1,22 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=resources/utils.js

'use strict';

compute_pressure_test(async t => {
const obs = await navigator.deviceCompute.query();
await new Promise(resolve => {
obs.addEventListener('update', event => {
assert_true((typeof event.cpuUtilization == 'number'));
assert_true((typeof event.cpuSpeedLimit == 'number'));
assert_greater_than_equal(
event.cpuUtilization, 0,
'CPU Utilization is greater or equal to zero');
assert_greater_than_equal(
event.cpuSpeedLimit, 0,
'CPU Utilization is greater or equal to zero');
resolve();
});
});
}, 'query(): returns an EventTarget that fires an "update" event with CPU data');
20 changes: 20 additions & 0 deletions compute-pressure/resources/utils.js
@@ -0,0 +1,20 @@
'use strict';

function isPlatformSupported() {
if (navigator.platform.indexOf('Android') != -1 ||
navigator.platform.indexOf('Linux') != -1) {
return true;
}
return false;
}

function compute_pressure_test(test_function, name, properties) {
return promise_test(async (t) => {
if (!isPlatformSupported()) {
await promise_rejects_dom(
t, 'NotSupportedError', navigator.deviceCompute.query());
return;
}
await test_function(t, name, properties);
});
}

0 comments on commit 13fd120

Please sign in to comment.