yield-priority-idle-callbacks.html (1769B)
1 <!doctype html> 2 <title>Scheduler: yield inheritance in requestIdleCallback</title> 3 <link rel="help" href="https://github.com/WICG/scheduling-apis"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <script> 8 'use strict'; 9 10 // Queues a requestIdleCallback that schedules 2 user-visible tasks, 2 11 // background tasks, another requestIdleCallback, and then yields 3 times using 12 // `yieldParams`. 13 // 14 // Returns {tasks, ids} where `tasks` is an array of promises associated with 15 // the tasks and `ids` is an array of task ids appended to by the scheduled 16 // tasks. 17 function postTestTasks() { 18 const ids = []; 19 const task = new Promise(resolve => { 20 requestIdleCallback(async () => { 21 ids.push('i1'); 22 23 const subtasks = []; 24 subtasks.push(scheduler.postTask(() => { ids.push('uv1'); })); 25 subtasks.push(scheduler.postTask(() => { ids.push('uv2'); })); 26 subtasks.push(scheduler.postTask(() => { ids.push('bg1'); }, {priority: 'background'})); 27 subtasks.push(scheduler.postTask(() => { ids.push('bg2'); }, {priority: 'background'})); 28 subtasks.push(new Promise(resolve => { 29 requestIdleCallback(() => { 30 ids.push('i2'); 31 resolve(); 32 }); 33 })); 34 35 for (let i = 1; i <= 3; i++) { 36 await scheduler.yield(); 37 ids.push('y' + i); 38 } 39 await Promise.all(subtasks); 40 resolve(); 41 }); 42 }); 43 return {task, ids}; 44 } 45 46 const expected_inherited_task_order = 'i1,uv1,uv2,y1,y2,y3,bg1,bg2,i2'; 47 48 promise_test(async t => { 49 const {task, ids} = postTestTasks(); 50 await task; 51 assert_equals(ids.join(), expected_inherited_task_order); 52 }, 'requestIdleCallback() yields at background priority when inheriting signal'); 53 54 </script>