Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute-Pressure: Initial web API for reporting compute pressure
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
1 parent
05aed25
commit 13fd120
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
22
compute-pressure/compute_pressure.tentative.https.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} |