diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js')
-rw-r--r-- | testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js b/testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js new file mode 100644 index 0000000000..1d188fad8b --- /dev/null +++ b/testing/web-platform/tests/compute-pressure/compute_pressure_disconnect.tentative.https.any.js @@ -0,0 +1,44 @@ +// 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(() => { + assert_unreached('The observer callback should not be called'); + }); + t.add_cleanup(() => observer.disconnect()); + observer.disconnect(); +}, 'Call disconnect() directly should not crash'); + +pressure_test(async (t, mockPressureService) => { + const observer1_changes = []; + const observer1 = new PressureObserver(change => { + observer1_changes.push(change); + }); + t.add_cleanup(() => observer1.disconnect()); + // Ensure that observer1's schema gets registered before observer2 starts. + await observer1.observe('cpu'); + observer1.disconnect(); + + const observer2_changes = []; + await new Promise((resolve, reject) => { + const observer2 = new PressureObserver(change => { + observer2_changes.push(change); + resolve(); + }); + t.add_cleanup(() => observer2.disconnect()); + observer2.observe('cpu').catch(reject); + mockPressureService.setPressureUpdate('cpu', 'critical'); + mockPressureService.startPlatformCollector(/*sampleRate=*/ 5.0); + }); + + assert_equals( + observer1_changes.length, 0, + 'disconnected observers should not receive callbacks'); + + assert_equals(observer2_changes.length, 1); + assert_equals(observer2_changes[0].length, 1); + assert_equals(observer2_changes[0][0].state, 'critical'); +}, 'Stopped PressureObserver do not receive changes'); |