From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/idle-detection/META.yml | 5 + .../basics.tentative.https.window.js | 98 ++++++ ...olicy-attribute-redirect-on-load.https.sub.html | 52 +++ ...-by-permissions-policy-attribute.https.sub.html | 48 +++ ...on-allowed-by-permissions-policy.https.sub.html | 57 ++++ ...ed-by-permissions-policy.https.sub.html.headers | 1 + ...ction-default-permissions-policy.https.sub.html | 39 +++ ...n-disabled-by-permissions-policy.https.sub.html | 56 +++ ...ed-by-permissions-policy.https.sub.html.headers | 1 + .../idle-permission.tentative.https.window.js | 34 ++ .../idlharness-worker.https.window.js | 10 + .../idle-detection/idlharness.https.window.js | 26 ++ .../tests/idle-detection/interceptor.https.html | 378 +++++++++++++++++++++ .../idle-detection/page-visibility.https.html | 79 +++++ ...tection-allowed-by-permissions-policy-worker.js | 16 + ...ection-disabled-by-permissions-policy-worker.js | 22 ++ .../resources/idle-detection-helper.js | 14 + .../idle-detection/resources/idlharness-worker.js | 22 ++ 18 files changed, 958 insertions(+) create mode 100644 testing/web-platform/tests/idle-detection/META.yml create mode 100644 testing/web-platform/tests/idle-detection/basics.tentative.https.window.js create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute.https.sub.html create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html.headers create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-default-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html create mode 100644 testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html.headers create mode 100644 testing/web-platform/tests/idle-detection/idle-permission.tentative.https.window.js create mode 100644 testing/web-platform/tests/idle-detection/idlharness-worker.https.window.js create mode 100644 testing/web-platform/tests/idle-detection/idlharness.https.window.js create mode 100644 testing/web-platform/tests/idle-detection/interceptor.https.html create mode 100644 testing/web-platform/tests/idle-detection/page-visibility.https.html create mode 100644 testing/web-platform/tests/idle-detection/resources/idle-detection-allowed-by-permissions-policy-worker.js create mode 100644 testing/web-platform/tests/idle-detection/resources/idle-detection-disabled-by-permissions-policy-worker.js create mode 100644 testing/web-platform/tests/idle-detection/resources/idle-detection-helper.js create mode 100644 testing/web-platform/tests/idle-detection/resources/idlharness-worker.js (limited to 'testing/web-platform/tests/idle-detection') diff --git a/testing/web-platform/tests/idle-detection/META.yml b/testing/web-platform/tests/idle-detection/META.yml new file mode 100644 index 0000000000..adbdc7bd93 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/META.yml @@ -0,0 +1,5 @@ +spec: https://wicg.github.io/idle-detection/ +suggested_reviewers: + - goto + - jsbell + - reillyg \ No newline at end of file diff --git a/testing/web-platform/tests/idle-detection/basics.tentative.https.window.js b/testing/web-platform/tests/idle-detection/basics.tentative.https.window.js new file mode 100644 index 0000000000..32cb6204b9 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/basics.tentative.https.window.js @@ -0,0 +1,98 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +// META: title=Idle Detection API: Basics + +'use strict'; + +promise_setup(async t => { + await test_driver.set_permission({name: 'idle-detection'}, 'granted'); +}) + +promise_test(async t => { + let detector = new IdleDetector(); + let watcher = new EventWatcher(t, detector, ["change"]); + let initial_state = watcher.wait_for("change"); + + await detector.start(); + await initial_state; + + assert_true(['active', 'idle'].includes(detector.userState), + 'has a valid user state'); + assert_true(['locked', 'unlocked'].includes(detector.screenState), + 'has a valid screen state'); +}, 'start() basics'); + +promise_test(async t => { + let used = false; + + const detector = new IdleDetector(); + detector.start({ + get threshold() { + used = true; + return 60000; + } + }); + + assert_true(used, 'start() options "threshold" member was used'); +}, 'start() uses threshold property'); + +promise_test(async t => { + let used = false; + + const controller = new AbortController(); + const detector = new IdleDetector(); + detector.start({ + get signal() { + used = true; + return controller.signal; + } + }); + + assert_true(used, 'start() options "signal" member was used'); +}, 'start() uses signal property'); + + +promise_test(async t => { + const detector = new IdleDetector(); + await promise_rejects_js(t, TypeError, detector.start({threshold: 0})); +}, 'start() rejects with invalid threshold (0)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await promise_rejects_js(t, TypeError, detector.start({threshold: 59000})); +}, 'start() rejects with threshold below minimum (59000)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await detector.start({threshold: 60000}); +}, 'start() rejects threshold (60000)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await detector.start({threshold: 61000}); +}, 'start() allows threshold (61000)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await promise_rejects_js(t, TypeError, detector.start({threshold: null})); +}, 'start() rejects with invalid threshold (null)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await promise_rejects_js(t, TypeError, detector.start({threshold: -1})); +}, 'start() rejects with invalid threshold (-1)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await promise_rejects_js(t, TypeError, detector.start({threshold: NaN})); +}, 'start() rejects with invalid threshold (NaN)'); + +promise_test(async t => { + const detector = new IdleDetector(); + await detector.start(); +}, 'start() uses a default value for the threshold when none is passed'); + +promise_test(async t => { + const detector = new IdleDetector(); + await detector.start({threshold: undefined}); +}, 'start() uses a default value for the threshold'); diff --git a/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html new file mode 100644 index 0000000000..e419840ccd --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html @@ -0,0 +1,52 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute.https.sub.html b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute.https.sub.html new file mode 100644 index 0000000000..e05772d9bc --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy-attribute.https.sub.html @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..6fae367730 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html @@ -0,0 +1,57 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..2bf18afe5f --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-allowed-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: idle-detection=* diff --git a/testing/web-platform/tests/idle-detection/idle-detection-default-permissions-policy.https.sub.html b/testing/web-platform/tests/idle-detection/idle-detection-default-permissions-policy.https.sub.html new file mode 100644 index 0000000000..90cb7f88d3 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-default-permissions-policy.https.sub.html @@ -0,0 +1,39 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html b/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..90317dece7 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html @@ -0,0 +1,56 @@ + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..289463c30d --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-detection-disabled-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: idle-detection=() diff --git a/testing/web-platform/tests/idle-detection/idle-permission.tentative.https.window.js b/testing/web-platform/tests/idle-detection/idle-permission.tentative.https.window.js new file mode 100644 index 0000000000..524062f9f3 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idle-permission.tentative.https.window.js @@ -0,0 +1,34 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +'use strict'; + +promise_test(async t => { + await test_driver.set_permission({name: 'idle-detection'}, 'denied'); + + let detector = new IdleDetector(); + await promise_rejects_dom(t, 'NotAllowedError', detector.start()); +}, 'Denying idle-detection permission should block access.'); + +promise_test(async t => { + await test_driver.set_permission({name: 'idle-detection'}, 'granted'); + + let detector = new IdleDetector(); + await detector.start(); + + assert_true( + ['active', 'idle'].includes(detector.userState), + 'has a valid user state'); + assert_true( + ['locked', 'unlocked'].includes(detector.screenState), + 'has a valid screen state'); +}, 'Granting idle-detection permission should allow access.'); + +promise_test(async t => { + await test_driver.set_permission({name: 'idle-detection'}, 'prompt'); + + await promise_rejects_dom(t, 'NotAllowedError', IdleDetector.requestPermission()); + + await test_driver.bless('request permission'); + let state = await IdleDetector.requestPermission(); + assert_equals(state, 'prompt'); +}, 'The idle-detection permission cannot be requested without a user gesture'); diff --git a/testing/web-platform/tests/idle-detection/idlharness-worker.https.window.js b/testing/web-platform/tests/idle-detection/idlharness-worker.https.window.js new file mode 100644 index 0000000000..e8fcf9ede6 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idlharness-worker.https.window.js @@ -0,0 +1,10 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js + +'use strict'; + +promise_test(async t => { + await test_driver.set_permission({name: 'idle-detection'}, 'granted'); + + await fetch_tests_from_worker(new Worker('resources/idlharness-worker.js')); +}, 'Run idlharness tests in a worker.'); diff --git a/testing/web-platform/tests/idle-detection/idlharness.https.window.js b/testing/web-platform/tests/idle-detection/idlharness.https.window.js new file mode 100644 index 0000000000..2f1758098f --- /dev/null +++ b/testing/web-platform/tests/idle-detection/idlharness.https.window.js @@ -0,0 +1,26 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js + +// https://github.com/samuelgoto/idle-detection + +'use strict'; + +idl_test( + ['idle-detection'], + ['dom', 'html'], + async (idl_array, t) => { + await test_driver.set_permission({ name: 'idle-detection' }, 'granted'); + + 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'], + }); + } +); diff --git a/testing/web-platform/tests/idle-detection/interceptor.https.html b/testing/web-platform/tests/idle-detection/interceptor.https.html new file mode 100644 index 0000000000..e9350ce8ce --- /dev/null +++ b/testing/web-platform/tests/idle-detection/interceptor.https.html @@ -0,0 +1,378 @@ + + +Tests the Idle Detection API + + + + + + + diff --git a/testing/web-platform/tests/idle-detection/page-visibility.https.html b/testing/web-platform/tests/idle-detection/page-visibility.https.html new file mode 100644 index 0000000000..550683f704 --- /dev/null +++ b/testing/web-platform/tests/idle-detection/page-visibility.https.html @@ -0,0 +1,79 @@ + + +Tests the Idle Detection API + + + + + + + + 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(); -- cgit v1.2.3