summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scheduler/task-signal-any-post-task-run-order.tentative.any.js
blob: 889217b08109080bd319d4c290fff7c0cf701521 (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
66
67
68
69
70
71
72
73
// META: title=Scheduler: Tasks Run in Priority Order
// META: global=window,worker

promise_test(async t => {
  const runOrder = [];
  const schedule = (id, signal) => scheduler.postTask(() => { runOrder.push(id); }, {signal});

  const tasks = [];
  tasks.push(schedule('B1', TaskSignal.any([], {priority: 'background'})));
  tasks.push(schedule('B2', TaskSignal.any([], {priority: 'background'})));
  tasks.push(schedule('UV1', TaskSignal.any([], {priority: 'user-visible'})));
  tasks.push(schedule('UV2', TaskSignal.any([], {priority: 'user-visible'})));
  tasks.push(schedule('UB1', TaskSignal.any([], {priority: 'user-blocking'})));
  tasks.push(schedule('UB2', TaskSignal.any([], {priority: 'user-blocking'})));

  await Promise.all(tasks);

  assert_equals(runOrder.toString(),'UB1,UB2,UV1,UV2,B1,B2');
}, 'scheduler.postTask() tasks run in priority order with a fixed priority composite signal');

promise_test(async t => {
  const runOrder = [];
  const schedule = (id, priorityOrSignal) => {
    if (priorityOrSignal instanceof TaskSignal) {
      return scheduler.postTask(() => { runOrder.push(id); }, {signal: priorityOrSignal});
    } else {
      return scheduler.postTask(() => { runOrder.push(id); }, {priority: priorityOrSignal});
    }
  };

  const controller = new TaskController({priority: 'user-blocking'});
  const signal = TaskSignal.any([], {priority: controller.signal});

  const tasks = [];
  tasks.push(schedule('B1', signal));
  tasks.push(schedule('B2', signal));
  tasks.push(schedule('UV1', 'user-visible'));
  tasks.push(schedule('UV2', 'user-visible'));
  tasks.push(schedule('UB1', 'user-blocking'));
  tasks.push(schedule('UB2', 'user-blocking'));

  controller.setPriority('background');

  await Promise.all(tasks);

  assert_equals(runOrder.toString(),'UB1,UB2,UV1,UV2,B1,B2');
}, 'scheduler.postTask() tasks run in priority order with a dynamic priority composite signal');

promise_test(async t => {
  const runOrder = [];
  const schedule = (id, priorityOrSignal) => {
    if (priorityOrSignal instanceof TaskSignal) {
      return scheduler.postTask(() => { runOrder.push(id); }, {signal: priorityOrSignal});
    } else {
      return scheduler.postTask(() => { runOrder.push(id); }, {priority: priorityOrSignal});
    }
  };

  const parentSignal = TaskSignal.any([], {priority: 'background'});
  const signal = TaskSignal.any([], {priority: parentSignal});

  const tasks = [];
  tasks.push(schedule('B1', signal));
  tasks.push(schedule('B2', signal));
  tasks.push(schedule('UV1', 'user-visible'));
  tasks.push(schedule('UV2', 'user-visible'));
  tasks.push(schedule('UB1', 'user-blocking'));
  tasks.push(schedule('UB2', 'user-blocking'));

  await Promise.all(tasks);

  assert_equals(runOrder.toString(),'UB1,UB2,UV1,UV2,B1,B2');
}, 'scheduler.postTask() tasks run in priority order with a composite signal whose source has fixed priority');