summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scheduler/tentative/yield/yield-inherit-across-promises.any.js
blob: eaa0125a78409b44f4d5c5b321cd74a8144a4f06 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';

function postInheritPriorityTestTask(config) {
  const ids = [];
  const task = scheduler.postTask(async () => {
    await new Promise(resolve => setTimeout(resolve));
    await fetch('/common/blank.html');
    await new Promise(resolve => setTimeout(resolve));
    const subtask = scheduler.postTask(() => { ids.push('subtask'); }, {priority: config.subTaskPriority});
    await scheduler.yield(config.yieldOptions);
    ids.push('yield');
    await subtask;
  }, config.taskOptions);
  return {task, ids}
}

for (let priority of ['user-blocking', 'background']) {
  const expected = priority == 'user-blocking' ? 'yield,subtask' : 'subtask,yield';
  promise_test(async t => {
    const config = {
      taskOptions: {priority},
      subTaskPriority: 'user-blocking',
      yieldOptions: {priority: 'inherit'},
    };
    const {task, ids} = postInheritPriorityTestTask(config);
    await task;
    assert_equals(ids.join(), expected);
  }, `yield() inherits priority (string) across promises (${priority})`);

  promise_test(async t => {
    const signal = (new TaskController({priority})).signal;
    const config = {
      taskOptions: {signal},
      subTaskPriority: 'user-blocking',
      yieldOptions: {signal: 'inherit'},
    };
    const {task, ids} = postInheritPriorityTestTask(config);
    await task;
    assert_equals(ids.join(), expected);
  }, `yield() inherits priority (signal) across promises (${priority})`);

  promise_test(async t => {
    const config = {
      taskOptions: {priority},
      subTaskPriority: 'user-blocking',
      yieldOptions: {signal: 'inherit'},
    };
    const {task, ids} = postInheritPriorityTestTask(config);
    await task;
    assert_equals(ids.join(), expected);
  }, `yield() inherits priority (priority string with signal inherit) across promises (${priority})`);
}

promise_test(async t => {
  const controller = new TaskController();
  const signal = controller.signal;
  return scheduler.postTask(async () => {
    await new Promise(resolve => setTimeout(resolve));
    await fetch('/common/blank.html');
    await new Promise(resolve => setTimeout(resolve));
    controller.abort();
    const p = scheduler.yield({signal: 'inherit'});
    await promise_rejects_dom(t, 'AbortError', p);
  }, {signal});
}, `yield() inherits abort across promises`);