summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/compute-pressure
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /testing/web-platform/tests/compute-pressure
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/compute-pressure')
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_duplicate_updates.https.any.js4
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_known_sources.https.any.js (renamed from testing/web-platform/tests/compute-pressure/compute_pressure_supported_sources.https.any.js)10
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_options.https.any.js43
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js4
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js4
-rw-r--r--testing/web-platform/tests/compute-pressure/compute_pressure_timestamp.https.any.js90
-rw-r--r--testing/web-platform/tests/compute-pressure/idlharness.https.any.js2
-rw-r--r--testing/web-platform/tests/compute-pressure/observe_return_type.https.any.js18
8 files changed, 120 insertions, 55 deletions
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_duplicate_updates.https.any.js b/testing/web-platform/tests/compute-pressure/compute_pressure_duplicate_updates.https.any.js
index 04c5df5e57..609fb5ad70 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_duplicate_updates.https.any.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_duplicate_updates.https.any.js
@@ -12,8 +12,8 @@ pressure_test(async (t, mockPressureService) => {
observer_changes.push(changes);
if (++n === 2)
resolve(observer_changes);
- }, {sampleInterval: 200});
- observer.observe('cpu');
+ });
+ observer.observe('cpu', {sampleInterval: 200});
const updatesDelivered = mockPressureService.updatesDelivered();
mockPressureService.setPressureUpdate('cpu', 'critical');
mockPressureService.startPlatformCollector(/*sampleInterval*/ 200);
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_supported_sources.https.any.js b/testing/web-platform/tests/compute-pressure/compute_pressure_known_sources.https.any.js
index 63f2666cca..5db3053ce9 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_supported_sources.https.any.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_known_sources.https.any.js
@@ -4,18 +4,18 @@
test(() => {
// Compute Pressure should support at least "cpu"
- const sources = PressureObserver.supportedSources;
+ const sources = PressureObserver.knownSources;
assert_in_array('cpu', sources);
}, 'PressureObserver should support at least "cpu"');
test(() => {
// Compute Pressure should be frozen array
- const sources = PressureObserver.supportedSources;
- assert_equals(sources, PressureObserver.supportedSources);
+ const sources = PressureObserver.knownSources;
+ assert_equals(sources, PressureObserver.knownSources);
}, 'PressureObserver must return always the same array');
test(() => {
// Compute Pressure should be frozen array
- let sources = PressureObserver.supportedSources;
- assert_equals(Object.isFrozen(), true);
+ let sources = PressureObserver.knownSources;
+ assert_equals(Object.isFrozen(sources), true);
}, 'PressureObserver must return a frozen array');
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_options.https.any.js b/testing/web-platform/tests/compute-pressure/compute_pressure_options.https.any.js
index d0760ef622..ecf3c29dbf 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_options.https.any.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_options.https.any.js
@@ -1,26 +1,31 @@
+// META: script=/resources/test-only-api.js
+// META: script=resources/pressure-helpers.js
// META: global=window,dedicatedworker,sharedworker
'use strict';
-test(t => {
- const observer = new PressureObserver(() => {}, {sampleInterval: 0});
- assert_equals(typeof observer, 'object');
-}, 'PressureObserver constructor doesnt throw error for sampleInterval value 0');
-
-
-test(t => {
- assert_throws_js(TypeError, () => {
- new PressureObserver(() => {}, {sampleInterval: -2});
+pressure_test(async (t, mockPressureService) => {
+ await new Promise(resolve => {
+ const observer = new PressureObserver(resolve);
+ t.add_cleanup(() => observer.disconnect());
+ observer.observe('cpu', {sampleInterval: 0});
+ mockPressureService.setPressureUpdate('cpu', 'critical');
+ mockPressureService.startPlatformCollector(/*sampleInterval=*/ 200);
});
-}, 'PressureObserver constructor requires a positive sampleInterval');
+}, 'PressureObserver observe method doesnt throw error for sampleInterval value 0');
-test(t => {
- assert_throws_js(TypeError, () => {
- new PressureObserver(() => {}, {sampleInterval: 2 ** 32});
- });
-}, 'PressureObserver constructor requires a sampleInterval in unsigned long range');
+promise_test(async t => {
+ const observer =
+ new PressureObserver(t.unreached_func('oops should not end up here'));
+ t.add_cleanup(() => observer.disconnect());
+ await promise_rejects_js(
+ t, TypeError, observer.observe('cpu', {sampleInterval: -2}));
+}, 'PressureObserver observe method requires a positive sampleInterval');
-test(t => {
- const observer = new PressureObserver(() => {}, {});
- assert_equals(typeof observer, 'object');
-}, 'PressureObserver constructor succeeds on empty sampleInterval');
+promise_test(async t => {
+ const observer =
+ new PressureObserver(t.unreached_func('oops should not end up here'));
+ t.add_cleanup(() => observer.disconnect());
+ await promise_rejects_js(
+ t, TypeError, observer.observe('cpu', {sampleInterval: 2 ** 32}));
+}, 'PressureObserver observe method requires a sampleInterval in unsigned long range');
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js b/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js
index e348a8ea08..f3e966de24 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js
@@ -17,9 +17,9 @@ pressure_test(async (t, mockPressureService) => {
const observerChanges = [];
const observer = new PressureObserver(changes => {
observerChanges.push(changes);
- }, {sampleInterval: sampleIntervalInMs});
+ });
- observer.observe('cpu');
+ observer.observe('cpu', {sampleInterval: sampleIntervalInMs});
mockPressureService.startPlatformCollector(sampleIntervalInMs);
let i = 0;
// mockPressureService.updatesDelivered() does not necessarily match
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js b/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js
index ebe33bc8bf..b481cf6c87 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js
@@ -31,9 +31,9 @@ pressure_test(async (t, mockPressureService) => {
}
}
observerChanges.push(changes);
- }, {sampleInterval: sampleIntervalInMs});
+ });
- observer.observe('cpu');
+ observer.observe('cpu', {sampleInterval: sampleIntervalInMs});
mockPressureService.startPlatformCollector(sampleIntervalInMs);
let i = 0;
// mockPressureService.updatesDelivered() does not necessarily match
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_timestamp.https.any.js b/testing/web-platform/tests/compute-pressure/compute_pressure_timestamp.https.any.js
index 09caeb3478..18db1dac46 100644
--- a/testing/web-platform/tests/compute-pressure/compute_pressure_timestamp.https.any.js
+++ b/testing/web-platform/tests/compute-pressure/compute_pressure_timestamp.https.any.js
@@ -5,32 +5,73 @@
'use strict';
pressure_test(async (t, mockPressureService) => {
+ const [change, timeOrigin] = await new Promise(resolve => {
+ const observer = new PressureObserver(change => {
+ resolve([change, performance.timeOrigin]);
+ });
+ t.add_cleanup(() => observer.disconnect());
+ observer.observe('cpu');
+ mockPressureService.setPressureUpdate('cpu', 'critical');
+ mockPressureService.startPlatformCollector(/*sampleInterval=*/ 200);
+ });
+ assert_greater_than(change[0].time, timeOrigin);
+}, 'Timestamp from update should be greater than timeOrigin');
+
+pressure_test(async (t, mockPressureService) => {
const readings = ['nominal', 'fair', 'serious', 'critical'];
const sampleInterval = 250;
- const pressureChanges = await new Promise(async resolve => {
- const observerChanges = [];
- const observer = new PressureObserver(changes => {
- observerChanges.push(changes);
- }, {sampleInterval});
- observer.observe('cpu');
+ const pressureChanges = [];
+ const observer = new PressureObserver(changes => {
+ pressureChanges.push(changes);
+ });
+ observer.observe('cpu', {sampleInterval});
- mockPressureService.startPlatformCollector(sampleInterval / 2);
- let i = 0;
- // mockPressureService.updatesDelivered() does not necessarily match
- // pressureChanges.length, as system load and browser optimizations can
- // cause the actual timer used by mockPressureService to deliver readings
- // to be a bit slower or faster than requested.
- while (observerChanges.length < 4) {
- mockPressureService.setPressureUpdate(
- 'cpu', readings[i++ % readings.length]);
- await t.step_wait(
- () => mockPressureService.updatesDelivered() >= i,
- `At least ${i} readings have been delivered`);
- }
- observer.disconnect();
- resolve(observerChanges);
+ mockPressureService.startPlatformCollector(sampleInterval / 2);
+ let i = 0;
+ // mockPressureService.updatesDelivered() does not necessarily match
+ // pressureChanges.length, as system load and browser optimizations can
+ // cause the actual timer used by mockPressureService to deliver readings
+ // to be a bit slower or faster than requested.
+ while (pressureChanges.length < 4) {
+ mockPressureService.setPressureUpdate(
+ 'cpu', readings[i++ % readings.length]);
+ await t.step_wait(
+ () => mockPressureService.updatesDelivered() >= i,
+ `At least ${i} readings have been delivered`);
+ }
+ observer.disconnect();
+
+ assert_equals(pressureChanges.length, 4);
+ assert_greater_than(pressureChanges[1][0].time, pressureChanges[0][0].time);
+ assert_greater_than(pressureChanges[2][0].time, pressureChanges[1][0].time);
+ assert_greater_than(pressureChanges[3][0].time, pressureChanges[2][0].time);
+}, 'Timestamp difference between two changes should be continuously increasing');
+
+pressure_test(async (t, mockPressureService) => {
+ const readings = ['nominal', 'fair', 'serious', 'critical'];
+
+ const sampleInterval = 250;
+ const pressureChanges = [];
+ const observer = new PressureObserver(change => {
+ pressureChanges.push(change);
});
+ observer.observe('cpu', {sampleInterval});
+
+ mockPressureService.startPlatformCollector(sampleInterval / 2);
+ let i = 0;
+ // mockPressureService.updatesDelivered() does not necessarily match
+ // pressureChanges.length, as system load and browser optimizations can
+ // cause the actual timer used by mockPressureService to deliver readings
+ // to be a bit slower or faster than requested.
+ while (pressureChanges.length < 4) {
+ mockPressureService.setPressureUpdate(
+ 'cpu', readings[i++ % readings.length]);
+ await t.step_wait(
+ () => mockPressureService.updatesDelivered() >= i,
+ `At least ${i} readings have been delivered`);
+ }
+ observer.disconnect();
assert_equals(pressureChanges.length, 4);
assert_greater_than_equal(
@@ -46,10 +87,10 @@ pressure_test(async (t, mockPressureService) => {
const sampleInterval = 1000;
const observer = new PressureObserver(changes => {
pressureChanges.push(changes);
- }, {sampleInterval});
+ });
await new Promise(async resolve => {
- observer.observe('cpu');
+ observer.observe('cpu', {sampleInterval});
mockPressureService.setPressureUpdate('cpu', 'critical');
mockPressureService.startPlatformCollector(sampleInterval);
await t.step_wait(() => pressureChanges.length == 1);
@@ -71,5 +112,6 @@ pressure_test(async (t, mockPressureService) => {
// should be deleted. So the second PressureRecord is not discarded even
// though the time interval does not meet the requirement.
assert_less_than(
- pressureChanges[1][0].time - pressureChanges[0][0].time, sampleInterval);
+ (pressureChanges[1][0].time - pressureChanges[0][0].time),
+ sampleInterval);
}, 'disconnect() should update [[LastRecordMap]]');
diff --git a/testing/web-platform/tests/compute-pressure/idlharness.https.any.js b/testing/web-platform/tests/compute-pressure/idlharness.https.any.js
index 48ab5615b0..6cd7e87b5b 100644
--- a/testing/web-platform/tests/compute-pressure/idlharness.https.any.js
+++ b/testing/web-platform/tests/compute-pressure/idlharness.https.any.js
@@ -11,5 +11,5 @@ idl_test(['compute-pressure'], ['dom', 'html'], async idl_array => {
PressureObserver: ['observer'],
});
- self.observer = new PressureObserver(() => {}, {sampleInterval: 1000});
+ self.observer = new PressureObserver(() => {});
});
diff --git a/testing/web-platform/tests/compute-pressure/observe_return_type.https.any.js b/testing/web-platform/tests/compute-pressure/observe_return_type.https.any.js
new file mode 100644
index 0000000000..b24878ab39
--- /dev/null
+++ b/testing/web-platform/tests/compute-pressure/observe_return_type.https.any.js
@@ -0,0 +1,18 @@
+// META: script=/resources/test-only-api.js
+// META: script=resources/pressure-helpers.js
+// META: global=window,dedicatedworker,sharedworker
+
+'use strict';
+
+// Regression test for https://issues.chromium.org/issues/333957909
+// Make sure that observe() always returns a Promise.
+pressure_test(async (t, mockPressureService) => {
+ const observer = new PressureObserver(() => {});
+ t.add_cleanup(() => observer.disconnect());
+
+ for (let i = 0; i < 2; i++) {
+ const promise = observer.observe('cpu');
+ assert_class_string(promise, 'Promise');
+ await promise;
+ }
+}, 'PressureObserver.observe() is idempotent');