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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<!doctype html>
<title>Scheduler: yield inheritance in requestIdleCallback</title>
<link rel="help" href="https://github.com/WICG/scheduling-apis">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
// Queues a requestIdleCallback that schedules 2 user-visible tasks, 2
// background tasks, another requestIdleCallback, and then yields 3 times using
// `yieldParams`.
//
// Returns {tasks, ids} where `tasks` is an array of promises associated with
// the tasks and `ids` is an array of task ids appended to by the scheduled
// tasks.
function postTestTasks(yieldParams) {
const ids = [];
const task = new Promise(resolve => {
requestIdleCallback(async () => {
ids.push('i1');
const subtasks = [];
subtasks.push(scheduler.postTask(() => { ids.push('uv1'); }));
subtasks.push(scheduler.postTask(() => { ids.push('uv2'); }));
subtasks.push(scheduler.postTask(() => { ids.push('bg1'); }, {priority: 'background'}));
subtasks.push(scheduler.postTask(() => { ids.push('bg2'); }, {priority: 'background'}));
subtasks.push(new Promise(resolve => {
requestIdleCallback(() => {
ids.push('i2');
resolve();
});
}));
for (let i = 1; i <= 3; i++) {
await scheduler.yield(yieldParams);
ids.push('y' + i);
}
await Promise.all(subtasks);
resolve();
});
});
return {task, ids};
}
const expected_inherited_task_order = 'i1,uv1,uv2,y1,y2,y3,bg1,bg2,i2';
promise_test(async t => {
const {task, ids} = postTestTasks({priority: "inherit"});
await task;
assert_equals(ids.join(), expected_inherited_task_order);
}, 'requestIdleCallback() yields at background priority when inheriting priority');
promise_test(async t => {
const {task, ids} = postTestTasks({signal: "inherit"});
await task;
assert_equals(ids.join(), expected_inherited_task_order);
}, 'requestIdleCallback() yields at background priority when inheriting signal');
</script>
|