summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scheduler
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/scheduler
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/scheduler')
-rw-r--r--testing/web-platform/tests/scheduler/META.yml4
-rw-r--r--testing/web-platform/tests/scheduler/post-task-abort-reason.any.js37
-rw-r--r--testing/web-platform/tests/scheduler/post-task-delay.any.js11
-rw-r--r--testing/web-platform/tests/scheduler/post-task-result-success.any.js8
-rw-r--r--testing/web-platform/tests/scheduler/post-task-result-throws.any.js9
-rw-r--r--testing/web-platform/tests/scheduler/post-task-run-order.any.js21
-rw-r--r--testing/web-platform/tests/scheduler/post-task-then-detach.html28
-rw-r--r--testing/web-platform/tests/scheduler/post-task-with-abort-signal-in-handler.any.js20
-rw-r--r--testing/web-platform/tests/scheduler/post-task-with-abort-signal.any.js11
-rw-r--r--testing/web-platform/tests/scheduler/post-task-with-aborted-signal.any.js10
-rw-r--r--testing/web-platform/tests/scheduler/post-task-with-signal-and-priority.any.js14
-rw-r--r--testing/web-platform/tests/scheduler/post-task-with-signal-from-detached-iframe.html32
-rw-r--r--testing/web-platform/tests/scheduler/post-task-without-signals.any.js10
-rw-r--r--testing/web-platform/tests/scheduler/scheduler-replaceable.any.js12
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-abort-completed-tasks.any.js19
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-abort-signal-and-priority.any.js16
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-abort1.any.js16
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-abort2.any.js23
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-setPriority-delayed-task.any.js31
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-setPriority-recursive.any.js12
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-setPriority-repeated.any.js60
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-setPriority1.any.js24
-rw-r--r--testing/web-platform/tests/scheduler/task-controller-setPriority2.any.js22
-rw-r--r--testing/web-platform/tests/scheduler/task-signal-onprioritychange.any.js14
24 files changed, 464 insertions, 0 deletions
diff --git a/testing/web-platform/tests/scheduler/META.yml b/testing/web-platform/tests/scheduler/META.yml
new file mode 100644
index 0000000000..ef9511daa4
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/META.yml
@@ -0,0 +1,4 @@
+spec: https://wicg.github.io/scheduling-apis/
+suggested_reviewers:
+ - shaseley
+ - natechapin
diff --git a/testing/web-platform/tests/scheduler/post-task-abort-reason.any.js b/testing/web-platform/tests/scheduler/post-task-abort-reason.any.js
new file mode 100644
index 0000000000..27eff9f080
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-abort-reason.any.js
@@ -0,0 +1,37 @@
+// META: title=Scheduler: postTask uses abort reason
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+ const reason = new Error("Custom Abort Error");
+ controller.abort(reason);
+ return promise_rejects_exactly(t, reason, scheduler.postTask(() => {}, {signal}));
+}, 'Calling postTask with an aborted TaskSignal rejects the promise with the abort reason');
+
+promise_test(t => {
+ const controller = new AbortController();
+ const signal = controller.signal;
+ const reason = new Error("Custom Abort Error");
+ controller.abort(reason);
+ return promise_rejects_exactly(t, reason, scheduler.postTask(() => {}, {signal}));
+}, 'Calling postTask with an aborted AbortSignal rejects the promise with the abort reason');
+
+promise_test(t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+ const reason = new Error("Custom Abort Error");
+ const result = scheduler.postTask(() => {}, {signal});
+ controller.abort(reason);
+ return promise_rejects_exactly(t, reason, result);
+}, 'Aborting a TaskSignal rejects the promise of a scheduled task with the abort reason');
+
+promise_test(t => {
+ const reason = new Error("Custom Abort Error");
+ const controller = new AbortController();
+ const signal = controller.signal;
+ const result = scheduler.postTask(() => {}, {signal});
+ controller.abort(reason);
+ return promise_rejects_exactly(t, reason, result);
+}, 'Aborting an AbortSignal rejects the promise of a scheduled task with the abort reason');
diff --git a/testing/web-platform/tests/scheduler/post-task-delay.any.js b/testing/web-platform/tests/scheduler/post-task-delay.any.js
new file mode 100644
index 0000000000..cf96f6703b
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-delay.any.js
@@ -0,0 +1,11 @@
+// META: title=Scheduler: postTask Delayed Tasks
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const start = performance.now();
+ return scheduler.postTask(() => {
+ const elapsed = performance.now() - start;
+ assert_greater_than_equal(elapsed, 10);
+ }, {priority: 'user-blocking', delay: 10});
+}, 'Tests basic scheduler.postTask with a delay');
diff --git a/testing/web-platform/tests/scheduler/post-task-result-success.any.js b/testing/web-platform/tests/scheduler/post-task-result-success.any.js
new file mode 100644
index 0000000000..dd73c148e9
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-result-success.any.js
@@ -0,0 +1,8 @@
+// META: title=Scheduler: postTask Promise Value
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const result = await scheduler.postTask(() => 1234);
+ assert_equals(result, 1234);
+}, 'Test the task promise is resolved with the callback return value');
diff --git a/testing/web-platform/tests/scheduler/post-task-result-throws.any.js b/testing/web-platform/tests/scheduler/post-task-result-throws.any.js
new file mode 100644
index 0000000000..7155c94eac
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-result-throws.any.js
@@ -0,0 +1,9 @@
+// META: title=Scheduler: postTask Error Propagation
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ const testError = new Error('Failed');
+ const task = scheduler.postTask(() => { throw testError; });
+ return promise_rejects_exactly(t, testError, task, 'postTask should propagate the error');
+}, 'Test postTask rejects the associated promise with the callback error');
diff --git a/testing/web-platform/tests/scheduler/post-task-run-order.any.js b/testing/web-platform/tests/scheduler/post-task-run-order.any.js
new file mode 100644
index 0000000000..acbe86744c
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-run-order.any.js
@@ -0,0 +1,21 @@
+// META: title=Scheduler: Tasks Run in Priority Order
+// META: global=window,worker
+
+promise_test(async t => {
+ const runOrder = [];
+ const schedule = (id, priority) => scheduler.postTask(() => { runOrder.push(id); }, {priority});
+
+ // Post tasks in reverse priority order and expect they are run from highest
+ // to lowest priority.
+ const tasks = [];
+ tasks.push(schedule('B1', 'background'));
+ tasks.push(schedule('B2', 'background'));
+ 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');
+}, 'Test scheduler.postTask task run in priority order');
diff --git a/testing/web-platform/tests/scheduler/post-task-then-detach.html b/testing/web-platform/tests/scheduler/post-task-then-detach.html
new file mode 100644
index 0000000000..402f34dc0c
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-then-detach.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<title>Scheduler: postTask in Detached Scheduler</title>
+<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
+<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';
+
+async_test(t => {
+ onload = () => {
+ let didRun = false;
+ const frame = document.body.appendChild(document.createElement('iframe'));
+ frame.contentWindow.scheduler.postTask(() => { didRun = true; });
+ document.body.removeChild(frame);
+
+ // We cannot assume anything about ordering between postTask tasks and
+ // non-postTask or postTask tasks from different schedulers, so the best we
+ // can do is give the task time to run.
+ t.step_timeout(() => {
+ assert_false(didRun, 'The task should not have run.');
+ t.done();
+ }, 10);
+ }
+}, 'Test scheduler.postTask() from an iframe that is removed before the task runs');
+
+</script>
diff --git a/testing/web-platform/tests/scheduler/post-task-with-abort-signal-in-handler.any.js b/testing/web-platform/tests/scheduler/post-task-with-abort-signal-in-handler.any.js
new file mode 100644
index 0000000000..1fd416c775
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-with-abort-signal-in-handler.any.js
@@ -0,0 +1,20 @@
+// META: title=Scheduler: postTask with a signal and abort the signal when running the callback
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+ return promise_rejects_dom(t, 'AbortError', scheduler.postTask(() => {
+ controller.abort();
+ }, { signal }));
+}, 'Posting a task with a signal and abort the signal when running the sync callback');
+
+promise_test(t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+ return scheduler.postTask(async () => {
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ controller.abort();
+ }, { signal });
+}, 'Posting a task with a signal and abort the signal when running the async callback');
diff --git a/testing/web-platform/tests/scheduler/post-task-with-abort-signal.any.js b/testing/web-platform/tests/scheduler/post-task-with-abort-signal.any.js
new file mode 100644
index 0000000000..41cbafba90
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-with-abort-signal.any.js
@@ -0,0 +1,11 @@
+// META: title=Scheduler: postTask and AbortSignal
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ const controller = new AbortController();
+ const signal = controller.signal;
+ const taskResult = scheduler.postTask(() => {}, {signal});
+ controller.abort();
+ return promise_rejects_dom(t, 'AbortError', taskResult);
+}, 'Test that scheduler.postTask() accepts an AbortSignal that is not also a TaskSignal');
diff --git a/testing/web-platform/tests/scheduler/post-task-with-aborted-signal.any.js b/testing/web-platform/tests/scheduler/post-task-with-aborted-signal.any.js
new file mode 100644
index 0000000000..4e5d42c048
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-with-aborted-signal.any.js
@@ -0,0 +1,10 @@
+// META: title=Scheduler: postTask with an Aborted Signal
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+ controller.abort();
+ return promise_rejects_dom(t, 'AbortError', scheduler.postTask(() => {}, {signal}));
+}, 'Posting a task with an aborted signal rejects with an AbortError');
diff --git a/testing/web-platform/tests/scheduler/post-task-with-signal-and-priority.any.js b/testing/web-platform/tests/scheduler/post-task-with-signal-and-priority.any.js
new file mode 100644
index 0000000000..ba40d7cf53
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-with-signal-and-priority.any.js
@@ -0,0 +1,14 @@
+// META: title=Scheduler: Signal and Priority Combination
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const task1Result = scheduler.postTask(() => 'task1', {priority: 'user-visible'});
+
+ const controller = new TaskController({priority: 'background'});
+ const signal = controller.signal
+ const task2Result = scheduler.postTask(() => 'task2', {priority: 'user-blocking', signal});
+
+ const result = await Promise.race([task1Result, task2Result]);
+ assert_equals('task2', result);
+}, 'Test when scheduler.postTask() is passed both a signal and a priority');
diff --git a/testing/web-platform/tests/scheduler/post-task-with-signal-from-detached-iframe.html b/testing/web-platform/tests/scheduler/post-task-with-signal-from-detached-iframe.html
new file mode 100644
index 0000000000..acd974cbc7
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-with-signal-from-detached-iframe.html
@@ -0,0 +1,32 @@
+<!doctype html>
+<title>Scheduler: postTask with Detached Frame's Signal</title>
+<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
+<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';
+
+promise_test(async t => {
+ await new Promise((resolve) => {
+ window.addEventListener('load', resolve);
+ });
+
+ const frame = document.createElement('iframe');
+ frame.srcdoc = `
+ <script>
+ const controller = new TaskController();
+ window.childFrameSignal = controller.signal;
+ <\/script>`
+ await new Promise((resolve) => {
+ frame.addEventListener('load', resolve)
+ document.body.appendChild(frame);
+ });
+
+ const signal = frame.contentWindow.childFrameSignal;
+ document.body.removeChild(frame);
+ return scheduler.postTask(() => {}, {signal});
+}, 'Test scheduler.postTask() with a signal from a detached iframe');
+
+</script>
diff --git a/testing/web-platform/tests/scheduler/post-task-without-signals.any.js b/testing/web-platform/tests/scheduler/post-task-without-signals.any.js
new file mode 100644
index 0000000000..f5fe3e11a6
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/post-task-without-signals.any.js
@@ -0,0 +1,10 @@
+// META: title=Scheduler: Basic Functionality without Signals
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ for (const priority of ['user-blocking', 'user-visible', 'background']) {
+ const result = await scheduler.postTask(() => priority, {priority});
+ assert_equals(result, priority);
+ }
+}, 'Basic functionality for scheduler.postTask() without using TaskSignals');
diff --git a/testing/web-platform/tests/scheduler/scheduler-replaceable.any.js b/testing/web-platform/tests/scheduler/scheduler-replaceable.any.js
new file mode 100644
index 0000000000..12bf1116dd
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/scheduler-replaceable.any.js
@@ -0,0 +1,12 @@
+// META: title=Scheduler: scheduler should be replaceable
+// META: global=window,worker
+'use strict';
+
+test(() => {
+ class Scheduler {
+ constructor() {
+ scheduler = this;
+ }
+ }
+ new Scheduler();
+}, 'Tests replacing window.scheduler with a different object');
diff --git a/testing/web-platform/tests/scheduler/task-controller-abort-completed-tasks.any.js b/testing/web-platform/tests/scheduler/task-controller-abort-completed-tasks.any.js
new file mode 100644
index 0000000000..fc96038e64
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-abort-completed-tasks.any.js
@@ -0,0 +1,19 @@
+// META: title=Scheduler: Aborting Completed Tasks is a No-op
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const controller1 = new TaskController();
+ const controller2 = new TaskController();
+
+ await scheduler.postTask(() => {}, {signal: controller1.signal});
+
+ const task = scheduler.postTask(() => {}, {signal: controller2.signal});
+ controller2.abort();
+ await promise_rejects_dom(t, 'AbortError', task);
+
+ // The tasks associated with these controllers have completed, so this should
+ // not lead to any unhandled rejections.
+ controller1.abort();
+ controller2.abort();
+}, 'Aborting completed tasks should be a no-op.');
diff --git a/testing/web-platform/tests/scheduler/task-controller-abort-signal-and-priority.any.js b/testing/web-platform/tests/scheduler/task-controller-abort-signal-and-priority.any.js
new file mode 100644
index 0000000000..168fe92f54
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-abort-signal-and-priority.any.js
@@ -0,0 +1,16 @@
+// META: title=Scheduler: TaskController.abort() with Signal and Priority
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+
+ const task1 = scheduler.postTask(() => {}, {signal});
+ const task2 = scheduler.postTask(() => {}, {priority: 'background', signal});
+
+ controller.abort();
+
+ await promise_rejects_dom(t, 'AbortError', task1);
+ return promise_rejects_dom(t, 'AbortError', task2);
+}, 'Test that when scheduler.postTask() is given both a signal and priority, the signal abort is honored');
diff --git a/testing/web-platform/tests/scheduler/task-controller-abort1.any.js b/testing/web-platform/tests/scheduler/task-controller-abort1.any.js
new file mode 100644
index 0000000000..fc7e02ce37
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-abort1.any.js
@@ -0,0 +1,16 @@
+// META: title=Scheduler: TaskController.abort() Basic Functionality
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+
+ let didRun = false;
+ const taskResult = scheduler.postTask(() => { didRun = true; }, {signal});
+
+ controller.abort();
+
+ await promise_rejects_dom(t, 'AbortError', taskResult);
+ assert_false(didRun);
+}, 'Test that TaskController.abort() prevents a task from running and rejects the promise');
diff --git a/testing/web-platform/tests/scheduler/task-controller-abort2.any.js b/testing/web-platform/tests/scheduler/task-controller-abort2.any.js
new file mode 100644
index 0000000000..075715b565
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-abort2.any.js
@@ -0,0 +1,23 @@
+// META: title=Scheduler: TaskController.abort() Aborts Correct Task
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const taskControllers = [];
+ const taskResults = [];
+
+ for (let i = 0; i < 5; i++) {
+ const controller = new TaskController();
+ taskControllers.push(controller);
+
+ const signal = controller.signal;
+ taskResults.push(scheduler.postTask(() => i, {signal}));
+ }
+
+ const abortedTask = taskResults.splice(2, 1)[0];
+ taskControllers[2].abort();
+ await promise_rejects_dom(t, 'AbortError', abortedTask);
+
+ const result = await Promise.all(taskResults);
+ assert_equals(result.toString(), '0,1,3,4');
+}, 'Test aborting a task aborts the appropriate task');
diff --git a/testing/web-platform/tests/scheduler/task-controller-setPriority-delayed-task.any.js b/testing/web-platform/tests/scheduler/task-controller-setPriority-delayed-task.any.js
new file mode 100644
index 0000000000..43d24c8f92
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-setPriority-delayed-task.any.js
@@ -0,0 +1,31 @@
+// META: title=Scheduler: Change Delayed Task Priority
+// META: global=window,worker
+'use strict';
+
+promise_test(t => {
+ let taskCount = 0;
+ const start = performance.now();
+ const controller = new TaskController({priority: 'background'});
+
+ const task1 = scheduler.postTask(() => {
+ assert_equals(++taskCount, 1);
+ controller.setPriority('user-blocking');
+ }, {priority: 'user-blocking', delay: 10});
+
+ const task2 = scheduler.postTask(() => {
+ assert_equals(++taskCount, 2);
+
+ const elapsed = performance.now() - start;
+
+ if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
+ // Firefox returns the timings with different precision,
+ // so we put 19 here.
+ assert_greater_than_equal(elapsed, 19);
+ } else {
+ assert_greater_than_equal(elapsed, 20);
+ }
+ }, {signal: controller.signal, delay: 20});
+
+ return Promise.all([task1, task2]);
+
+}, "Tests delay when changing a delayed task's priority");
diff --git a/testing/web-platform/tests/scheduler/task-controller-setPriority-recursive.any.js b/testing/web-platform/tests/scheduler/task-controller-setPriority-recursive.any.js
new file mode 100644
index 0000000000..ebc4ccd950
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-setPriority-recursive.any.js
@@ -0,0 +1,12 @@
+// META: title=Scheduler: Recursive TaskController.setPriority()
+// META: global=window,worker
+'use strict';
+
+async_test(t => {
+ const controller = new TaskController();
+ controller.signal.onprioritychange = t.step_func_done(() => {
+ assert_equals(controller.signal.priority, 'background');
+ assert_throws_dom('NotAllowedError', () => { controller.setPriority('user-blocking'); });
+ });
+ controller.setPriority('background');
+}, 'Test that TaskController.setPriority() throws an error if called recursively');
diff --git a/testing/web-platform/tests/scheduler/task-controller-setPriority-repeated.any.js b/testing/web-platform/tests/scheduler/task-controller-setPriority-repeated.any.js
new file mode 100644
index 0000000000..fae3ec6c48
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-setPriority-repeated.any.js
@@ -0,0 +1,60 @@
+// META: title=Scheduler: TaskController.setPriority() repeated calls
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+
+ const tasks = [];
+ const runOrder = [];
+ const callback = id => { runOrder.push(id); };
+
+ tasks.push(scheduler.postTask(() => callback(0), {signal}));
+ tasks.push(scheduler.postTask(() => callback(1), {priority: 'user-blocking'}));
+ tasks.push(scheduler.postTask(() => callback(2), {priority: 'user-visible' }));
+
+ controller.setPriority('background');
+ assert_equals(signal.priority, 'background');
+
+ await Promise.all(tasks);
+ assert_equals(runOrder.toString(), '1,2,0');
+
+ while (tasks.length) { tasks.pop(); }
+ while (runOrder.length) { runOrder.pop(); }
+
+ tasks.push(scheduler.postTask(() => callback(3), {signal}));
+ tasks.push(scheduler.postTask(() => callback(4), {priority: 'user-blocking'}));
+ tasks.push(scheduler.postTask(() => callback(5), {priority: 'user-visible' }));
+
+ controller.setPriority('user-blocking');
+ assert_equals(signal.priority, 'user-blocking');
+
+ await Promise.all(tasks);
+ assert_equals(runOrder.toString(), '3,4,5');
+}, 'TaskController.setPriority() changes the priority of all associated tasks when called repeatedly');
+
+promise_test(async t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+
+ const tasks = [];
+ const runOrder = [];
+ const callback = id => { runOrder.push(id); };
+
+ tasks.push(scheduler.postTask(() => callback(0), {signal}));
+ tasks.push(scheduler.postTask(() => callback(1), {priority: 'user-blocking'}));
+ tasks.push(scheduler.postTask(() => callback(2), {priority: 'user-visible' }));
+
+ controller.setPriority('background');
+ assert_equals(signal.priority, 'background');
+
+ controller.setPriority('user-visible');
+ assert_equals(signal.priority, 'user-visible');
+
+ controller.setPriority('user-blocking');
+ assert_equals(signal.priority, 'user-blocking');
+
+ await Promise.all(tasks);
+ assert_equals(runOrder.toString(), '0,1,2');
+}, 'TaskController.setPriority() changes the priority of all associated tasks when called repeatedly before tasks run');
diff --git a/testing/web-platform/tests/scheduler/task-controller-setPriority1.any.js b/testing/web-platform/tests/scheduler/task-controller-setPriority1.any.js
new file mode 100644
index 0000000000..a59c20cacc
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-setPriority1.any.js
@@ -0,0 +1,24 @@
+// META: title=Scheduler: TaskController.setPriority()
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const controller = new TaskController();
+ const signal = controller.signal;
+
+ const tasks = [];
+ const runOrder = [];
+ const callback = id => { runOrder.push(id); };
+
+ for (let i = 0; i < 5; i++)
+ tasks.push(scheduler.postTask(() => callback(i), {signal}));
+ tasks.push(scheduler.postTask(() => callback(5), {priority: 'user-blocking'}));
+ tasks.push(scheduler.postTask(() => callback(6), {priority: 'user-visible' }));
+
+ controller.setPriority('background');
+ assert_equals(signal.priority, 'background');
+
+ await Promise.all(tasks);
+
+ assert_equals(runOrder.toString(), '5,6,0,1,2,3,4');
+}, 'Test that TaskController.setPriority() changes the priority of all associated tasks');
diff --git a/testing/web-platform/tests/scheduler/task-controller-setPriority2.any.js b/testing/web-platform/tests/scheduler/task-controller-setPriority2.any.js
new file mode 100644
index 0000000000..716b3af33e
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-controller-setPriority2.any.js
@@ -0,0 +1,22 @@
+// META: title=Scheduler: TaskController.setPriority and Task Order
+// META: global=window,worker
+'use strict';
+
+promise_test(async t => {
+ const tasks = [];
+ const runOrder = [];
+ const taskControllers = [];
+
+ for (let i = 0; i < 5; i++) {
+ taskControllers.push(new TaskController({priority: 'background'}));
+ const signal = taskControllers[i].signal;
+ tasks.push(scheduler.postTask(() => { runOrder.push(i); }, {signal}));
+ }
+
+ taskControllers[2].setPriority('user-blocking');
+ assert_equals(taskControllers[2].signal.priority, 'user-blocking');
+
+ await Promise.all(tasks);
+
+ assert_equals(runOrder.toString(), '2,0,1,3,4');
+}, 'Test TaskController.setPriority() affects task order.');
diff --git a/testing/web-platform/tests/scheduler/task-signal-onprioritychange.any.js b/testing/web-platform/tests/scheduler/task-signal-onprioritychange.any.js
new file mode 100644
index 0000000000..7f59e1f1f8
--- /dev/null
+++ b/testing/web-platform/tests/scheduler/task-signal-onprioritychange.any.js
@@ -0,0 +1,14 @@
+// META: title=Scheduler: TaskSignal onprioritychange
+// META: global=window,worker
+'use strict';
+
+async_test(t => {
+ const controller = new TaskController({priority: 'user-visible'});
+ controller.signal.onprioritychange = t.step_func_done((event) => {
+ assert_equals(controller.signal.priority, 'background');
+ assert_equals(event.type, 'prioritychange');
+ assert_equals(event.target.priority, 'background');
+ assert_equals(event.previousPriority, 'user-visible');
+ });
+ controller.setPriority('background');
+}, 'Test that TaskSignal.onprioritychange listens for prioritychange events');