summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/idle-detection/resources
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/idle-detection/resources')
-rw-r--r--testing/web-platform/tests/idle-detection/resources/idle-detection-allowed-by-permissions-policy-worker.js16
-rw-r--r--testing/web-platform/tests/idle-detection/resources/idle-detection-disabled-by-permissions-policy-worker.js22
-rw-r--r--testing/web-platform/tests/idle-detection/resources/idle-detection-helper.js14
-rw-r--r--testing/web-platform/tests/idle-detection/resources/idlharness-worker.js22
4 files changed, 74 insertions, 0 deletions
diff --git a/testing/web-platform/tests/idle-detection/resources/idle-detection-allowed-by-permissions-policy-worker.js b/testing/web-platform/tests/idle-detection/resources/idle-detection-allowed-by-permissions-policy-worker.js
new file mode 100644
index 0000000000..1fe410ed11
--- /dev/null
+++ b/testing/web-platform/tests/idle-detection/resources/idle-detection-allowed-by-permissions-policy-worker.js
@@ -0,0 +1,16 @@
+'use strict';
+
+importScripts('/resources/testharness.js');
+
+let workerType;
+
+if (typeof postMessage === 'function') {
+ workerType = 'dedicated';
+}
+
+promise_test(async () => {
+ await new IdleDetector().start()
+},
+ `Inherited header permissions policy allows ${workerType} workers.`)
+
+done();
diff --git a/testing/web-platform/tests/idle-detection/resources/idle-detection-disabled-by-permissions-policy-worker.js b/testing/web-platform/tests/idle-detection/resources/idle-detection-disabled-by-permissions-policy-worker.js
new file mode 100644
index 0000000000..c30f7c188e
--- /dev/null
+++ b/testing/web-platform/tests/idle-detection/resources/idle-detection-disabled-by-permissions-policy-worker.js
@@ -0,0 +1,22 @@
+'use strict';
+
+importScripts('/resources/testharness.js');
+
+const header = 'Permissions-Policy header idle-detection=()';
+let workerType;
+
+if (typeof postMessage === 'function') {
+ workerType = 'dedicated';
+}
+
+promise_test(async () => {
+ try {
+ await new IdleDetector().start();
+ assert_unreached('expected start() to throw with SecurityError');
+ } catch (error) {
+ assert_equals(error.name, 'SecurityError');
+ }
+},
+`Inherited ${header} disallows ${workerType} workers.`);
+
+done();
diff --git a/testing/web-platform/tests/idle-detection/resources/idle-detection-helper.js b/testing/web-platform/tests/idle-detection/resources/idle-detection-helper.js
new file mode 100644
index 0000000000..f053e635e0
--- /dev/null
+++ b/testing/web-platform/tests/idle-detection/resources/idle-detection-helper.js
@@ -0,0 +1,14 @@
+'use strict';
+
+// These tests rely on the User Agent providing an implementation of
+// platform nfc backends.
+//
+// In Chromium-based browsers this implementation is provided by a polyfill
+// in order to reduce the amount of test-only code shipped to users. To enable
+// these tests the browser must be run with these options:
+//
+// --enable-blink-features=MojoJS,MojoJSTest
+
+async function loadChromiumResources() {
+ await import('/resources/chromium/mock-idle-detection.js');
+}
diff --git a/testing/web-platform/tests/idle-detection/resources/idlharness-worker.js b/testing/web-platform/tests/idle-detection/resources/idlharness-worker.js
new file mode 100644
index 0000000000..9733050284
--- /dev/null
+++ b/testing/web-platform/tests/idle-detection/resources/idlharness-worker.js
@@ -0,0 +1,22 @@
+'use strict';
+
+importScripts("/resources/testharness.js");
+importScripts("/resources/WebIDLParser.js", "/resources/idlharness.js");
+
+idl_test(
+ ['idle-detection'],
+ ['dom', 'html'],
+ async (idl_array, t) => {
+ self.idle = new IdleDetector();
+ let watcher = new EventWatcher(t, self.idle, ["change"]);
+ let initial_state = watcher.wait_for("change");
+ await self.idle.start();
+ await initial_state;
+
+ idl_array.add_objects({
+ IdleDetector: ['idle'],
+ });
+ }
+);
+
+done();