blob: 74d37bd6e5cc75ce317380b42df63b1bdf1352e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// META: script=/resources/test-only-api.js
// META: script=resources/pressure-helpers.js
// META: global=window,dedicatedworker,sharedworker
'use strict';
pressure_test(async (t, mockPressureService) => {
const observer1_changes = [];
const observer1 = new PressureObserver(changes => {
observer1_changes.push(changes);
});
t.add_cleanup(() => observer1.disconnect());
// Ensure that observer1's schema gets registered before observer2 starts.
const promise = observer1.observe('cpu');
observer1.disconnect();
observer1.disconnect();
await promise_rejects_dom(t, 'AbortError', promise);
const observer2_changes = [];
await new Promise((resolve, reject) => {
const observer2 = new PressureObserver(changes => {
observer2_changes.push(changes);
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,
'stopped observers should not receive callbacks');
assert_equals(observer2_changes.length, 1);
assert_equals(observer2_changes[0][0].state, 'critical');
}, 'Stopped PressureObserver do not receive changes');
|